blob: 80a3d3c2207e2d76bd36cd5d6523c1f454f9dae0 [file] [log] [blame]
Randall Spanglerc0e37422012-06-08 12:30:17 -07001/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Randall Spangler54218662011-02-07 11:20:20 -08002 * 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
J. Richard Barnettedbffddc2011-08-25 11:22:43 -0700126 /* If the currently running system specifies its debug status, use
127 * that in preference to other indicators. */
128 f = fopen(KERNEL_CMDLINE_PATH, "r");
129 if (NULL != f) {
Randall Spangler196e1772011-03-10 11:31:06 -0800130 if (NULL == fgets(buf, sizeof(buf), f))
J. Richard Barnettedbffddc2011-08-25 11:22:43 -0700131 buf[0] = 0;
Randall Spangler196e1772011-03-10 11:31:06 -0800132 fclose(f);
133 }
134 for (t = strtok_r(buf, " ", &saveptr); t; t=strtok_r(NULL, " ", &saveptr)) {
135 if (0 == strcmp(t, "cros_debug"))
136 return 1;
Randall Spangler227f7922011-03-11 13:34:56 -0800137 else if (0 == strcmp(t, "cros_nodebug"))
138 return 0;
Randall Spangler196e1772011-03-10 11:31:06 -0800139 }
140
J. Richard Barnettedbffddc2011-08-25 11:22:43 -0700141 /* Command line is silent; allow debug if the dev switch is on. */
Randall Spanglereb591952011-04-07 10:02:00 -0700142 if (1 == VbGetSystemPropertyInt("devsw_boot"))
Randall Spangler196e1772011-03-10 11:31:06 -0800143 return 1;
144
145 /* All other cases disallow debug. */
146 return 0;
147}
148
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800149
Randall Spangler71415712011-03-21 11:04:50 -0700150char* GetVdatLoadFirmwareDebug(char* dest, int size,
151 const VbSharedDataHeader* sh) {
152 snprintf(dest, size,
153 "Check A result=%d\n"
154 "Check B result=%d\n"
155 "Firmware index booted=0x%02x\n"
156 "TPM combined version at start=0x%08x\n"
157 "Lowest combined version from firmware=0x%08x\n",
158 sh->check_fw_a_result,
159 sh->check_fw_b_result,
160 sh->firmware_index,
161 sh->fw_version_tpm_start,
162 sh->fw_version_lowest);
163 return dest;
164}
165
166
167#define TRUNCATED "\n(truncated)\n"
168
169char* GetVdatLoadKernelDebug(char* dest, int size,
170 const VbSharedDataHeader* sh) {
171 int used = 0;
172 int first_call_tracked = 0;
173 int call;
174
175 /* Make sure we have space for truncation warning */
176 if (size < strlen(TRUNCATED) + 1)
177 return NULL;
178 size -= strlen(TRUNCATED) + 1;
179
180 used += snprintf(
181 dest + used, size - used,
182 "Calls to LoadKernel()=%d\n",
183 sh->lk_call_count);
184 if (used > size)
185 goto LoadKernelDebugExit;
186
187 /* Report on the last calls */
188 if (sh->lk_call_count > VBSD_MAX_KERNEL_CALLS)
189 first_call_tracked = sh->lk_call_count - VBSD_MAX_KERNEL_CALLS;
190 for (call = first_call_tracked; call < sh->lk_call_count; call++) {
191 const VbSharedDataKernelCall* shc =
192 sh->lk_calls + (call & (VBSD_MAX_KERNEL_CALLS - 1));
193 int first_part_tracked = 0;
194 int part;
195
196 used += snprintf(
197 dest + used, size - used,
198 "Call %d:\n"
199 " Boot flags=0x%02x\n"
200 " Boot mode=%d\n"
201 " Test error=%d\n"
202 " Return code=%d\n"
203 " Debug flags=0x%02x\n"
204 " Drive sectors=%" PRIu64 "\n"
205 " Sector size=%d\n"
206 " Check result=%d\n"
207 " Kernel partitions found=%d\n",
208 call + 1,
209 shc->boot_flags,
210 shc->boot_mode,
211 shc->test_error_num,
212 shc->return_code,
213 shc->flags,
214 shc->sector_count,
215 shc->sector_size,
216 shc->check_result,
217 shc->kernel_parts_found);
218 if (used > size)
219 goto LoadKernelDebugExit;
220
221 /* If we found too many partitions, only prints ones where the
222 * structure has info. */
223 if (shc->kernel_parts_found > VBSD_MAX_KERNEL_PARTS)
224 first_part_tracked = shc->kernel_parts_found - VBSD_MAX_KERNEL_PARTS;
225
226 /* Report on the partitions checked */
227 for (part = first_part_tracked; part < shc->kernel_parts_found; part++) {
228 const VbSharedDataKernelPart* shp =
229 shc->parts + (part & (VBSD_MAX_KERNEL_PARTS - 1));
230
231 used += snprintf(
232 dest + used, size - used,
233 " Kernel %d:\n"
234 " GPT index=%d\n"
235 " Start sector=%" PRIu64 "\n"
236 " Sector count=%" PRIu64 "\n"
237 " Combined version=0x%08x\n"
238 " Check result=%d\n"
239 " Debug flags=0x%02x\n",
240 part + 1,
241 shp->gpt_index,
242 shp->sector_start,
243 shp->sector_count,
244 shp->combined_version,
245 shp->check_result,
246 shp->flags);
247 if (used > size)
248 goto LoadKernelDebugExit;
249 }
250 }
251
252LoadKernelDebugExit:
253
254 /* Warn if data was truncated; we left space for this above. */
255 if (used > size)
256 strcat(dest, TRUNCATED);
257
258 return dest;
259}
260
261
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700262char* GetVdatString(char* dest, int size, VdatStringField field)
263{
Randall Spanglereb591952011-04-07 10:02:00 -0700264 VbSharedDataHeader* sh = VbSharedDataRead();
Randall Spangler71415712011-03-21 11:04:50 -0700265 char* value = dest;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700266
Randall Spanglereb591952011-04-07 10:02:00 -0700267 if (!sh)
268 return NULL;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700269
270 switch (field) {
271 case VDAT_STRING_TIMERS:
272 snprintf(dest, size,
273 "LFS=%" PRIu64 ",%" PRIu64
274 " LF=%" PRIu64 ",%" PRIu64
275 " LK=%" PRIu64 ",%" PRIu64,
Randall Spangler96191122011-07-08 14:01:54 -0700276 sh->timer_vb_init_enter,
277 sh->timer_vb_init_exit,
278 sh->timer_vb_select_firmware_enter,
279 sh->timer_vb_select_firmware_exit,
280 sh->timer_vb_select_and_load_kernel_enter,
281 sh->timer_vb_select_and_load_kernel_exit);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700282 break;
283
284 case VDAT_STRING_LOAD_FIRMWARE_DEBUG:
Randall Spangler71415712011-03-21 11:04:50 -0700285 value = GetVdatLoadFirmwareDebug(dest, size, sh);
286 break;
287
288 case VDAT_STRING_LOAD_KERNEL_DEBUG:
289 value = GetVdatLoadKernelDebug(dest, size, sh);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700290 break;
291
Randall Spanglera185b8d2011-07-15 16:28:38 -0700292 case VDAT_STRING_MAINFW_ACT:
293 switch(sh->firmware_index) {
294 case 0:
295 StrCopy(dest, "A", size);
296 break;
297 case 1:
298 StrCopy(dest, "B", size);
299 break;
300 case 0xFF:
301 StrCopy(dest, "recovery", size);
302 break;
303 default:
304 value = NULL;
305 }
306 break;
307
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700308 default:
Randall Spanglereb591952011-04-07 10:02:00 -0700309 value = NULL;
310 break;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700311 }
312
Randall Spangler32a65262011-06-27 10:49:11 -0700313 free(sh);
Randall Spangler71415712011-03-21 11:04:50 -0700314 return value;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700315}
316
317
318int GetVdatInt(VdatIntField field) {
Randall Spanglereb591952011-04-07 10:02:00 -0700319 VbSharedDataHeader* sh = VbSharedDataRead();
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700320 int value = -1;
321
Randall Spanglereb591952011-04-07 10:02:00 -0700322 if (!sh)
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700323 return -1;
324
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700325 switch (field) {
326 case VDAT_INT_FLAGS:
327 value = (int)sh->flags;
328 break;
Randall Spangler5ac39bf2011-03-17 17:58:56 -0700329 case VDAT_INT_FW_VERSION_TPM:
330 value = (int)sh->fw_version_tpm;
331 break;
332 case VDAT_INT_KERNEL_VERSION_TPM:
333 value = (int)sh->kernel_version_tpm;
334 break;
Randall Spanglercabe6b32011-03-18 12:44:27 -0700335 case VDAT_INT_TRIED_FIRMWARE_B:
336 value = (sh->flags & VBSD_FWB_TRIED ? 1 : 0);
337 break;
338 case VDAT_INT_KERNEL_KEY_VERIFIED:
339 value = (sh->flags & VBSD_KERNEL_KEY_VERIFIED ? 1 : 0);
340 break;
Randall Spangler7adcc602011-06-24 16:11:45 -0700341 case VDAT_INT_RECOVERY_REASON:
342 /* Field added in struct version 2 */
343 if (sh->struct_version >= 2)
344 value = sh->recovery_reason;
345 break;
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700346 }
347
Randall Spangler32a65262011-06-27 10:49:11 -0700348 free(sh);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700349 return value;
350}
351
352
Randall Spangler54218662011-02-07 11:20:20 -0800353int VbGetSystemPropertyInt(const char* name) {
Randall Spanglerc80fe652011-02-17 11:06:47 -0800354 int value = -1;
Randall Spangler54218662011-02-07 11:20:20 -0800355
Randall Spanglereb591952011-04-07 10:02:00 -0700356 /* Check architecture-dependent properties first */
357 value = VbGetArchPropertyInt(name);
358 if (-1 != value)
359 return value;
360
361 /* NV storage values */
Randall Spanglercabe6b32011-03-18 12:44:27 -0700362 else if (!strcasecmp(name,"kern_nv")) {
Randall Spangler618d17d2011-03-01 10:33:11 -0800363 value = VbGetNvStorage(VBNV_KERNEL_FIELD);
Randall Spanglerb4167142011-03-01 13:04:22 -0800364 } else if (!strcasecmp(name,"nvram_cleared")) {
365 value = VbGetNvStorage(VBNV_KERNEL_SETTINGS_RESET);
Randall Spanglereb591952011-04-07 10:02:00 -0700366 } else if (!strcasecmp(name,"recovery_request")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800367 value = VbGetNvStorage(VBNV_RECOVERY_REQUEST);
Randall Spanglere73302c2011-02-18 14:53:01 -0800368 } else if (!strcasecmp(name,"dbg_reset")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800369 value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE);
Bill Richardson35d07332012-05-25 12:55:58 -0700370 } else if (!strcasecmp(name,"disable_dev_request")) {
371 value = VbGetNvStorage(VBNV_DISABLE_DEV_REQUEST);
Randall Spanglere73302c2011-02-18 14:53:01 -0800372 } else if (!strcasecmp(name,"fwb_tries")) {
Randall Spangler0f8ffb12011-02-25 09:50:54 -0800373 value = VbGetNvStorage(VBNV_TRY_B_COUNT);
Randall Spanglerd7728232011-04-08 14:04:21 -0700374 } else if (!strcasecmp(name,"fwupdate_tries")) {
375 value = VbGetNvStorage(VBNV_KERNEL_FIELD);
376 if (value != -1)
377 value &= KERN_NV_FWUPDATE_TRIES_MASK;
Randall Spangler44a12762011-04-12 13:16:40 -0700378 } else if (!strcasecmp(name,"loc_idx")) {
379 value = VbGetNvStorage(VBNV_LOCALIZATION_INDEX);
Randall Spanglerdaa807c2011-07-11 10:55:18 -0700380 } else if (!strcasecmp(name,"dev_boot_usb")) {
381 value = VbGetNvStorage(VBNV_DEV_BOOT_USB);
Bill Richardson7272a692011-11-17 10:48:59 -0800382 } else if (!strcasecmp(name,"dev_boot_signed_only")) {
383 value = VbGetNvStorage(VBNV_DEV_BOOT_SIGNED_ONLY);
Bill Richardson17b82242012-06-26 16:33:56 -0700384 } else if (!strcasecmp(name,"oprom_needed")) {
385 value = VbGetNvStorage(VBNV_OPROM_NEEDED);
Randall Spanglere73302c2011-02-18 14:53:01 -0800386 }
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800387 /* Other parameters */
Randall Spanglereb591952011-04-07 10:02:00 -0700388 else if (!strcasecmp(name,"cros_debug")) {
Randall Spangler196e1772011-03-10 11:31:06 -0800389 value = VbGetCrosDebug();
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700390 } else if (!strcasecmp(name,"vdat_flags")) {
391 value = GetVdatInt(VDAT_INT_FLAGS);
Randall Spangler5ac39bf2011-03-17 17:58:56 -0700392 } else if (!strcasecmp(name,"tpm_fwver")) {
393 value = GetVdatInt(VDAT_INT_FW_VERSION_TPM);
394 } else if (!strcasecmp(name,"tpm_kernver")) {
395 value = GetVdatInt(VDAT_INT_KERNEL_VERSION_TPM);
Randall Spanglercabe6b32011-03-18 12:44:27 -0700396 } else if (!strcasecmp(name,"tried_fwb")) {
397 value = GetVdatInt(VDAT_INT_TRIED_FIRMWARE_B);
Randall Spangler7adcc602011-06-24 16:11:45 -0700398 } else if (!strcasecmp(name,"recovery_reason")) {
399 value = GetVdatInt(VDAT_INT_RECOVERY_REASON);
Randall Spanglerb47ed5a2011-02-23 13:05:40 -0800400 }
Randall Spangler54218662011-02-07 11:20:20 -0800401
Randall Spanglerc80fe652011-02-17 11:06:47 -0800402 return value;
Randall Spangler54218662011-02-07 11:20:20 -0800403}
404
Randall Spangler54218662011-02-07 11:20:20 -0800405
Randall Spanglereb591952011-04-07 10:02:00 -0700406const char* VbGetSystemPropertyString(const char* name, char* dest, int size) {
407 /* Check architecture-dependent properties first */
408 if (VbGetArchPropertyString(name, dest, size))
409 return dest;
410
411 if (!strcasecmp(name,"kernkey_vfy")) {
Randall Spanglercabe6b32011-03-18 12:44:27 -0700412 switch(GetVdatInt(VDAT_INT_KERNEL_KEY_VERIFIED)) {
Randall Spangler17260282011-02-25 12:06:26 -0800413 case 0:
414 return "hash";
415 case 1:
416 return "sig";
417 default:
418 return NULL;
419 }
Randall Spanglera185b8d2011-07-15 16:28:38 -0700420 } else if (!strcasecmp(name, "mainfw_act")) {
421 return GetVdatString(dest, size, VDAT_STRING_MAINFW_ACT);
Randall Spanglerf4ba19d2011-03-17 16:10:21 -0700422 } else if (!strcasecmp(name, "vdat_timers")) {
423 return GetVdatString(dest, size, VDAT_STRING_TIMERS);
424 } else if (!strcasecmp(name, "vdat_lfdebug")) {
425 return GetVdatString(dest, size, VDAT_STRING_LOAD_FIRMWARE_DEBUG);
Randall Spangler71415712011-03-21 11:04:50 -0700426 } else if (!strcasecmp(name, "vdat_lkdebug")) {
427 return GetVdatString(dest, size, VDAT_STRING_LOAD_KERNEL_DEBUG);
Randall Spanglereb591952011-04-07 10:02:00 -0700428 }
429
430 return NULL;
Randall Spangler54218662011-02-07 11:20:20 -0800431}
432
433
Randall Spangler54218662011-02-07 11:20:20 -0800434int VbSetSystemPropertyInt(const char* name, int value) {
Randall Spanglereb591952011-04-07 10:02:00 -0700435 /* Check architecture-dependent properties first */
Randall Spanglerd7728232011-04-08 14:04:21 -0700436
Randall Spanglereb591952011-04-07 10:02:00 -0700437 if (0 == VbSetArchPropertyInt(name, value))
438 return 0;
Randall Spangler54218662011-02-07 11:20:20 -0800439
Randall Spanglereb591952011-04-07 10:02:00 -0700440 /* NV storage values */
Randall Spanglerb4167142011-03-01 13:04:22 -0800441 if (!strcasecmp(name,"nvram_cleared")) {
442 /* Can only clear this flag; it's set inside the NV storage library. */
443 return VbSetNvStorage(VBNV_KERNEL_SETTINGS_RESET, 0);
Randall Spanglereb591952011-04-07 10:02:00 -0700444 } else if (!strcasecmp(name,"recovery_request")) {
445 return VbSetNvStorage(VBNV_RECOVERY_REQUEST, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800446 } else if (!strcasecmp(name,"dbg_reset")) {
Randall Spanglereb591952011-04-07 10:02:00 -0700447 return VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value);
Bill Richardson35d07332012-05-25 12:55:58 -0700448 } else if (!strcasecmp(name,"disable_dev_request")) {
449 return VbSetNvStorage(VBNV_DISABLE_DEV_REQUEST, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800450 } else if (!strcasecmp(name,"fwb_tries")) {
Randall Spanglereb591952011-04-07 10:02:00 -0700451 return VbSetNvStorage(VBNV_TRY_B_COUNT, value);
Randall Spanglerd7728232011-04-08 14:04:21 -0700452 } else if (!strcasecmp(name,"fwupdate_tries")) {
453 int kern_nv = VbGetNvStorage(VBNV_KERNEL_FIELD);
454 if (kern_nv == -1)
455 return -1;
456 kern_nv &= ~KERN_NV_FWUPDATE_TRIES_MASK;
457 kern_nv |= (value & KERN_NV_FWUPDATE_TRIES_MASK);
458 return VbSetNvStorage(VBNV_KERNEL_FIELD, kern_nv);
Randall Spangler44a12762011-04-12 13:16:40 -0700459 } else if (!strcasecmp(name,"loc_idx")) {
460 return VbSetNvStorage(VBNV_LOCALIZATION_INDEX, value);
Randall Spanglerdaa807c2011-07-11 10:55:18 -0700461 } else if (!strcasecmp(name,"dev_boot_usb")) {
462 return VbSetNvStorage(VBNV_DEV_BOOT_USB, value);
Bill Richardson7272a692011-11-17 10:48:59 -0800463 } else if (!strcasecmp(name,"dev_boot_signed_only")) {
464 return VbSetNvStorage(VBNV_DEV_BOOT_SIGNED_ONLY, value);
Bill Richardson17b82242012-06-26 16:33:56 -0700465 } else if (!strcasecmp(name,"oprom_needed")) {
466 return VbSetNvStorage(VBNV_OPROM_NEEDED, value);
Randall Spanglere73302c2011-02-18 14:53:01 -0800467 }
468
Randall Spangler54218662011-02-07 11:20:20 -0800469 return -1;
470}
471
472
Randall Spangler54218662011-02-07 11:20:20 -0800473int VbSetSystemPropertyString(const char* name, const char* value) {
Randall Spanglereb591952011-04-07 10:02:00 -0700474 /* Chain to architecture-dependent properties */
475 return VbSetArchPropertyString(name, value);
Randall Spangler54218662011-02-07 11:20:20 -0800476}