| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (c) 2011 NVIDIA Corporation. All rights reserved. | 2 * Copyright (c) 2011 NVIDIA Corporation. All rights reserved. |
| 3 * | 3 * |
| 4 * See file CREDITS for list of people who contributed to this | 4 * See file CREDITS for list of people who contributed to this |
| 5 * project. | 5 * project. |
| 6 * | 6 * |
| 7 * This program is free software; you can redistribute it and/or | 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 | 8 * modify it under the terms of the GNU General Public License as |
| 9 * published by the Free Software Foundation; either version 2 of | 9 * published by the Free Software Foundation; either version 2 of |
| 10 * the License, or (at your option) any later version. | 10 * the License, or (at your option) any later version. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include <string.h> | 28 #include <string.h> |
| 29 | 29 |
| 30 int enable_debug = 0; | 30 int enable_debug = 0; |
| 31 | 31 |
| 32 typedef struct { | 32 typedef struct { |
| 33 nvbct_lib_id id; | 33 nvbct_lib_id id; |
| 34 char const * message; | 34 char const * message; |
| 35 } value_data; | 35 } value_data; |
| 36 | 36 |
| 37 static value_data const values[] = { | 37 static value_data const values[] = { |
| 38 » {nvbct_lib_id_boot_data_version, "Version................: 0x%08x\n"}, | 38 » {nvbct_lib_id_boot_data_version, |
| 39 » {nvbct_lib_id_block_size_log2, "Block size (log2)......: %d\n"}, | 39 » "Version..................: 0x%08x\n"}, |
| 40 » {nvbct_lib_id_page_size_log2, "Page size (log2).......: %d\n"}, | 40 » {nvbct_lib_id_block_size_log2, |
| 41 » {nvbct_lib_id_partition_size, "Parition size..........: 0x%08x\n"}, | 41 » "Block size (log2)........: %d\n"}, |
| 42 » {nvbct_lib_id_bootloader_used, "Bootloader used........: %d\n"}, | 42 » {nvbct_lib_id_page_size_log2, |
| 43 » {nvbct_lib_id_bootloaders_max, "Bootloaders max........: %d\n"}, | 43 » "Page size (log2).........: %d\n"}, |
| 44 » {nvbct_lib_id_bct_size, "BCT size...............: %d\n"}, | 44 » {nvbct_lib_id_partition_size, |
| 45 » {nvbct_lib_id_hash_size, "Hash size..............: %d\n"}, | 45 » "Parition size............: 0x%08x\n"}, |
| 46 » {nvbct_lib_id_crypto_offset, "Crypto offset..........: %d\n"}, | 46 » {nvbct_lib_id_bootloader_used, |
| 47 » {nvbct_lib_id_crypto_length, "Crypto length..........: %d\n"}, | 47 » "Bootloader used..........: %d\n"}, |
| 48 » {nvbct_lib_id_max_bct_search_blks, "Max BCT search blocks..: %d\n"}, | 48 » {nvbct_lib_id_bootloaders_max, |
| 49 » "Bootloaders max..........: %d\n"}, |
| 50 » {nvbct_lib_id_bct_size, |
| 51 » "BCT size.................: %d\n"}, |
| 52 » {nvbct_lib_id_hash_size, |
| 53 » "Hash size................: %d\n"}, |
| 54 » {nvbct_lib_id_crypto_offset, |
| 55 » "Crypto offset............: %d\n"}, |
| 56 » {nvbct_lib_id_crypto_length, |
| 57 » "Crypto length............: %d\n"}, |
| 58 » {nvbct_lib_id_max_bct_search_blks, |
| 59 » "Max BCT search blocks....: %d\n"}, |
| 60 » {nvbct_lib_id_num_param_sets, |
| 61 » "Device parameters used...: %d\n"}, |
| 49 }; | 62 }; |
| 50 | 63 |
| 51 static value_data const bl_values[] = { | 64 static value_data const bl_values[] = { |
| 52 » {nvbct_lib_id_bl_version, " Version.......: 0x%08x\n"}, | 65 » {nvbct_lib_id_bl_version, |
| 53 » {nvbct_lib_id_bl_start_blk, " Start block...: %d\n"}, | 66 » " Version.......: 0x%08x\n"}, |
| 54 » {nvbct_lib_id_bl_start_page, " Start page....: %d\n"}, | 67 » {nvbct_lib_id_bl_start_blk, |
| 55 » {nvbct_lib_id_bl_length, " Length........: %d\n"}, | 68 » " Start block...: %d\n"}, |
| 56 » {nvbct_lib_id_bl_load_addr, " Load address..: 0x%08x\n"}, | 69 » {nvbct_lib_id_bl_start_page, |
| 57 » {nvbct_lib_id_bl_entry_point, " Entry point...: 0x%08x\n"}, | 70 » " Start page....: %d\n"}, |
| 58 » {nvbct_lib_id_bl_attribute, " Attributes....: 0x%08x\n"}, | 71 » {nvbct_lib_id_bl_length, |
| 72 » " Length........: %d\n"}, |
| 73 » {nvbct_lib_id_bl_load_addr, |
| 74 » " Load address..: 0x%08x\n"}, |
| 75 » {nvbct_lib_id_bl_entry_point, |
| 76 » " Entry point...: 0x%08x\n"}, |
| 77 » {nvbct_lib_id_bl_attribute, |
| 78 » " Attributes....: 0x%08x\n"}, |
| 79 }; |
| 80 |
| 81 static value_data const»spi_values[] = { |
| 82 » {nvbct_lib_id_spiflash_read_command_type_fast, |
| 83 » " Command fast...: %d\n"}, |
| 84 » {nvbct_lib_id_spiflash_clock_source, |
| 85 » " Clock source...: %d\n"}, |
| 86 » {nvbct_lib_id_spiflash_clock_divider, |
| 87 » " Clock divider..: %d\n"}, |
| 88 }; |
| 89 |
| 90 static value_data const»sdmmc_values[] = { |
| 91 » {nvbct_lib_id_sdmmc_clock_divider, |
| 92 » " Clock divider..: %d\n"}, |
| 93 » {nvbct_lib_id_sdmmc_data_width, |
| 94 » " Data width.....: %d\n"}, |
| 95 » {nvbct_lib_id_sdmmc_max_power_class_supported, |
| 96 » " Power class....: %d\n"}, |
| 59 }; | 97 }; |
| 60 | 98 |
| 61 static void | 99 static void |
| 62 usage(void) | 100 usage(void) |
| 63 { | 101 { |
| 64 printf("Usage: bct_dump bctfile\n"); | 102 printf("Usage: bct_dump bctfile\n"); |
| 65 printf(" bctfile BCT filename to read and display\n"); | 103 printf(" bctfile BCT filename to read and display\n"); |
| 66 } | 104 } |
| 67 | 105 |
| 68 int | 106 int |
| 69 main(int argc, char *argv[]) | 107 main(int argc, char *argv[]) |
| 70 { | 108 { |
| 71 int e; | 109 int e; |
| 72 build_image_context context; | 110 build_image_context context; |
| 73 u_int32_t bootloaders_used; | 111 u_int32_t bootloaders_used; |
| 112 u_int32_t parameters_used; |
| 113 nvboot_dev_type type; |
| 74 u_int32_t data; | 114 u_int32_t data; |
| 75 int i; | 115 int i; |
| 76 int j; | 116 int j; |
| 117 value_data const * device_values; |
| 118 int device_count; |
| 77 | 119 |
| 78 if (argc != 2) | 120 if (argc != 2) |
| 79 usage(); | 121 usage(); |
| 80 | 122 |
| 81 memset(&context, 0, sizeof(build_image_context)); | 123 memset(&context, 0, sizeof(build_image_context)); |
| 82 | 124 |
| 83 context.bct_filename = argv[1]; | 125 context.bct_filename = argv[1]; |
| 84 | 126 |
| 85 /* Set up the Nvbctlib function pointers. */ | 127 /* Set up the Nvbctlib function pointers. */ |
| 86 nvbct_lib_get_fns(&(context.bctlib)); | 128 nvbct_lib_get_fns(&(context.bctlib)); |
| 87 | 129 |
| 88 e = init_context(&context); | 130 e = init_context(&context); |
| 89 if (e != 0) { | 131 if (e != 0) { |
| 90 printf("context initialization failed. Aborting.\n"); | 132 printf("context initialization failed. Aborting.\n"); |
| 91 return e; | 133 return e; |
| 92 } | 134 } |
| 93 | 135 |
| 94 read_bct_file(&context); | 136 read_bct_file(&context); |
| 95 | 137 |
| 138 /* Display root values */ |
| 96 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) { | 139 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) { |
| 97 e = context.bctlib.get_value(values[i].id, &data, context.bct); | 140 e = context.bctlib.get_value(values[i].id, &data, context.bct); |
| 98 printf(values[i].message, e == 0 ? data : -1); | 141 printf(values[i].message, e == 0 ? data : -1); |
| 99 } | 142 } |
| 100 | 143 |
| 144 /* Display bootloader values */ |
| 101 e = context.bctlib.get_value(nvbct_lib_id_bootloader_used, | 145 e = context.bctlib.get_value(nvbct_lib_id_bootloader_used, |
| 102 &bootloaders_used, | 146 &bootloaders_used, |
| 103 context.bct); | 147 context.bct); |
| 104 | 148 |
| 105 for (i = 0; (e == 0) && (i < bootloaders_used); ++i) { | 149 for (i = 0; (e == 0) && (i < bootloaders_used); ++i) { |
| 106 printf("Bootloader[%d]\n", i); | 150 printf("Bootloader[%d]\n", i); |
| 107 | 151 |
| 108 for (j = 0; j < sizeof(bl_values) / sizeof(bl_values[0]); ++j) { | 152 for (j = 0; j < sizeof(bl_values) / sizeof(bl_values[0]); ++j) { |
| 109 e = context.bctlib.getbl_param(i, | 153 e = context.bctlib.getbl_param(i, |
| 110 bl_values[j].id, | 154 bl_values[j].id, |
| 111 &data, | 155 &data, |
| 112 context.bct); | 156 context.bct); |
| 113 printf(bl_values[j].message, e == 0 ? data : -1); | 157 printf(bl_values[j].message, e == 0 ? data : -1); |
| 114 } | 158 } |
| 115 } | 159 } |
| 116 | 160 |
| 161 /* Display device values */ |
| 162 e = context.bctlib.get_value(nvbct_lib_id_num_param_sets, |
| 163 ¶meters_used, |
| 164 context.bct); |
| 165 |
| 166 for (i = 0; (e == 0) && (i < parameters_used); ++i) { |
| 167 printf("DeviceParameter[%d]\n", i); |
| 168 |
| 169 e = context.bctlib.getdev_param(i, |
| 170 nvbct_lib_id_dev_type, |
| 171 &type, |
| 172 context.bct); |
| 173 |
| 174 switch (type) |
| 175 { |
| 176 case nvboot_dev_type_spi: |
| 177 printf(" Type...........: SPI\n"); |
| 178 device_values = spi_values; |
| 179 device_count = (sizeof(spi_values) / |
| 180 sizeof(spi_values[0])); |
| 181 break; |
| 182 |
| 183 case nvboot_dev_type_sdmmc: |
| 184 printf(" Type...........: SDMMC\n"); |
| 185 device_values = sdmmc_values; |
| 186 device_count = (sizeof(sdmmc_values) / |
| 187 sizeof(sdmmc_values[0])); |
| 188 break; |
| 189 |
| 190 default: |
| 191 printf(" Type...........: Unknown (%d)\n", |
| 192 type); |
| 193 device_values = NULL; |
| 194 device_count = 0; |
| 195 break; |
| 196 } |
| 197 |
| 198 for (j = 0; j < device_count; ++j) { |
| 199 value_data value = device_values[j]; |
| 200 |
| 201 e = context.bctlib.getdev_param(i, |
| 202 value.id, |
| 203 &data, |
| 204 context.bct); |
| 205 printf(value.message, e == 0 ? data : -1); |
| 206 } |
| 207 } |
| 208 |
| 117 /* Clean up memory. */ | 209 /* Clean up memory. */ |
| 118 cleanup_context(&context); | 210 cleanup_context(&context); |
| 119 | 211 |
| 120 return e; | 212 return e; |
| 121 } | 213 } |
| OLD | NEW |