blob: 34c1de175759cd69da7f6e4df5aadb190026a684 [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 Spanglerd7728232011-04-08 14:04:21 -070046/* Masks for kern_nv usage by kernel */
47#define KERN_NV_FWUPDATE_TRIES_MASK 0x0000000F
48
49
Randall Spanglerc80fe652011-02-17 11:06:47 -080050/* Return true if the FWID starts with the specified string. */
Randall Spanglereb591952011-04-07 10:02:00 -070051int FwidStartsWith(const char *start) {
Randall Spanglerc80fe652011-02-17 11:06:47 -080052 char fwid[128];
53 if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid)))
54 return 0;
55
56 return 0 == strncmp(fwid, start, strlen(start));
57}
58
59
Randall Spangler0f8ffb12011-02-25 09:50:54 -080060int VbGetNvStorage(VbNvParam param) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -080061 VbNvContext vnc;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080062 uint32_t value;
63 int retval;
64
Randall Spangler0f8ffb12011-02-25 09:50:54 -080065 /* TODO: locking around NV access */
Randall Spanglereb591952011-04-07 10:02:00 -070066
67 if (0 != VbReadNvStorage(&vnc))
Randall Spangler0f8ffb12011-02-25 09:50:54 -080068 return -1;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080069 if (0 != VbNvSetup(&vnc))
70 return -1;
71 retval = VbNvGet(&vnc, param, &value);
72 if (0 != VbNvTeardown(&vnc))
73 return -1;
74 if (0 != retval)
75 return -1;
76
77 /* TODO: If vnc.raw_changed, attempt to reopen NVRAM for write and
78 * save the new defaults. If we're able to, log. */
79 /* TODO: release lock */
80
81 return (int)value;
82}
83
84
Randall Spangler0f8ffb12011-02-25 09:50:54 -080085int VbSetNvStorage(VbNvParam param, int value) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -080086 VbNvContext vnc;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080087 int retval = -1;
88 int i;
89
Randall Spanglereb591952011-04-07 10:02:00 -070090 if (0 != VbReadNvStorage(&vnc))
Randall Spangler0f8ffb12011-02-25 09:50:54 -080091 return -1;
Randall Spangler0f8ffb12011-02-25 09:50:54 -080092
93 if (0 != VbNvSetup(&vnc))
94 goto VbSetNvCleanup;
95 i = VbNvSet(&vnc, param, (uint32_t)value);
96 if (0 != VbNvTeardown(&vnc))
97 goto VbSetNvCleanup;
98 if (0 != i)
99 goto VbSetNvCleanup;
100
101 if (vnc.raw_changed) {
Randall Spanglerd7728232011-04-08 14:04:21 -0700102 if (0 != VbWriteNvStorage(&vnc))
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800103 goto VbSetNvCleanup;
104 }
105
106 /* Success */
107 retval = 0;
108
109VbSetNvCleanup:
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800110 /* TODO: release lock */
111 return retval;
112}
113
114
Randall Spangler196e1772011-03-10 11:31:06 -0800115/* Determine whether OS-level debugging should be allowed. Passed the
116 * destination and its size. Returns 1 if yes, 0 if no, -1 if error. */
117int VbGetCrosDebug(void) {
118 FILE* f = NULL;
119 char buf[4096] = "";
Randall Spangler196e1772011-03-10 11:31:06 -0800120 char *t, *saveptr;
121
Randall Spanglereb591952011-04-07 10:02:00 -0700122 /* Try reading firmware type. */
123 if (VbGetArchPropertyString("mainfw_type", buf, sizeof(buf))) {
124 if (0 == strcmp(buf, "recovery"))
125 return 0; /* Recovery mode never allows debug. */
126 else if (0 == strcmp(buf, "developer"))
127 return 1; /* Developer firmware always allows debug. */
128 }
Randall Spangler196e1772011-03-10 11:31:06 -0800129
130 /* Normal new firmware, older ChromeOS firmware, or non-Chrome firmware.
Randall Spangler227f7922011-03-11 13:34:56 -0800131 * For all these cases, check /proc/cmdline for cros_[no]debug. */
Randall Spangler196e1772011-03-10 11:31:06 -0800132 f = fopen(KERNEL_CMDLINE_PATH, "rt");
133 if (f) {
134 if (NULL == fgets(buf, sizeof(buf), f))
135 *buf = 0;
136 fclose(f);
137 }
138 for (t = strtok_r(buf, " ", &saveptr); t; t=strtok_r(NULL, " ", &saveptr)) {
139 if (0 == strcmp(t, "cros_debug"))
140 return 1;
Randall Spangler227f7922011-03-11 13:34:56 -0800141 else if (0 == strcmp(t, "cros_nodebug"))
142 return 0;
Randall Spangler196e1772011-03-10 11:31:06 -0800143 }
144
145 /* Normal new firmware or older Chrome OS firmware allows debug if the
146 * dev switch is on. */
Randall Spanglereb591952011-04-07 10:02:00 -0700147 if (1 == VbGetSystemPropertyInt("devsw_boot"))
Randall Spangler196e1772011-03-10 11:31:06 -0800148 return 1;
149
150 /* All other cases disallow debug. */
151 return 0;
152}
153
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800154
Randall Spangler71415712011-03-21 11:04:50 -0700155char* GetVdatLoadFirmwareDebug(char* dest, int size,
156 const VbSharedDataHeader* sh) {
157 snprintf(dest, size,
158 "Check A result=%d\n"
159 "Check B result=%d\n"
160 "Firmware index booted=0x%02x\n"
161 "TPM combined version at start=0x%08x\n"
162 "Lowest combined version from firmware=0x%08x\n",
163 sh->check_fw_a_result,
164 sh->check_fw_b_result,
165 sh->firmware_index,
166 sh->fw_version_tpm_start,
167 sh->fw_version_lowest);
168 return dest;
169}
170
171
172#define TRUNCATED "\n(truncated)\n"
173
174char* GetVdatLoadKernelDebug(char* dest, int size,
175 const VbSharedDataHeader* sh) {
176 int used = 0;
177 int first_call_tracked = 0;
178 int call;
179
180 /* Make sure we have space for truncation warning */
181 if (size < strlen(TRUNCATED) + 1)
182 return NULL;
183 size -= strlen(TRUNCATED) + 1;
184
185 used += snprintf(
186 dest + used, size - used,
187 "Calls to LoadKernel()=%d\n",
188 sh->lk_call_count);
189 if (used > size)
190 goto LoadKernelDebugExit;
191
192 /* Report on the last calls */
193 if (sh->lk_call_count > VBSD_MAX_KERNEL_CALLS)
194 first_call_tracked = sh->lk_call_count - VBSD_MAX_KERNEL_CALLS;
195 for (call = first_call_tracked; call < sh->lk_call_count; call++) {
196 const VbSharedDataKernelCall* shc =
197 sh->lk_calls + (call & (VBSD_MAX_KERNEL_CALLS - 1));
198 int first_part_tracked = 0;
199 int part;
200
201 used += snprintf(
202 dest + used, size - used,
203 "Call %d:\n"
204 " Boot flags=0x%02x\n"
205 " Boot mode=%d\n"
206 " Test error=%d\n"
207 " Return code=%d\n"
208 " Debug flags=0x%02x\n"
209 " Drive sectors=%" PRIu64 "\n"
210 " Sector size=%d\n"
211 " Check result=%d\n"
212 " Kernel partitions found=%d\n",
213 call + 1,
214 shc->boot_flags,
215 shc->boot_mode,
216 shc->test_error_num,
217 shc->return_code,
218 shc->flags,
219 shc->sector_count,
220 shc->sector_size,
221 shc->check_result,
222 shc->kernel_parts_found);
223 if (used > size)
224 goto LoadKernelDebugExit;
225
226 /* If we found too many partitions, only prints ones where the
227 * structure has info. */
228 if (shc->kernel_parts_found > VBSD_MAX_KERNEL_PARTS)
229 first_part_tracked = shc->kernel_parts_found - VBSD_MAX_KERNEL_PARTS;
230
231 /* Report on the partitions checked */
232 for (part = first_part_tracked; part < shc->kernel_parts_found; part++) {
233 const VbSharedDataKernelPart* shp =
234 shc->parts + (part & (VBSD_MAX_KERNEL_PARTS - 1));
235
236 used += snprintf(
237 dest + used, size - used,
238 " Kernel %d:\n"
239 " GPT index=%d\n"
240 " Start sector=%" PRIu64 "\n"
241 " Sector count=%" PRIu64 "\n"
242 " Combined version=0x%08x\n"
243 " Check result=%d\n"
244 " Debug flags=0x%02x\n",
245 part + 1,
246 shp->gpt_index,
247 shp->sector_start,
248 shp->sector_count,
249 shp->combined_version,
250 shp->check_result,
251 shp->flags);
252 if (used > size)
253 goto LoadKernelDebugExit;
254 }
255 }
256
257LoadKernelDebugExit:
258
259 /* Warn if data was truncated; we left space for this above. */
260 if (used > size)
261 strcat(dest, TRUNCATED);
262
263 return dest;
264}
265
266
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700267char* GetVdatString(char* dest, int size, VdatStringField field)
268{
Randall Spanglereb591952011-04-07 10:02:00 -0700269 VbSharedDataHeader* sh = VbSharedDataRead();
Randall Spangler71415712011-03-21 11:04:50 -0700270 char* value = dest;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700271
Randall Spanglereb591952011-04-07 10:02:00 -0700272 if (!sh)
273 return NULL;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700274
275 switch (field) {
276 case VDAT_STRING_TIMERS:
277 snprintf(dest, size,
278 "LFS=%" PRIu64 ",%" PRIu64
279 " LF=%" PRIu64 ",%" PRIu64
280 " LK=%" PRIu64 ",%" PRIu64,
Randall Spangler96191122011-07-08 14:01:54 -0700281 sh->timer_vb_init_enter,
282 sh->timer_vb_init_exit,
283 sh->timer_vb_select_firmware_enter,
284 sh->timer_vb_select_firmware_exit,
285 sh->timer_vb_select_and_load_kernel_enter,
286 sh->timer_vb_select_and_load_kernel_exit);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700287 break;
288
289 case VDAT_STRING_LOAD_FIRMWARE_DEBUG:
Randall Spangler71415712011-03-21 11:04:50 -0700290 value = GetVdatLoadFirmwareDebug(dest, size, sh);
291 break;
292
293 case VDAT_STRING_LOAD_KERNEL_DEBUG:
294 value = GetVdatLoadKernelDebug(dest, size, sh);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700295 break;
296
Randall Spanglera185b8d2011-07-15 16:28:38 -0700297 case VDAT_STRING_MAINFW_ACT:
298 switch(sh->firmware_index) {
299 case 0:
300 StrCopy(dest, "A", size);
301 break;
302 case 1:
303 StrCopy(dest, "B", size);
304 break;
305 case 0xFF:
306 StrCopy(dest, "recovery", size);
307 break;
308 default:
309 value = NULL;
310 }
311 break;
312
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700313 default:
Randall Spanglereb591952011-04-07 10:02:00 -0700314 value = NULL;
315 break;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700316 }
317
Randall Spangler32a65262011-06-27 10:49:11 -0700318 free(sh);
Randall Spangler71415712011-03-21 11:04:50 -0700319 return value;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700320}
321
322
323int GetVdatInt(VdatIntField field) {
Randall Spanglereb591952011-04-07 10:02:00 -0700324 VbSharedDataHeader* sh = VbSharedDataRead();
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700325 int value = -1;
326
Randall Spanglereb591952011-04-07 10:02:00 -0700327 if (!sh)
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700328 return -1;
329
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700330 switch (field) {
331 case VDAT_INT_FLAGS:
332 value = (int)sh->flags;
333 break;
Randall Spangler5ac39bf2011-03-17 17:58:56 -0700334 case VDAT_INT_FW_VERSION_TPM:
335 value = (int)sh->fw_version_tpm;
336 break;
337 case VDAT_INT_KERNEL_VERSION_TPM:
338 value = (int)sh->kernel_version_tpm;
339 break;
Randall Spanglercabe6b32011-03-18 12:44:27 -0700340 case VDAT_INT_TRIED_FIRMWARE_B:
341 value = (sh->flags & VBSD_FWB_TRIED ? 1 : 0);
342 break;
343 case VDAT_INT_KERNEL_KEY_VERIFIED:
344 value = (sh->flags & VBSD_KERNEL_KEY_VERIFIED ? 1 : 0);
345 break;
Randall Spangler7adcc602011-06-24 16:11:45 -0700346 case VDAT_INT_RECOVERY_REASON:
347 /* Field added in struct version 2 */
348 if (sh->struct_version >= 2)
349 value = sh->recovery_reason;
350 break;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700351 }
352
Randall Spangler32a65262011-06-27 10:49:11 -0700353 free(sh);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700354 return value;
355}
356
357
Randall Spangler54218662011-02-07 11:20:20 -0800358int VbGetSystemPropertyInt(const char* name) {
Randall Spanglerc80fe652011-02-17 11:06:47 -0800359 int value = -1;
Randall Spangler54218662011-02-07 11:20:20 -0800360
Randall Spanglereb591952011-04-07 10:02:00 -0700361 /* Check architecture-dependent properties first */
362 value = VbGetArchPropertyInt(name);
363 if (-1 != value)
364 return value;
365
366 /* NV storage values */
Randall Spanglercabe6b32011-03-18 12:44:27 -0700367 else if (!strcasecmp(name,"kern_nv")) {
Randall Spangler618d17d2011-03-01 10:33:11 -0800368 value = VbGetNvStorage(VBNV_KERNEL_FIELD);
Randall Spanglerb4167142011-03-01 13:04:22 -0800369 } else if (!strcasecmp(name,"nvram_cleared")) {
370 value = VbGetNvStorage(VBNV_KERNEL_SETTINGS_RESET);
Randall Spanglerb17e8d32011-03-15 09:50:38 -0700371 } else if (!strcasecmp(name,"vbtest_errfunc")) {
372 value = VbGetNvStorage(VBNV_TEST_ERROR_FUNC);
373 } else if (!strcasecmp(name,"vbtest_errno")) {
374 value = VbGetNvStorage(VBNV_TEST_ERROR_NUM);
Randall Spanglereb591952011-04-07 10:02:00 -0700375 } else if (!strcasecmp(name,"recovery_request")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800376 value = VbGetNvStorage(VBNV_RECOVERY_REQUEST);
Randall Spanglere73302c2011-02-18 14:53:01 -0800377 } else if (!strcasecmp(name,"dbg_reset")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800378 value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE);
Randall Spanglere73302c2011-02-18 14:53:01 -0800379 } else if (!strcasecmp(name,"fwb_tries")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800380 value = VbGetNvStorage(VBNV_TRY_B_COUNT);
Randall Spanglerd7728232011-04-08 14:04:21 -0700381 } else if (!strcasecmp(name,"fwupdate_tries")) {
382 value = VbGetNvStorage(VBNV_KERNEL_FIELD);
383 if (value != -1)
384 value &= KERN_NV_FWUPDATE_TRIES_MASK;
Randall Spangler44a12762011-04-12 13:16:40 -0700385 } else if (!strcasecmp(name,"loc_idx")) {
386 value = VbGetNvStorage(VBNV_LOCALIZATION_INDEX);
Randall Spanglerdaa807c2011-07-11 10:55:18 -0700387 } else if (!strcasecmp(name,"dev_boot_usb")) {
388 value = VbGetNvStorage(VBNV_DEV_BOOT_USB);
Randall Spanglere73302c2011-02-18 14:53:01 -0800389 }
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800390 /* Other parameters */
Randall Spanglereb591952011-04-07 10:02:00 -0700391 else if (!strcasecmp(name,"cros_debug")) {
Randall Spangler196e1772011-03-10 11:31:06 -0800392 value = VbGetCrosDebug();
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700393 } else if (!strcasecmp(name,"vdat_flags")) {
394 value = GetVdatInt(VDAT_INT_FLAGS);
Randall Spangler5ac39bf2011-03-17 17:58:56 -0700395 } else if (!strcasecmp(name,"tpm_fwver")) {
396 value = GetVdatInt(VDAT_INT_FW_VERSION_TPM);
397 } else if (!strcasecmp(name,"tpm_kernver")) {
398 value = GetVdatInt(VDAT_INT_KERNEL_VERSION_TPM);
Randall Spanglercabe6b32011-03-18 12:44:27 -0700399 } else if (!strcasecmp(name,"tried_fwb")) {
400 value = GetVdatInt(VDAT_INT_TRIED_FIRMWARE_B);
Randall Spangler7adcc602011-06-24 16:11:45 -0700401 } else if (!strcasecmp(name,"recovery_reason")) {
402 value = GetVdatInt(VDAT_INT_RECOVERY_REASON);
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800403 }
Randall Spangler54218662011-02-07 11:20:20 -0800404
Randall Spanglerc80fe652011-02-17 11:06:47 -0800405 return value;
Randall Spangler54218662011-02-07 11:20:20 -0800406}
407
Randall Spangler54218662011-02-07 11:20:20 -0800408
Randall Spanglereb591952011-04-07 10:02:00 -0700409const char* VbGetSystemPropertyString(const char* name, char* dest, int size) {
410 /* Check architecture-dependent properties first */
411 if (VbGetArchPropertyString(name, dest, size))
412 return dest;
413
414 if (!strcasecmp(name,"kernkey_vfy")) {
Randall Spanglercabe6b32011-03-18 12:44:27 -0700415 switch(GetVdatInt(VDAT_INT_KERNEL_KEY_VERIFIED)) {
Randall Spangler17260282011-02-25 12:06:26 -0800416 case 0:
417 return "hash";
418 case 1:
419 return "sig";
420 default:
421 return NULL;
422 }
Randall Spanglera185b8d2011-07-15 16:28:38 -0700423 } else if (!strcasecmp(name, "mainfw_act")) {
424 return GetVdatString(dest, size, VDAT_STRING_MAINFW_ACT);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700425 } else if (!strcasecmp(name, "vdat_timers")) {
426 return GetVdatString(dest, size, VDAT_STRING_TIMERS);
427 } else if (!strcasecmp(name, "vdat_lfdebug")) {
428 return GetVdatString(dest, size, VDAT_STRING_LOAD_FIRMWARE_DEBUG);
Randall Spangler71415712011-03-21 11:04:50 -0700429 } else if (!strcasecmp(name, "vdat_lkdebug")) {
430 return GetVdatString(dest, size, VDAT_STRING_LOAD_KERNEL_DEBUG);
Randall Spanglereb591952011-04-07 10:02:00 -0700431 }
432
433 return NULL;
Randall Spangler54218662011-02-07 11:20:20 -0800434}
435
436
Randall Spangler54218662011-02-07 11:20:20 -0800437int VbSetSystemPropertyInt(const char* name, int value) {
Randall Spanglereb591952011-04-07 10:02:00 -0700438 /* Check architecture-dependent properties first */
Randall Spanglerd7728232011-04-08 14:04:21 -0700439
Randall Spanglereb591952011-04-07 10:02:00 -0700440 if (0 == VbSetArchPropertyInt(name, value))
441 return 0;
Randall Spangler54218662011-02-07 11:20:20 -0800442
Randall Spanglereb591952011-04-07 10:02:00 -0700443 /* NV storage values */
Randall Spanglerb4167142011-03-01 13:04:22 -0800444 if (!strcasecmp(name,"nvram_cleared")) {
445 /* Can only clear this flag; it's set inside the NV storage library. */
446 return VbSetNvStorage(VBNV_KERNEL_SETTINGS_RESET, 0);
447 } else if (!strcasecmp(name,"kern_nv")) {
Randall Spangler618d17d2011-03-01 10:33:11 -0800448 return VbSetNvStorage(VBNV_KERNEL_FIELD, value);
Randall Spanglerb17e8d32011-03-15 09:50:38 -0700449 } else if (!strcasecmp(name,"vbtest_errfunc")) {
450 return VbSetNvStorage(VBNV_TEST_ERROR_FUNC, value);
451 } else if (!strcasecmp(name,"vbtest_errno")) {
452 return VbSetNvStorage(VBNV_TEST_ERROR_NUM, value);
Randall Spanglereb591952011-04-07 10:02:00 -0700453 } else if (!strcasecmp(name,"recovery_request")) {
454 return VbSetNvStorage(VBNV_RECOVERY_REQUEST, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800455 } else if (!strcasecmp(name,"dbg_reset")) {
Randall Spanglereb591952011-04-07 10:02:00 -0700456 return VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800457 } else if (!strcasecmp(name,"fwb_tries")) {
Randall Spanglereb591952011-04-07 10:02:00 -0700458 return VbSetNvStorage(VBNV_TRY_B_COUNT, value);
Randall Spanglerd7728232011-04-08 14:04:21 -0700459 } else if (!strcasecmp(name,"fwupdate_tries")) {
460 int kern_nv = VbGetNvStorage(VBNV_KERNEL_FIELD);
461 if (kern_nv == -1)
462 return -1;
463 kern_nv &= ~KERN_NV_FWUPDATE_TRIES_MASK;
464 kern_nv |= (value & KERN_NV_FWUPDATE_TRIES_MASK);
465 return VbSetNvStorage(VBNV_KERNEL_FIELD, kern_nv);
Randall Spangler44a12762011-04-12 13:16:40 -0700466 } else if (!strcasecmp(name,"loc_idx")) {
467 return VbSetNvStorage(VBNV_LOCALIZATION_INDEX, value);
Randall Spanglerdaa807c2011-07-11 10:55:18 -0700468 } else if (!strcasecmp(name,"dev_boot_usb")) {
469 return VbSetNvStorage(VBNV_DEV_BOOT_USB, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800470 }
471
Randall Spangler54218662011-02-07 11:20:20 -0800472 return -1;
473}
474
475
Randall Spangler54218662011-02-07 11:20:20 -0800476int VbSetSystemPropertyString(const char* name, const char* value) {
Randall Spanglereb591952011-04-07 10:02:00 -0700477 /* Chain to architecture-dependent properties */
478 return VbSetArchPropertyString(name, value);
Randall Spangler54218662011-02-07 11:20:20 -0800479}