blob: 3e12b993b39c2e8476a3355953aba8a07b7cb510 [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
99static void
100usage(void)
101{
102 printf("Usage: bct_dump bctfile\n");
103 printf(" bctfile BCT filename to read and display\n");
104}
105
106int
107main(int argc, char *argv[])
108{
109 int e;
110 build_image_context context;
111 u_int32_t bootloaders_used;
Anton Staaf496f9652011-03-02 09:23:27 -0800112 u_int32_t parameters_used;
113 nvboot_dev_type type;
Anton Staafc6244272011-02-24 10:17:50 -0800114 u_int32_t data;
115 int i;
116 int j;
Anton Staaf496f9652011-03-02 09:23:27 -0800117 value_data const * device_values;
118 int device_count;
Anton Staafc6244272011-02-24 10:17:50 -0800119
120 if (argc != 2)
121 usage();
122
123 memset(&context, 0, sizeof(build_image_context));
124
125 context.bct_filename = argv[1];
126
127 /* Set up the Nvbctlib function pointers. */
128 nvbct_lib_get_fns(&(context.bctlib));
129
130 e = init_context(&context);
131 if (e != 0) {
132 printf("context initialization failed. Aborting.\n");
133 return e;
134 }
135
136 read_bct_file(&context);
137
Anton Staaf496f9652011-03-02 09:23:27 -0800138 /* Display root values */
Anton Staafc6244272011-02-24 10:17:50 -0800139 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
140 e = context.bctlib.get_value(values[i].id, &data, context.bct);
141 printf(values[i].message, e == 0 ? data : -1);
142 }
143
Anton Staaf496f9652011-03-02 09:23:27 -0800144 /* Display bootloader values */
Anton Staafc6244272011-02-24 10:17:50 -0800145 e = context.bctlib.get_value(nvbct_lib_id_bootloader_used,
Anton Staaf2b6c88c2011-03-02 09:22:25 -0800146 &bootloaders_used,
147 context.bct);
Anton Staafc6244272011-02-24 10:17:50 -0800148
149 for (i = 0; (e == 0) && (i < bootloaders_used); ++i) {
150 printf("Bootloader[%d]\n", i);
151
152 for (j = 0; j < sizeof(bl_values) / sizeof(bl_values[0]); ++j) {
153 e = context.bctlib.getbl_param(i,
Anton Staaf2b6c88c2011-03-02 09:22:25 -0800154 bl_values[j].id,
155 &data,
156 context.bct);
Anton Staafc6244272011-02-24 10:17:50 -0800157 printf(bl_values[j].message, e == 0 ? data : -1);
158 }
159 }
160
Anton Staaf496f9652011-03-02 09:23:27 -0800161 /* Display device values */
162 e = context.bctlib.get_value(nvbct_lib_id_num_param_sets,
163 &parameters_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
Anton Staafc6244272011-02-24 10:17:50 -0800209 /* Clean up memory. */
210 cleanup_context(&context);
211
212 return e;
213}