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

Side by Side Diff: utility/dump_kernel_config.c

Issue 6677033: Revert "Add --kloadaddr option to utilities" (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.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 | utility/vbutil_kernel.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Exports the kernel commandline from a given partition/image. 5 * Exports the kernel commandline from a given partition/image.
6 */ 6 */
7 7
8 #include <getopt.h>
9 #include <inttypes.h> /* For uint64_t */ 8 #include <inttypes.h> /* For uint64_t */
10 #include <stdio.h> 9 #include <stdio.h>
11 #include <stdlib.h> 10 #include <stdlib.h>
12 #include <sys/mman.h> 11 #include <sys/mman.h>
13 #include <unistd.h> 12 #include <unistd.h>
14 13
15 #include "kernel_blob.h" 14 #include "kernel_blob.h"
16 #include "utility.h" 15 #include "utility.h"
17 #include "vboot_common.h" 16 #include "vboot_common.h"
18 #include "vboot_struct.h" 17 #include "vboot_struct.h"
19 18
20 enum {
21 OPT_KLOADADDR = 1000,
22 };
23
24 static struct option long_opts[] = {
25 { "kloadaddr", 1, 0, OPT_KLOADADDR },
26 { NULL, 0, 0, 0 }
27 };
28
29 /* Print help and return error */ 19 /* Print help and return error */
30 static int PrintHelp(void) { 20 static int PrintHelp(void) {
31 puts("dump_kernel_config - Prints the kernel command line\n" 21 puts("dump_kernel_config - Prints the kernel command line\n"
32 "\n" 22 "\n"
33 "Usage: dump_kernel_config [--kloadaddr <ADDRESS>] " 23 "Usage: dump_kernel_config <image/blockdevice>\n"
34 "<image/blockdevice>\n"
35 "\n" 24 "\n"
36 ""); 25 "");
37 return 1; 26 return 1;
38 } 27 }
39 28
40 static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size, 29 static uint8_t* find_kernel_config(uint8_t* blob, uint64_t blob_size) {
41 uint64_t kernel_body_load_address) {
42 VbKeyBlockHeader* key_block; 30 VbKeyBlockHeader* key_block;
43 VbKernelPreambleHeader* preamble; 31 VbKernelPreambleHeader* preamble;
44 struct linux_kernel_params *params; 32 struct linux_kernel_params *params;
45 uint32_t now = 0; 33 uint32_t now = 0;
46 uint32_t offset = 0; 34 uint32_t offset = 0;
47 35
48 /* Skip the key block */ 36 /* Skip the key block */
49 key_block = (VbKeyBlockHeader*)blob; 37 key_block = (VbKeyBlockHeader*)blob;
50 now += key_block->key_block_size; 38 now += key_block->key_block_size;
51 if (now + blob > blob + blob_size) { 39 if (now + blob > blob + blob_size) {
52 error("key_block_size advances past the end of the blob\n"); 40 error("key_block_size advances past the end of the blob\n");
53 return NULL; 41 return NULL;
54 } 42 }
55 43
56 /* Open up the preamble */ 44 /* Open up the preamble */
57 preamble = (VbKernelPreambleHeader*)(blob + now); 45 preamble = (VbKernelPreambleHeader*)(blob + now);
58 now += preamble->preamble_size; 46 now += preamble->preamble_size;
59 if (now + blob > blob + blob_size) { 47 if (now + blob > blob + blob_size) {
60 error("preamble_size advances past the end of the blob\n"); 48 error("preamble_size advances past the end of the blob\n");
61 return NULL; 49 return NULL;
62 } 50 }
63 51
64 /* The parameters are packed before the bootloader and there is no specific 52 /* The parameters are packed before the bootloader and there is no specific
65 * pointer to it so we just walk back by its allocated size. */ 53 * pointer to it so we just walk back by its allocated size. */
66 offset = preamble->bootloader_address - 54 offset = preamble->bootloader_address -
67 (kernel_body_load_address + CROS_PARAMS_SIZE) + now; 55 (CROS_32BIT_ENTRY_ADDR + CROS_PARAMS_SIZE) + now;
68 if (offset > blob_size) { 56 if (offset > blob_size) {
69 error("params are outside of the memory blob: %x\n", offset); 57 error("params are outside of the memory blob: %x\n", offset);
70 return NULL; 58 return NULL;
71 } 59 }
72 params = (struct linux_kernel_params *)(blob + offset); 60 params = (struct linux_kernel_params *)(blob + offset);
73 61
74 /* Grab the offset to the kernel command line using the supplied pointer. */ 62 /* Grab the offset to the kernel command line using the supplied pointer. */
75 offset = params->cmd_line_ptr - kernel_body_load_address + now; 63 offset = params->cmd_line_ptr - CROS_32BIT_ENTRY_ADDR + now;
76 if (offset > blob_size) { 64 if (offset > blob_size) {
77 error("cmdline is outside of the memory blob: %x\n", offset); 65 error("cmdline is outside of the memory blob: %x\n", offset);
78 return NULL; 66 return NULL;
79 } 67 }
80 return (uint8_t *)(blob + offset); 68 return (uint8_t *)(blob + offset);
81 } 69 }
82 70
83 static void* MapFile(const char *filename, size_t *size) { 71 static void* MapFile(const char *filename, size_t *size) {
84 FILE* f; 72 FILE* f;
85 uint8_t* buf; 73 uint8_t* buf;
(...skipping 23 matching lines...) Expand all
109 return NULL; 97 return NULL;
110 } 98 }
111 99
112 fclose(f); 100 fclose(f);
113 return buf; 101 return buf;
114 } 102 }
115 103
116 int main(int argc, char* argv[]) { 104 int main(int argc, char* argv[]) {
117 uint8_t* blob; 105 uint8_t* blob;
118 size_t blob_size; 106 size_t blob_size;
119 char* infile = NULL; 107 char* infile = argv[1];
120 uint8_t *config = NULL; 108 uint8_t *config = NULL;
121 uint64_t kernel_body_load_address = CROS_32BIT_ENTRY_ADDR;
122 int parse_error = 0;
123 char *e;
124 int i;
125 109
126 while (((i = getopt_long(argc, argv, ":", long_opts, NULL)) != -1) && 110 if (argc < 2)
127 !parse_error) {
128 switch (i) {
129 default:
130 case '?':
131 /* Unhandled option */
132 parse_error = 1;
133 break;
134
135 case 0:
136 /* silently handled option */
137 break;
138
139 case OPT_KLOADADDR:
140 kernel_body_load_address = strtoul(optarg, &e, 0);
141 if (!*optarg || (e && *e)) {
142 fprintf(stderr, "Invalid --kloadaddr\n");
143 parse_error = 1;
144 }
145 break;
146 }
147 }
148
149 if (optind >= argc) {
150 fprintf(stderr, "Expected argument after options\n");
151 parse_error = 1;
152 } else
153 infile = argv[optind];
154
155 if (parse_error)
156 return PrintHelp(); 111 return PrintHelp();
157 112
158 if (!infile || !*infile) { 113 if (!infile || !*infile) {
159 error("Must specify filename\n"); 114 error("Must specify filename\n");
160 return 1; 115 return 1;
161 } 116 }
162 117
163 /* Map the kernel image blob. */ 118 /* Map the kernel image blob. */
164 blob = MapFile(infile, &blob_size); 119 blob = MapFile(infile, &blob_size);
165 if (!blob) { 120 if (!blob) {
166 error("Error reading input file\n"); 121 error("Error reading input file\n");
167 return 1; 122 return 1;
168 } 123 }
169 124
170 config = find_kernel_config(blob, (uint64_t)blob_size, 125 config = find_kernel_config(blob, (uint64_t)blob_size);
171 kernel_body_load_address);
172 if (!config) { 126 if (!config) {
173 error("Error parsing input file\n"); 127 error("Error parsing input file\n");
174 munmap(blob, blob_size); 128 munmap(blob, blob_size);
175 return 1; 129 return 1;
176 } 130 }
177 131
178 printf("%.*s", CROS_CONFIG_SIZE, config); 132 printf("%.*s", CROS_CONFIG_SIZE, config);
179 munmap(blob, blob_size); 133 munmap(blob, blob_size);
180 return 0; 134 return 0;
181 } 135 }
OLDNEW
« no previous file with comments | « no previous file | utility/vbutil_kernel.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698