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

Side by Side Diff: utility/crossystem_main.c

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

Powered by Google App Engine
This is Rietveld 408576698