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

Side by Side Diff: utility/crossystem_main.c

Issue 6719005: Cherry-pick vboot_reference files from TOT to support crossystem (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@0.11.257.B
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 | « tests/vboot_nvstorage_test.c ('k') | utility/load_kernel_test.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) 2011 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2011 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 * Chrome OS firmware/system interface utility 5 * Chrome OS firmware/system interface utility
6 */ 6 */
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include "crossystem.h" 12 #include "crossystem.h"
13 13
14 /* Max length of a string parameter */
15 #define MAX_STRING 8192
16
17 /* Flags for Param */
18 #define IS_STRING 0x01 /* String (not present = integer) */
19 #define CAN_WRITE 0x02 /* Writable (not present = read-only */
20 #define NO_PRINT_ALL 0x04 /* Don't print contents of parameter when
21 * doing a print-all */
22
14 typedef struct Param { 23 typedef struct Param {
15 const char* name; /* Parameter name */ 24 const char* name; /* Parameter name */
16 int is_string; /* 0 if integer, 1 if string */ 25 int flags; /* Flags (see above) */
17 int can_write; /* 0 if read-only, 1 if writable */
18 const char* desc; /* Human-readable description */ 26 const char* desc; /* Human-readable description */
19 const char* format; /* Format string, if non-NULL and 0==is_string*/ 27 const char* format; /* Format string, if non-NULL and 0==is_string*/
20 } Param; 28 } Param;
21 29
22 /* List of parameters, terminated with a param with NULL name */ 30 /* List of parameters, terminated with a param with NULL name */
23 const Param sys_param_list[] = { 31 const Param sys_param_list[] = {
24 /* Read-only integers */ 32 /* Read-only integers */
25 {"devsw_cur", 0, 0, "Developer switch current position"}, 33 {"devsw_cur", 0, "Developer switch current position"},
26 {"devsw_boot", 0, 0, "Developer switch position at boot"}, 34 {"devsw_boot", 0, "Developer switch position at boot"},
27 {"recoverysw_cur", 0, 0, "Recovery switch current position"}, 35 {"recoverysw_cur", 0, "Recovery switch current position"},
28 {"recoverysw_boot", 0, 0, "Recovery switch position at boot"}, 36 {"recoverysw_boot", 0, "Recovery switch position at boot"},
29 {"recoverysw_ec_boot", 0, 0, "Recovery switch position at EC boot"}, 37 {"recoverysw_ec_boot", 0, "Recovery switch position at EC boot"},
30 {"wpsw_cur", 0, 0, "Firmware write protect switch current position"}, 38 {"wpsw_cur", 0, "Firmware write protect hardware switch current position"},
31 {"wpsw_boot", 0, 0, "Firmware write protect switch position at boot"}, 39 {"wpsw_boot", 0, "Firmware write protect hardware switch position at boot"},
32 {"recovery_reason", 0, 0, "Recovery mode reason for current boot"}, 40 {"recovery_reason", 0, "Recovery mode reason for current boot"},
33 {"savedmem_base", 0, 0, "RAM debug data area physical address", "0x%08x"}, 41 {"savedmem_base", 0, "RAM debug data area physical address", "0x%08x"},
34 {"savedmem_size", 0, 0, "RAM debug data area size in bytes"}, 42 {"savedmem_size", 0, "RAM debug data area size in bytes"},
35 {"fmap_base", 0, 0, "Main firmware flashmap physical address", "0x%08x"}, 43 {"fmap_base", 0, "Main firmware flashmap physical address", "0x%08x"},
36 {"tried_fwb", 0, 0, "Tried firmware B before A this boot"}, 44 {"tried_fwb", 0, "Tried firmware B before A this boot"},
37 {"cros_debug", 0, 0, "OS should allow debug features"}, 45 {"cros_debug", 0, "OS should allow debug features"},
46 {"vdat_flags", 0, "Flags from VbSharedData", "0x%08x"},
47 {"tpm_fwver", 0, "Firmware version stored in TPM", "0x%08x"},
48 {"tpm_kernver", 0, "Kernel version stored in TPM", "0x%08x"},
38 /* Read-only strings */ 49 /* Read-only strings */
39 {"hwid", 1, 0, "Hardware ID"}, 50 {"hwid", IS_STRING, "Hardware ID"},
40 {"fwid", 1, 0, "Active firmware ID"}, 51 {"fwid", IS_STRING, "Active firmware ID"},
41 {"ro_fwid", 1, 0, "Read-only firmware ID"}, 52 {"ro_fwid", IS_STRING, "Read-only firmware ID"},
42 {"mainfw_act", 1, 0, "Active main firmware"}, 53 {"mainfw_act", IS_STRING, "Active main firmware"},
43 {"mainfw_type", 1, 0, "Active main firmware type"}, 54 {"mainfw_type", IS_STRING, "Active main firmware type"},
44 {"ecfw_act", 1, 0, "Active EC firmware"}, 55 {"ecfw_act", IS_STRING, "Active EC firmware"},
45 {"kernkey_vfy", 1, 0, "Type of verification done on kernel key block"}, 56 {"kernkey_vfy", IS_STRING, "Type of verification done on kernel key block"},
57 {"vdat_timers", IS_STRING, "Timer values from VbSharedData"},
46 /* Writable integers */ 58 /* Writable integers */
47 {"nvram_cleared", 0, 1, "Have NV settings been lost? Write 0 to clear"}, 59 {"nvram_cleared", CAN_WRITE, "Have NV settings been lost? Write 0 to clear"},
48 {"kern_nv", 0, 1, "Non-volatile field for kernel use", "0x%08x"}, 60 {"kern_nv", CAN_WRITE, "Non-volatile field for kernel use", "0x%08x"},
49 {"recovery_request", 0, 1, "Recovery mode request (writable)"}, 61 {"recovery_request", CAN_WRITE, "Recovery mode request (writable)"},
50 {"dbg_reset", 0, 1, "Debug reset mode request (writable)"}, 62 {"dbg_reset", CAN_WRITE, "Debug reset mode request (writable)"},
51 {"fwb_tries", 0, 1, "Try firmware B count (writable)"}, 63 {"fwb_tries", CAN_WRITE, "Try firmware B count (writable)"},
52 64 {"vbtest_errfunc", CAN_WRITE, "Verified boot test error function (writable)"},
53 /* TODO: implement the following: 65 {"vbtest_errno", CAN_WRITE, "Verified boot test error number (writable)"},
54 * nvram_cleared 66 /* Fields not shown in a print-all list */
55 */ 67 {"vdat_lfdebug", IS_STRING|NO_PRINT_ALL,
56 68 "LoadFirmware() debug data (not in print-all)"},
69 {"vdat_lkdebug", IS_STRING|NO_PRINT_ALL,
70 "LoadKernel() debug data (not in print-all)"},
57 /* Terminate with null name */ 71 /* Terminate with null name */
58 {NULL, 0, 0, NULL} 72 {NULL, 0, NULL}
59 }; 73 };
60 74
61 75
62 /* Print help */ 76 /* Print help */
63 void PrintHelp(const char *progname) { 77 void PrintHelp(const char *progname) {
64 const Param *p; 78 const Param *p;
65 79
66 printf("\nUsage:\n" 80 printf("\nUsage:\n"
67 " %s\n" 81 " %s\n"
68 " Prints all parameters with descriptions and current values.\n" 82 " Prints all parameters with descriptions and current values.\n"
(...skipping 21 matching lines...) Expand all
90 return p; 104 return p;
91 } 105 }
92 return NULL; 106 return NULL;
93 } 107 }
94 108
95 109
96 /* Set the specified parameter. 110 /* Set the specified parameter.
97 * 111 *
98 * Returns 0 if success, non-zero if error. */ 112 * Returns 0 if success, non-zero if error. */
99 int SetParam(const Param* p, const char* value) { 113 int SetParam(const Param* p, const char* value) {
100 if (!p->can_write) 114 if (!(p->flags & CAN_WRITE))
101 return 1; /* Parameter is read-only */ 115 return 1; /* Parameter is read-only */
102 116
103 if (p->is_string) { 117 if (p->flags & IS_STRING) {
104 return (0 == VbSetSystemPropertyString(p->name, value) ? 0 : 1); 118 return (0 == VbSetSystemPropertyString(p->name, value) ? 0 : 1);
105 } else { 119 } else {
106 char* e; 120 char* e;
107 int i = (int)strtol(value, &e, 0); 121 int i = (int)strtol(value, &e, 0);
108 if (!*value || (e && *e)) 122 if (!*value || (e && *e))
109 return 1; 123 return 1;
110 return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1); 124 return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1);
111 } 125 }
112 } 126 }
113 127
114 128
115 /* Compares the parameter with the expected value. 129 /* Compares the parameter with the expected value.
116 * 130 *
117 * Returns 0 if success (match), non-zero if error (mismatch). */ 131 * Returns 0 if success (match), non-zero if error (mismatch). */
118 int CheckParam(const Param* p, char* expect) { 132 int CheckParam(const Param* p, char* expect) {
119 if (p->is_string) { 133 if (p->flags & IS_STRING) {
120 char buf[256]; 134 char buf[MAX_STRING];
121 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); 135 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf));
122 if (!v || 0 != strcmp(v, expect)) 136 if (!v || 0 != strcmp(v, expect))
123 return 1; 137 return 1;
124 } else { 138 } else {
125 char* e; 139 char* e;
126 int i = (int)strtol(expect, &e, 0); 140 int i = (int)strtol(expect, &e, 0);
127 int v = VbGetSystemPropertyInt(p->name); 141 int v = VbGetSystemPropertyInt(p->name);
128 if (!*expect || (e && *e)) 142 if (!*expect || (e && *e))
129 return 1; 143 return 1;
130 if (v == -1 || i != v) 144 if (v == -1 || i != v)
131 return 1; 145 return 1;
132 } 146 }
133 return 0; 147 return 0;
134 } 148 }
135 149
136 150
137 /* Print the specified parameter. 151 /* Print the specified parameter.
138 * 152 *
139 * Returns 0 if success, non-zero if error. */ 153 * Returns 0 if success, non-zero if error. */
140 int PrintParam(const Param* p) { 154 int PrintParam(const Param* p) {
141 if (p->is_string) { 155 if (p->flags & IS_STRING) {
142 char buf[256]; 156 char buf[MAX_STRING];
143 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); 157 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf));
144 if (!v) 158 if (!v)
145 return 1; 159 return 1;
146 printf("%s", v); 160 printf("%s", v);
147 } else { 161 } else {
148 int v = VbGetSystemPropertyInt(p->name); 162 int v = VbGetSystemPropertyInt(p->name);
149 if (v == -1) 163 if (v == -1)
150 return 1; 164 return 1;
151 printf(p->format ? p->format : "%d", v); 165 printf(p->format ? p->format : "%d", v);
152 } 166 }
153 return 0; 167 return 0;
154 } 168 }
155 169
156 170
157 /* Print all parameters with descriptions, 171 /* Print all parameters with descriptions,
158 * 172 *
159 * Returns 0 if success, non-zero if error. */ 173 * Returns 0 if success, non-zero if error. */
160 int PrintAllParams(void) { 174 int PrintAllParams(void) {
161 const Param* p; 175 const Param* p;
162 int retval = 0; 176 int retval = 0;
163 char buf[256]; 177 char buf[MAX_STRING];
164 const char* value; 178 const char* value;
165 179
166 for (p = sys_param_list; p->name; p++) { 180 for (p = sys_param_list; p->name; p++) {
167 if (p->is_string) { 181 if (p->flags & NO_PRINT_ALL)
182 continue;
183 if (p->flags & IS_STRING) {
168 value = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); 184 value = VbGetSystemPropertyString(p->name, buf, sizeof(buf));
169 } else { 185 } else {
170 int v = VbGetSystemPropertyInt(p->name); 186 int v = VbGetSystemPropertyInt(p->name);
171 if (v == -1) 187 if (v == -1)
172 value = NULL; 188 value = NULL;
173 else { 189 else {
174 snprintf(buf, sizeof(buf), p->format ? p->format : "%d", v); 190 snprintf(buf, sizeof(buf), p->format ? p->format : "%d", v);
175 value = buf; 191 value = buf;
176 } 192 }
177 } 193 }
178 printf("%-22s = %-20s # %s\n", 194 printf("%-22s = %-30s # %s\n",
179 p->name, (value ? value : "(error)"), p->desc); 195 p->name, (value ? value : "(error)"), p->desc);
180 } 196 }
181 return retval; 197 return retval;
182 } 198 }
183 199
184 200
185 int main(int argc, char* argv[]) { 201 int main(int argc, char* argv[]) {
186 int retval = 0; 202 int retval = 0;
187 int i; 203 int i;
188 204
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (has_set) 241 if (has_set)
226 retval = SetParam(p, value); 242 retval = SetParam(p, value);
227 else if (has_expect) 243 else if (has_expect)
228 retval = CheckParam(p, value); 244 retval = CheckParam(p, value);
229 else 245 else
230 retval = PrintParam(p); 246 retval = PrintParam(p);
231 } 247 }
232 248
233 return retval; 249 return retval;
234 } 250 }
OLDNEW
« no previous file with comments | « tests/vboot_nvstorage_test.c ('k') | utility/load_kernel_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698