Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 1 | /** |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 2 | * Copyright (c) 2012 NVIDIA Corporation. All rights reserved. |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include "cbootimage.h" |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 24 | #include "data_layout.h" |
| 25 | #include "context.h" |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 26 | #include "parse.h" |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 27 | #include "t20/nvboot_bct_t20.h" |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 28 | #include <string.h> |
| 29 | |
| 30 | int enable_debug = 0; |
| 31 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 32 | bct_parse_interface *g_bct_parse_interf; |
| 33 | |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 34 | typedef struct { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 35 | parse_token id; |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 36 | char const * message; |
| 37 | } value_data; |
| 38 | |
| 39 | static value_data const values[] = { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 40 | { token_boot_data_version, "Version = 0x%08x;\n" }, |
| 41 | { token_block_size_log2, "BlockSize = 0x%08x;\n" }, |
| 42 | { token_page_size_log2, "PageSize = 0x%08x;\n" }, |
| 43 | { token_partition_size, "PartitionSize = 0x%08x;\n" }, |
| 44 | { token_bootloader_used, "# Bootloader used = %d;\n" }, |
| 45 | { token_bootloaders_max, "# Bootloaders max = %d;\n" }, |
| 46 | { token_bct_size, "# BCT size = %d;\n" }, |
| 47 | { token_hash_size, "# Hash size = %d;\n" }, |
| 48 | { token_crypto_offset, "# Crypto offset = %d;\n" }, |
| 49 | { token_crypto_length, "# Crypto length = %d;\n" }, |
| 50 | { token_max_bct_search_blks, "# Max BCT search blocks = %d;\n" }, |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | static value_data const bl_values[] = { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 54 | { token_bl_version, "Version = 0x%08x;\n" }, |
| 55 | { token_bl_start_blk, "Start block = %d;\n" }, |
| 56 | { token_bl_start_page, "Start page = %d;\n" }, |
| 57 | { token_bl_length, "Length = %d;\n" }, |
| 58 | { token_bl_load_addr, "Load address = 0x%08x;\n" }, |
| 59 | { token_bl_entry_point, "Entry point = 0x%08x;\n" }, |
| 60 | { token_bl_attribute, "Attributes = 0x%08x;\n" }, |
Vincent Palatin | 9947584 | 2011-03-07 16:09:25 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 63 | /*****************************************************************************/ |
| 64 | static void usage(void) |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 65 | { |
| 66 | printf("Usage: bct_dump bctfile\n"); |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 67 | printf(" bctfile BCT filename to read and display\n"); |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 68 | } |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 69 | /*****************************************************************************/ |
| 70 | static int max_width(field_item const * table) |
| 71 | { |
| 72 | int width = 0; |
| 73 | int i; |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 74 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 75 | for (i = 0; table[i].name != NULL; ++i) { |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 76 | int length = strlen(table[i].name); |
| 77 | |
| 78 | if (width < length) |
| 79 | width = length; |
| 80 | } |
| 81 | |
| 82 | return width; |
| 83 | } |
| 84 | /*****************************************************************************/ |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 85 | static enum_item const * find_enum_item(build_image_context *context, |
| 86 | enum_item const * table, |
| 87 | u_int32_t value) |
| 88 | { |
| 89 | int i; |
| 90 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 91 | for (i = 0; table[i].name != NULL; ++i) { |
| 92 | if (table[i].value == value) |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 93 | return table + i; |
| 94 | } |
| 95 | |
| 96 | return NULL; |
| 97 | } |
| 98 | /*****************************************************************************/ |
| 99 | static void display_enum_value(build_image_context *context, |
| 100 | enum_item const * table, |
| 101 | u_int32_t value) |
| 102 | { |
| 103 | enum_item const * e_item = find_enum_item(context, table, value); |
| 104 | |
| 105 | if (e_item) |
| 106 | printf("%s", e_item->name); |
| 107 | else |
| 108 | printf("<UNKNOWN ENUM VALUE (%d)>", value); |
| 109 | } |
| 110 | /*****************************************************************************/ |
| 111 | static int display_field_value(build_image_context *context, |
| 112 | field_item const * item, |
| 113 | u_int32_t value) |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 114 | { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 115 | switch (item->type) { |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 116 | case field_type_enum: |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 117 | display_enum_value(context, item->enum_table, value); |
| 118 | break; |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 119 | |
| 120 | case field_type_u32: |
| 121 | printf("0x%08x", value); |
| 122 | break; |
| 123 | |
| 124 | case field_type_u8: |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 125 | printf("%d", value); |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 126 | break; |
| 127 | |
| 128 | default: |
| 129 | printf("<UNKNOWN FIELD TYPE (%d)>", item->type); |
| 130 | return 1; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | /*****************************************************************************/ |
| 136 | int main(int argc, char *argv[]) |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 137 | { |
| 138 | int e; |
| 139 | build_image_context context; |
| 140 | u_int32_t bootloaders_used; |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 141 | u_int32_t parameters_used; |
Vincent Palatin | 9947584 | 2011-03-07 16:09:25 -0500 | [diff] [blame] | 142 | u_int32_t sdram_used; |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 143 | nvboot_dev_type type; |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 144 | nvboot_config_table *bct = NULL; |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 145 | u_int32_t data; |
| 146 | int i; |
| 147 | int j; |
| 148 | |
| 149 | if (argc != 2) |
| 150 | usage(); |
| 151 | |
| 152 | memset(&context, 0, sizeof(build_image_context)); |
| 153 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 154 | g_bct_parse_interf = malloc(sizeof(bct_parse_interface)); |
| 155 | if (g_bct_parse_interf == NULL) { |
| 156 | printf("Insufficient memory to proceed.\n"); |
| 157 | return -EINVAL; |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 160 | context.bct_filename = argv[1]; |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 161 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 162 | e = read_bct_file(&context); |
| 163 | if (e != 0) |
| 164 | return e; |
| 165 | bct = (nvboot_config_table *)(context.bct); |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 166 | /* Display root values */ |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 167 | for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 168 | e = g_bct_parse_interf->get_value(values[i].id, |
| 169 | &data, |
| 170 | context.bct); |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 171 | |
| 172 | if (e != 0) |
| 173 | data = -1; |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 174 | else if (values[i].id == token_block_size_log2 || |
| 175 | values[i].id == token_page_size_log2) |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 176 | data = 1 << data; |
| 177 | |
| 178 | printf(values[i].message, data); |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 181 | /* Display bootloader values */ |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 182 | e = g_bct_parse_interf->get_value(token_bootloader_used, |
Anton Staaf | 2b6c88c | 2011-03-02 09:22:25 -0800 | [diff] [blame] | 183 | &bootloaders_used, |
| 184 | context.bct); |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 185 | |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 186 | if ((e == 0) && (bootloaders_used > 0)) { |
| 187 | int bl_count = sizeof(bl_values) / sizeof(bl_values[0]); |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 188 | |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 189 | printf("#\n" |
| 190 | "# These values are set by cbootimage using the\n" |
| 191 | "# bootloader provided by the Bootloader=...\n" |
| 192 | "# configuration option.\n" |
| 193 | "#\n"); |
| 194 | |
| 195 | for (i = 0; i < bootloaders_used; ++i) { |
| 196 | for (j = 0; j < bl_count; ++j) { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 197 | e = g_bct_parse_interf->getbl_param(i, |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 198 | bl_values[j].id, |
| 199 | &data, |
| 200 | context.bct); |
| 201 | printf("# Bootloader[%d].", i); |
| 202 | |
| 203 | if (e != 0) |
| 204 | data = -1; |
| 205 | |
| 206 | printf(bl_values[j].message, data); |
| 207 | } |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 211 | /* Display flash device parameters */ |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 212 | e = g_bct_parse_interf->get_value(token_num_param_sets, |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 213 | ¶meters_used, |
| 214 | context.bct); |
| 215 | |
| 216 | for (i = 0; (e == 0) && (i < parameters_used); ++i) { |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 217 | field_item const * device_field_table = NULL; |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 218 | char const * prefix = NULL; |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 219 | field_item const * item; |
| 220 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 221 | e = g_bct_parse_interf->get_dev_param(&context, |
| 222 | i, |
| 223 | token_dev_type, |
| 224 | &type); |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 225 | printf("\n" |
| 226 | "DevType[%d] = ", i); |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 227 | display_enum_value(&context, s_devtype_table_t20, type); |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 228 | printf(";\n"); |
| 229 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 230 | switch (type) { |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 231 | case nvboot_dev_type_spi: |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 232 | device_field_table = s_spiflash_table_t20; |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 233 | prefix = "SpiFlashParams"; |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 234 | break; |
| 235 | |
| 236 | case nvboot_dev_type_sdmmc: |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 237 | if (bct->boot_data_version == |
| 238 | NVBOOT_BOOTDATA_VERSION(3, 1)) |
| 239 | device_field_table = s_sdmmc_table_t30; |
| 240 | else |
| 241 | device_field_table = s_sdmmc_table_t20; |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 242 | prefix = "SdmmcParams"; |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 243 | break; |
| 244 | |
| 245 | case nvboot_dev_type_nand: |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 246 | if (bct->boot_data_version == |
| 247 | NVBOOT_BOOTDATA_VERSION(3, 1)) |
| 248 | device_field_table = s_nand_table_t30; |
| 249 | else |
| 250 | device_field_table = s_nand_table_t20; |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 251 | prefix = "NandParams"; |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 252 | break; |
| 253 | |
| 254 | default: |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 255 | device_field_table = NULL; |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 256 | prefix = ""; |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 257 | break; |
| 258 | } |
| 259 | |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 260 | if (!device_field_table) |
| 261 | continue; |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 262 | |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 263 | int width = max_width(device_field_table); |
| 264 | |
| 265 | for (item = device_field_table; item->name != NULL; ++item) { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 266 | g_bct_parse_interf->get_dev_param(&context, |
| 267 | i, |
| 268 | item->token, |
| 269 | &data); |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 270 | printf("DeviceParam[%d].%s.%-*s = ", |
| 271 | i, prefix, width, item->name); |
| 272 | |
| 273 | if (e != 0) |
| 274 | printf("<ERROR reading parameter (%d)>", e); |
| 275 | else |
| 276 | display_field_value(&context, item, data); |
| 277 | |
| 278 | printf(";\n"); |
Anton Staaf | 496f965 | 2011-03-02 09:23:27 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 282 | /* Display SDRAM parameters */ |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 283 | e = g_bct_parse_interf->get_value(token_num_sdram_sets, |
Vincent Palatin | 9947584 | 2011-03-07 16:09:25 -0500 | [diff] [blame] | 284 | &sdram_used, |
| 285 | context.bct); |
| 286 | |
| 287 | for (i = 0; (e == 0) && (i < sdram_used); ++i) { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 288 | field_item const *s_sdram_field_table; |
| 289 | field_item const *item; |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 290 | |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 291 | printf("\n"); |
| 292 | |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 293 | if (bct->boot_data_version == NVBOOT_BOOTDATA_VERSION(3, 1)) |
| 294 | s_sdram_field_table = s_sdram_field_table_t30; |
| 295 | else |
| 296 | s_sdram_field_table = s_sdram_field_table_t20; |
| 297 | |
| 298 | int width = max_width(s_sdram_field_table); |
| 299 | |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 300 | for (item = s_sdram_field_table; item->name != NULL; ++item) { |
Peer Chen | 6f2cbc7 | 2012-03-13 11:12:39 +0800 | [diff] [blame] | 301 | e = g_bct_parse_interf ->get_sdram_param(&context, |
| 302 | i, |
| 303 | item->token, |
| 304 | &data); |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 305 | printf("SDRAM[%d].%-*s = ", i, width, item->name); |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 306 | |
| 307 | if (e != 0) |
| 308 | printf("<ERROR reading parameter (%d)>", e); |
| 309 | else |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 310 | display_field_value(&context, item, data); |
Anton Staaf | e517a4f | 2011-03-14 12:28:06 -0700 | [diff] [blame] | 311 | |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 312 | printf(";\n"); |
Vincent Palatin | 9947584 | 2011-03-07 16:09:25 -0500 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Anton Staaf | c624427 | 2011-02-24 10:17:50 -0800 | [diff] [blame] | 316 | /* Clean up memory. */ |
| 317 | cleanup_context(&context); |
| 318 | |
| 319 | return e; |
| 320 | } |
Anton Staaf | 20379c1 | 2011-03-14 15:38:59 -0700 | [diff] [blame] | 321 | /*****************************************************************************/ |