Accept void pointer as input data type for get/set_value functions

This change uses void * as input data type for
cbootimage_soc_config.get/set_value and context_set_value functions.
This makes the functions can accept various data types based on
different tokens.

Signed-off-by: Penny Chiu <pchiu@nvidia.com>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
This commit is contained in:
Penny Chiu
2014-04-11 17:50:39 +08:00
committed by Stephen Warren
parent ee24d10641
commit b81d219677
10 changed files with 75 additions and 69 deletions

View File

@@ -31,12 +31,16 @@ cleanup_context(build_image_context *context)
int
init_context(build_image_context *context)
{
u_int32_t value;
/* Set defaults */
context->memory = new_block_list();
context->next_bct_blk = 0; /* Default to block 0 */
context_set_value(context, token_redundancy, 1);
context_set_value(context, token_version, 1);
context_set_value(context, token_bct_copy, 2);
value = 1;
context_set_value(context, token_redundancy, &value);
context_set_value(context, token_version, &value);
value = 2;
context_set_value(context, token_bct_copy, &value);
return 0;
}

View File

@@ -366,6 +366,7 @@ write_bootloaders(build_image_context *context)
u_int32_t current_blk;
u_int32_t current_page;
u_int32_t pages_in_bl;
u_int32_t bootloader_used;
u_int8_t *bl_storage; /* Holds the Bl after reading */
u_int8_t *buffer; /* Holds the Bl for writing */
u_int8_t *src; /* Scans through the Bl during writing */
@@ -554,8 +555,9 @@ write_bootloaders(build_image_context *context)
free(buffer);
}
bootloader_used = context->redundancy + bl_move_count;
g_soc_config->set_value(token_bootloader_used,
context->redundancy + bl_move_count,
&bootloader_used,
context->bct);
if (enable_debug) {
@@ -752,7 +754,7 @@ begin_update(build_image_context *context)
}
g_soc_config->set_value(token_boot_data_version,
context->boot_data_version, context->bct);
&(context->boot_data_version), context->bct);
g_soc_config->get_value(token_hash_size,
&hash_size, context->bct);
g_soc_config->get_value(token_reserved_size,
@@ -761,7 +763,7 @@ begin_update(build_image_context *context)
&reserved_offset, context->bct);
/* Set the odm data */
g_soc_config->set_value(token_odm_data,
context->odm_data, context->bct);
&(context->odm_data), context->bct);
/* Initialize the bad block table field. */
g_soc_config->init_bad_block_table(context);

View File

@@ -482,7 +482,7 @@ static int parse_value_u32(build_image_context *context,
if (rest == NULL)
return 1;
return context_set_value(context, token, value);
return context_set_value(context, token, &value);
}
/*

View File

@@ -717,12 +717,12 @@ typedef struct cbootimage_soc_config_rec {
* Set the specified bct value stored in context bct data structure.
*
* @param id The parse token value
* @param data Value to set
* @param data Pointer of value to set
* @param bct Bct pointer
* @return 0 and -ENODATA for success and failure
*/
int (*set_value)(parse_token id,
u_int32_t data,
void *data,
u_int8_t *bct);
/*
* Get the specified bct value or some constant value of clocks and
@@ -734,7 +734,7 @@ typedef struct cbootimage_soc_config_rec {
* @return 0 and -ENODATA for success and failure
*/
int (*get_value)(parse_token id,
u_int32_t *data,
void *data,
u_int8_t *bct);
/*
* Set the bct crypto hash data.

View File

@@ -122,37 +122,37 @@ set_bootloader(build_image_context *context,
*
* @param context The main context pointer
* @param token The parse token value
* @param value The value to set
* @param value The pointer of value to set
* @return 0 for success
*/
int context_set_value(build_image_context *context,
parse_token token,
u_int32_t value)
void *value)
{
assert(context != NULL);
switch (token) {
case token_attribute:
context->newbl_attr = value;
context->newbl_attr = *((u_int32_t *)value);
break;
case token_block_size:
context->block_size = value;
context->block_size_log2 = log2(value);
context->block_size = *((u_int32_t *)value);
context->block_size_log2 = log2(*((u_int32_t *)value));
if (context->memory != NULL) {
printf("Error: Too late to change block size.\n");
return 1;
}
if (value != (u_int32_t)(1 << context->block_size_log2)) {
if (context->block_size != (u_int32_t)(1 << context->block_size_log2)) {
printf("Error: Block size must be a power of 2.\n");
return 1;
}
context->pages_per_blk= 1 << (context->block_size_log2-
context->page_size_log2);
g_soc_config->set_value(token_block_size_log2,
context->block_size_log2, context->bct);
&(context->block_size_log2), context->bct);
break;
case token_partition_size:
@@ -161,16 +161,16 @@ int context_set_value(build_image_context *context,
return 1;
}
context->partition_size= value;
context->partition_size= *((u_int32_t *)value);
g_soc_config->set_value(token_partition_size,
value, context->bct);
break;
case token_page_size:
context->page_size = value;
context->page_size_log2 = log2(value);
context->page_size = *((u_int32_t *)value);
context->page_size_log2 = log2(*((u_int32_t *)value));
if (value != (u_int32_t)(1 << context->page_size_log2)) {
if (context->page_size != (u_int32_t)(1 << context->page_size_log2)) {
printf("Error: Page size must be a power of 2.\n");
return 1;
}
@@ -178,22 +178,22 @@ int context_set_value(build_image_context *context,
context->page_size_log2);
g_soc_config->set_value(token_page_size_log2,
context->page_size_log2, context->bct);
&(context->page_size_log2), context->bct);
break;
case token_redundancy:
context->redundancy = value;
context->redundancy = *((u_int32_t *)value);
break;
case token_version:
context->version = value;
context->version = *((u_int32_t *)value);
break;
case token_bct_copy:
context->bct_copy = value;
context->bct_copy = *((u_int32_t *)value);
break;
case token_odm_data:
context->odm_data = value;
context->odm_data = *((u_int32_t *)value);
break;
case token_pre_bct_pad_blocks:
@@ -201,7 +201,7 @@ int context_set_value(build_image_context *context,
printf("Error: Too late to pre-BCT pad.\n");
return 1;
}
context->pre_bct_pad_blocks = value;
context->pre_bct_pad_blocks = *((u_int32_t *)value);
break;
DEFAULT();

View File

@@ -38,7 +38,7 @@ set_bootloader(build_image_context *context,
int
context_set_value(build_image_context *context,
parse_token token,
u_int32_t value);
void *value);
int
read_from_image(char *filename,

View File

@@ -59,22 +59,22 @@ case token_bl_##x:\
#define CASE_GET_NVU32(id) \
case token_##id:\
if (bct == NULL) return -ENODATA; \
*data = bct_ptr->id; \
*((u_int32_t *)data) = bct_ptr->id; \
break
#define CASE_GET_CONST(id, val) \
case token_##id:\
*data = val; \
*((u_int32_t *)data) = val; \
break
#define CASE_GET_CONST_PREFIX(id, val_prefix) \
case token_##id:\
*data = val_prefix##_##id; \
*((u_int32_t *)data) = val_prefix##_##id; \
break
#define CASE_SET_NVU32(id) \
case token_##id:\
bct_ptr->id = data; \
bct_ptr->id = *((u_int32_t *)data); \
break
#define CASE_GET_DATA(id, size) \
@@ -901,7 +901,7 @@ t114_setbl_param(u_int32_t set,
}
int
t114_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
t114_bct_get_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;
nvboot_config_table samplebct; /* Used for computing offsets. */
@@ -940,25 +940,25 @@ t114_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
break;
case token_reserved_offset:
*data = (u_int8_t *)&(samplebct.reserved)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.reserved)
- (u_int8_t *)&samplebct;
break;
case token_bct_size:
*data = sizeof(nvboot_config_table);
*((u_int32_t *)data) = sizeof(nvboot_config_table);
break;
CASE_GET_CONST(hash_size, sizeof(nvboot_hash));
case token_crypto_offset:
/* Offset to region in BCT to encrypt & sign */
*data = (u_int8_t *)&(samplebct.random_aes_blk)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.random_aes_blk)
- (u_int8_t *)&samplebct;
break;
case token_crypto_length:
/* size of region in BCT to encrypt & sign */
*data = (u_int8_t *)bct_ptr + sizeof(nvboot_config_table)
*((u_int32_t *)data) = (u_int8_t *)bct_ptr + sizeof(nvboot_config_table)
- (u_int8_t *)&(bct_ptr->random_aes_blk);
break;
@@ -985,7 +985,7 @@ t114_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
}
int
t114_bct_set_value(parse_token id, u_int32_t data, u_int8_t *bct)
t114_bct_set_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;

View File

@@ -60,22 +60,22 @@ case token_bl_##x:\
case token_##id:\
if (bct == NULL) \
return -ENODATA; \
*data = bct_ptr->id; \
*((u_int32_t *)data) = bct_ptr->id; \
break
#define CASE_GET_CONST(id, val) \
case token_##id:\
*data = val; \
*((u_int32_t *)data) = val; \
break
#define CASE_GET_CONST_PREFIX(id, val_prefix) \
case token_##id:\
*data = val_prefix##_##id; \
*((u_int32_t *)data) = val_prefix##_##id; \
break
#define CASE_SET_NVU32(id) \
case token_##id:\
bct_ptr->id = data; \
bct_ptr->id = *((u_int32_t *)data); \
break
#define CASE_GET_DATA(id, size) \
@@ -902,7 +902,7 @@ t124_setbl_param(u_int32_t set,
}
int
t124_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
t124_bct_get_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;
nvboot_config_table samplebct; /* Used for computing offsets. */
@@ -941,25 +941,25 @@ t124_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
break;
case token_reserved_offset:
*data = (u_int8_t *)&(samplebct.reserved)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.reserved)
- (u_int8_t *)&samplebct;
break;
case token_bct_size:
*data = sizeof(nvboot_config_table);
*((u_int32_t *)data) = sizeof(nvboot_config_table);
break;
CASE_GET_CONST(hash_size, sizeof(nvboot_hash));
case token_crypto_offset:
/* Offset to region in BCT to encrypt & sign */
*data = (u_int8_t *)&(samplebct.random_aes_blk)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.random_aes_blk)
- (u_int8_t *)&samplebct;
break;
case token_crypto_length:
/* size of region in BCT to encrypt & sign */
*data = (u_int8_t *)bct_ptr + sizeof(nvboot_config_table)
*((u_int32_t *)data) = (u_int8_t *)bct_ptr + sizeof(nvboot_config_table)
- (u_int8_t *)&(bct_ptr->random_aes_blk);
break;
@@ -986,11 +986,11 @@ t124_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
}
int
t124_bct_set_value(parse_token id, u_int32_t data, u_int8_t *bct)
t124_bct_set_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;
if (bct == NULL)
if (data == NULL || bct == NULL)
return -ENODATA;
switch (id) {

View File

@@ -59,22 +59,22 @@ case token_bl_##x:\
#define CASE_GET_NVU32(id) \
case token_##id:\
if (bct == NULL) return -ENODATA; \
*data = bct_ptr->id; \
*((u_int32_t *)data) = bct_ptr->id; \
break
#define CASE_GET_CONST(id, val) \
case token_##id:\
*data = val; \
*((u_int32_t *)data) = val; \
break
#define CASE_GET_CONST_PREFIX(id, val_prefix) \
case token_##id:\
*data = val_prefix##_##id; \
*((u_int32_t *)data) = val_prefix##_##id; \
break
#define CASE_SET_NVU32(id) \
case token_##id:\
bct_ptr->id = data; \
bct_ptr->id = *((u_int32_t *)data); \
break
#define CASE_GET_DATA(id, size) \
@@ -490,7 +490,7 @@ t20_setbl_param(u_int32_t set,
}
int
t20_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
t20_bct_get_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;
nvboot_config_table samplebct; /* Used for computing offsets. */
@@ -523,25 +523,25 @@ t20_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
CASE_GET_CONST(reserved_size, NVBOOT_BCT_RESERVED_SIZE);
case token_reserved_offset:
*data = (u_int8_t *)&(samplebct.reserved)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.reserved)
- (u_int8_t *)&samplebct;
break;
case token_bct_size:
*data = sizeof(nvboot_config_table);
*((u_int32_t *)data) = sizeof(nvboot_config_table);
break;
CASE_GET_CONST(hash_size, sizeof(nvboot_hash));
case token_crypto_offset:
/* Offset to region in BCT to encrypt & sign */
*data = (u_int8_t *)&(samplebct.random_aes_blk)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.random_aes_blk)
- (u_int8_t *)&samplebct;
break;
case token_crypto_length:
/* size of region in BCT to encrypt & sign */
*data = sizeof(nvboot_config_table) - sizeof(nvboot_hash);
*((u_int32_t *)data) = sizeof(nvboot_config_table) - sizeof(nvboot_hash);
break;
CASE_GET_CONST(max_bct_search_blks, NVBOOT_MAX_BCT_SEARCH_BLOCKS);
@@ -569,7 +569,7 @@ t20_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
}
int
t20_bct_set_value(parse_token id, u_int32_t data, u_int8_t *bct)
t20_bct_set_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;

View File

@@ -59,22 +59,22 @@ case token_bl_##x:\
#define CASE_GET_NVU32(id) \
case token_##id:\
if (bct == NULL) return -ENODATA; \
*data = bct_ptr->id; \
*((u_int32_t *)data) = bct_ptr->id; \
break
#define CASE_GET_CONST(id, val) \
case token_##id:\
*data = val; \
*((u_int32_t *)data) = val; \
break
#define CASE_GET_CONST_PREFIX(id, val_prefix) \
case token_##id:\
*data = val_prefix##_##id; \
*((u_int32_t *)data) = val_prefix##_##id; \
break
#define CASE_SET_NVU32(id) \
case token_##id:\
bct_ptr->id = data; \
bct_ptr->id = *((u_int32_t *)data); \
break
#define CASE_GET_DATA(id, size) \
@@ -697,7 +697,7 @@ t30_setbl_param(u_int32_t set,
}
int
t30_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
t30_bct_get_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;
nvboot_config_table samplebct; /* Used for computing offsets. */
@@ -730,25 +730,25 @@ t30_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
CASE_GET_CONST(reserved_size, NVBOOT_BCT_RESERVED_SIZE);
case token_reserved_offset:
*data = (u_int8_t *)&(samplebct.reserved)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.reserved)
- (u_int8_t *)&samplebct;
break;
case token_bct_size:
*data = sizeof(nvboot_config_table);
*((u_int32_t *)data) = sizeof(nvboot_config_table);
break;
CASE_GET_CONST(hash_size, sizeof(nvboot_hash));
case token_crypto_offset:
/* Offset to region in BCT to encrypt & sign */
*data = (u_int8_t *)&(samplebct.random_aes_blk)
*((u_int32_t *)data) = (u_int8_t *)&(samplebct.random_aes_blk)
- (u_int8_t *)&samplebct;
break;
case token_crypto_length:
/* size of region in BCT to encrypt & sign */
*data = sizeof(nvboot_config_table) - sizeof(nvboot_hash);
*((u_int32_t *)data) = sizeof(nvboot_config_table) - sizeof(nvboot_hash);
break;
CASE_GET_CONST(max_bct_search_blks, NVBOOT_MAX_BCT_SEARCH_BLOCKS);
@@ -776,7 +776,7 @@ t30_bct_get_value(parse_token id, u_int32_t *data, u_int8_t *bct)
}
int
t30_bct_set_value(parse_token id, u_int32_t data, u_int8_t *bct)
t30_bct_set_value(parse_token id, void *data, u_int8_t *bct)
{
nvboot_config_table *bct_ptr = (nvboot_config_table *)bct;