blob: 5bd4c62b4e1b1b7065a1ecd1a631c9c7c0495bdf [file] [log] [blame]
Randall Spangler54218662011-02-07 11:20:20 -08001/* 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
3 * found in the LICENSE file.
4 */
5
6#include <stdio.h>
7#include <string.h>
Vadim Bendebury20084232011-03-15 09:29:48 -07008#include <sys/types.h>
9#include <sys/stat.h>
10#include <unistd.h>
11#include <ctype.h>
Randall Spangler54218662011-02-07 11:20:20 -080012
13#include "host_common.h"
14
15#include "crossystem.h"
Randall Spanglereb591952011-04-07 10:02:00 -070016#include "crossystem_arch.h"
Randall Spangler54218662011-02-07 11:20:20 -080017#include "utility.h"
18#include "vboot_common.h"
Randall Spanglere73302c2011-02-18 14:53:01 -080019#include "vboot_nvstorage.h"
Randall Spanglerf4ba19d2011-03-17 16:10:21 -070020#include "vboot_struct.h"
Randall Spangler54218662011-02-07 11:20:20 -080021
Randall Spangler196e1772011-03-10 11:31:06 -080022/* Filename for kernel command line */
23#define KERNEL_CMDLINE_PATH "/proc/cmdline"
24
Randall Spanglerf4ba19d2011-03-17 16:10:21 -070025/* Fields that GetVdatString() can get */
26typedef enum VdatStringField {
Randall Spangler71415712011-03-21 11:04:50 -070027 VDAT_STRING_TIMERS = 0, /* Timer values */
28 VDAT_STRING_LOAD_FIRMWARE_DEBUG, /* LoadFirmware() debug information */
Randall Spanglera185b8d2011-07-15 16:28:38 -070029 VDAT_STRING_LOAD_KERNEL_DEBUG, /* LoadKernel() debug information */
30 VDAT_STRING_MAINFW_ACT /* Active main firmware */
Randall Spanglerf4ba19d2011-03-17 16:10:21 -070031} VdatStringField;
32
33
34/* Fields that GetVdatInt() can get */
35typedef enum VdatIntField {
Randall Spanglercabe6b32011-03-18 12:44:27 -070036 VDAT_INT_FLAGS = 0, /* Flags */
37 VDAT_INT_FW_VERSION_TPM, /* Current firmware version in TPM */
38 VDAT_INT_KERNEL_VERSION_TPM, /* Current kernel version in TPM */
39 VDAT_INT_TRIED_FIRMWARE_B, /* Tried firmware B due to fwb_tries */
Randall Spangler7adcc602011-06-24 16:11:45 -070040 VDAT_INT_KERNEL_KEY_VERIFIED, /* Kernel key verified using
Randall Spanglercabe6b32011-03-18 12:44:27 -070041 * signature, not just hash */
Randall Spangler7adcc602011-06-24 16:11:45 -070042 VDAT_INT_RECOVERY_REASON /* Recovery reason for current boot */
Randall Spanglerf4ba19d2011-03-17 16:10:21 -070043} VdatIntField;
44
45
Randall Spanglerff3f0002011-07-26 10:43:53 -070046/* Masks for kern_nv usage by kernel. */
Randall Spanglerd7728232011-04-08 14:04:21 -070047#define KERN_NV_FWUPDATE_TRIES_MASK 0x0000000F
Randall Spanglerff3f0002011-07-26 10:43:53 -070048/* If you want to use the remaining currently-unused bits in kern_nv
49 * for something kernel-y, define a new field (the way we did for
50 * fwupdate_tries). Don't just modify kern_nv directly, because that
51 * makes it too easy to accidentally corrupt other sub-fields. */
52#define KERN_NV_CURRENTLY_UNUSED 0xFFFFFFF0
Randall Spanglerd7728232011-04-08 14:04:21 -070053
Randall Spanglerc80fe652011-02-17 11:06:47 -080054/* Return true if the FWID starts with the specified string. */
Randall Spanglereb591952011-04-07 10:02:00 -070055int FwidStartsWith(const char *start) {
Randall Spanglerc80fe652011-02-17 11:06:47 -080056 char fwid[128];
57 if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid)))
58 return 0;
59
60 return 0 == strncmp(fwid, start, strlen(start));
61}
62
63
Randall Spangler0f8ffb12011-02-25 09:50:54 -080064int VbGetNvStorage(VbNvParam param) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -080065 VbNvContext vnc;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080066 uint32_t value;
67 int retval;
68
Randall Spangler0f8ffb12011-02-25 09:50:54 -080069 /* TODO: locking around NV access */
Randall Spanglereb591952011-04-07 10:02:00 -070070
71 if (0 != VbReadNvStorage(&vnc))
Randall Spangler0f8ffb12011-02-25 09:50:54 -080072 return -1;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080073 if (0 != VbNvSetup(&vnc))
74 return -1;
75 retval = VbNvGet(&vnc, param, &value);
76 if (0 != VbNvTeardown(&vnc))
77 return -1;
78 if (0 != retval)
79 return -1;
80
81 /* TODO: If vnc.raw_changed, attempt to reopen NVRAM for write and
82 * save the new defaults. If we're able to, log. */
83 /* TODO: release lock */
84
85 return (int)value;
86}
87
88
Randall Spangler0f8ffb12011-02-25 09:50:54 -080089int VbSetNvStorage(VbNvParam param, int value) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -080090 VbNvContext vnc;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080091 int retval = -1;
92 int i;
93
Randall Spanglereb591952011-04-07 10:02:00 -070094 if (0 != VbReadNvStorage(&vnc))
Randall Spangler0f8ffb12011-02-25 09:50:54 -080095 return -1;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080096
97 if (0 != VbNvSetup(&vnc))
98 goto VbSetNvCleanup;
99 i = VbNvSet(&vnc, param, (uint32_t)value);
100 if (0 != VbNvTeardown(&vnc))
101 goto VbSetNvCleanup;
102 if (0 != i)
103 goto VbSetNvCleanup;
104
105 if (vnc.raw_changed) {
Randall Spanglerd7728232011-04-08 14:04:21 -0700106 if (0 != VbWriteNvStorage(&vnc))
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800107 goto VbSetNvCleanup;
108 }
109
110 /* Success */
111 retval = 0;
112
113VbSetNvCleanup:
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800114 /* TODO: release lock */
115 return retval;
116}
117
118
Randall Spangler196e1772011-03-10 11:31:06 -0800119/* Determine whether OS-level debugging should be allowed. Passed the
120 * destination and its size. Returns 1 if yes, 0 if no, -1 if error. */
121int VbGetCrosDebug(void) {
122 FILE* f = NULL;
123 char buf[4096] = "";
Randall Spangler196e1772011-03-10 11:31:06 -0800124 char *t, *saveptr;
125
Randall Spanglereb591952011-04-07 10:02:00 -0700126 /* Try reading firmware type. */
127 if (VbGetArchPropertyString("mainfw_type", buf, sizeof(buf))) {
128 if (0 == strcmp(buf, "recovery"))
129 return 0; /* Recovery mode never allows debug. */
130 else if (0 == strcmp(buf, "developer"))
131 return 1; /* Developer firmware always allows debug. */
132 }
Randall Spangler196e1772011-03-10 11:31:06 -0800133
134 /* Normal new firmware, older ChromeOS firmware, or non-Chrome firmware.
Randall Spangler227f7922011-03-11 13:34:56 -0800135 * For all these cases, check /proc/cmdline for cros_[no]debug. */
Randall Spangler196e1772011-03-10 11:31:06 -0800136 f = fopen(KERNEL_CMDLINE_PATH, "rt");
137 if (f) {
138 if (NULL == fgets(buf, sizeof(buf), f))
139 *buf = 0;
140 fclose(f);
141 }
142 for (t = strtok_r(buf, " ", &saveptr); t; t=strtok_r(NULL, " ", &saveptr)) {
143 if (0 == strcmp(t, "cros_debug"))
144 return 1;
Randall Spangler227f7922011-03-11 13:34:56 -0800145 else if (0 == strcmp(t, "cros_nodebug"))
146 return 0;
Randall Spangler196e1772011-03-10 11:31:06 -0800147 }
148
149 /* Normal new firmware or older Chrome OS firmware allows debug if the
150 * dev switch is on. */
Randall Spanglereb591952011-04-07 10:02:00 -0700151 if (1 == VbGetSystemPropertyInt("devsw_boot"))
Randall Spangler196e1772011-03-10 11:31:06 -0800152 return 1;
153
154 /* All other cases disallow debug. */
155 return 0;
156}
157
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800158
Randall Spangler71415712011-03-21 11:04:50 -0700159char* GetVdatLoadFirmwareDebug(char* dest, int size,
160 const VbSharedDataHeader* sh) {
161 snprintf(dest, size,
162 "Check A result=%d\n"
163 "Check B result=%d\n"
164 "Firmware index booted=0x%02x\n"
165 "TPM combined version at start=0x%08x\n"
166 "Lowest combined version from firmware=0x%08x\n",
167 sh->check_fw_a_result,
168 sh->check_fw_b_result,
169 sh->firmware_index,
170 sh->fw_version_tpm_start,
171 sh->fw_version_lowest);
172 return dest;
173}
174
175
176#define TRUNCATED "\n(truncated)\n"
177
178char* GetVdatLoadKernelDebug(char* dest, int size,
179 const VbSharedDataHeader* sh) {
180 int used = 0;
181 int first_call_tracked = 0;
182 int call;
183
184 /* Make sure we have space for truncation warning */
185 if (size < strlen(TRUNCATED) + 1)
186 return NULL;
187 size -= strlen(TRUNCATED) + 1;
188
189 used += snprintf(
190 dest + used, size - used,
191 "Calls to LoadKernel()=%d\n",
192 sh->lk_call_count);
193 if (used > size)
194 goto LoadKernelDebugExit;
195
196 /* Report on the last calls */
197 if (sh->lk_call_count > VBSD_MAX_KERNEL_CALLS)
198 first_call_tracked = sh->lk_call_count - VBSD_MAX_KERNEL_CALLS;
199 for (call = first_call_tracked; call < sh->lk_call_count; call++) {
200 const VbSharedDataKernelCall* shc =
201 sh->lk_calls + (call & (VBSD_MAX_KERNEL_CALLS - 1));
202 int first_part_tracked = 0;
203 int part;
204
205 used += snprintf(
206 dest + used, size - used,
207 "Call %d:\n"
208 " Boot flags=0x%02x\n"
209 " Boot mode=%d\n"
210 " Test error=%d\n"
211 " Return code=%d\n"
212 " Debug flags=0x%02x\n"
213 " Drive sectors=%" PRIu64 "\n"
214 " Sector size=%d\n"
215 " Check result=%d\n"
216 " Kernel partitions found=%d\n",
217 call + 1,
218 shc->boot_flags,
219 shc->boot_mode,
220 shc->test_error_num,
221 shc->return_code,
222 shc->flags,
223 shc->sector_count,
224 shc->sector_size,
225 shc->check_result,
226 shc->kernel_parts_found);
227 if (used > size)
228 goto LoadKernelDebugExit;
229
230 /* If we found too many partitions, only prints ones where the
231 * structure has info. */
232 if (shc->kernel_parts_found > VBSD_MAX_KERNEL_PARTS)
233 first_part_tracked = shc->kernel_parts_found - VBSD_MAX_KERNEL_PARTS;
234
235 /* Report on the partitions checked */
236 for (part = first_part_tracked; part < shc->kernel_parts_found; part++) {
237 const VbSharedDataKernelPart* shp =
238 shc->parts + (part & (VBSD_MAX_KERNEL_PARTS - 1));
239
240 used += snprintf(
241 dest + used, size - used,
242 " Kernel %d:\n"
243 " GPT index=%d\n"
244 " Start sector=%" PRIu64 "\n"
245 " Sector count=%" PRIu64 "\n"
246 " Combined version=0x%08x\n"
247 " Check result=%d\n"
248 " Debug flags=0x%02x\n",
249 part + 1,
250 shp->gpt_index,
251 shp->sector_start,
252 shp->sector_count,
253 shp->combined_version,
254 shp->check_result,
255 shp->flags);
256 if (used > size)
257 goto LoadKernelDebugExit;
258 }
259 }
260
261LoadKernelDebugExit:
262
263 /* Warn if data was truncated; we left space for this above. */
264 if (used > size)
265 strcat(dest, TRUNCATED);
266
267 return dest;
268}
269
270
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700271char* GetVdatString(char* dest, int size, VdatStringField field)
272{
Randall Spanglereb591952011-04-07 10:02:00 -0700273 VbSharedDataHeader* sh = VbSharedDataRead();
Randall Spangler71415712011-03-21 11:04:50 -0700274 char* value = dest;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700275
Randall Spanglereb591952011-04-07 10:02:00 -0700276 if (!sh)
277 return NULL;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700278
279 switch (field) {
280 case VDAT_STRING_TIMERS:
281 snprintf(dest, size,
282 "LFS=%" PRIu64 ",%" PRIu64
283 " LF=%" PRIu64 ",%" PRIu64
284 " LK=%" PRIu64 ",%" PRIu64,
Randall Spangler96191122011-07-08 14:01:54 -0700285 sh->timer_vb_init_enter,
286 sh->timer_vb_init_exit,
287 sh->timer_vb_select_firmware_enter,
288 sh->timer_vb_select_firmware_exit,
289 sh->timer_vb_select_and_load_kernel_enter,
290 sh->timer_vb_select_and_load_kernel_exit);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700291 break;
292
293 case VDAT_STRING_LOAD_FIRMWARE_DEBUG:
Randall Spangler71415712011-03-21 11:04:50 -0700294 value = GetVdatLoadFirmwareDebug(dest, size, sh);
295 break;
296
297 case VDAT_STRING_LOAD_KERNEL_DEBUG:
298 value = GetVdatLoadKernelDebug(dest, size, sh);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700299 break;
300
Randall Spanglera185b8d2011-07-15 16:28:38 -0700301 case VDAT_STRING_MAINFW_ACT:
302 switch(sh->firmware_index) {
303 case 0:
304 StrCopy(dest, "A", size);
305 break;
306 case 1:
307 StrCopy(dest, "B", size);
308 break;
309 case 0xFF:
310 StrCopy(dest, "recovery", size);
311 break;
312 default:
313 value = NULL;
314 }
315 break;
316
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700317 default:
Randall Spanglereb591952011-04-07 10:02:00 -0700318 value = NULL;
319 break;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700320 }
321
Randall Spangler32a65262011-06-27 10:49:11 -0700322 free(sh);
Randall Spangler71415712011-03-21 11:04:50 -0700323 return value;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700324}
325
326
327int GetVdatInt(VdatIntField field) {
Randall Spanglereb591952011-04-07 10:02:00 -0700328 VbSharedDataHeader* sh = VbSharedDataRead();
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700329 int value = -1;
330
Randall Spanglereb591952011-04-07 10:02:00 -0700331 if (!sh)
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700332 return -1;
333
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700334 switch (field) {
335 case VDAT_INT_FLAGS:
336 value = (int)sh->flags;
337 break;
Randall Spangler5ac39bf2011-03-17 17:58:56 -0700338 case VDAT_INT_FW_VERSION_TPM:
339 value = (int)sh->fw_version_tpm;
340 break;
341 case VDAT_INT_KERNEL_VERSION_TPM:
342 value = (int)sh->kernel_version_tpm;
343 break;
Randall Spanglercabe6b32011-03-18 12:44:27 -0700344 case VDAT_INT_TRIED_FIRMWARE_B:
345 value = (sh->flags & VBSD_FWB_TRIED ? 1 : 0);
346 break;
347 case VDAT_INT_KERNEL_KEY_VERIFIED:
348 value = (sh->flags & VBSD_KERNEL_KEY_VERIFIED ? 1 : 0);
349 break;
Randall Spangler7adcc602011-06-24 16:11:45 -0700350 case VDAT_INT_RECOVERY_REASON:
351 /* Field added in struct version 2 */
352 if (sh->struct_version >= 2)
353 value = sh->recovery_reason;
354 break;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700355 }
356
Randall Spangler32a65262011-06-27 10:49:11 -0700357 free(sh);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700358 return value;
359}
360
361
Randall Spangler54218662011-02-07 11:20:20 -0800362int VbGetSystemPropertyInt(const char* name) {
Randall Spanglerc80fe652011-02-17 11:06:47 -0800363 int value = -1;
Randall Spangler54218662011-02-07 11:20:20 -0800364
Randall Spanglereb591952011-04-07 10:02:00 -0700365 /* Check architecture-dependent properties first */
366 value = VbGetArchPropertyInt(name);
367 if (-1 != value)
368 return value;
369
370 /* NV storage values */
Randall Spanglercabe6b32011-03-18 12:44:27 -0700371 else if (!strcasecmp(name,"kern_nv")) {
Randall Spangler618d17d2011-03-01 10:33:11 -0800372 value = VbGetNvStorage(VBNV_KERNEL_FIELD);
Randall Spanglerb4167142011-03-01 13:04:22 -0800373 } else if (!strcasecmp(name,"nvram_cleared")) {
374 value = VbGetNvStorage(VBNV_KERNEL_SETTINGS_RESET);
Randall Spanglerb17e8d32011-03-15 09:50:38 -0700375 } else if (!strcasecmp(name,"vbtest_errfunc")) {
376 value = VbGetNvStorage(VBNV_TEST_ERROR_FUNC);
377 } else if (!strcasecmp(name,"vbtest_errno")) {
378 value = VbGetNvStorage(VBNV_TEST_ERROR_NUM);
Randall Spanglereb591952011-04-07 10:02:00 -0700379 } else if (!strcasecmp(name,"recovery_request")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800380 value = VbGetNvStorage(VBNV_RECOVERY_REQUEST);
Randall Spanglere73302c2011-02-18 14:53:01 -0800381 } else if (!strcasecmp(name,"dbg_reset")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800382 value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE);
Randall Spanglere73302c2011-02-18 14:53:01 -0800383 } else if (!strcasecmp(name,"fwb_tries")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800384 value = VbGetNvStorage(VBNV_TRY_B_COUNT);
Randall Spanglerd7728232011-04-08 14:04:21 -0700385 } else if (!strcasecmp(name,"fwupdate_tries")) {
386 value = VbGetNvStorage(VBNV_KERNEL_FIELD);
387 if (value != -1)
388 value &= KERN_NV_FWUPDATE_TRIES_MASK;
Randall Spangler44a12762011-04-12 13:16:40 -0700389 } else if (!strcasecmp(name,"loc_idx")) {
390 value = VbGetNvStorage(VBNV_LOCALIZATION_INDEX);
Randall Spanglerdaa807c2011-07-11 10:55:18 -0700391 } else if (!strcasecmp(name,"dev_boot_usb")) {
392 value = VbGetNvStorage(VBNV_DEV_BOOT_USB);
Bill Richardsonfa9d7782011-11-09 09:11:34 -0800393 } else if (!strcasecmp(name,"dev_boot_custom")) {
394 value = VbGetNvStorage(VBNV_DEV_BOOT_CUSTOM);
Randall Spanglere73302c2011-02-18 14:53:01 -0800395 }
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800396 /* Other parameters */
Randall Spanglereb591952011-04-07 10:02:00 -0700397 else if (!strcasecmp(name,"cros_debug")) {
Randall Spangler196e1772011-03-10 11:31:06 -0800398 value = VbGetCrosDebug();
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700399 } else if (!strcasecmp(name,"vdat_flags")) {
400 value = GetVdatInt(VDAT_INT_FLAGS);
Randall Spangler5ac39bf2011-03-17 17:58:56 -0700401 } else if (!strcasecmp(name,"tpm_fwver")) {
402 value = GetVdatInt(VDAT_INT_FW_VERSION_TPM);
403 } else if (!strcasecmp(name,"tpm_kernver")) {
404 value = GetVdatInt(VDAT_INT_KERNEL_VERSION_TPM);
Randall Spanglercabe6b32011-03-18 12:44:27 -0700405 } else if (!strcasecmp(name,"tried_fwb")) {
406 value = GetVdatInt(VDAT_INT_TRIED_FIRMWARE_B);
Randall Spangler7adcc602011-06-24 16:11:45 -0700407 } else if (!strcasecmp(name,"recovery_reason")) {
408 value = GetVdatInt(VDAT_INT_RECOVERY_REASON);
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800409 }
Randall Spangler54218662011-02-07 11:20:20 -0800410
Randall Spanglerc80fe652011-02-17 11:06:47 -0800411 return value;
Randall Spangler54218662011-02-07 11:20:20 -0800412}
413
Randall Spangler54218662011-02-07 11:20:20 -0800414
Randall Spanglereb591952011-04-07 10:02:00 -0700415const char* VbGetSystemPropertyString(const char* name, char* dest, int size) {
416 /* Check architecture-dependent properties first */
417 if (VbGetArchPropertyString(name, dest, size))
418 return dest;
419
420 if (!strcasecmp(name,"kernkey_vfy")) {
Randall Spanglercabe6b32011-03-18 12:44:27 -0700421 switch(GetVdatInt(VDAT_INT_KERNEL_KEY_VERIFIED)) {
Randall Spangler17260282011-02-25 12:06:26 -0800422 case 0:
423 return "hash";
424 case 1:
425 return "sig";
426 default:
427 return NULL;
428 }
Randall Spanglera185b8d2011-07-15 16:28:38 -0700429 } else if (!strcasecmp(name, "mainfw_act")) {
430 return GetVdatString(dest, size, VDAT_STRING_MAINFW_ACT);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700431 } else if (!strcasecmp(name, "vdat_timers")) {
432 return GetVdatString(dest, size, VDAT_STRING_TIMERS);
433 } else if (!strcasecmp(name, "vdat_lfdebug")) {
434 return GetVdatString(dest, size, VDAT_STRING_LOAD_FIRMWARE_DEBUG);
Randall Spangler71415712011-03-21 11:04:50 -0700435 } else if (!strcasecmp(name, "vdat_lkdebug")) {
436 return GetVdatString(dest, size, VDAT_STRING_LOAD_KERNEL_DEBUG);
Randall Spanglereb591952011-04-07 10:02:00 -0700437 }
438
439 return NULL;
Randall Spangler54218662011-02-07 11:20:20 -0800440}
441
442
Randall Spangler54218662011-02-07 11:20:20 -0800443int VbSetSystemPropertyInt(const char* name, int value) {
Randall Spanglereb591952011-04-07 10:02:00 -0700444 /* Check architecture-dependent properties first */
Randall Spanglerd7728232011-04-08 14:04:21 -0700445
Randall Spanglereb591952011-04-07 10:02:00 -0700446 if (0 == VbSetArchPropertyInt(name, value))
447 return 0;
Randall Spangler54218662011-02-07 11:20:20 -0800448
Randall Spanglereb591952011-04-07 10:02:00 -0700449 /* NV storage values */
Randall Spanglerb4167142011-03-01 13:04:22 -0800450 if (!strcasecmp(name,"nvram_cleared")) {
451 /* Can only clear this flag; it's set inside the NV storage library. */
452 return VbSetNvStorage(VBNV_KERNEL_SETTINGS_RESET, 0);
Randall Spanglerb17e8d32011-03-15 09:50:38 -0700453 } else if (!strcasecmp(name,"vbtest_errfunc")) {
454 return VbSetNvStorage(VBNV_TEST_ERROR_FUNC, value);
455 } else if (!strcasecmp(name,"vbtest_errno")) {
456 return VbSetNvStorage(VBNV_TEST_ERROR_NUM, value);
Randall Spanglereb591952011-04-07 10:02:00 -0700457 } else if (!strcasecmp(name,"recovery_request")) {
458 return VbSetNvStorage(VBNV_RECOVERY_REQUEST, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800459 } else if (!strcasecmp(name,"dbg_reset")) {
Randall Spanglereb591952011-04-07 10:02:00 -0700460 return VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800461 } else if (!strcasecmp(name,"fwb_tries")) {
Randall Spanglereb591952011-04-07 10:02:00 -0700462 return VbSetNvStorage(VBNV_TRY_B_COUNT, value);
Randall Spanglerd7728232011-04-08 14:04:21 -0700463 } else if (!strcasecmp(name,"fwupdate_tries")) {
464 int kern_nv = VbGetNvStorage(VBNV_KERNEL_FIELD);
465 if (kern_nv == -1)
466 return -1;
467 kern_nv &= ~KERN_NV_FWUPDATE_TRIES_MASK;
468 kern_nv |= (value & KERN_NV_FWUPDATE_TRIES_MASK);
469 return VbSetNvStorage(VBNV_KERNEL_FIELD, kern_nv);
Randall Spangler44a12762011-04-12 13:16:40 -0700470 } else if (!strcasecmp(name,"loc_idx")) {
471 return VbSetNvStorage(VBNV_LOCALIZATION_INDEX, value);
Randall Spanglerdaa807c2011-07-11 10:55:18 -0700472 } else if (!strcasecmp(name,"dev_boot_usb")) {
473 return VbSetNvStorage(VBNV_DEV_BOOT_USB, value);
Bill Richardsonfa9d7782011-11-09 09:11:34 -0800474 } else if (!strcasecmp(name,"dev_boot_custom")) {
475 return VbSetNvStorage(VBNV_DEV_BOOT_CUSTOM, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800476 }
477
Randall Spangler54218662011-02-07 11:20:20 -0800478 return -1;
479}
480
481
Randall Spangler54218662011-02-07 11:20:20 -0800482int VbSetSystemPropertyString(const char* name, const char* value) {
Randall Spanglereb591952011-04-07 10:02:00 -0700483 /* Chain to architecture-dependent properties */
484 return VbSetArchPropertyString(name, value);
Randall Spangler54218662011-02-07 11:20:20 -0800485}