Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: bct_dump.c

Issue 6683050: Finish conversion of bct_dump to generate config files that cbootimage can parse. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cbootimage.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 #include <string.h> 29 #include <string.h>
30 30
31 int enable_debug = 0; 31 int enable_debug = 0;
32 32
33 typedef struct { 33 typedef struct {
34 nvbct_lib_id id; 34 nvbct_lib_id id;
35 char const * message; 35 char const * message;
36 } value_data; 36 } value_data;
37 37
38 static value_data const values[] = { 38 static value_data const values[] = {
39 » {nvbct_lib_id_boot_data_version, 39 » { nvbct_lib_id_boot_data_version, "Version = 0x%08x;\n" },
40 » "Version..................: 0x%08x\n"}, 40 » { nvbct_lib_id_block_size_log2,» "BlockSize = 0x%08x;\n" },
Vincent Palatin 2011/03/14 21:11:10 I'm seeing mixed tabs and spaces between the 2 col
41 » {nvbct_lib_id_block_size_log2, 41 » { nvbct_lib_id_page_size_log2, "PageSize = 0x%08x;\n" },
42 » "Block size (log2)........: %d\n"}, 42 » { nvbct_lib_id_partition_size,» "PartitionSize = 0x%08x;\n" },
43 » {nvbct_lib_id_page_size_log2, 43 » { nvbct_lib_id_bootloader_used,» "# Bootloader used = %d;\n" },
44 » "Page size (log2).........: %d\n"}, 44 » { nvbct_lib_id_bootloaders_max, "# Bootloaders max = %d;\n" },
45 » {nvbct_lib_id_partition_size, 45 » { nvbct_lib_id_bct_size, "# BCT size = %d;\n" },
46 » "Parition size............: 0x%08x\n"}, 46 » { nvbct_lib_id_hash_size, "# Hash size = %d;\n" },
47 » {nvbct_lib_id_bootloader_used, 47 » { nvbct_lib_id_crypto_offset, "# Crypto offset = %d;\n" },
48 » "Bootloader used..........: %d\n"}, 48 » { nvbct_lib_id_crypto_length, "# Crypto length = %d;\n" },
49 » {nvbct_lib_id_bootloaders_max, 49 » { nvbct_lib_id_max_bct_search_blks, "# Max BCT search blocks = %d;\n" },
50 » "Bootloaders max..........: %d\n"},
51 » {nvbct_lib_id_bct_size,
52 » "BCT size.................: %d\n"},
53 » {nvbct_lib_id_hash_size,
54 » "Hash size................: %d\n"},
55 » {nvbct_lib_id_crypto_offset,
56 » "Crypto offset............: %d\n"},
57 » {nvbct_lib_id_crypto_length,
58 » "Crypto length............: %d\n"},
59 » {nvbct_lib_id_max_bct_search_blks,
60 » "Max BCT search blocks....: %d\n"},
61 » {nvbct_lib_id_num_param_sets,
62 » "Device parameters used...: %d\n"},
63 }; 50 };
64 51
65 static value_data const bl_values[] = { 52 static value_data const bl_values[] = {
66 » {nvbct_lib_id_bl_version, 53 » { nvbct_lib_id_bl_version, "Version = 0x%08x;\n" },
67 » " Version.......: 0x%08x\n"}, 54 » { nvbct_lib_id_bl_start_blk, "Start block = %d;\n" },
68 » {nvbct_lib_id_bl_start_blk, 55 » { nvbct_lib_id_bl_start_page, "Start page = %d;\n" },
69 » " Start block...: %d\n"}, 56 » { nvbct_lib_id_bl_length, "Length = %d;\n" },
70 » {nvbct_lib_id_bl_start_page, 57 » { nvbct_lib_id_bl_load_addr, "Load address = 0x%08x;\n" },
71 » " Start page....: %d\n"}, 58 » { nvbct_lib_id_bl_entry_point, "Entry point = 0x%08x;\n" },
72 » {nvbct_lib_id_bl_length, 59 » { nvbct_lib_id_bl_attribute, "Attributes = 0x%08x;\n" },
73 » " Length........: %d\n"},
74 » {nvbct_lib_id_bl_load_addr,
75 » " Load address..: 0x%08x\n"},
76 » {nvbct_lib_id_bl_entry_point,
77 » " Entry point...: 0x%08x\n"},
78 » {nvbct_lib_id_bl_attribute,
79 » " Attributes....: 0x%08x\n"},
80 };
81
82 static const char *sdram_types[nvboot_memory_type_num] = {
83 » "None", "DDR", "LPDDR", "DDR2", "LPDDR2"
84 }; 60 };
85 61
86 /*****************************************************************************/ 62 /*****************************************************************************/
87 static void usage(void) 63 static void usage(void)
88 { 64 {
89 printf("Usage: bct_dump bctfile\n"); 65 printf("Usage: bct_dump bctfile\n");
90 printf(" bctfile BCT filename to read and display\n"); 66 printf(" bctfile BCT filename to read and display\n");
91 } 67 }
92 /*****************************************************************************/ 68 /*****************************************************************************/
93 static int max_width(field_item const * table) 69 static int max_width(field_item const * table)
94 { 70 {
95 int width = 0; 71 int width = 0;
96 int i; 72 int i;
97 73
98 for (i = 0; table[i].name != NULL; ++i) 74 for (i = 0; table[i].name != NULL; ++i)
99 { 75 {
100 int length = strlen(table[i].name); 76 int length = strlen(table[i].name);
101 77
102 if (width < length) 78 if (width < length)
103 width = length; 79 width = length;
104 } 80 }
105 81
106 return width; 82 return width;
107 } 83 }
108 /*****************************************************************************/ 84 /*****************************************************************************/
109 static int display_field_value(field_item const * item, u_int32_t value) 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
91 » for (i = 0; table[i].name != NULL; ++i)
92 » {
93 » » u_int32_t» table_value;
94
95 » » if (!context->bctlib.get_value(table[i].value,
96 » » » » » &table_value,
97 » » » » » context->bct) &&
98 » » table_value == value)
99 » » » return table + i;
100 » }
101
102 » return NULL;
103 }
104 /*****************************************************************************/
105 static void display_enum_value(build_image_context *context,
106 » » » enum_item const * table,
107 » » » u_int32_t value)
108 {
109 » enum_item const * e_item = find_enum_item(context, table, value);
110
111 » if (e_item)
112 » » printf("%s", e_item->name);
113 » else
114 » » printf("<UNKNOWN ENUM VALUE (%d)>", value);
115 }
116 /*****************************************************************************/
117 static int display_field_value(build_image_context *context,
118 » » » field_item const * item,
119 » » » u_int32_t value)
110 { 120 {
111 switch (item->type) 121 switch (item->type)
112 { 122 {
113 case field_type_enum: 123 case field_type_enum:
114 » » » /* 124 » » » display_enum_value(context, item->enum_table, value);
115 » » » * It would be ideal if we could take the enum value 125 » » » break;
116 » » » * and programatically look up a string that the parse
117 » » » * would accept for this field. The problem is that
118 » » » * the mapping between field values and nvbct_lib_id
119 » » » * values is hard coded in the nvbctlib source. For
120 » » » * now we drop down to the u32 printing code.
121 » » » *
122 » » » * TODO(robotboy): Fix this
123 » » » */
124 126
125 case field_type_u32: 127 case field_type_u32:
126 printf("0x%08x", value); 128 printf("0x%08x", value);
127 break; 129 break;
128 130
129 case field_type_u8: 131 case field_type_u8:
130 » » » printf("0x%02x", value); 132 » » » printf("%d", value);
131 break; 133 break;
132 134
133 default: 135 default:
134 printf("<UNKNOWN FIELD TYPE (%d)>", item->type); 136 printf("<UNKNOWN FIELD TYPE (%d)>", item->type);
135 return 1; 137 return 1;
136 } 138 }
137 139
138 return 0; 140 return 0;
139 } 141 }
140 /*****************************************************************************/ 142 /*****************************************************************************/
(...skipping 23 matching lines...) Expand all
164 if (e != 0) { 166 if (e != 0) {
165 printf("context initialization failed. Aborting.\n"); 167 printf("context initialization failed. Aborting.\n");
166 return e; 168 return e;
167 } 169 }
168 170
169 read_bct_file(&context); 171 read_bct_file(&context);
170 172
171 /* Display root values */ 173 /* Display root values */
172 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) { 174 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
173 e = context.bctlib.get_value(values[i].id, &data, context.bct); 175 e = context.bctlib.get_value(values[i].id, &data, context.bct);
174 » » printf(values[i].message, e == 0 ? data : -1); 176
177 » » if (e != 0)
178 » » » data = -1;
179 » » else if (values[i].id == nvbct_lib_id_block_size_log2 ||
180 » » » values[i].id == nvbct_lib_id_page_size_log2)
181 » » » data = 1 << data;
182
183 » » printf(values[i].message, data);
175 } 184 }
176 185
177 /* Display bootloader values */ 186 /* Display bootloader values */
178 e = context.bctlib.get_value(nvbct_lib_id_bootloader_used, 187 e = context.bctlib.get_value(nvbct_lib_id_bootloader_used,
179 &bootloaders_used, 188 &bootloaders_used,
180 context.bct); 189 context.bct);
181 190
182 » for (i = 0; (e == 0) && (i < bootloaders_used); ++i) { 191 » if ((e == 0) && (bootloaders_used > 0)) {
183 » » printf("Bootloader[%d]\n", i); 192 » » int bl_count = sizeof(bl_values) / sizeof(bl_values[0]);
184 193
185 » » for (j = 0; j < sizeof(bl_values) / sizeof(bl_values[0]); ++j) { 194 » » printf("#\n"
186 » » » e = context.bctlib.getbl_param(i, 195 » » "# These values are set by cbootimage using the\n"
187 » » » » » » bl_values[j].id, 196 » » "# bootloader provided by the Bootloader=...\n"
188 » » » » » » &data, 197 » » "# configuration option.\n"
189 » » » » » » context.bct); 198 » » "#\n");
190 » » » printf(bl_values[j].message, e == 0 ? data : -1); 199
200 » » for (i = 0; i < bootloaders_used; ++i) {
201 » » » for (j = 0; j < bl_count; ++j) {
202 » » » » e = context.bctlib.getbl_param(i,
203 » » » » » » » bl_values[j].id,
204 » » » » » » » &data,
205 » » » » » » » context.bct);
206 » » » » printf("# Bootloader[%d].", i);
207
208 » » » » if (e != 0)
209 » » » » » data = -1;
210
211 » » » » printf(bl_values[j].message, data);
212 » » » }
191 } 213 }
192 } 214 }
193 215
194 » /* Display device values */ 216 » /* Display flash device parameters */
195 e = context.bctlib.get_value(nvbct_lib_id_num_param_sets, 217 e = context.bctlib.get_value(nvbct_lib_id_num_param_sets,
196 &parameters_used, 218 &parameters_used,
197 context.bct); 219 context.bct);
198 220
199 for (i = 0; (e == 0) && (i < parameters_used); ++i) { 221 for (i = 0; (e == 0) && (i < parameters_used); ++i) {
200 field_item const * device_field_table = NULL; 222 field_item const * device_field_table = NULL;
223 char const * prefix = NULL;
201 field_item const * item; 224 field_item const * item;
202 225
203 printf("DeviceParameter[%d]\n", i);
204
205 e = context.bctlib.getdev_param(i, 226 e = context.bctlib.getdev_param(i,
206 nvbct_lib_id_dev_type, 227 nvbct_lib_id_dev_type,
207 &type, 228 &type,
208 context.bct); 229 context.bct);
209 230
231 printf("\n"
232 "DevType[%d] = ", i);
233 display_enum_value(&context, s_devtype_table, type);
234 printf(";\n");
235
210 switch (type) 236 switch (type)
211 { 237 {
212 case nvboot_dev_type_spi: 238 case nvboot_dev_type_spi:
213 printf(" Type = SPI\n");
214 device_field_table = s_spiflash_table; 239 device_field_table = s_spiflash_table;
240 prefix = "SpiFlashParams";
215 break; 241 break;
216 242
217 case nvboot_dev_type_sdmmc: 243 case nvboot_dev_type_sdmmc:
218 printf(" Type = SDMMC\n");
219 device_field_table = s_sdmmc_table; 244 device_field_table = s_sdmmc_table;
245 prefix = "SdmmcParams";
220 break; 246 break;
221 247
222 case nvboot_dev_type_nand: 248 case nvboot_dev_type_nand:
223 printf(" Type = NAND\n");
224 device_field_table = s_nand_table; 249 device_field_table = s_nand_table;
250 prefix = "NandParams";
225 break; 251 break;
226 252
227 default: 253 default:
228 device_field_table = NULL; 254 device_field_table = NULL;
229 » » » » printf(" Type = <UNKNOWN TYPE (%d)>\n", 255 » » » » prefix = "";
230 » » » » type);
231 break; 256 break;
232 } 257 }
233 258
234 if (!device_field_table) 259 if (!device_field_table)
235 continue; 260 continue;
236 261
237 int width = max_width(device_field_table); 262 int width = max_width(device_field_table);
238 263
239 for (item = device_field_table; item->name != NULL; ++item) { 264 for (item = device_field_table; item->name != NULL; ++item) {
240 e = context.bctlib.getdev_param(i, 265 e = context.bctlib.getdev_param(i,
241 item->enum_value, 266 item->enum_value,
242 &data, 267 &data,
243 context.bct); 268 context.bct);
244 » » » printf(" %-*s = 0x%08x\n", 269 » » » printf("DeviceParam[%d].%s.%-*s = ",
245 » » » width, item->name, 270 » » » i, prefix, width, item->name);
246 » » » e == 0 ? data : -1); 271
272 » » » if (e != 0)
273 » » » » printf("<ERROR reading parameter (%d)>", e);
274 » » » else
275 » » » » display_field_value(&context, item, data);
276
277 » » » printf(";\n");
247 } 278 }
248 } 279 }
249 280
250 » /* Display SDRAM parameters sets */ 281 » /* Display SDRAM parameters */
251 e = context.bctlib.get_value(nvbct_lib_id_num_sdram_sets, 282 e = context.bctlib.get_value(nvbct_lib_id_num_sdram_sets,
252 &sdram_used, 283 &sdram_used,
253 context.bct); 284 context.bct);
254 285
255 for (i = 0; (e == 0) && (i < sdram_used); ++i) { 286 for (i = 0; (e == 0) && (i < sdram_used); ++i) {
256 printf("SDRAMParameter[%d]\n", i);
257
258 e = context.bctlib.get_sdram_params(i,
259 nvbct_lib_id_sdram_memory_type,
260 &type,
261 context.bct);
262
263 printf(" Type............................: %s\n",
264 type < nvboot_memory_type_num ? sdram_types[type]
265 : "Unknown");
266
267 int width = max_width(s_sdram_field_table); 287 int width = max_width(s_sdram_field_table);
268 field_item const * item; 288 field_item const * item;
269 289
290 printf("\n");
291
270 for (item = s_sdram_field_table; item->name != NULL; ++item) { 292 for (item = s_sdram_field_table; item->name != NULL; ++item) {
271 e = context.bctlib.get_sdram_params(i, 293 e = context.bctlib.get_sdram_params(i,
272 item->enum_value, 294 item->enum_value,
273 &data, 295 &data,
274 context.bct); 296 context.bct);
275 » » » printf(" %-*s = ", width, item->name); 297 » » » printf("SDRAM[%d].%-*s = ", i, width, item->name);
276 298
277 if (e != 0) 299 if (e != 0)
278 printf("<ERROR reading parameter (%d)>", e); 300 printf("<ERROR reading parameter (%d)>", e);
279 else 301 else
280 » » » » display_field_value(item, data); 302 » » » » display_field_value(&context, item, data);
281 303
282 » » » printf("\n"); 304 » » » printf(";\n");
283 } 305 }
284 } 306 }
285 307
286 /* Clean up memory. */ 308 /* Clean up memory. */
287 cleanup_context(&context); 309 cleanup_context(&context);
288 310
289 return e; 311 return e;
290 } 312 }
313 /*****************************************************************************/
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698