blob: 725970b0a099fc428ca4e3f5d0097251d37c0ca6 [file] [log] [blame]
Anton Staafc6244272011-02-24 10:17:50 -08001/**
2 * Copyright (c) 2011 NVIDIA Corporation. All rights reserved.
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"
24#include "nvbctlib.h"
25#include "data_layout.h"
26#include "context.h"
27
28#include <string.h>
29
30int enable_debug = 0;
31
32typedef struct {
33 nvbct_lib_id id;
34 char const * message;
35} value_data;
36
37static value_data const values[] = {
Anton Staaf496f9652011-03-02 09:23:27 -080038 {nvbct_lib_id_boot_data_version,
39 "Version..................: 0x%08x\n"},
40 {nvbct_lib_id_block_size_log2,
41 "Block size (log2)........: %d\n"},
42 {nvbct_lib_id_page_size_log2,
43 "Page size (log2).........: %d\n"},
44 {nvbct_lib_id_partition_size,
45 "Parition size............: 0x%08x\n"},
46 {nvbct_lib_id_bootloader_used,
47 "Bootloader used..........: %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"},
Anton Staafc6244272011-02-24 10:17:50 -080062};
63
64static value_data const bl_values[] = {
Anton Staaf496f9652011-03-02 09:23:27 -080065 {nvbct_lib_id_bl_version,
66 " Version.......: 0x%08x\n"},
67 {nvbct_lib_id_bl_start_blk,
68 " Start block...: %d\n"},
69 {nvbct_lib_id_bl_start_page,
70 " Start page....: %d\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
81static 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
90static 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"},
Anton Staafc6244272011-02-24 10:17:50 -080097};
98
Vincent Palatin99475842011-03-07 16:09:25 -050099static value_data const sdram_values[] = {
100 {nvbct_lib_id_sdram_pllm_charge_pump_setup_ctrl,
101 " PLLM_CHARGE_PUMP_SETUP_CTRL.....: 0x%08x\n"},
102 {nvbct_lib_id_sdram_pllm_loop_filter_setup_ctrl,
103 " PLLM_LOOP_FILTER_SETUP_CTRL.....: 0x%08x\n"},
104 {nvbct_lib_id_sdram_pllm_input_divider,
105 " PLLM_INPUT_DIVIDER..............: 0x%08x\n"},
106 {nvbct_lib_id_sdram_pllm_feedback_divider,
107 " PLLM_FEEDBACK_DIVIDER...........: 0x%08x\n"},
108 {nvbct_lib_id_sdram_pllm_post_divider,
109 " PLLM_POST_DIVIDER...............: 0x%08x\n"},
110 {nvbct_lib_id_sdram_pllm_stable_time,
111 " PLLM_STABLE_TIME................: 0x%08x\n"},
112 {nvbct_lib_id_sdram_emc_clock_divider,
113 " EMC_CLOCK_DIVIDER...............: 0x%08x\n"},
114 {nvbct_lib_id_sdram_emc_auto_cal_interval,
115 " EMC_AUTO_CAL_INTERVAL...........: 0x%08x\n"},
116 {nvbct_lib_id_sdram_emc_auto_cal_config,
117 " EMC_AUTO_CAL_CONFIG.............: 0x%08x\n"},
118 {nvbct_lib_id_sdram_emc_auto_cal_wait,
119 " EMC_AUTO_CAL_WAIT...............: 0x%08x\n"},
120 {nvbct_lib_id_sdram_emc_pin_program_wait,
121 " EMC_PIN_PROGRAM_WAIT............: 0x%08x\n"},
122 {nvbct_lib_id_sdram_emc_rc,
123 " EMC_RC..........................: 0x%08x\n"},
124 {nvbct_lib_id_sdram_emc_rfc,
125 " EMC_RFC.........................: 0x%08x\n"},
126 {nvbct_lib_id_sdram_emc_ras,
127 " EMC_RAS.........................: 0x%08x\n"},
128 {nvbct_lib_id_sdram_emc_rp,
129 " EMC_RP..........................: 0x%08x\n"},
130 {nvbct_lib_id_sdram_emc_r2w,
131 " EMC_R2W.........................: 0x%08x\n"},
132 {nvbct_lib_id_sdram_emc_w2r,
133 " EMC_W2R.........................: 0x%08x\n"},
134 {nvbct_lib_id_sdram_emc_r2p,
135 " EMC_R2P.........................: 0x%08x\n"},
136 {nvbct_lib_id_sdram_emc_w2p,
137 " EMC_W2P.........................: 0x%08x\n"},
138 {nvbct_lib_id_sdram_emc_rd_rcd,
139 " EMC_RD_RCD......................: 0x%08x\n"},
140 {nvbct_lib_id_sdram_emc_wr_rcd,
141 " EMC_WR_RCD......................: 0x%08x\n"},
142 {nvbct_lib_id_sdram_emc_rrd,
143 " EMC_RRD.........................: 0x%08x\n"},
144 {nvbct_lib_id_sdram_emc_rext,
145 " EMC_REXT........................: 0x%08x\n"},
146 {nvbct_lib_id_sdram_emc_wdv,
147 " EMC_WDV.........................: 0x%08x\n"},
148 {nvbct_lib_id_sdram_emc_quse,
149 " EMC_QUSE........................: 0x%08x\n"},
150 {nvbct_lib_id_sdram_emc_qrst,
151 " EMC_QRST........................: 0x%08x\n"},
152 {nvbct_lib_id_sdram_emc_qsafe,
153 " EMC_QSAFE.......................: 0x%08x\n"},
154 {nvbct_lib_id_sdram_emc_rdv,
155 " EMC_RDV.........................: 0x%08x\n"},
156 {nvbct_lib_id_sdram_emc_refresh,
157 " EMC_REFRESH.....................: 0x%08x\n"},
158 {nvbct_lib_id_sdram_emc_burst_refresh_num,
159 " EMC_BURST_REFRESH_NUM...........: 0x%08x\n"},
160 {nvbct_lib_id_sdram_emc_pdex2wr,
161 " EMC_PDEX2WR.....................: 0x%08x\n"},
162 {nvbct_lib_id_sdram_emc_pdex2rd,
163 " EMC_PDEX2RD.....................: 0x%08x\n"},
164 {nvbct_lib_id_sdram_emc_pchg2pden,
165 " EMC_PCHG2PDEN...................: 0x%08x\n"},
166 {nvbct_lib_id_sdram_emc_act2pden,
167 " EMC_ACT2PDEN....................: 0x%08x\n"},
168 {nvbct_lib_id_sdram_emc_ar2pden,
169 " EMC_AR2PDEN.....................: 0x%08x\n"},
170 {nvbct_lib_id_sdram_emc_rw2pden,
171 " EMC_RW2PDEN.....................: 0x%08x\n"},
172 {nvbct_lib_id_sdram_emc_txsr,
173 " EMC_TXSR........................: 0x%08x\n"},
174 {nvbct_lib_id_sdram_emc_tcke,
175 " EMC_TCKE........................: 0x%08x\n"},
176 {nvbct_lib_id_sdram_emc_tfaw,
177 " EMC_TFAW........................: 0x%08x\n"},
178 {nvbct_lib_id_sdram_emc_trpab,
179 " EMC_TRPAB.......................: 0x%08x\n"},
180 {nvbct_lib_id_sdram_emc_tclkstable,
181 " EMC_TCLKSTABLE..................: 0x%08x\n"},
182 {nvbct_lib_id_sdram_emc_tclkstop,
183 " EMC_TCLKSTOP....................: 0x%08x\n"},
184 {nvbct_lib_id_sdram_emc_trefbw,
185 " EMC_TREFBW......................: 0x%08x\n"},
186 {nvbct_lib_id_sdram_emc_quse_extra,
187 " EMC_QUSE_EXTRA..................: 0x%08x\n"},
188 {nvbct_lib_id_sdram_emc_fbio_cfg1,
189 " EMC_FBIO_CFG1...................: 0x%08x\n"},
190 {nvbct_lib_id_sdram_emc_fbio_dqsib_dly,
191 " EMC_FBIO_DQSIB_DLY..............: 0x%08x\n"},
192 {nvbct_lib_id_sdram_emc_fbio_dqsib_dly_msb,
193 " EMC_FBIO_DQSIB_DLY_MSB..........: 0x%08x\n"},
194 {nvbct_lib_id_sdram_emc_fbio_quse_dly,
195 " EMC_FBIO_QUSE_DLY...............: 0x%08x\n"},
196 {nvbct_lib_id_sdram_emc_fbio_quse_dly_msb,
197 " EMC_FBIO_QUSE_DLY_MSB...........: 0x%08x\n"},
198 {nvbct_lib_id_sdram_emc_fbio_cfg5,
199 " EMC_FBIO_CFG5...................: 0x%08x\n"},
200 {nvbct_lib_id_sdram_emc_fbio_cfg6,
201 " EMC_FBIO_CFG6...................: 0x%08x\n"},
202 {nvbct_lib_id_sdram_emc_fbio_spare,
203 " EMC_FBIO_SPARE..................: 0x%08x\n"},
204 {nvbct_lib_id_sdram_emc_mrs,
205 " EMC_MRS.........................: 0x%08x\n"},
206 {nvbct_lib_id_sdram_emc_emrs,
207 " EMC_EMRS........................: 0x%08x\n"},
208 {nvbct_lib_id_sdram_emc_mrw1,
209 " EMC_MRW1........................: 0x%08x\n"},
210 {nvbct_lib_id_sdram_emc_mrw2,
211 " EMC_MRW2........................: 0x%08x\n"},
212 {nvbct_lib_id_sdram_emc_mrw3,
213 " EMC_MRW3........................: 0x%08x\n"},
214 {nvbct_lib_id_sdram_emc_mrw_reset_command,
215 " EMC_MRW_RESET_COMMAND...........: 0x%08x\n"},
216 {nvbct_lib_id_sdram_emc_mrw_reset_ninit_wait,
217 " EMC_MRW_RESET_NINIT_WAIT........: 0x%08x\n"},
218 {nvbct_lib_id_sdram_emc_adr_cfg,
219 " EMC_ADR_CFG.....................: 0x%08x\n"},
220 {nvbct_lib_id_sdram_emc_adr_cfg1,
221 " EMC_ADR_CFG1....................: 0x%08x\n"},
222 {nvbct_lib_id_sdram_mc_emem_Cfg,
223 " MC_EMEM_CFG.....................: 0x%08x\n"},
224 {nvbct_lib_id_sdram_mc_lowlatency_config,
225 " MC_LOWLATENCY_CONFIG............: 0x%08x\n"},
226 {nvbct_lib_id_sdram_emc_cfg,
227 " EMC_CFG.........................: 0x%08x\n"},
228 {nvbct_lib_id_sdram_emc_cfg2,
229 " EMC_CFG2........................: 0x%08x\n"},
230 {nvbct_lib_id_sdram_emc_dbg,
231 " EMC_DBG.........................: 0x%08x\n"},
232 {nvbct_lib_id_sdram_ahb_arbitration_xbar_ctrl,
233 " AHB_ARBITRATION_XBAR_CTRL.......: 0x%08x\n"},
234 {nvbct_lib_id_sdram_emc_cfg_dig_dll,
235 " EMC_CFG_DIG_DLL.................: 0x%08x\n"},
236 {nvbct_lib_id_sdram_emc_dll_xform_dqs,
237 " EMC_DLL_XFORM_DQS...............: 0x%08x\n"},
238 {nvbct_lib_id_sdram_emc_dll_xform_quse,
239 " EMC_DLL_XFORM_QUSE..............: 0x%08x\n"},
240 {nvbct_lib_id_sdram_warm_boot_wait,
241 " WARM_BOOT_WAIT..................: 0x%08x\n"},
242 {nvbct_lib_id_sdram_emc_ctt_term_ctrl,
243 " EMC_CTT_TERM_CTRL...............: 0x%08x\n"},
244 {nvbct_lib_id_sdram_emc_odt_write,
245 " EMC_ODT_WRITE...................: 0x%08x\n"},
246 {nvbct_lib_id_sdram_emc_odt_read,
247 " EMC_ODT_READ....................: 0x%08x\n"},
248 {nvbct_lib_id_sdram_emc_zcal_ref_cnt,
249 " EMC_ZCAL_REF_CNT................: 0x%08x\n"},
250 {nvbct_lib_id_sdram_emc_zcal_wait_cnt,
251 " EMC_ZCAL_WAIT_CNT...............: 0x%08x\n"},
252 {nvbct_lib_id_sdram_emc_zcal_mrw_cmd,
253 " EMC_ZCAL_MRW_CMD................: 0x%08x\n"},
254 {nvbct_lib_id_sdram_emc_mrs_reset_dll,
255 " EMC_MRS_RESET_DLL...............: 0x%08x\n"},
256 {nvbct_lib_id_sdram_emc_mrw_zq_init_dev0,
257 " EMC_MRW_ZQ_INIT_DEV0............: 0x%08x\n"},
258 {nvbct_lib_id_sdram_emc_mrw_zq_init_dev1,
259 " EMC_MRW_ZQ_INIT_DEV1............: 0x%08x\n"},
260 {nvbct_lib_id_sdram_emc_mrw_zq_init_wait,
261 " EMC_MRW_ZQ_INIT_WAIT............: 0x%08x\n"},
262 {nvbct_lib_id_sdram_emc_mrs_reset_dll_wait,
263 " EMC_MRS_RESET_DLL_WAIT..........: 0x%08x\n"},
264 {nvbct_lib_id_sdram_emc_emrs_emr2,
265 " EMC_EMRS_EMR2...................: 0x%08x\n"},
266 {nvbct_lib_id_sdram_emc_emrs_emr3,
267 " EMC_EMRS_EMR3...................: 0x%08x\n"},
268 {nvbct_lib_id_sdram_emc_emrs_ddr2_dll_enable,
269 " EMC_EMRS_DDR2_DLL_ENABLE........: 0x%08x\n"},
270 {nvbct_lib_id_sdram_emc_mrs_ddr2_dll_reset,
271 " EMC_MRS_DDR2_DLL_RESET..........: 0x%08x\n"},
272 {nvbct_lib_id_sdram_emc_emrs_ddr2_ocd_calib,
273 " EMC_EMRS_DDR2_OCD_CALIB.........: 0x%08x\n"},
274 {nvbct_lib_id_sdram_emc_ddr2_wait,
275 " EMC_DDR2_WAIT...................: 0x%08x\n"},
276 {nvbct_lib_id_sdram_emc_cfg_clktrim0,
277 " EMC_CFG_CLKTRIM0................: 0x%08x\n"},
278 {nvbct_lib_id_sdram_emc_cfg_clktrim1,
279 " EMC_CFG_CLKTRIM1................: 0x%08x\n"},
280 {nvbct_lib_id_sdram_emc_cfg_clktrim2,
281 " EMC_CFG_CLKTRIM2................: 0x%08x\n"},
282 {nvbct_lib_id_sdram_pmc_ddr_pwr,
283 " PMC_DDR_PWR.....................: 0x%08x\n"},
284 {nvbct_lib_id_sdram_apb_misc_gp_xm2cfga_pad_ctrl,
285 " APB_MISC_GP_XM2CFGA_PAD_CTRL....: 0x%08x\n"},
286 {nvbct_lib_id_sdram_apb_misc_gp_xm2cfgc_pad_ctrl,
287 " APB_MISC_GP_XM2CFGC_PAD_CTRL....: 0x%08x\n"},
288 {nvbct_lib_id_sdram_apb_misc_gp_xm2cfgc_pad_ctrl2,
289 " APB_MISC_GP_XM2CFGC_PAD_CTRL2...: 0x%08x\n"},
290 {nvbct_lib_id_sdram_apb_misc_gp_xm2cfgd_pad_ctrl,
291 " APB_MISC_GP_XM2CFGD_PAD_CTRL....: 0x%08x\n"},
292 {nvbct_lib_id_sdram_apb_misc_gp_xm2cfgd_pad_ctrl2,
293 " APB_MISC_GP_XM2CFGD_PAD_CTRL2...: 0x%08x\n"},
294 {nvbct_lib_id_sdram_apb_misc_gp_xm2clkcfg_Pad_ctrl,
295 " APB_MISC_GP_XM2CLKCFG_PAD_CTRL..: 0x%08x\n"},
296 {nvbct_lib_id_sdram_apb_misc_gp_xm2comp_pad_ctrl,
297 " APB_MISC_GP_XM2COMP_PAD_CTRL....: 0x%08x\n"},
298 {nvbct_lib_id_sdram_apb_misc_gp_xm2vttgen_pad_ctrl,
299 " APB_MISC_GP_XM2VTTGEN_PAD_CTRL..: 0x%08x\n"},
300};
301
302static const char *sdram_types[nvboot_memory_type_num] = {
303 "None", "DDR", "LPDDR", "DDR2", "LPDDR2"
304};
305
Anton Staafc6244272011-02-24 10:17:50 -0800306static void
307usage(void)
308{
309 printf("Usage: bct_dump bctfile\n");
310 printf(" bctfile BCT filename to read and display\n");
311}
312
313int
314main(int argc, char *argv[])
315{
316 int e;
317 build_image_context context;
318 u_int32_t bootloaders_used;
Anton Staaf496f9652011-03-02 09:23:27 -0800319 u_int32_t parameters_used;
Vincent Palatin99475842011-03-07 16:09:25 -0500320 u_int32_t sdram_used;
Anton Staaf496f9652011-03-02 09:23:27 -0800321 nvboot_dev_type type;
Anton Staafc6244272011-02-24 10:17:50 -0800322 u_int32_t data;
323 int i;
324 int j;
Anton Staaf496f9652011-03-02 09:23:27 -0800325 value_data const * device_values;
326 int device_count;
Anton Staafc6244272011-02-24 10:17:50 -0800327
328 if (argc != 2)
329 usage();
330
331 memset(&context, 0, sizeof(build_image_context));
332
333 context.bct_filename = argv[1];
334
335 /* Set up the Nvbctlib function pointers. */
336 nvbct_lib_get_fns(&(context.bctlib));
337
338 e = init_context(&context);
339 if (e != 0) {
340 printf("context initialization failed. Aborting.\n");
341 return e;
342 }
343
344 read_bct_file(&context);
345
Anton Staaf496f9652011-03-02 09:23:27 -0800346 /* Display root values */
Anton Staafc6244272011-02-24 10:17:50 -0800347 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
348 e = context.bctlib.get_value(values[i].id, &data, context.bct);
349 printf(values[i].message, e == 0 ? data : -1);
350 }
351
Anton Staaf496f9652011-03-02 09:23:27 -0800352 /* Display bootloader values */
Anton Staafc6244272011-02-24 10:17:50 -0800353 e = context.bctlib.get_value(nvbct_lib_id_bootloader_used,
Anton Staaf2b6c88c2011-03-02 09:22:25 -0800354 &bootloaders_used,
355 context.bct);
Anton Staafc6244272011-02-24 10:17:50 -0800356
357 for (i = 0; (e == 0) && (i < bootloaders_used); ++i) {
358 printf("Bootloader[%d]\n", i);
359
360 for (j = 0; j < sizeof(bl_values) / sizeof(bl_values[0]); ++j) {
361 e = context.bctlib.getbl_param(i,
Anton Staaf2b6c88c2011-03-02 09:22:25 -0800362 bl_values[j].id,
363 &data,
364 context.bct);
Anton Staafc6244272011-02-24 10:17:50 -0800365 printf(bl_values[j].message, e == 0 ? data : -1);
366 }
367 }
368
Anton Staaf496f9652011-03-02 09:23:27 -0800369 /* Display device values */
370 e = context.bctlib.get_value(nvbct_lib_id_num_param_sets,
371 &parameters_used,
372 context.bct);
373
374 for (i = 0; (e == 0) && (i < parameters_used); ++i) {
375 printf("DeviceParameter[%d]\n", i);
376
377 e = context.bctlib.getdev_param(i,
378 nvbct_lib_id_dev_type,
379 &type,
380 context.bct);
381
382 switch (type)
383 {
384 case nvboot_dev_type_spi:
385 printf(" Type...........: SPI\n");
386 device_values = spi_values;
387 device_count = (sizeof(spi_values) /
388 sizeof(spi_values[0]));
389 break;
390
391 case nvboot_dev_type_sdmmc:
392 printf(" Type...........: SDMMC\n");
393 device_values = sdmmc_values;
394 device_count = (sizeof(sdmmc_values) /
395 sizeof(sdmmc_values[0]));
396 break;
397
398 default:
399 printf(" Type...........: Unknown (%d)\n",
400 type);
401 device_values = NULL;
402 device_count = 0;
403 break;
404 }
405
406 for (j = 0; j < device_count; ++j) {
407 value_data value = device_values[j];
408
409 e = context.bctlib.getdev_param(i,
410 value.id,
411 &data,
412 context.bct);
413 printf(value.message, e == 0 ? data : -1);
414 }
415 }
416
Vincent Palatin99475842011-03-07 16:09:25 -0500417 /* Display SDRAM parameters sets */
418 e = context.bctlib.get_value(nvbct_lib_id_num_sdram_sets,
419 &sdram_used,
420 context.bct);
421
422 for (i = 0; (e == 0) && (i < sdram_used); ++i) {
423 printf("SDRAMParameter[%d]\n", i);
424
425 e = context.bctlib.get_sdram_params(i,
426 nvbct_lib_id_sdram_memory_type,
427 &type,
428 context.bct);
429
430 printf(" Type............................: %s\n",
431 type < nvboot_memory_type_num ? sdram_types[type]
432 : "Unknown");
433
434 for (j = 0; j < sizeof(sdram_values) / sizeof(sdram_values[0]);
435 ++j) {
436 e = context.bctlib.get_sdram_params(i,
437 sdram_values[j].id,
438 &data,
439 context.bct);
440 printf(sdram_values[j].message, e == 0 ? data : -1);
441 }
442 }
443
Anton Staafc6244272011-02-24 10:17:50 -0800444 /* Clean up memory. */
445 cleanup_context(&context);
446
447 return e;
448}