OLD | NEW |
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 |
14 /* Flags for Param */ | 17 /* Flags for Param */ |
15 #define IS_STRING 0x01 /* String (not present = integer) */ | 18 #define IS_STRING 0x01 /* String (not present = integer) */ |
16 #define CAN_WRITE 0x02 /* Writable (not present = read-only */ | 19 #define CAN_WRITE 0x02 /* Writable (not present = read-only */ |
17 #define NO_PRINT_ALL 0x04 /* Don't print contents of parameter when | 20 #define NO_PRINT_ALL 0x04 /* Don't print contents of parameter when |
18 * doing a print-all */ | 21 * doing a print-all */ |
19 | 22 |
20 typedef struct Param { | 23 typedef struct Param { |
21 const char* name; /* Parameter name */ | 24 const char* name; /* Parameter name */ |
22 int flags; /* Flags (see above) */ | 25 int flags; /* Flags (see above) */ |
23 const char* desc; /* Human-readable description */ | 26 const char* desc; /* Human-readable description */ |
(...skipping 21 matching lines...) Expand all Loading... |
45 {"tpm_kernver", 0, "Kernel version stored in TPM", "0x%08x"}, | 48 {"tpm_kernver", 0, "Kernel version stored in TPM", "0x%08x"}, |
46 /* Read-only strings */ | 49 /* Read-only strings */ |
47 {"hwid", IS_STRING, "Hardware ID"}, | 50 {"hwid", IS_STRING, "Hardware ID"}, |
48 {"fwid", IS_STRING, "Active firmware ID"}, | 51 {"fwid", IS_STRING, "Active firmware ID"}, |
49 {"ro_fwid", IS_STRING, "Read-only firmware ID"}, | 52 {"ro_fwid", IS_STRING, "Read-only firmware ID"}, |
50 {"mainfw_act", IS_STRING, "Active main firmware"}, | 53 {"mainfw_act", IS_STRING, "Active main firmware"}, |
51 {"mainfw_type", IS_STRING, "Active main firmware type"}, | 54 {"mainfw_type", IS_STRING, "Active main firmware type"}, |
52 {"ecfw_act", IS_STRING, "Active EC firmware"}, | 55 {"ecfw_act", IS_STRING, "Active EC firmware"}, |
53 {"kernkey_vfy", IS_STRING, "Type of verification done on kernel key block"}, | 56 {"kernkey_vfy", IS_STRING, "Type of verification done on kernel key block"}, |
54 {"vdat_timers", IS_STRING, "Timer values from VbSharedData"}, | 57 {"vdat_timers", IS_STRING, "Timer values from VbSharedData"}, |
55 {"vdat_lfdebug", IS_STRING, "LoadFirmware() debug data VbSharedData"}, | |
56 /* Writable integers */ | 58 /* Writable integers */ |
57 {"nvram_cleared", CAN_WRITE, "Have NV settings been lost? Write 0 to clear"}, | 59 {"nvram_cleared", CAN_WRITE, "Have NV settings been lost? Write 0 to clear"}, |
58 {"kern_nv", CAN_WRITE, "Non-volatile field for kernel use", "0x%08x"}, | 60 {"kern_nv", CAN_WRITE, "Non-volatile field for kernel use", "0x%08x"}, |
59 {"recovery_request", CAN_WRITE, "Recovery mode request (writable)"}, | 61 {"recovery_request", CAN_WRITE, "Recovery mode request (writable)"}, |
60 {"dbg_reset", CAN_WRITE, "Debug reset mode request (writable)"}, | 62 {"dbg_reset", CAN_WRITE, "Debug reset mode request (writable)"}, |
61 {"fwb_tries", CAN_WRITE, "Try firmware B count (writable)"}, | 63 {"fwb_tries", CAN_WRITE, "Try firmware B count (writable)"}, |
62 {"vbtest_errfunc", CAN_WRITE, "Verified boot test error function (writable)"}, | 64 {"vbtest_errfunc", CAN_WRITE, "Verified boot test error function (writable)"}, |
63 {"vbtest_errno", CAN_WRITE, "Verified boot test error number (writable)"}, | 65 {"vbtest_errno", CAN_WRITE, "Verified boot test error number (writable)"}, |
64 | 66 /* Fields not shown in a print-all list */ |
| 67 {"vdat_lfdebug", IS_STRING|NO_PRINT_ALL, |
| 68 "LoadFirmware() debug data (not in print-all)"}, |
| 69 {"vdat_lkdebug", IS_STRING|NO_PRINT_ALL, |
| 70 "LoadKernel() debug data (not in print-all)"}, |
65 /* Terminate with null name */ | 71 /* Terminate with null name */ |
66 {NULL, 0, NULL} | 72 {NULL, 0, NULL} |
67 }; | 73 }; |
68 | 74 |
69 | 75 |
70 /* Print help */ | 76 /* Print help */ |
71 void PrintHelp(const char *progname) { | 77 void PrintHelp(const char *progname) { |
72 const Param *p; | 78 const Param *p; |
73 | 79 |
74 printf("\nUsage:\n" | 80 printf("\nUsage:\n" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1); | 124 return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1); |
119 } | 125 } |
120 } | 126 } |
121 | 127 |
122 | 128 |
123 /* Compares the parameter with the expected value. | 129 /* Compares the parameter with the expected value. |
124 * | 130 * |
125 * Returns 0 if success (match), non-zero if error (mismatch). */ | 131 * Returns 0 if success (match), non-zero if error (mismatch). */ |
126 int CheckParam(const Param* p, char* expect) { | 132 int CheckParam(const Param* p, char* expect) { |
127 if (p->flags & IS_STRING) { | 133 if (p->flags & IS_STRING) { |
128 char buf[256]; | 134 char buf[MAX_STRING]; |
129 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); | 135 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); |
130 if (!v || 0 != strcmp(v, expect)) | 136 if (!v || 0 != strcmp(v, expect)) |
131 return 1; | 137 return 1; |
132 } else { | 138 } else { |
133 char* e; | 139 char* e; |
134 int i = (int)strtol(expect, &e, 0); | 140 int i = (int)strtol(expect, &e, 0); |
135 int v = VbGetSystemPropertyInt(p->name); | 141 int v = VbGetSystemPropertyInt(p->name); |
136 if (!*expect || (e && *e)) | 142 if (!*expect || (e && *e)) |
137 return 1; | 143 return 1; |
138 if (v == -1 || i != v) | 144 if (v == -1 || i != v) |
139 return 1; | 145 return 1; |
140 } | 146 } |
141 return 0; | 147 return 0; |
142 } | 148 } |
143 | 149 |
144 | 150 |
145 /* Print the specified parameter. | 151 /* Print the specified parameter. |
146 * | 152 * |
147 * Returns 0 if success, non-zero if error. */ | 153 * Returns 0 if success, non-zero if error. */ |
148 int PrintParam(const Param* p) { | 154 int PrintParam(const Param* p) { |
149 if (p->flags & IS_STRING) { | 155 if (p->flags & IS_STRING) { |
150 char buf[256]; | 156 char buf[MAX_STRING]; |
151 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); | 157 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); |
152 if (!v) | 158 if (!v) |
153 return 1; | 159 return 1; |
154 printf("%s", v); | 160 printf("%s", v); |
155 } else { | 161 } else { |
156 int v = VbGetSystemPropertyInt(p->name); | 162 int v = VbGetSystemPropertyInt(p->name); |
157 if (v == -1) | 163 if (v == -1) |
158 return 1; | 164 return 1; |
159 printf(p->format ? p->format : "%d", v); | 165 printf(p->format ? p->format : "%d", v); |
160 } | 166 } |
161 return 0; | 167 return 0; |
162 } | 168 } |
163 | 169 |
164 | 170 |
165 /* Print all parameters with descriptions, | 171 /* Print all parameters with descriptions, |
166 * | 172 * |
167 * Returns 0 if success, non-zero if error. */ | 173 * Returns 0 if success, non-zero if error. */ |
168 int PrintAllParams(void) { | 174 int PrintAllParams(void) { |
169 const Param* p; | 175 const Param* p; |
170 int retval = 0; | 176 int retval = 0; |
171 char buf[256]; | 177 char buf[MAX_STRING]; |
172 const char* value; | 178 const char* value; |
173 | 179 |
174 for (p = sys_param_list; p->name; p++) { | 180 for (p = sys_param_list; p->name; p++) { |
175 if (p->flags & NO_PRINT_ALL) | 181 if (p->flags & NO_PRINT_ALL) |
176 continue; | 182 continue; |
177 if (p->flags & IS_STRING) { | 183 if (p->flags & IS_STRING) { |
178 value = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); | 184 value = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); |
179 } else { | 185 } else { |
180 int v = VbGetSystemPropertyInt(p->name); | 186 int v = VbGetSystemPropertyInt(p->name); |
181 if (v == -1) | 187 if (v == -1) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if (has_set) | 241 if (has_set) |
236 retval = SetParam(p, value); | 242 retval = SetParam(p, value); |
237 else if (has_expect) | 243 else if (has_expect) |
238 retval = CheckParam(p, value); | 244 retval = CheckParam(p, value); |
239 else | 245 else |
240 retval = PrintParam(p); | 246 retval = PrintParam(p); |
241 } | 247 } |
242 | 248 |
243 return retval; | 249 return retval; |
244 } | 250 } |
OLD | NEW |