Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: host/lib/crossystem.c

Issue 6813056: Add crossystem fwupdate_tries and fix nv storage writes (Closed) Base URL: ssh://gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utility/crossystem_main.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 5
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 23 matching lines...) Expand all
34 typedef enum VdatIntField { 34 typedef enum VdatIntField {
35 VDAT_INT_FLAGS = 0, /* Flags */ 35 VDAT_INT_FLAGS = 0, /* Flags */
36 VDAT_INT_FW_VERSION_TPM, /* Current firmware version in TPM */ 36 VDAT_INT_FW_VERSION_TPM, /* Current firmware version in TPM */
37 VDAT_INT_KERNEL_VERSION_TPM, /* Current kernel version in TPM */ 37 VDAT_INT_KERNEL_VERSION_TPM, /* Current kernel version in TPM */
38 VDAT_INT_TRIED_FIRMWARE_B, /* Tried firmware B due to fwb_tries */ 38 VDAT_INT_TRIED_FIRMWARE_B, /* Tried firmware B due to fwb_tries */
39 VDAT_INT_KERNEL_KEY_VERIFIED /* Kernel key verified using 39 VDAT_INT_KERNEL_KEY_VERIFIED /* Kernel key verified using
40 * signature, not just hash */ 40 * signature, not just hash */
41 } VdatIntField; 41 } VdatIntField;
42 42
43 43
44 /* Masks for kern_nv usage by kernel */
45 #define KERN_NV_FWUPDATE_TRIES_MASK 0x0000000F
46
47
44 /* Return true if the FWID starts with the specified string. */ 48 /* Return true if the FWID starts with the specified string. */
45 int FwidStartsWith(const char *start) { 49 int FwidStartsWith(const char *start) {
46 char fwid[128]; 50 char fwid[128];
47 if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid))) 51 if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid)))
48 return 0; 52 return 0;
49 53
50 return 0 == strncmp(fwid, start, strlen(start)); 54 return 0 == strncmp(fwid, start, strlen(start));
51 } 55 }
52 56
53 57
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 90
87 if (0 != VbNvSetup(&vnc)) 91 if (0 != VbNvSetup(&vnc))
88 goto VbSetNvCleanup; 92 goto VbSetNvCleanup;
89 i = VbNvSet(&vnc, param, (uint32_t)value); 93 i = VbNvSet(&vnc, param, (uint32_t)value);
90 if (0 != VbNvTeardown(&vnc)) 94 if (0 != VbNvTeardown(&vnc))
91 goto VbSetNvCleanup; 95 goto VbSetNvCleanup;
92 if (0 != i) 96 if (0 != i)
93 goto VbSetNvCleanup; 97 goto VbSetNvCleanup;
94 98
95 if (vnc.raw_changed) { 99 if (vnc.raw_changed) {
96 if (0 != VbReadNvStorage(&vnc)) 100 if (0 != VbWriteNvStorage(&vnc))
97 goto VbSetNvCleanup; 101 goto VbSetNvCleanup;
98 } 102 }
99 103
100 /* Success */ 104 /* Success */
101 retval = 0; 105 retval = 0;
102 106
103 VbSetNvCleanup: 107 VbSetNvCleanup:
104 /* TODO: release lock */ 108 /* TODO: release lock */
105 return retval; 109 return retval;
106 } 110 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } else if (!strcasecmp(name,"vbtest_errfunc")) { 348 } else if (!strcasecmp(name,"vbtest_errfunc")) {
345 value = VbGetNvStorage(VBNV_TEST_ERROR_FUNC); 349 value = VbGetNvStorage(VBNV_TEST_ERROR_FUNC);
346 } else if (!strcasecmp(name,"vbtest_errno")) { 350 } else if (!strcasecmp(name,"vbtest_errno")) {
347 value = VbGetNvStorage(VBNV_TEST_ERROR_NUM); 351 value = VbGetNvStorage(VBNV_TEST_ERROR_NUM);
348 } else if (!strcasecmp(name,"recovery_request")) { 352 } else if (!strcasecmp(name,"recovery_request")) {
349 value = VbGetNvStorage(VBNV_RECOVERY_REQUEST); 353 value = VbGetNvStorage(VBNV_RECOVERY_REQUEST);
350 } else if (!strcasecmp(name,"dbg_reset")) { 354 } else if (!strcasecmp(name,"dbg_reset")) {
351 value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); 355 value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE);
352 } else if (!strcasecmp(name,"fwb_tries")) { 356 } else if (!strcasecmp(name,"fwb_tries")) {
353 value = VbGetNvStorage(VBNV_TRY_B_COUNT); 357 value = VbGetNvStorage(VBNV_TRY_B_COUNT);
358 } else if (!strcasecmp(name,"fwupdate_tries")) {
359 value = VbGetNvStorage(VBNV_KERNEL_FIELD);
360 if (value != -1)
361 value &= KERN_NV_FWUPDATE_TRIES_MASK;
354 } 362 }
355 /* Other parameters */ 363 /* Other parameters */
356 else if (!strcasecmp(name,"cros_debug")) { 364 else if (!strcasecmp(name,"cros_debug")) {
357 value = VbGetCrosDebug(); 365 value = VbGetCrosDebug();
358 } else if (!strcasecmp(name,"vdat_flags")) { 366 } else if (!strcasecmp(name,"vdat_flags")) {
359 value = GetVdatInt(VDAT_INT_FLAGS); 367 value = GetVdatInt(VDAT_INT_FLAGS);
360 } else if (!strcasecmp(name,"tpm_fwver")) { 368 } else if (!strcasecmp(name,"tpm_fwver")) {
361 value = GetVdatInt(VDAT_INT_FW_VERSION_TPM); 369 value = GetVdatInt(VDAT_INT_FW_VERSION_TPM);
362 } else if (!strcasecmp(name,"tpm_kernver")) { 370 } else if (!strcasecmp(name,"tpm_kernver")) {
363 value = GetVdatInt(VDAT_INT_KERNEL_VERSION_TPM); 371 value = GetVdatInt(VDAT_INT_KERNEL_VERSION_TPM);
(...skipping 26 matching lines...) Expand all
390 } else if (!strcasecmp(name, "vdat_lkdebug")) { 398 } else if (!strcasecmp(name, "vdat_lkdebug")) {
391 return GetVdatString(dest, size, VDAT_STRING_LOAD_KERNEL_DEBUG); 399 return GetVdatString(dest, size, VDAT_STRING_LOAD_KERNEL_DEBUG);
392 } 400 }
393 401
394 return NULL; 402 return NULL;
395 } 403 }
396 404
397 405
398 int VbSetSystemPropertyInt(const char* name, int value) { 406 int VbSetSystemPropertyInt(const char* name, int value) {
399 /* Check architecture-dependent properties first */ 407 /* Check architecture-dependent properties first */
408
400 if (0 == VbSetArchPropertyInt(name, value)) 409 if (0 == VbSetArchPropertyInt(name, value))
401 return 0; 410 return 0;
402 411
403 /* NV storage values */ 412 /* NV storage values */
404 if (!strcasecmp(name,"nvram_cleared")) { 413 if (!strcasecmp(name,"nvram_cleared")) {
405 /* Can only clear this flag; it's set inside the NV storage library. */ 414 /* Can only clear this flag; it's set inside the NV storage library. */
406 return VbSetNvStorage(VBNV_KERNEL_SETTINGS_RESET, 0); 415 return VbSetNvStorage(VBNV_KERNEL_SETTINGS_RESET, 0);
407 } else if (!strcasecmp(name,"kern_nv")) { 416 } else if (!strcasecmp(name,"kern_nv")) {
408 return VbSetNvStorage(VBNV_KERNEL_FIELD, value); 417 return VbSetNvStorage(VBNV_KERNEL_FIELD, value);
409 } else if (!strcasecmp(name,"vbtest_errfunc")) { 418 } else if (!strcasecmp(name,"vbtest_errfunc")) {
410 return VbSetNvStorage(VBNV_TEST_ERROR_FUNC, value); 419 return VbSetNvStorage(VBNV_TEST_ERROR_FUNC, value);
411 } else if (!strcasecmp(name,"vbtest_errno")) { 420 } else if (!strcasecmp(name,"vbtest_errno")) {
412 return VbSetNvStorage(VBNV_TEST_ERROR_NUM, value); 421 return VbSetNvStorage(VBNV_TEST_ERROR_NUM, value);
413 } else if (!strcasecmp(name,"recovery_request")) { 422 } else if (!strcasecmp(name,"recovery_request")) {
414 return VbSetNvStorage(VBNV_RECOVERY_REQUEST, value); 423 return VbSetNvStorage(VBNV_RECOVERY_REQUEST, value);
415 } else if (!strcasecmp(name,"dbg_reset")) { 424 } else if (!strcasecmp(name,"dbg_reset")) {
416 return VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value); 425 return VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value);
417 } else if (!strcasecmp(name,"fwb_tries")) { 426 } else if (!strcasecmp(name,"fwb_tries")) {
418 return VbSetNvStorage(VBNV_TRY_B_COUNT, value); 427 return VbSetNvStorage(VBNV_TRY_B_COUNT, value);
428 } else if (!strcasecmp(name,"fwupdate_tries")) {
429 int kern_nv = VbGetNvStorage(VBNV_KERNEL_FIELD);
430 if (kern_nv == -1)
431 return -1;
432 kern_nv &= ~KERN_NV_FWUPDATE_TRIES_MASK;
433 kern_nv |= (value & KERN_NV_FWUPDATE_TRIES_MASK);
434 return VbSetNvStorage(VBNV_KERNEL_FIELD, kern_nv);
419 } 435 }
420 436
421 return -1; 437 return -1;
422 } 438 }
423 439
424 440
425 int VbSetSystemPropertyString(const char* name, const char* value) { 441 int VbSetSystemPropertyString(const char* name, const char* value) {
426 /* Chain to architecture-dependent properties */ 442 /* Chain to architecture-dependent properties */
427 return VbSetArchPropertyString(name, value); 443 return VbSetArchPropertyString(name, value);
428 } 444 }
OLDNEW
« no previous file with comments | « no previous file | utility/crossystem_main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698