| 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> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 {"recoverysw_cur", 0, 0, "Recovery switch current position"}, | 27 {"recoverysw_cur", 0, 0, "Recovery switch current position"}, |
| 28 {"recoverysw_boot", 0, 0, "Recovery switch position at boot"}, | 28 {"recoverysw_boot", 0, 0, "Recovery switch position at boot"}, |
| 29 {"recoverysw_ec_boot", 0, 0, "Recovery switch position at EC boot"}, | 29 {"recoverysw_ec_boot", 0, 0, "Recovery switch position at EC boot"}, |
| 30 {"wpsw_cur", 0, 0, "Firmware write protect switch current position"}, | 30 {"wpsw_cur", 0, 0, "Firmware write protect switch current position"}, |
| 31 {"wpsw_boot", 0, 0, "Firmware write protect switch position at boot"}, | 31 {"wpsw_boot", 0, 0, "Firmware write protect switch position at boot"}, |
| 32 {"recovery_reason", 0, 0, "Recovery mode reason for current boot"}, | 32 {"recovery_reason", 0, 0, "Recovery mode reason for current boot"}, |
| 33 {"savedmem_base", 0, 0, "RAM debug data area physical address", "0x%08x"}, | 33 {"savedmem_base", 0, 0, "RAM debug data area physical address", "0x%08x"}, |
| 34 {"savedmem_size", 0, 0, "RAM debug data area size in bytes"}, | 34 {"savedmem_size", 0, 0, "RAM debug data area size in bytes"}, |
| 35 {"fmap_base", 0, 0, "Main firmware flashmap physical address", "0x%08x"}, | 35 {"fmap_base", 0, 0, "Main firmware flashmap physical address", "0x%08x"}, |
| 36 {"tried_fwb", 0, 0, "Tried firmware B before A this boot"}, | 36 {"tried_fwb", 0, 0, "Tried firmware B before A this boot"}, |
| 37 {"cros_debug", 0, 0, "OS should allow debug features"}, |
| 37 /* Read-only strings */ | 38 /* Read-only strings */ |
| 38 {"hwid", 1, 0, "Hardware ID"}, | 39 {"hwid", 1, 0, "Hardware ID"}, |
| 39 {"fwid", 1, 0, "Active firmware ID"}, | 40 {"fwid", 1, 0, "Active firmware ID"}, |
| 40 {"ro_fwid", 1, 0, "Read-only firmware ID"}, | 41 {"ro_fwid", 1, 0, "Read-only firmware ID"}, |
| 41 {"mainfw_act", 1, 0, "Active main firmware"}, | 42 {"mainfw_act", 1, 0, "Active main firmware"}, |
| 42 {"mainfw_type", 1, 0, "Active main firmware type"}, | 43 {"mainfw_type", 1, 0, "Active main firmware type"}, |
| 43 {"ecfw_act", 1, 0, "Active EC firmware"}, | 44 {"ecfw_act", 1, 0, "Active EC firmware"}, |
| 44 {"kernkey_vfy", 1, 0, "Type of verification done on kernel key block"}, | 45 {"kernkey_vfy", 1, 0, "Type of verification done on kernel key block"}, |
| 45 /* Writable integers */ | 46 /* Writable integers */ |
| 46 {"nvram_cleared", 0, 1, "Have NV settings been lost? Write 0 to clear"}, | 47 {"nvram_cleared", 0, 1, "Have NV settings been lost? Write 0 to clear"}, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 void PrintHelp(const char *progname) { | 63 void PrintHelp(const char *progname) { |
| 63 const Param *p; | 64 const Param *p; |
| 64 | 65 |
| 65 printf("\nUsage:\n" | 66 printf("\nUsage:\n" |
| 66 " %s\n" | 67 " %s\n" |
| 67 " Prints all parameters with descriptions and current values.\n" | 68 " Prints all parameters with descriptions and current values.\n" |
| 68 " %s [param1 [param2 [...]]]\n" | 69 " %s [param1 [param2 [...]]]\n" |
| 69 " Prints the current value(s) of the parameter(s).\n" | 70 " Prints the current value(s) of the parameter(s).\n" |
| 70 " %s [param1=value1] [param2=value2 [...]]]\n" | 71 " %s [param1=value1] [param2=value2 [...]]]\n" |
| 71 " Sets the parameter(s) to the specified value(s).\n" | 72 " Sets the parameter(s) to the specified value(s).\n" |
| 73 " %s [param1?value1] [param2?value2 [...]]]\n" |
| 74 " Checks if the parameter(s) all contain the specified value(s).\n" |
| 75 "Stops at the first error." |
| 72 "\n" | 76 "\n" |
| 73 "Valid parameters:\n", progname, progname, progname); | 77 "Valid parameters:\n", progname, progname, progname, progname); |
| 74 for (p = sys_param_list; p->name; p++) | 78 for (p = sys_param_list; p->name; p++) |
| 75 printf(" %-22s %s\n", p->name, p->desc); | 79 printf(" %-22s %s\n", p->name, p->desc); |
| 76 } | 80 } |
| 77 | 81 |
| 78 | 82 |
| 79 /* Find the parameter in the list. | 83 /* Find the parameter in the list. |
| 80 * | 84 * |
| 81 * Returns the parameter, or NULL if no match. */ | 85 * Returns the parameter, or NULL if no match. */ |
| 82 const Param* FindParam(const char* name) { | 86 const Param* FindParam(const char* name) { |
| 83 const Param* p; | 87 const Param* p; |
| 84 for (p = sys_param_list; p->name; p++) { | 88 for (p = sys_param_list; p->name; p++) { |
| 85 if (!strcasecmp(p->name, name)) | 89 if (!strcasecmp(p->name, name)) |
| 86 return p; | 90 return p; |
| 87 } | 91 } |
| 88 return NULL; | 92 return NULL; |
| 89 } | 93 } |
| 90 | 94 |
| 91 | 95 |
| 92 /* Set the specified parameter. | 96 /* Set the specified parameter. |
| 93 * | 97 * |
| 94 * Returns 0 if success, non-zero if error. */ | 98 * Returns 0 if success, non-zero if error. */ |
| 95 int SetParam(const Param* p, const char* value) { | 99 int SetParam(const Param* p, const char* value) { |
| 96 if (!p->can_write) | 100 if (!p->can_write) |
| 97 return 1; /* Parameter is read-only */ | 101 return 1; /* Parameter is read-only */ |
| 98 | 102 |
| 99 if (p->is_string) { | 103 if (p->is_string) { |
| 100 return (0 == VbSetSystemPropertyString(p->name, value) ? 0 : 1); | 104 return (0 == VbSetSystemPropertyString(p->name, value) ? 0 : 1); |
| 101 } else { | 105 } else { |
| 102 char* e; | 106 char* e; |
| 103 int i = strtol(value, &e, 0); | 107 int i = (int)strtol(value, &e, 0); |
| 104 if (!*value || (e && *e)) | 108 if (!*value || (e && *e)) |
| 105 return 1; | 109 return 1; |
| 106 return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1); | 110 return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1); |
| 107 } | 111 } |
| 108 } | 112 } |
| 109 | 113 |
| 110 | 114 |
| 115 /* Compares the parameter with the expected value. |
| 116 * |
| 117 * Returns 0 if success (match), non-zero if error (mismatch). */ |
| 118 int CheckParam(const Param* p, char* expect) { |
| 119 if (p->is_string) { |
| 120 char buf[256]; |
| 121 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); |
| 122 if (!v || 0 != strcmp(v, expect)) |
| 123 return 1; |
| 124 } else { |
| 125 char* e; |
| 126 int i = (int)strtol(expect, &e, 0); |
| 127 int v = VbGetSystemPropertyInt(p->name); |
| 128 if (!*expect || (e && *e)) |
| 129 return 1; |
| 130 if (v == -1 || i != v) |
| 131 return 1; |
| 132 } |
| 133 return 0; |
| 134 } |
| 135 |
| 136 |
| 111 /* Print the specified parameter. | 137 /* Print the specified parameter. |
| 112 * | 138 * |
| 113 * Returns 0 if success, non-zero if error. */ | 139 * Returns 0 if success, non-zero if error. */ |
| 114 int PrintParam(const Param* p) { | 140 int PrintParam(const Param* p) { |
| 115 if (p->is_string) { | 141 if (p->is_string) { |
| 116 char buf[256]; | 142 char buf[256]; |
| 117 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); | 143 const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); |
| 118 if (!v) | 144 if (!v) |
| 119 return 1; | 145 return 1; |
| 120 printf("%s", v); | 146 printf("%s", v); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return PrintAllParams(); | 197 return PrintAllParams(); |
| 172 | 198 |
| 173 /* Print help if needed */ | 199 /* Print help if needed */ |
| 174 if (!strcasecmp(argv[1], "-h") || !strcmp(argv[1], "-?")) { | 200 if (!strcasecmp(argv[1], "-h") || !strcmp(argv[1], "-?")) { |
| 175 PrintHelp(progname); | 201 PrintHelp(progname); |
| 176 return 0; | 202 return 0; |
| 177 } | 203 } |
| 178 | 204 |
| 179 /* Otherwise, loop through params and get/set them */ | 205 /* Otherwise, loop through params and get/set them */ |
| 180 for (i = 1; i < argc && retval == 0; i++) { | 206 for (i = 1; i < argc && retval == 0; i++) { |
| 181 char* name = strtok(argv[i], "="); | 207 int has_set = (NULL != strchr(argv[i], '=')); |
| 182 char* value = strtok(NULL, "="); | 208 int has_expect = (NULL != strchr(argv[i], '?')); |
| 209 char* name = strtok(argv[i], "=?"); |
| 210 char* value = strtok(NULL, "=?"); |
| 183 const Param* p = FindParam(name); | 211 const Param* p = FindParam(name); |
| 184 if (!p) { | 212 if (!p) { |
| 185 fprintf(stderr, "Invalid parameter name: %s\n", name); | 213 fprintf(stderr, "Invalid parameter name: %s\n", name); |
| 186 PrintHelp(progname); | 214 PrintHelp(progname); |
| 187 return 1; | 215 return 1; |
| 188 } | 216 } |
| 217 if (has_set && has_expect) { |
| 218 fprintf(stderr, "Use either = or ? in a parameter, but not both.\n"); |
| 219 PrintHelp(progname); |
| 220 return 1; |
| 221 } |
| 189 | 222 |
| 190 if (i > 1) | 223 if (i > 1) |
| 191 printf(" "); /* Output params space-delimited */ | 224 printf(" "); /* Output params space-delimited */ |
| 192 if (value) | 225 if (has_set) |
| 193 retval = SetParam(p, value); | 226 retval = SetParam(p, value); |
| 227 else if (has_expect) |
| 228 retval = CheckParam(p, value); |
| 194 else | 229 else |
| 195 retval = PrintParam(p); | 230 retval = PrintParam(p); |
| 196 } | 231 } |
| 197 | 232 |
| 198 return retval; | 233 return retval; |
| 199 } | 234 } |
| OLD | NEW |