Re-enable jtag function for Tegra124
v3 cover Re-enable jtag function for Tegra124
This patch series is used to update BCT configs to re-enable jtag function for Tegra124.
Since the secure jtag is disabled by default once SECURITY_MODE fuse is blown. BOOTROM will re-enable secure jtag function if BCT has SecureJTAGControl=1 and a matching chip UID included.
After applying these changes, cbootimage can access jtag control and chip uid fields. It can also read the BCT data from pre-built image, update the BCT configs based on config file, and generate a new image file.
Changes from V2:
- Improvement based on V2 reviewed comments.
- Disallow the update image feature for T20/T30.
Penny Chiu (7):
Add format functions to express BCT and bootloader data value Add page_size validation when setting page_size value Accept void pointer as input data type for get/set_value functions Add token_supported function
Use block_size and page_size tokens when dump BCT data Add Tegra124 bct data access for jtag control and chip uid Add update BCT configs feature
src/bct_dump.c | 111 +++++++++++++++++++++++++++++++---------------- src/cbootimage.c | 103 ++++++++++++++++++++++++++++++++++++------- src/cbootimage.h | 9 +++- src/context.c | 10 +++-- src/data_layout.c | 80 +++++++++++++++++++++++++++------- src/data_layout.h | 9 ++++ src/parse.c | 76 ++++++++++++++++++++++++++++++++ src/parse.h | 23 ++++++++-- src/set.c | 77 ++++++++++++++++++++++---------- src/set.h | 4 +- src/t114/nvbctlib_t114.c | 65 ++++++++++++++++++++++----- src/t124/nvbctlib_t124.c | 78 ++++++++++++++++++++++++++++----- src/t20/nvbctlib_t20.c | 65 ++++++++++++++++++++++----- src/t30/nvbctlib_t30.c | 65 ++++++++++++++++++++++----- 14 files changed, 634 insertions(+), 141 deletions(-)
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1397209843-31275-1-git-send-email-pchiu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
PATCH v3 1/7 Add format functions to express BCT and bootloader data value
Add a new field to the value_data table, which is the function to use to format the data value.
--- src/bct_dump.c | 59 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 21 deletions(-)
src/bct_dump.c +38 -21
@@ -27,37 +27,54 @@int enable_debug;cbootimage_soc_config * g_soc_config; +static void format_u32_hex8 (char const * message,void * data); +static void format_u32 (char const * message,void * data); + +typedef void (*format_function )(char const * message,void * data); +typedef struct {parse_token id;char const * message; +format_function format; }value_data ;static value_data const values[] = { - { token_boot_data_version,"Version = 0x%08x;\n" }, - { token_block_size_log2,"BlockSize = 0x%08x;\n" }, - { token_page_size_log2,"PageSize = 0x%08x;\n" }, - { token_partition_size,"PartitionSize = 0x%08x;\n" }, - { token_odm_data,"OdmData = 0x%08x;\n\n" }, - { token_bootloader_used,"# Bootloader used = %d;\n" }, - { token_bootloaders_max,"# Bootloaders max = %d;\n" }, - { token_bct_size,"# BCT size = %d;\n" }, - { token_hash_size,"# Hash size = %d;\n" }, - { token_crypto_offset,"# Crypto offset = %d;\n" }, - { token_crypto_length,"# Crypto length = %d;\n" }, - { token_max_bct_search_blks,"# Max BCT search blocks = %d;\n" }, + { token_boot_data_version,"Version = " , format_u32_hex8 }, + { token_block_size_log2,"BlockSize = " , format_u32_hex8 }, + { token_page_size_log2,"PageSize = " , format_u32_hex8 }, + { token_partition_size,"PartitionSize = " , format_u32_hex8 }, + { token_odm_data,"OdmData = " , format_u32_hex8 }, + { token_bootloader_used,"# Bootloader used = " , format_u32 }, + { token_bootloaders_max,"# Bootloaders max = " , format_u32 }, + { token_bct_size,"# BCT size = " , format_u32 }, + { token_hash_size,"# Hash size = " , format_u32 }, + { token_crypto_offset,"# Crypto offset = " , format_u32 }, + { token_crypto_length,"# Crypto length = " , format_u32 }, + { token_max_bct_search_blks,"# Max BCT search blocks = " , format_u32 }, };static value_data const bl_values[] = { - { token_bl_version,"Version = 0x%08x;\n" }, - { token_bl_start_blk,"Start block = %d;\n" }, - { token_bl_start_page,"Start page = %d;\n" }, - { token_bl_length,"Length = %d;\n" }, - { token_bl_load_addr,"Load address = 0x%08x;\n" }, - { token_bl_entry_point,"Entry point = 0x%08x;\n" }, - { token_bl_attribute,"Attributes = 0x%08x;\n" }, + { token_bl_version,"Version = " , format_u32_hex8 }, + { token_bl_start_blk,"Start block = " , format_u32 }, + { token_bl_start_page,"Start page = " , format_u32 }, + { token_bl_length,"Length = " , format_u32 }, + { token_bl_load_addr,"Load address = " , format_u32_hex8 }, + { token_bl_entry_point,"Entry point = " , format_u32_hex8 }, + { token_bl_attribute,"Attributes = " , format_u32_hex8 }, };/*****************************************************************************/ +static void format_u32_hex8 (char const * message,void * data) +{ +printf ("%s0x%08x;\n" , message, *((u_int32_t *) data)); +} + +static void format_u32 (char const * message,void * data) +{ +printf ("%s%d;\n" , message, *((u_int32_t *) data)); +} + +/*****************************************************************************/ static void usage (void ) {printf ("Usage: bct_dump bctfile\n" );
@@ -164,7 +181,7 @@ int main(int argc, char *argv[]) values[i].id == token_page_size_log2) data =1 << data; -printf (values[i].message, data); + values[i].format (values[i].message, &data); }/* Display bootloader values */
@@ -192,7 +209,7 @@ int main(int argc, char *argv[])if (e !=0 ) data =-1 ; -printf (bl_values[j].message, data); + bl_values[j].format (bl_values[j].message, &data); } } }
Signature · 1 line
1.9.1
PATCH v3 2/7 Add page_size validation when setting page_size value
In reply to a message not in the archiveThe valid page_size value should be a power of two, so add this check when setting page_size value.
--- src/set.c | 5 +++++ 1 file changed, 5 insertions(+)
src/set.c +5 -0
@@ -169,6 +169,11 @@ int context_set_value(build_image_context *context,case token_page_size: context->page_size = value; context->page_size_log2 =log2 (value); + +if (value != (u_int32_t)(1 << context->page_size_log2)) { +printf ("Error: Page size must be a power of 2.\n" ); +return 1 ; + } context->pages_per_blk=1 << (context->block_size_log2- context->page_size_log2);
Signature · 1 line
1.9.1
PATCH v3 3/7 Accept void pointer as input data type for get/set_value functions
In reply to a message not in the archiveThis 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.
--- src/context.c | 10 +++++++--- src/data_layout.c | 8 +++++--- src/parse.c | 2 +- src/parse.h | 6 +++--- src/set.c | 34 +++++++++++++++++----------------- src/set.h | 2 +- src/t114/nvbctlib_t114.c | 20 ++++++++++---------- src/t124/nvbctlib_t124.c | 22 +++++++++++----------- src/t20/nvbctlib_t20.c | 20 ++++++++++---------- src/t30/nvbctlib_t30.c | 20 ++++++++++---------- 10 files changed, 75 insertions(+), 69 deletions(-)
src/context.c +7 -3
@@ -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 ; }
src/data_layout.c +5 -3
@@ -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);
src/parse.c +1 -1
@@ -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); }/*
src/parse.h +3 -3
@@ -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.
src/set.c +17 -17
@@ -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 ();
src/set.h +1 -1
@@ -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,
src/t114/nvbctlib_t114.c +10 -10
@@ -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;
src/t124/nvbctlib_t124.c +11 -11
@@ -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) {
src/t20/nvbctlib_t20.c +10 -10
@@ -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;
src/t30/nvbctlib_t30.c +10 -10
@@ -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;
Signature · 1 line
1.9.1
PATCH v3 4/7 Add token_supported function
In reply to a message not in the archiveAdd a function called token_supported in cbootimage_soc_config. It is used to check if the input token is supported in specific tegra soc.
--- src/bct_dump.c | 3 +++ src/cbootimage.h | 1 + src/parse.h | 8 ++++++++ src/t114/nvbctlib_t114.c | 27 +++++++++++++++++++++++++++ src/t124/nvbctlib_t124.c | 27 +++++++++++++++++++++++++++ src/t20/nvbctlib_t20.c | 27 +++++++++++++++++++++++++++ src/t30/nvbctlib_t30.c | 27 +++++++++++++++++++++++++++ 7 files changed, 120 insertions(+)
src/bct_dump.c +3 -0
@@ -171,6 +171,9 @@ int main(int argc, char *argv[])/* Display root values */ for (i =0 ; i <sizeof (values) /sizeof (values[0 ]); ++i) { +if (!g_soc_config->token_supported (values[i].id)) +continue ; + e = g_soc_config->get_value (values[i].id, &data, context.bct);
src/cbootimage.h +1 -0
@@ -38,6 +38,7 @@#define NVBOOT_BOOTDATA_VERSION (a, b) ((((a)&0xffff) << 16) | ((b)&0xffff))#define NVBOOT_BAD_BLOCK_TABLE_SIZE 4096#define NV_MAX (a, b) (((a) > (b)) ? (a) : (b)) +#define ARRAY_SIZE (a) (sizeof(a) / sizeof((a)[0]))#define BOOTDATA_VERSION_T20 NVBOOT_BOOTDATA_VERSION(0x2, 0x1)#define BOOTDATA_VERSION_T30 NVBOOT_BOOTDATA_VERSION(0x3, 0x1)
src/parse.h +8 -0
@@ -750,6 +750,14 @@ typedef struct cbootimage_soc_config_rec {u_int32_t length, u_int8_t *bct); +/* +* Check if the token is supported to dump +* +* @param id The parse token value +* @return 0 and 1 for unsupported and supported +*/ +int (*token_supported)(parse_token id); +void (*init_bad_block_table)(build_image_context *context);enum_item *devtype_table;
src/t114/nvbctlib_t114.c +27 -0
@@ -96,6 +96,21 @@ default : \ token, __LINE__); \ return 1 +parse_token t114_root_token_list[] = { + token_boot_data_version, + token_block_size_log2, + token_page_size_log2, + token_partition_size, + token_odm_data, + token_bootloader_used, + token_bootloaders_max, + token_bct_size, + token_hash_size, + token_crypto_offset, + token_crypto_length, + token_max_bct_search_blks +}; + int t114_set_dev_param(build_image_context *context, u_int32_t index,
@@ -1037,6 +1052,17 @@ t114_bct_set_data(parse_token id,return 0 ; } +int t114_bct_token_supported (parse_token token) +{ +int index; + +for (index =0 ; index <ARRAY_SIZE (t114_root_token_list); index++) +if (t114_root_token_list[index] == token) +return 1 ; + +return 0 ; +} +void t114_init_bad_block_table (build_image_context *context) {u_int32_t bytes_per_entry;
@@ -1070,6 +1096,7 @@ cbootimage_soc_config tegra114_config = { .set_value = t114_bct_set_value, .get_value = t114_bct_get_value, .set_data = t114_bct_set_data, + .token_supported = t114_bct_token_supported, .devtype_table = s_devtype_table_t114, .sdmmc_data_width_table = s_sdmmc_data_width_table_t114,
src/t124/nvbctlib_t124.c +27 -0
@@ -99,6 +99,21 @@ default : \ token, __LINE__); \ return 1 +parse_token t124_root_token_list[] = { + token_boot_data_version, + token_block_size_log2, + token_page_size_log2, + token_partition_size, + token_odm_data, + token_bootloader_used, + token_bootloaders_max, + token_bct_size, + token_hash_size, + token_crypto_offset, + token_crypto_length, + token_max_bct_search_blks +}; + int t124_set_dev_param(build_image_context *context, u_int32_t index,
@@ -1039,6 +1054,17 @@ t124_bct_set_data(parse_token id,return 0 ; } +int t124_bct_token_supported (parse_token token) +{ +int index; + +for (index =0 ; index <ARRAY_SIZE (t124_root_token_list); index++) +if (t124_root_token_list[index] == token) +return 1 ; + +return 0 ; +} +void t124_init_bad_block_table (build_image_context *context) {u_int32_t bytes_per_entry;
@@ -1072,6 +1098,7 @@ cbootimage_soc_config tegra124_config = { .set_value = t124_bct_set_value, .get_value = t124_bct_get_value, .set_data = t124_bct_set_data, + .token_supported = t124_bct_token_supported, .devtype_table = s_devtype_table_t124, .sdmmc_data_width_table = s_sdmmc_data_width_table_t124,
src/t20/nvbctlib_t20.c +27 -0
@@ -96,6 +96,21 @@ default : \ token, __LINE__); \ return 1 +parse_token t20_root_token_list[] = { + token_boot_data_version, + token_block_size_log2, + token_page_size_log2, + token_partition_size, + token_odm_data, + token_bootloader_used, + token_bootloaders_max, + token_bct_size, + token_hash_size, + token_crypto_offset, + token_crypto_length, + token_max_bct_search_blks +}; + int t20_set_dev_param(build_image_context *context, u_int32_t index,
@@ -618,6 +633,17 @@ t20_bct_set_data(parse_token id,return 0 ; } +int t20_bct_token_supported (parse_token token) +{ +int index; + +for (index =0 ; index <ARRAY_SIZE (t20_root_token_list); index++) +if (t20_root_token_list[index] == token) +return 1 ; + +return 0 ; +} +void t20_init_bad_block_table (build_image_context *context) {u_int32_t bytes_per_entry;
@@ -651,6 +677,7 @@ cbootimage_soc_config tegra20_config = { .set_value = t20_bct_set_value, .get_value = t20_bct_get_value, .set_data = t20_bct_set_data, + .token_supported = t20_bct_token_supported, .devtype_table = s_devtype_table_t20, .sdmmc_data_width_table = s_sdmmc_data_width_table_t20,
src/t30/nvbctlib_t30.c +27 -0
@@ -96,6 +96,21 @@ default : \ token, __LINE__); \ return 1 +parse_token t30_root_token_list[] = { + token_boot_data_version, + token_block_size_log2, + token_page_size_log2, + token_partition_size, + token_odm_data, + token_bootloader_used, + token_bootloaders_max, + token_bct_size, + token_hash_size, + token_crypto_offset, + token_crypto_length, + token_max_bct_search_blks +}; + int t30_set_dev_param(build_image_context *context, u_int32_t index,
@@ -825,6 +840,17 @@ t30_bct_set_data(parse_token id,return 0 ; } +int t30_bct_token_supported (parse_token token) +{ +int index; + +for (index =0 ; index <ARRAY_SIZE (t30_root_token_list); index++) +if (t30_root_token_list[index] == token) +return 1 ; + +return 0 ; +} +void t30_init_bad_block_table (build_image_context *context) {u_int32_t bytes_per_entry;
@@ -858,6 +884,7 @@ cbootimage_soc_config tegra30_config = { .set_value = t30_bct_set_value, .get_value = t30_bct_get_value, .set_data = t30_bct_set_data, + .token_supported = t30_bct_token_supported, .devtype_table = s_devtype_table_t30, .sdmmc_data_width_table = s_sdmmc_data_width_table_t30,
Signature · 1 line
1.9.1
PATCH v3 5/7 Use block_size and page_size tokens when dump BCT data
In reply to a message not in the archiveChange to use block_size and page_size tokens instead of block_size_log2 and page_size_log2 tokens when dump BCT data.
--- src/bct_dump.c | 7 ++----- src/t114/nvbctlib_t114.c | 16 ++++++++++++++-- src/t124/nvbctlib_t124.c | 16 ++++++++++++++-- src/t20/nvbctlib_t20.c | 16 ++++++++++++++-- src/t30/nvbctlib_t30.c | 16 ++++++++++++++-- 5 files changed, 58 insertions(+), 13 deletions(-)
src/bct_dump.c +2 -5
@@ -40,8 +40,8 @@ typedef struct {static value_data const values[] = { { token_boot_data_version,"Version = " , format_u32_hex8 }, - { token_block_size_log2,"BlockSize = " , format_u32_hex8 }, - { token_page_size_log2,"PageSize = " , format_u32_hex8 }, + { token_block_size,"BlockSize = " , format_u32_hex8 }, + { token_page_size,"PageSize = " , format_u32_hex8 }, { token_partition_size,"PartitionSize = " , format_u32_hex8 }, { token_odm_data,"OdmData = " , format_u32_hex8 }, { token_bootloader_used,"# Bootloader used = " , format_u32 },
@@ -180,9 +180,6 @@ int main(int argc, char *argv[])if (e !=0 ) data =-1 ; -else if (values[i].id == token_block_size_log2 || - values[i].id == token_page_size_log2) - data =1 << data; values[i].format (values[i].message, &data); }
src/t114/nvbctlib_t114.c +14 -2
@@ -98,8 +98,8 @@ default : \parse_token t114_root_token_list[] = { token_boot_data_version, - token_block_size_log2, - token_page_size_log2, + token_block_size, + token_page_size, token_partition_size, token_odm_data, token_bootloader_used,
@@ -941,6 +941,18 @@ t114_bct_get_value(parse_token id, void *data, u_int8_t *bct)CASE_GET_NVU32 (bootloader_used);CASE_GET_NVU32 (odm_data); +case token_block_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->block_size_log2; +break ; + +case token_page_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->page_size_log2; +break ; +/* * Constants. */
src/t124/nvbctlib_t124.c +14 -2
@@ -101,8 +101,8 @@ default : \parse_token t124_root_token_list[] = { token_boot_data_version, - token_block_size_log2, - token_page_size_log2, + token_block_size, + token_page_size, token_partition_size, token_odm_data, token_bootloader_used,
@@ -942,6 +942,18 @@ t124_bct_get_value(parse_token id, void *data, u_int8_t *bct)CASE_GET_NVU32 (bootloader_used);CASE_GET_NVU32 (odm_data); +case token_block_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->block_size_log2; +break ; + +case token_page_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->page_size_log2; +break ; +/* * Constants. */
src/t20/nvbctlib_t20.c +14 -2
@@ -98,8 +98,8 @@ default : \parse_token t20_root_token_list[] = { token_boot_data_version, - token_block_size_log2, - token_page_size_log2, + token_block_size, + token_page_size, token_partition_size, token_odm_data, token_bootloader_used,
@@ -530,6 +530,18 @@ t20_bct_get_value(parse_token id, void *data, u_int8_t *bct)CASE_GET_NVU32 (bootloader_used);CASE_GET_NVU32 (odm_data); +case token_block_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->block_size_log2; +break ; + +case token_page_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->page_size_log2; +break ; +/* * Constants. */
src/t30/nvbctlib_t30.c +14 -2
@@ -98,8 +98,8 @@ default : \parse_token t30_root_token_list[] = { token_boot_data_version, - token_block_size_log2, - token_page_size_log2, + token_block_size, + token_page_size, token_partition_size, token_odm_data, token_bootloader_used,
@@ -737,6 +737,18 @@ t30_bct_get_value(parse_token id, void *data, u_int8_t *bct)CASE_GET_NVU32 (bootloader_used);CASE_GET_NVU32 (odm_data); +case token_block_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->block_size_log2; +break ; + +case token_page_size: +if (bct ==NULL ) +return -ENODATA ; + *((u_int32_t *)data) =1 << bct_ptr->page_size_log2; +break ; +/* * Constants. */
Signature · 1 line
1.9.1
PATCH v3 6/7 Add Tegra124 bct data access for jtag control and chip uid
In reply to a message not in the archiveAdd support for read secure_jtag_control and unique_chip_id from cfg file and write them into BCT structure, and bct_dump can also parse the two fields and show the data.
--- src/bct_dump.c | 48 +++++++++++++++++++++--------- src/cbootimage.h | 2 ++ src/parse.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ src/parse.h | 2 ++ src/set.c | 12 ++++++++ src/t124/nvbctlib_t124.c | 13 ++++++++- 6 files changed, 138 insertions(+), 15 deletions(-)
src/bct_dump.c +34 -14
@@ -29,6 +29,7 @@ cbootimage_soc_config * g_soc_config;static void format_u32_hex8 (char const * message,void * data);static void format_u32 (char const * message,void * data); +static void format_chipuid (char const * message,void * data);typedef void (*format_function )(char const * message,void * data);
@@ -38,12 +39,21 @@ typedef struct {format_function format; } value_data; +typedef union { +u_int32_t val; +u_int8_t uid[16 ]; +}param_types ; + +#define MAX_PARAM_SIZE sizeof(param_types) +static value_data const values[] = { { token_boot_data_version,"Version = " , format_u32_hex8 }, { token_block_size,"BlockSize = " , format_u32_hex8 }, { token_page_size,"PageSize = " , format_u32_hex8 }, { token_partition_size,"PartitionSize = " , format_u32_hex8 }, { token_odm_data,"OdmData = " , format_u32_hex8 }, + { token_secure_jtag_control,"JtagCtrl = " , format_u32_hex8 }, + { token_unique_chip_id,"ChipUid = " , format_chipuid }, { token_bootloader_used,"# Bootloader used = " , format_u32 }, { token_bootloaders_max,"# Bootloaders max = " , format_u32 }, { token_bct_size,"# BCT size = " , format_u32 },
@@ -74,6 +84,19 @@ static void format_u32(char const * message, void * data)printf ("%s%d;\n" , message, *((u_int32_t *) data)); } +static void format_chipuid (char const * message,void * data) +{ +u_int8_t *uid = (u_int8_t *)data; +int byte_index; +char uid_str[35 ] ="0x" ; +char *s = &uid_str[2 ]; + +for (byte_index =15 ; byte_index >=0 ; byte_index--, s +=2 ) +sprintf (s,"%02x" , uid[byte_index]); + +printf ("%s%s;\n" , message, uid_str); +} +/*****************************************************************************/ static void usage (void ) {
@@ -155,7 +178,7 @@ int main(int argc, char *argv[])u_int32_t parameters_used;u_int32_t sdram_used;nvboot_dev_type type; -u_int32_t data; +param_types data;int i;int j;
@@ -174,12 +197,9 @@ int main(int argc, char *argv[])if (!g_soc_config->token_supported (values[i].id))continue ; - e = g_soc_config->get_value (values[i].id, - &data, - context.bct); - -if (e !=0 ) - data =-1 ; + e = g_soc_config->get_value (values[i].id, &data, context.bct); +if (e) +memset (&data,0 ,MAX_PARAM_SIZE ); values[i].format (values[i].message, &data); }
@@ -202,12 +222,12 @@ int main(int argc, char *argv[])for (j =0 ; j < bl_count; ++j) { e = g_soc_config->getbl_param (i, bl_values[j].id, - &data, + &data.val, context.bct);printf ("# Bootloader[%d]." , i); -if (e !=0 ) - data =-1 ; +if (e) + data.val =-1 ; bl_values[j].format (bl_values[j].message, &data); }
@@ -264,14 +284,14 @@ int main(int argc, char *argv[]) g_soc_config->get_dev_param (&context, i, item->token, - &data); + &data.val);printf ("DeviceParam[%d].%s.%-*s = " , i, prefix, width, item->name);if (e !=0 )printf ("<ERROR reading parameter (%d)>" , e);else -display_field_value (&context, item, data); +display_field_value (&context, item, data.val);printf (";\n" ); }
@@ -293,13 +313,13 @@ int main(int argc, char *argv[]) e = g_soc_config->get_sdram_param (&context, i, item->token, - &data); + &data.val);printf ("SDRAM[%d].%-*s = " , i, width, item->name);if (e !=0 )printf ("<ERROR reading parameter (%d)>" , e);else -display_field_value (&context, item, data); +display_field_value (&context, item, data.val);printf (";\n" ); }
src/cbootimage.h +2 -0
@@ -97,6 +97,8 @@ typedef struct build_image_context_recu_int32_t boot_data_version;/* The boot data version of BCT */ u_int8_t bct_init;/* The flag for the memory allocation of bct */ u_int32_t odm_data;/* The odm data value */ +u_int8_t unique_chip_id[16 ];/* The unique chip uid */ +u_int8_t secure_jtag_control;/* The flag for enabling jtag control */ } build_image_context;/* Function prototypes */
src/parse.c +76 -0
106 lines not on this page · raw message
src/parse.h +2 -0
@@ -108,6 +108,8 @@ typedef enum token_dev_type_spi, token_num_sdram_sets, token_pre_bct_pad_blocks, + token_unique_chip_id, + token_secure_jtag_control, token_nand_clock_divider, token_nand_nand_timing,
src/set.c +12 -0
@@ -204,6 +204,18 @@ int context_set_value(build_image_context *context, context->pre_bct_pad_blocks = *((u_int32_t *)value);break ; +case token_secure_jtag_control: + context->secure_jtag_control = *((u_int32_t *)value); + g_soc_config->set_value (token_secure_jtag_control, + value, context->bct); +break ; + +case token_unique_chip_id: +memcpy (context->unique_chip_id, value,16 ); + g_soc_config->set_value (token_unique_chip_id, + value, context->bct); +break ; +DEFAULT (); }
src/t124/nvbctlib_t124.c +12 -1
@@ -111,7 +111,9 @@ parse_token t124_root_token_list[] = { token_hash_size, token_crypto_offset, token_crypto_length, - token_max_bct_search_blks + token_max_bct_search_blks, + token_unique_chip_id, + token_secure_jtag_control };int
@@ -941,6 +943,7 @@ t124_bct_get_value(parse_token id, void *data, u_int8_t *bct)CASE_GET_NVU32 (num_sdram_sets);CASE_GET_NVU32 (bootloader_used);CASE_GET_NVU32 (odm_data); +CASE_GET_NVU32 (secure_jtag_control);case token_block_size:if (bct ==NULL )
@@ -967,6 +970,10 @@ t124_bct_get_value(parse_token id, void *data, u_int8_t *bct) sizeof(nvboot_hash));break ; +case token_unique_chip_id: +memcpy (data, &(bct_ptr->unique_chip_id),sizeof (nvboot_ecid)); +break ; +case token_reserved_offset: *((u_int32_t *)data) = (u_int8_t *)&(samplebct.reserved) - (u_int8_t *)&samplebct;
@@ -1032,6 +1039,10 @@ t124_bct_set_value(parse_token id, void *data, u_int8_t *bct)CASE_SET_NVU32 (num_sdram_sets);CASE_SET_NVU32 (bootloader_used);CASE_SET_NVU32 (odm_data); +CASE_SET_NVU32 (secure_jtag_control); +case token_unique_chip_id: +memcpy (&bct_ptr->unique_chip_id, data,sizeof (nvboot_ecid)); +break ;default :return -ENODATA ;
Signature · 1 line
1.9.1
PATCH v3 7/7 Add update BCT configs feature
In reply to a message not in the archiveThis feature reads the BCT data from BCT or BCT with bootloader appended binary, updates the BCT data based on config file, then writes to new image file.
--- src/cbootimage.c | 103 ++++++++++++++++++++++++++++++++++++++++------- src/cbootimage.h | 6 ++- src/data_layout.c | 72 +++++++++++++++++++++++++++------ src/data_layout.h | 9 +++++ src/parse.h | 7 ++++ src/set.c | 28 +++++++++---- src/set.h | 2 + src/t114/nvbctlib_t114.c | 6 +++ src/t124/nvbctlib_t124.c | 6 +++ src/t20/nvbctlib_t20.c | 6 +++ src/t30/nvbctlib_t30.c | 6 +++ 11 files changed, 214 insertions(+), 37 deletions(-)
src/cbootimage.c +88 -15
@@ -49,6 +49,7 @@ struct option cbootcmd[] = { {"tegra", 1, NULL, 't'}, {"odmdata", 1, NULL, 'o'}, {"soc", 1, NULL, 's'}, + {"update", 0, NULL, 'u'}, {0, 0, 0, 0}, };
@@ -63,7 +64,7 @@ write_image_file(build_image_context *context)static void usage (void ) { -printf ("Usage: cbootimage [options] configfile imagename\n" ); +printf ("Usage: cbootimage [options] configfile [inputimage] outputimage\n" );printf (" options:\n" );printf (" -h, --help, -? Display this message.\n" );printf (" -d, --debug Output debugging information.\n" );
@@ -75,18 +76,23 @@ usage(void)printf (" -s|--soc tegraNN Select target device. Must be one of:\n" );printf (" tegra20, tegra30, tegra114, tegra124.\n" );printf (" Default: tegra20.\n" ); +printf (" -u|--update Copy input image data and update bct\n" ); +printf (" configs into new image file.\n" ); +printf (" This feature is only for tegra114/124.\n" );printf (" configfile File with configuration information\n" ); -printf (" imagename Output image name\n" ); +printf (" inputimage Input image name. This is required\n" ); +printf (" if -u|--update option is used.\n" ); +printf (" outputimage Output image name\n" ); }static int process_command_line (int argc,char *argv[],build_image_context *context) { -int c; +int c, num_filenames =2 ; context->generate_bct =0 ; -while ((c =getopt_long (argc, argv,"hdg:t:o:s:" , cbootcmd,NULL )) !=-1 ) { +while ((c =getopt_long (argc, argv,"hdg:t:o:s:u" , cbootcmd,NULL )) !=-1 ) {switch (c) {case 'h' : help_only =1 ;
@@ -131,10 +137,14 @@ process_command_line(int argc, char *argv[], build_image_context *context)case 'o' : context->odm_data =strtoul (optarg,NULL ,16 );break ; +case 'u' : + context->update_image =1 ; + num_filenames =3 ; +break ; } } -if (argc - optind !=2 ) { +if (argc - optind != num_filenames) {printf ("Missing configuration and/or image file name.\n" );usage ();return -EINVAL ;
@@ -145,14 +155,26 @@ process_command_line(int argc, char *argv[], build_image_context *context)t20_get_soc_config (context, &g_soc_config);/* Open the configuration file. */ - context->config_file =fopen (argv[optind],"r" ); + context->config_file =fopen (argv[optind++],"r" );if (context->config_file ==NULL ) {printf ("Error opening config file.\n" );return -ENODATA ; } +/* Record the input image filename if update_image is necessary */ +if (context->update_image) + { +if (context->boot_data_version !=BOOTDATA_VERSION_T114 && + context->boot_data_version !=BOOTDATA_VERSION_T124 ) { +printf ("Update image feature is only for Tegra114 and Tegra124.\n" ); +return -EINVAL ; + } + + context->input_image_filename = argv[optind++]; + } +/* Record the output filename */ - context->image_filename = argv[optind +1 ]; + context->output_image_filename = argv[optind++];return 0 ; }
@@ -190,18 +212,69 @@ main(int argc, char *argv[]) }/* Open the raw output file. */ - context.raw_file =fopen (context.image_filename, -"w+" ); + context.raw_file =fopen (context.output_image_filename,"w+" );if (context.raw_file ==NULL ) {printf ("Error opening raw file %s.\n" , - context.image_filename); + context.output_image_filename); goto fail; } -/* first, if we aren't generating the bct, read in config file */ -if (context.generate_bct ==0 ) { -process_config_file (&context,1 ); +/* Read the bct data from image if bct configs needs to be updated */ +if (context.update_image) { +u_int32_t offset =0 , bct_size, actual_size; +u_int8_t *data_block; +struct stat stats; + +if (stat (context.input_image_filename, &stats) !=0 ) { +printf ("Error: Unable to query info on input file path %s\n" , + context.input_image_filename); + goto fail; + } + +/* Get BCT_SIZE from input image file */ + bct_size =get_bct_size_from_image (&context); +if (!bct_size) { +printf ("Error: Invalid input image file %s\n" , + context.input_image_filename); + goto fail; + } + +while (stats.st_size > offset) { +/* Read a block of data into memory */ +if (read_from_image (context.input_image_filename, offset, bct_size, + &data_block, &actual_size, file_type_bct)) { +printf ("Error reading image file %s.\n" , context.input_image_filename); + goto fail; + } + +/* Check if memory data is valid BCT */ + context.bct = data_block; +if (data_is_valid_bct (&context)) { +fseek (context.config_file,0 ,SEEK_SET ); +process_config_file (&context,0 ); + e =sign_bct (&context, context.bct); +if (e !=0 ) { +printf ("Signing BCT failed, error: %d.\n" , e); + goto fail; + } + } + +/* Write the block of data to file */ +if (actual_size !=write_data_block (context.raw_file, offset, actual_size, data_block)) { +printf ("Error writing image file %s.\n" , context.output_image_filename); + goto fail; + } + + offset += bct_size; + } + +printf ("Image file %s has been successfully generated!\n" , + context.output_image_filename); + goto fail; } +/* If we aren't generating the bct, read in config file */ +else if (context.generate_bct ==0 ) +process_config_file (&context,1 );/* Generate the new bct file */ else {/* Initialize the bct memory */
@@ -218,7 +291,7 @@ main(int argc, char *argv[])fwrite (context.bct,1 , context.bct_size, context.raw_file);printf ("New BCT file %s has been successfully generated!\n" , - context.image_filename); + context.output_image_filename); goto fail; }
@@ -234,7 +307,7 @@ main(int argc, char *argv[])printf ("Error writing image file.\n" ); else printf("Image file %s has been successfully generated!\n", - context.image_filename); + context.output_image_filename); fail:/* Close the file(s). */
src/cbootimage.h +5 -1
@@ -45,6 +45,8 @@#define BOOTDATA_VERSION_T114 NVBOOT_BOOTDATA_VERSION(0x35, 0x1)#define BOOTDATA_VERSION_T124 NVBOOT_BOOTDATA_VERSION(0x40, 0x1) +#define NVBOOT_CONFIG_TABLE_SIZE_MAX 8192 +/* * Enumerations */
@@ -61,7 +63,8 @@ typedef enum typedef struct build_image_context_rec { FILE *config_file; - char *image_filename; + char *output_image_filename; + char *input_image_filename; FILE *raw_file; u_int32_t block_size; u_int32_t block_size_log2;
@@ -99,6 +102,7 @@ typedef struct build_image_context_recu_int32_t odm_data;/* The odm data value */ u_int8_t unique_chip_id[16 ];/* The unique chip uid */ u_int8_t secure_jtag_control;/* The flag for enabling jtag control */ +u_int8_t update_image;/* The flag for updating image */ } build_image_context;/* Function prototypes */
src/data_layout.c +59 -13
98 lines not on this page · raw message
src/data_layout.h +9 -0
@@ -50,6 +50,15 @@ int write_block_raw(struct build_image_context_rec *context);int +write_data_block (FILE *fp,u_int32_t offset,u_int32_t size,u_int8_t *buffer); + +int +data_is_valid_bct (build_image_context *context); + +int +get_bct_size_from_image (build_image_context *context); + +int begin_update (build_image_context *context);#endif /* #ifndef INCLUDED_DATA_LAYOUT_H */
src/parse.h +7 -0
@@ -753,6 +753,13 @@ typedef struct cbootimage_soc_config_rec { u_int8_t *bct);/* +* Get the BCT structure size +* +* @return BCT size +*/ +int (*get_bct_size)(); + +/* * Check if the token is supported to dump * * @param id The parse token value
src/set.c +20 -8
@@ -43,6 +43,8 @@int read_from_image (char *filename, +u_int32_t offset, +u_int32_t max_size,u_int8_t **image,u_int32_t *actual_size,file_type f_type)
@@ -57,6 +59,8 @@ read_from_image(char *filename,return result; } +fseek (fp, offset,SEEK_SET ); +if (stat (filename, &stats) !=0 ) {printf ("Error: Unable to query info on bootloader path %s\n" , filename);
@@ -64,14 +68,21 @@ read_from_image(char *filename, goto cleanup; } - *actual_size = (u_int32_t )stats.st_size; - -if (f_type == file_type_bl && *actual_size >MAX_BOOTLOADER_SIZE ) { -printf ("Error: Bootloader file %s is too large.\n" , - filename); - result =1 ; - goto cleanup; +if (f_type == file_type_bl) { +if ((stats.st_size - offset) > max_size) { +printf ("Error: Bootloader file %s is too large.\n" , + filename); + result =1 ; + goto cleanup; + } + *actual_size = (u_int32_t )stats.st_size; + }else { +if ((stats.st_size - offset) < max_size) + *actual_size = stats.st_size - offset; +else + *actual_size = max_size; } + *image =malloc (*actual_size);if (*image ==NULL ) { result =1 ;
@@ -80,7 +91,8 @@ read_from_image(char *filename,memset (*image,0 , *actual_size); -if (fread (*image,1 , (size_t )stats.st_size, fp) != stats.st_size) { +if (fread (*image,1 , (size_t )(*actual_size), fp) != + (size_t )(*actual_size)) { result =1 ; goto cleanup; }
src/set.h +2 -0
@@ -42,6 +42,8 @@ context_set_value(build_image_context *context,int read_from_image (char *filename, +u_int32_t offset, +u_int32_t max_size,u_int8_t **Image,u_int32_t *actual_size,file_type f_type);
src/t114/nvbctlib_t114.c +6 -0
@@ -1064,6 +1064,11 @@ t114_bct_set_data(parse_token id,return 0 ; } +int t114_get_bct_size () +{ +return sizeof (nvboot_config_table); +} +int t114_bct_token_supported (parse_token token) {int index;
@@ -1108,6 +1113,7 @@ cbootimage_soc_config tegra114_config = { .set_value = t114_bct_set_value, .get_value = t114_bct_get_value, .set_data = t114_bct_set_data, + .get_bct_size = t114_get_bct_size, .token_supported = t114_bct_token_supported, .devtype_table = s_devtype_table_t114,
src/t124/nvbctlib_t124.c +6 -0
@@ -1077,6 +1077,11 @@ t124_bct_set_data(parse_token id,return 0 ; } +int t124_get_bct_size () +{ +return sizeof (nvboot_config_table); +} +int t124_bct_token_supported (parse_token token) {int index;
@@ -1121,6 +1126,7 @@ cbootimage_soc_config tegra124_config = { .set_value = t124_bct_set_value, .get_value = t124_bct_get_value, .set_data = t124_bct_set_data, + .get_bct_size = t124_get_bct_size, .token_supported = t124_bct_token_supported, .devtype_table = s_devtype_table_t124,
src/t20/nvbctlib_t20.c +6 -0
@@ -645,6 +645,11 @@ t20_bct_set_data(parse_token id,return 0 ; } +int t20_get_bct_size () +{ +return sizeof (nvboot_config_table); +} +int t20_bct_token_supported (parse_token token) {int index;
@@ -689,6 +694,7 @@ cbootimage_soc_config tegra20_config = { .set_value = t20_bct_set_value, .get_value = t20_bct_get_value, .set_data = t20_bct_set_data, + .get_bct_size = t20_get_bct_size, .token_supported = t20_bct_token_supported, .devtype_table = s_devtype_table_t20,
src/t30/nvbctlib_t30.c +6 -0
@@ -852,6 +852,11 @@ t30_bct_set_data(parse_token id,return 0 ; } +int t30_get_bct_size () +{ +return sizeof (nvboot_config_table); +} +int t30_bct_token_supported (parse_token token) {int index;
@@ -896,6 +901,7 @@ cbootimage_soc_config tegra30_config = { .set_value = t30_bct_set_value, .get_value = t30_bct_get_value, .set_data = t30_bct_set_data, + .get_bct_size = t30_get_bct_size, .token_supported = t30_bct_token_supported, .devtype_table = s_devtype_table_t30,
Signature · 1 line
1.9.1
Quoted 7 lines · Penny Chiu
This patch series is used to update BCT configs to re-enable jtag function for Tegra124.
Since the secure jtag is disabled by default once
SECURITY_MODEfuse is blown. BOOTROM will re-enable secure jtag function if BCT has SecureJTAGControl=1 and a matching chip UID included.
Quoted 7 lines
After applying these changes, cbootimage can access jtag control and chip uid fields. It can also read the BCT data from pre-built image, update the BCT configs based on config file, and generate a new image file.
Changes from V2:
- Improvement based on V2 reviewed comments.
- Disallow the update image feature for T20/T30.
The changelog would be a bit more useful if it enumerated the changes that were made; that first bullet point basically says "something changed". Also, putting changelogs into the individual patches would be useful; reviewers can skim patches where nothing changed, if they reviewed the previous version.
Quoted 10 lines · Penny Chiu
This patch series is used to update BCT configs to re-enable jtag function for Tegra124.
Since the secure jtag is disabled by default once
SECURITY_MODEfuse is blown. BOOTROM will re-enable secure jtag function if BCT has SecureJTAGControl=1 and a matching chip UID included.After applying these changes, cbootimage can access jtag control and chip uid fields. It can also read the BCT data from pre-built image, update the BCT configs based on config file, and generate a new image file.
Thanks for the revisions. I have applied the whole series, and pushed it to github.
Do you need a tagged release created?