diff options
Diffstat (limited to 'bct_dump.c')
-rw-r--r-- | bct_dump.c | 154 |
1 files changed, 81 insertions, 73 deletions
@@ -1,5 +1,5 @@ /** - * Copyright (c) 2011 NVIDIA Corporation. All rights reserved. + * Copyright (c) 2012 NVIDIA Corporation. All rights reserved. * * See file CREDITS for list of people who contributed to this * project. @@ -21,49 +21,50 @@ */ #include "cbootimage.h" -#include "nvbctlib.h" #include "data_layout.h" #include "context.h" #include "parse.h" - +#include "t20/nvboot_bct_t20.h" #include <string.h> int enable_debug = 0; +bct_parse_interface *g_bct_parse_interf; + typedef struct { - nvbct_lib_id id; + parse_token id; char const * message; } value_data; static value_data const values[] = { - { nvbct_lib_id_boot_data_version, "Version = 0x%08x;\n" }, - { nvbct_lib_id_block_size_log2, "BlockSize = 0x%08x;\n" }, - { nvbct_lib_id_page_size_log2, "PageSize = 0x%08x;\n" }, - { nvbct_lib_id_partition_size, "PartitionSize = 0x%08x;\n" }, - { nvbct_lib_id_bootloader_used, "# Bootloader used = %d;\n" }, - { nvbct_lib_id_bootloaders_max, "# Bootloaders max = %d;\n" }, - { nvbct_lib_id_bct_size, "# BCT size = %d;\n" }, - { nvbct_lib_id_hash_size, "# Hash size = %d;\n" }, - { nvbct_lib_id_crypto_offset, "# Crypto offset = %d;\n" }, - { nvbct_lib_id_crypto_length, "# Crypto length = %d;\n" }, - { nvbct_lib_id_max_bct_search_blks, "# Max BCT search blocks = %d;\n" }, + { 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_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" }, }; static value_data const bl_values[] = { - { nvbct_lib_id_bl_version, "Version = 0x%08x;\n" }, - { nvbct_lib_id_bl_start_blk, "Start block = %d;\n" }, - { nvbct_lib_id_bl_start_page, "Start page = %d;\n" }, - { nvbct_lib_id_bl_length, "Length = %d;\n" }, - { nvbct_lib_id_bl_load_addr, "Load address = 0x%08x;\n" }, - { nvbct_lib_id_bl_entry_point, "Entry point = 0x%08x;\n" }, - { nvbct_lib_id_bl_attribute, "Attributes = 0x%08x;\n" }, + { 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" }, }; /*****************************************************************************/ static void usage(void) { printf("Usage: bct_dump bctfile\n"); - printf(" bctfile BCT filename to read and display\n"); + printf(" bctfile BCT filename to read and display\n"); } /*****************************************************************************/ static int max_width(field_item const * table) @@ -71,8 +72,7 @@ static int max_width(field_item const * table) int width = 0; int i; - for (i = 0; table[i].name != NULL; ++i) - { + for (i = 0; table[i].name != NULL; ++i) { int length = strlen(table[i].name); if (width < length) @@ -88,14 +88,8 @@ static enum_item const * find_enum_item(build_image_context *context, { int i; - for (i = 0; table[i].name != NULL; ++i) - { - u_int32_t table_value; - - if (!context->bctlib.get_value(table[i].value, - &table_value, - context->bct) && - table_value == value) + for (i = 0; table[i].name != NULL; ++i) { + if (table[i].value == value) return table + i; } @@ -118,8 +112,7 @@ static int display_field_value(build_image_context *context, field_item const * item, u_int32_t value) { - switch (item->type) - { + switch (item->type) { case field_type_enum: display_enum_value(context, item->enum_table, value); break; @@ -148,6 +141,7 @@ int main(int argc, char *argv[]) u_int32_t parameters_used; u_int32_t sdram_used; nvboot_dev_type type; + nvboot_config_table *bct = NULL; u_int32_t data; int i; int j; @@ -157,34 +151,35 @@ int main(int argc, char *argv[]) memset(&context, 0, sizeof(build_image_context)); - context.bct_filename = argv[1]; - - /* Set up the Nvbctlib function pointers. */ - nvbct_lib_get_fns(&(context.bctlib)); - - e = init_context(&context); - if (e != 0) { - printf("context initialization failed. Aborting.\n"); - return e; + g_bct_parse_interf = malloc(sizeof(bct_parse_interface)); + if (g_bct_parse_interf == NULL) { + printf("Insufficient memory to proceed.\n"); + return -EINVAL; } - read_bct_file(&context); + context.bct_filename = argv[1]; + e = read_bct_file(&context); + if (e != 0) + return e; + bct = (nvboot_config_table *)(context.bct); /* Display root values */ for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) { - e = context.bctlib.get_value(values[i].id, &data, context.bct); + e = g_bct_parse_interf->get_value(values[i].id, + &data, + context.bct); if (e != 0) data = -1; - else if (values[i].id == nvbct_lib_id_block_size_log2 || - values[i].id == nvbct_lib_id_page_size_log2) + else if (values[i].id == token_block_size_log2 || + values[i].id == token_page_size_log2) data = 1 << data; printf(values[i].message, data); } /* Display bootloader values */ - e = context.bctlib.get_value(nvbct_lib_id_bootloader_used, + e = g_bct_parse_interf->get_value(token_bootloader_used, &bootloaders_used, context.bct); @@ -199,7 +194,7 @@ int main(int argc, char *argv[]) for (i = 0; i < bootloaders_used; ++i) { for (j = 0; j < bl_count; ++j) { - e = context.bctlib.getbl_param(i, + e = g_bct_parse_interf->getbl_param(i, bl_values[j].id, &data, context.bct); @@ -214,7 +209,7 @@ int main(int argc, char *argv[]) } /* Display flash device parameters */ - e = context.bctlib.get_value(nvbct_lib_id_num_param_sets, + e = g_bct_parse_interf->get_value(token_num_param_sets, ¶meters_used, context.bct); @@ -223,30 +218,36 @@ int main(int argc, char *argv[]) char const * prefix = NULL; field_item const * item; - e = context.bctlib.getdev_param(i, - nvbct_lib_id_dev_type, - &type, - context.bct); - + e = g_bct_parse_interf->get_dev_param(&context, + i, + token_dev_type, + &type); printf("\n" "DevType[%d] = ", i); - display_enum_value(&context, s_devtype_table, type); + display_enum_value(&context, s_devtype_table_t20, type); printf(";\n"); - switch (type) - { + switch (type) { case nvboot_dev_type_spi: - device_field_table = s_spiflash_table; + device_field_table = s_spiflash_table_t20; prefix = "SpiFlashParams"; break; case nvboot_dev_type_sdmmc: - device_field_table = s_sdmmc_table; + if (bct->boot_data_version == + NVBOOT_BOOTDATA_VERSION(3, 1)) + device_field_table = s_sdmmc_table_t30; + else + device_field_table = s_sdmmc_table_t20; prefix = "SdmmcParams"; break; case nvboot_dev_type_nand: - device_field_table = s_nand_table; + if (bct->boot_data_version == + NVBOOT_BOOTDATA_VERSION(3, 1)) + device_field_table = s_nand_table_t30; + else + device_field_table = s_nand_table_t20; prefix = "NandParams"; break; @@ -262,10 +263,10 @@ int main(int argc, char *argv[]) int width = max_width(device_field_table); for (item = device_field_table; item->name != NULL; ++item) { - e = context.bctlib.getdev_param(i, - item->enum_value, - &data, - context.bct); + g_bct_parse_interf->get_dev_param(&context, + i, + item->token, + &data); printf("DeviceParam[%d].%s.%-*s = ", i, prefix, width, item->name); @@ -279,21 +280,28 @@ int main(int argc, char *argv[]) } /* Display SDRAM parameters */ - e = context.bctlib.get_value(nvbct_lib_id_num_sdram_sets, + e = g_bct_parse_interf->get_value(token_num_sdram_sets, &sdram_used, context.bct); for (i = 0; (e == 0) && (i < sdram_used); ++i) { - int width = max_width(s_sdram_field_table); - field_item const * item; + field_item const *s_sdram_field_table; + field_item const *item; printf("\n"); + if (bct->boot_data_version == NVBOOT_BOOTDATA_VERSION(3, 1)) + s_sdram_field_table = s_sdram_field_table_t30; + else + s_sdram_field_table = s_sdram_field_table_t20; + + int width = max_width(s_sdram_field_table); + for (item = s_sdram_field_table; item->name != NULL; ++item) { - e = context.bctlib.get_sdram_params(i, - item->enum_value, - &data, - context.bct); + e = g_bct_parse_interf ->get_sdram_param(&context, + i, + item->token, + &data); printf("SDRAM[%d].%-*s = ", i, width, item->name); if (e != 0) |