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 | 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 #define ACPI_VBNV_PATH ACPI_BASE_PATH "/VBNV" | 77 #define ACPI_VBNV_PATH ACPI_BASE_PATH "/VBNV" |
78 #define ACPI_VDAT_PATH ACPI_BASE_PATH "/VDAT" | 78 #define ACPI_VDAT_PATH ACPI_BASE_PATH "/VDAT" |
79 | 79 |
80 /* Base name for GPIO files */ | 80 /* Base name for GPIO files */ |
81 #define GPIO_BASE_PATH "/sys/class/gpio" | 81 #define GPIO_BASE_PATH "/sys/class/gpio" |
82 #define GPIO_EXPORT_PATH GPIO_BASE_PATH "/export" | 82 #define GPIO_EXPORT_PATH GPIO_BASE_PATH "/export" |
83 | 83 |
84 /* Filename for NVRAM file */ | 84 /* Filename for NVRAM file */ |
85 #define NVRAM_PATH "/dev/nvram" | 85 #define NVRAM_PATH "/dev/nvram" |
86 | 86 |
| 87 /* Filename for legacy firmware update tries */ |
| 88 #define NEED_FWUPDATE_PATH "/mnt/stateful_partition/.need_firmware_update" |
| 89 |
87 | 90 |
88 int VbReadNvStorage(VbNvContext* vnc) { | 91 int VbReadNvStorage(VbNvContext* vnc) { |
89 FILE* f; | 92 FILE* f; |
90 int offs; | 93 int offs; |
91 | 94 |
92 /* Get the byte offset from VBNV */ | 95 /* Get the byte offset from VBNV */ |
93 offs = ReadFileInt(ACPI_VBNV_PATH ".0"); | 96 offs = ReadFileInt(ACPI_VBNV_PATH ".0"); |
94 if (offs == -1) | 97 if (offs == -1) |
95 return -1; | 98 return -1; |
96 if (VBNV_BLOCK_SIZE > ReadFileInt(ACPI_VBNV_PATH ".1")) | 99 if (VBNV_BLOCK_SIZE > ReadFileInt(ACPI_VBNV_PATH ".1")) |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 value = VbGetCmosRebootField(CMOSRF_RECOVERY); | 518 value = VbGetCmosRebootField(CMOSRF_RECOVERY); |
516 } else if (!strcasecmp(name,"dbg_reset")) { | 519 } else if (!strcasecmp(name,"dbg_reset")) { |
517 value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); | 520 value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); |
518 if (-1 == value) | 521 if (-1 == value) |
519 value = VbGetCmosRebootField(CMOSRF_DEBUG_RESET); | 522 value = VbGetCmosRebootField(CMOSRF_DEBUG_RESET); |
520 } else if (!strcasecmp(name,"fwb_tries")) { | 523 } else if (!strcasecmp(name,"fwb_tries")) { |
521 value = VbGetNvStorage(VBNV_TRY_B_COUNT); | 524 value = VbGetNvStorage(VBNV_TRY_B_COUNT); |
522 if (-1 == value) | 525 if (-1 == value) |
523 value = VbGetCmosRebootField(CMOSRF_TRY_B); | 526 value = VbGetCmosRebootField(CMOSRF_TRY_B); |
524 } | 527 } |
| 528 /* Firmware update tries is now stored in the kernel field. On |
| 529 * older systems where it's not, it was stored in a file in the |
| 530 * stateful partition. */ |
| 531 else if (!strcasecmp(name,"fwupdate_tries")) { |
| 532 if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) |
| 533 return -1; /* NvStorage supported; fail through arch-specific |
| 534 * implementation to normal implementation. */ |
| 535 |
| 536 /* Read value from file; missing file means value=0. */ |
| 537 value = ReadFileInt(NEED_FWUPDATE_PATH); |
| 538 if (-1 == value) |
| 539 value = 0; |
| 540 } |
525 | 541 |
526 return value; | 542 return value; |
527 } | 543 } |
528 | 544 |
529 | 545 |
530 const char* VbGetArchPropertyString(const char* name, char* dest, int size) { | 546 const char* VbGetArchPropertyString(const char* name, char* dest, int size) { |
531 | 547 |
532 if (!strcasecmp(name,"arch")) { | 548 if (!strcasecmp(name,"arch")) { |
533 return StrCopy(dest, "x86", size); | 549 return StrCopy(dest, "x86", size); |
534 } else if (!strcasecmp(name,"hwid")) { | 550 } else if (!strcasecmp(name,"hwid")) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 return VbSetCmosRebootField(CMOSRF_RECOVERY, value); | 590 return VbSetCmosRebootField(CMOSRF_RECOVERY, value); |
575 } else if (!strcasecmp(name,"dbg_reset")) { | 591 } else if (!strcasecmp(name,"dbg_reset")) { |
576 if (0 == VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value)) | 592 if (0 == VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value)) |
577 return 0; | 593 return 0; |
578 return VbSetCmosRebootField(CMOSRF_DEBUG_RESET, value); | 594 return VbSetCmosRebootField(CMOSRF_DEBUG_RESET, value); |
579 } else if (!strcasecmp(name,"fwb_tries")) { | 595 } else if (!strcasecmp(name,"fwb_tries")) { |
580 if (0 == VbSetNvStorage(VBNV_TRY_B_COUNT, value)) | 596 if (0 == VbSetNvStorage(VBNV_TRY_B_COUNT, value)) |
581 return 0; | 597 return 0; |
582 return VbSetCmosRebootField(CMOSRF_TRY_B, value); | 598 return VbSetCmosRebootField(CMOSRF_TRY_B, value); |
583 } | 599 } |
| 600 /* Firmware update tries is now stored in the kernel field. On |
| 601 * older systems where it's not, it was stored in a file in the |
| 602 * stateful partition. */ |
| 603 else if (!strcasecmp(name,"fwupdate_tries")) { |
| 604 if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) |
| 605 return -1; /* NvStorage supported; fail through arch-specific |
| 606 * implementation to normal implementation */ |
| 607 |
| 608 if (value) { |
| 609 char buf[32]; |
| 610 snprintf(buf, sizeof(buf), "%d", value); |
| 611 return WriteFile(NEED_FWUPDATE_PATH, buf, strlen(buf)); |
| 612 } else { |
| 613 /* No update tries, so remove file if it exists. */ |
| 614 unlink(NEED_FWUPDATE_PATH); |
| 615 return 0; |
| 616 } |
| 617 } |
584 | 618 |
585 return -1; | 619 return -1; |
586 } | 620 } |
587 | 621 |
588 | 622 |
589 int VbSetArchPropertyString(const char* name, const char* value) { | 623 int VbSetArchPropertyString(const char* name, const char* value) { |
590 /* If there were settable architecture-dependent string properties, | 624 /* If there were settable architecture-dependent string properties, |
591 * they'd be here. */ | 625 * they'd be here. */ |
592 return -1; | 626 return -1; |
593 } | 627 } |
OLD | NEW |