blob: 15f937b64902347b68772c836087ea3ca4192de8 [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[] = {
38 {nvbct_lib_id_boot_data_version, "Version................: 0x%08x\n"},
39 {nvbct_lib_id_block_size_log2, "Block size (log2)......: %d\n"},
40 {nvbct_lib_id_page_size_log2, "Page size (log2).......: %d\n"},
41 {nvbct_lib_id_partition_size, "Parition size..........: 0x%08x\n"},
42 {nvbct_lib_id_bootloader_used, "Bootloader used........: %d\n"},
43 {nvbct_lib_id_bootloaders_max, "Bootloaders max........: %d\n"},
44 {nvbct_lib_id_bct_size, "BCT size...............: %d\n"},
45 {nvbct_lib_id_hash_size, "Hash size..............: %d\n"},
46 {nvbct_lib_id_crypto_offset, "Crypto offset..........: %d\n"},
47 {nvbct_lib_id_crypto_length, "Crypto length..........: %d\n"},
48 {nvbct_lib_id_max_bct_search_blks, "Max BCT search blocks..: %d\n"},
49};
50
51static value_data const bl_values[] = {
52 {nvbct_lib_id_bl_version, " Version.......: 0x%08x\n"},
53 {nvbct_lib_id_bl_start_blk, " Start block...: %d\n"},
54 {nvbct_lib_id_bl_start_page, " Start page....: %d\n"},
55 {nvbct_lib_id_bl_length, " Length........: %d\n"},
56 {nvbct_lib_id_bl_load_addr, " Load address..: 0x%08x\n"},
57 {nvbct_lib_id_bl_entry_point, " Entry point...: 0x%08x\n"},
58 {nvbct_lib_id_bl_attribute, " Attributes....: 0x%08x\n"},
59};
60
61static void
62usage(void)
63{
64 printf("Usage: bct_dump bctfile\n");
65 printf(" bctfile BCT filename to read and display\n");
66}
67
68int
69main(int argc, char *argv[])
70{
71 int e;
72 build_image_context context;
73 u_int32_t bootloaders_used;
74 u_int32_t data;
75 int i;
76 int j;
77
78 if (argc != 2)
79 usage();
80
81 memset(&context, 0, sizeof(build_image_context));
82
83 context.bct_filename = argv[1];
84
85 /* Set up the Nvbctlib function pointers. */
86 nvbct_lib_get_fns(&(context.bctlib));
87
88 e = init_context(&context);
89 if (e != 0) {
90 printf("context initialization failed. Aborting.\n");
91 return e;
92 }
93
94 read_bct_file(&context);
95
96 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
97 e = context.bctlib.get_value(values[i].id, &data, context.bct);
98 printf(values[i].message, e == 0 ? data : -1);
99 }
100
101 e = context.bctlib.get_value(nvbct_lib_id_bootloader_used,
Anton Staaf2b6c88c2011-03-02 09:22:25 -0800102 &bootloaders_used,
103 context.bct);
Anton Staafc6244272011-02-24 10:17:50 -0800104
105 for (i = 0; (e == 0) && (i < bootloaders_used); ++i) {
106 printf("Bootloader[%d]\n", i);
107
108 for (j = 0; j < sizeof(bl_values) / sizeof(bl_values[0]); ++j) {
109 e = context.bctlib.getbl_param(i,
Anton Staaf2b6c88c2011-03-02 09:22:25 -0800110 bl_values[j].id,
111 &data,
112 context.bct);
Anton Staafc6244272011-02-24 10:17:50 -0800113 printf(bl_values[j].message, e == 0 ? data : -1);
114 }
115 }
116
117 /* Clean up memory. */
118 cleanup_context(&context);
119
120 return e;
121}