diff options
author | Randall Spangler <rspangler@chromium.org> | 2017-11-27 15:37:13 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-12-11 15:16:25 -0800 |
commit | dff5852c2f41c240842b49549b212c36287d5e26 (patch) | |
tree | 20f31422c7dd6868ce58b156634ab5290963acfc /host | |
parent | 626340420e2ebc42f8f24b0b2c3d56cc73dc6e60 (diff) | |
download | vboot-dff5852c2f41c240842b49549b212c36287d5e26.tar.gz |
vboot: Use 2nvstorage instead of vboot_nvstorage
Remove the old vboot1 vboot_nvstorage library (VbNv*() functions) and
use the vboot2 library (vb2_nv_*()) instead. This is needed in
preparation for moving to 64-byte records; no sense in implementing
that change twice...
Should be (better be) no change in system behavior.
BUG=chromium:789276
BRANCH=none
TEST=make runtests
compare output of crossystem before/after change (should be identical)
Change-Id: I10f9975b0824263064b9a74a3c6daadcecc085d3
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/794732
Diffstat (limited to 'host')
-rw-r--r-- | host/arch/arm/lib/crossystem_arch.c | 30 | ||||
-rw-r--r-- | host/arch/mips/lib/crossystem_arch.c | 5 | ||||
-rw-r--r-- | host/arch/x86/lib/crossystem_arch.c | 43 | ||||
-rw-r--r-- | host/include/crossystem_vbnv.h | 10 | ||||
-rw-r--r-- | host/lib/crossystem.c | 235 | ||||
-rw-r--r-- | host/lib/include/crossystem_arch.h | 12 |
6 files changed, 163 insertions, 172 deletions
diff --git a/host/arch/arm/lib/crossystem_arch.c b/host/arch/arm/lib/crossystem_arch.c index 27741783..0a308416 100644 --- a/host/arch/arm/lib/crossystem_arch.c +++ b/host/arch/arm/lib/crossystem_arch.c @@ -20,7 +20,6 @@ #include <netinet/in.h> #include "vboot_common.h" -#include "vboot_nvstorage.h" #include "host_common.h" #include "crossystem.h" #include "crossystem_arch.h" @@ -245,8 +244,7 @@ out: return ret; } - -static int VbReadNvStorage_disk(VbNvContext* vnc) +static int vb2_read_nv_storage_disk(struct vb2_context *ctx) { int nvctx_fd = -1; uint8_t sector[SECTOR_SIZE]; @@ -262,7 +260,7 @@ static int VbReadNvStorage_disk(VbNvContext* vnc) return E_FAIL; snprintf(nvctx_path, sizeof(nvctx_path), NVCTX_PATH, emmc_dev); - if (size != sizeof(vnc->raw) || (size + offset > SECTOR_SIZE)) + if (size != sizeof(ctx->nvdata) || (size + offset > SECTOR_SIZE)) return E_FAIL; nvctx_fd = open(nvctx_path, O_RDONLY); @@ -279,7 +277,7 @@ static int VbReadNvStorage_disk(VbNvContext* vnc) __FUNCTION__, nvctx_path); goto out; } - memcpy(vnc->raw, sector+offset, size); + memcpy(ctx->nvdata, sector+offset, size); rv = 0; out: @@ -289,7 +287,7 @@ out: return rv; } -static int VbWriteNvStorage_disk(VbNvContext* vnc) +static int vb2_write_nv_storage_disk(struct vb2_context *ctx) { int nvctx_fd = -1; uint8_t sector[SECTOR_SIZE]; @@ -305,7 +303,7 @@ static int VbWriteNvStorage_disk(VbNvContext* vnc) return E_FAIL; snprintf(nvctx_path, sizeof(nvctx_path), NVCTX_PATH, emmc_dev); - if (size != sizeof(vnc->raw) || (size + offset > SECTOR_SIZE)) + if (size != sizeof(ctx->nvdata) || (size + offset > SECTOR_SIZE)) return E_FAIL; do { @@ -323,7 +321,7 @@ static int VbWriteNvStorage_disk(VbNvContext* vnc) __FUNCTION__, nvctx_path); break; } - memcpy(sector+offset, vnc->raw, size); + memcpy(sector+offset, ctx->nvdata, size); lseek(nvctx_fd, lba * SECTOR_SIZE, SEEK_SET); rv = write(nvctx_fd, sector, SECTOR_SIZE); if (rv <= 0) { @@ -351,35 +349,35 @@ static int VbWriteNvStorage_disk(VbNvContext* vnc) return rv; } -int VbReadNvStorage(VbNvContext* vnc) +int vb2_read_nv_storage(struct vb2_context *ctx) { /* Default to disk for older firmware which does not provide storage * type */ char *media; if (!FdtPropertyExist(FDT_NVSTORAGE_TYPE_PROP)) - return VbReadNvStorage_disk(vnc); + return vb2_read_nv_storage_disk(ctx); media = ReadFdtString(FDT_NVSTORAGE_TYPE_PROP); if (!strcmp(media, "disk")) - return VbReadNvStorage_disk(vnc); + return vb2_read_nv_storage_disk(ctx); if (!strcmp(media, "cros-ec") || !strcmp(media, "mkbp") || !strcmp(media, "flash")) - return VbReadNvStorage_mosys(vnc); + return vb2_read_nv_storage_mosys(ctx); return -1; } -int VbWriteNvStorage(VbNvContext* vnc) +int vb2_write_nv_storage(struct vb2_context *ctx) { /* Default to disk for older firmware which does not provide storage * type */ char *media; if (!FdtPropertyExist(FDT_NVSTORAGE_TYPE_PROP)) - return VbWriteNvStorage_disk(vnc); + return vb2_write_nv_storage_disk(ctx); media = ReadFdtString(FDT_NVSTORAGE_TYPE_PROP); if (!strcmp(media, "disk")) - return VbWriteNvStorage_disk(vnc); + return vb2_write_nv_storage_disk(ctx); if (!strcmp(media, "cros-ec") || !strcmp(media, "mkbp") || !strcmp(media, "flash")) - return VbWriteNvStorage_mosys(vnc); + return vb2_write_nv_storage_mosys(ctx); return -1; } diff --git a/host/arch/mips/lib/crossystem_arch.c b/host/arch/mips/lib/crossystem_arch.c index c0b25877..5c92c9d5 100644 --- a/host/arch/mips/lib/crossystem_arch.c +++ b/host/arch/mips/lib/crossystem_arch.c @@ -6,7 +6,6 @@ #include <string.h> #include "vboot_common.h" -#include "vboot_nvstorage.h" #include "host_common.h" #include "crossystem.h" #include "crossystem_arch.h" @@ -15,12 +14,12 @@ * wherever possible. They will need real implementation as part of of MIPS * firmware bringup. */ -int VbReadNvStorage(VbNvContext* vnc) +int vb2_read_nv_storage(struct vb2_context *ctx) { return -1; } -int VbWriteNvStorage(VbNvContext* vnc) +int vb2_write_nv_storage(struct vb2_context *ctx) { return -1; } diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c index 9f8ca663..f026a14f 100644 --- a/host/arch/x86/lib/crossystem_arch.c +++ b/host/arch/x86/lib/crossystem_arch.c @@ -22,7 +22,6 @@ #include "host_common.h" #include "utility.h" #include "vboot_common.h" -#include "vboot_nvstorage.h" #include "vboot_struct.h" @@ -156,7 +155,7 @@ static int VbCmosWrite(unsigned offs, size_t size, const void *ptr) } -int VbReadNvStorage(VbNvContext* vnc) +int vb2_read_nv_storage(struct vb2_context *ctx) { unsigned offs, blksz; @@ -168,18 +167,18 @@ int VbReadNvStorage(VbNvContext* vnc) if (VBNV_BLOCK_SIZE > blksz) return -1; /* NV storage block is too small */ - if (0 != VbCmosRead(offs, VBNV_BLOCK_SIZE, vnc->raw)) + if (0 != VbCmosRead(offs, sizeof(ctx->nvdata), ctx->nvdata)) return -1; return 0; } -int VbWriteNvStorage(VbNvContext* vnc) +int vb2_write_nv_storage(struct vb2_context *ctx) { unsigned offs, blksz; - if (!vnc->raw_changed) + if (!(ctx->flags & VB2_CONTEXT_NVDATA_CHANGED)) return 0; /* Nothing changed, so no need to write */ /* Get the byte offset from VBNV */ @@ -190,14 +189,14 @@ int VbWriteNvStorage(VbNvContext* vnc) if (VBNV_BLOCK_SIZE > blksz) return -1; /* NV storage block is too small */ - if (0 != VbCmosWrite(offs, VBNV_BLOCK_SIZE, vnc->raw)) + if (0 != VbCmosWrite(offs, sizeof(ctx->nvdata), ctx->nvdata)) return -1; /* Also attempt to write using mosys if using vboot2 */ VbSharedDataHeader *sh = VbSharedDataRead(); if (sh) { if (sh->flags & VBSD_BOOT_FIRMWARE_VBOOT2) - VbWriteNvStorage_mosys(vnc); + vb2_write_nv_storage_mosys(ctx); free(sh); } @@ -453,19 +452,19 @@ static int VbGetRecoveryReason(void) switch(value) { case BINF0_NORMAL: case BINF0_DEVELOPER: - return VBNV_RECOVERY_NOT_REQUESTED; + return VB2_RECOVERY_NOT_REQUESTED; case BINF0_RECOVERY_BUTTON: - return VBNV_RECOVERY_RO_MANUAL; + return VB2_RECOVERY_RO_MANUAL; case BINF0_RECOVERY_DEV_SCREEN_KEY: - return VBNV_RECOVERY_RW_DEV_SCREEN; + return VB2_RECOVERY_RW_DEV_SCREEN; case BINF0_RECOVERY_RW_FW_BAD: - return VBNV_RECOVERY_RO_INVALID_RW; + return VB2_RECOVERY_RO_INVALID_RW; case BINF0_RECOVERY_NO_OS: - return VBNV_RECOVERY_RW_NO_OS; + return VB2_RECOVERY_RW_NO_OS; case BINF0_RECOVERY_BAD_OS: - return VBNV_RECOVERY_RW_INVALID_OS; + return VB2_RECOVERY_RW_INVALID_OS; case BINF0_RECOVERY_OS_INITIATED: - return VBNV_RECOVERY_LEGACY; + return VB2_RECOVERY_LEGACY; default: /* Other values don't map cleanly to firmware type. */ return -1; @@ -817,15 +816,15 @@ int VbGetArchPropertyInt(const char* name) /* NV storage values. If unable to get from NV storage, fall back to * the CMOS reboot field used by older BIOS (e.g. Mario). */ if (!strcasecmp(name,"recovery_request")) { - value = VbGetNvStorage(VBNV_RECOVERY_REQUEST); + value = vb2_get_nv_storage(VB2_NV_RECOVERY_REQUEST); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_RECOVERY); } else if (!strcasecmp(name,"dbg_reset")) { - value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); + value = vb2_get_nv_storage(VB2_NV_DEBUG_RESET_MODE); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_DEBUG_RESET); } else if (!strcasecmp(name,"fwb_tries")) { - value = VbGetNvStorage(VBNV_TRY_B_COUNT); + value = vb2_get_nv_storage(VB2_NV_TRY_COUNT); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_TRY_B); } @@ -835,7 +834,7 @@ int VbGetArchPropertyInt(const char* name) * stateful partition. */ if (!strcasecmp(name,"fwupdate_tries")) { unsigned fwupdate_value; - if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) + if (-1 != vb2_get_nv_storage(VB2_NV_KERNEL_FIELD)) return -1; /* NvStorage supported; fail through * arch-specific implementation to normal * implementation. */ @@ -900,15 +899,15 @@ int VbSetArchPropertyInt(const char* name, int value) /* NV storage values. If unable to get from NV storage, fall back to * the CMOS reboot field used by older BIOS. */ if (!strcasecmp(name,"recovery_request")) { - if (0 == VbSetNvStorage(VBNV_RECOVERY_REQUEST, value)) + if (0 == vb2_set_nv_storage(VB2_NV_RECOVERY_REQUEST, value)) return 0; return VbSetCmosRebootField(CMOSRF_RECOVERY, value); } else if (!strcasecmp(name,"dbg_reset")) { - if (0 == VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value)) + if (0 == vb2_set_nv_storage(VB2_NV_DEBUG_RESET_MODE, value)) return 0; return VbSetCmosRebootField(CMOSRF_DEBUG_RESET, value); } else if (!strcasecmp(name,"fwb_tries")) { - if (0 == VbSetNvStorage(VBNV_TRY_B_COUNT, value)) + if (0 == vb2_set_nv_storage(VB2_NV_TRY_COUNT, value)) return 0; return VbSetCmosRebootField(CMOSRF_TRY_B, value); } @@ -916,7 +915,7 @@ int VbSetArchPropertyInt(const char* name, int value) * older systems where it's not, it was stored in a file in the * stateful partition. */ else if (!strcasecmp(name,"fwupdate_tries")) { - if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) + if (-1 != vb2_get_nv_storage(VB2_NV_KERNEL_FIELD)) return -1; /* NvStorage supported; fail through * arch-specific implementation to normal * implementation */ diff --git a/host/include/crossystem_vbnv.h b/host/include/crossystem_vbnv.h index 64e0c7c7..64b6b1d6 100644 --- a/host/include/crossystem_vbnv.h +++ b/host/include/crossystem_vbnv.h @@ -12,21 +12,21 @@ extern "C" { #endif -#include <vboot_nvstorage.h> +struct vb2_context; /** - * Attempt to read VbNvContext using mosys. + * Attempt to read non-volatile storage using mosys. * * Returns 0 if success, non-zero if error. */ -int VbReadNvStorage_mosys(VbNvContext* vnc); +int vb2_read_nv_storage_mosys(struct vb2_context *ctx); /** - * Attempt to write VbNvContext using mosys. + * Attempt to write non-volatile storage using mosys. * * Returns 0 if success, non-zero if error. */ -int VbWriteNvStorage_mosys(VbNvContext* vnc); +int vb2_write_nv_storage_mosys(struct vb2_context* ctx); #ifdef __cplusplus } diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c index 216ff32c..5a758616 100644 --- a/host/lib/crossystem.c +++ b/host/lib/crossystem.c @@ -16,6 +16,10 @@ #include <fcntl.h> #include <unistd.h> +#include "2sysincludes.h" +#include "2api.h" +#include "2nvstorage.h" + #include "host_common.h" #include "crossystem.h" @@ -23,7 +27,6 @@ #include "crossystem_vbnv.h" #include "utility.h" #include "vboot_common.h" -#include "vboot_nvstorage.h" #include "vboot_struct.h" /* Filename for kernel command line */ @@ -93,75 +96,58 @@ int FwidStartsWith(const char *start) static int vnc_read; -int VbGetNvStorage(VbNvParam param) +int vb2_get_nv_storage(enum vb2_nv_param param) { - uint32_t value; - int retval; - static VbNvContext cached_vnc; + static struct vb2_context cached_ctx; /* TODO: locking around NV access */ if (!vnc_read) { - if (0 != VbReadNvStorage(&cached_vnc)) + memset(&cached_ctx, 0, sizeof(cached_ctx)); + if (0 != vb2_read_nv_storage(&cached_ctx)) return -1; - vnc_read = 1; - } + vb2_nv_init(&cached_ctx); - if (0 != VbNvSetup(&cached_vnc)) - return -1; - retval = VbNvGet(&cached_vnc, param, &value); - if (0 != VbNvTeardown(&cached_vnc)) - return -1; - if (0 != retval) - return -1; + /* TODO: If vnc.raw_changed, attempt to reopen NVRAM for write + * and save the new defaults. If we're able to, log. */ - /* TODO: If vnc.raw_changed, attempt to reopen NVRAM for write and - * save the new defaults. If we're able to, log. */ - /* TODO: release lock */ + vnc_read = 1; + } - return (int)value; + return (int)vb2_nv_get(&cached_ctx, param); } -int VbSetNvStorage(VbNvParam param, int value) +int vb2_set_nv_storage(enum vb2_nv_param param, int value) { - VbNvContext vnc; - int retval = -1; - int i; + struct vb2_context ctx; - if (0 != VbReadNvStorage(&vnc)) + /* TODO: locking around NV access */ + memset(&ctx, 0, sizeof(ctx)); + if (0 != vb2_read_nv_storage(&ctx)) return -1; + vb2_nv_init(&ctx); + vb2_nv_set(&ctx, param, (uint32_t)value); - if (0 != VbNvSetup(&vnc)) - goto VbSetNvCleanup; - i = VbNvSet(&vnc, param, (uint32_t)value); - if (0 != VbNvTeardown(&vnc)) - goto VbSetNvCleanup; - if (0 != i) - goto VbSetNvCleanup; - - if (vnc.raw_changed) { + if (ctx.flags & VB2_CONTEXT_NVDATA_CHANGED) { vnc_read = 0; - if (0 != VbWriteNvStorage(&vnc)) - goto VbSetNvCleanup; + if (0 != vb2_write_nv_storage(&ctx)) + return -1; } /* Success */ - retval = 0; - -VbSetNvCleanup: - /* TODO: release lock */ - return retval; + return 0; } /* - * Set a param value, and try to flag it for persistent backup. - * It's okay if backup isn't supported. It's best-effort only. + * Set a param value, and try to flag it for persistent backup. It's okay if + * backup isn't supported (which it isn't, in current designs). It's + * best-effort only. */ -static int VbSetNvStorage_WithBackup(VbNvParam param, int value) +static int vb2_set_nv_storage_with_backup(enum vb2_nv_param param, int value) { int retval; - retval = VbSetNvStorage(param, value); + retval = vb2_set_nv_storage(param, value); if (!retval) - VbSetNvStorage(VBNV_BACKUP_NVRAM_REQUEST, 1); + vb2_set_nv_storage(VB2_NV_BACKUP_NVRAM_REQUEST, 1); return retval; } @@ -468,63 +454,62 @@ int VbGetSystemPropertyInt(const char *name) /* NV storage values */ else if (!strcasecmp(name,"kern_nv")) { - value = VbGetNvStorage(VBNV_KERNEL_FIELD); + value = vb2_get_nv_storage(VB2_NV_KERNEL_FIELD); } else if (!strcasecmp(name,"nvram_cleared")) { - value = VbGetNvStorage(VBNV_KERNEL_SETTINGS_RESET); + value = vb2_get_nv_storage(VB2_NV_KERNEL_SETTINGS_RESET); } else if (!strcasecmp(name,"recovery_request")) { - value = VbGetNvStorage(VBNV_RECOVERY_REQUEST); + value = vb2_get_nv_storage(VB2_NV_RECOVERY_REQUEST); } else if (!strcasecmp(name,"dbg_reset")) { - value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); + value = vb2_get_nv_storage(VB2_NV_DEBUG_RESET_MODE); } else if (!strcasecmp(name,"disable_dev_request")) { - value = VbGetNvStorage(VBNV_DISABLE_DEV_REQUEST); + value = vb2_get_nv_storage(VB2_NV_DISABLE_DEV_REQUEST); } else if (!strcasecmp(name,"clear_tpm_owner_request")) { - value = VbGetNvStorage(VBNV_CLEAR_TPM_OWNER_REQUEST); + value = vb2_get_nv_storage(VB2_NV_CLEAR_TPM_OWNER_REQUEST); } else if (!strcasecmp(name,"clear_tpm_owner_done")) { - value = VbGetNvStorage(VBNV_CLEAR_TPM_OWNER_DONE); + value = vb2_get_nv_storage(VB2_NV_CLEAR_TPM_OWNER_DONE); } else if (!strcasecmp(name,"tpm_rebooted")) { - value = VbGetNvStorage(VBNV_TPM_REQUESTED_REBOOT); - } else if (!strcasecmp(name,"fwb_tries")) { - value = VbGetNvStorage(VBNV_TRY_B_COUNT); + value = vb2_get_nv_storage(VB2_NV_TPM_REQUESTED_REBOOT); + } else if (!strcasecmp(name,"fwb_tries") || + !strcasecmp(name,"fw_try_count")) { + value = vb2_get_nv_storage(VB2_NV_TRY_COUNT); } else if (!strcasecmp(name,"fw_vboot2")) { value = GetVdatInt(VDAT_INT_FW_BOOT2); - } else if (!strcasecmp(name,"fw_try_count")) { - value = VbGetNvStorage(VBNV_FW_TRY_COUNT); } else if (!strcasecmp(name,"fwupdate_tries")) { - value = VbGetNvStorage(VBNV_KERNEL_FIELD); + value = vb2_get_nv_storage(VB2_NV_KERNEL_FIELD); if (value != -1) value &= KERN_NV_FWUPDATE_TRIES_MASK; } else if (!strcasecmp(name,"block_devmode")) { - value = VbGetNvStorage(VBNV_KERNEL_FIELD); + value = vb2_get_nv_storage(VB2_NV_KERNEL_FIELD); if (value != -1) { value &= KERN_NV_BLOCK_DEVMODE_FLAG; value = !!value; } } else if (!strcasecmp(name,"tpm_attack")) { - value = VbGetNvStorage(VBNV_KERNEL_FIELD); + value = vb2_get_nv_storage(VB2_NV_KERNEL_FIELD); if (value != -1) { value &= KERN_NV_TPM_ATTACK_FLAG; value = !!value; } } else if (!strcasecmp(name,"loc_idx")) { - value = VbGetNvStorage(VBNV_LOCALIZATION_INDEX); + value = vb2_get_nv_storage(VB2_NV_LOCALIZATION_INDEX); } else if (!strcasecmp(name,"backup_nvram_request")) { - value = VbGetNvStorage(VBNV_BACKUP_NVRAM_REQUEST); + value = vb2_get_nv_storage(VB2_NV_BACKUP_NVRAM_REQUEST); } else if (!strcasecmp(name,"dev_boot_usb")) { - value = VbGetNvStorage(VBNV_DEV_BOOT_USB); + value = vb2_get_nv_storage(VB2_NV_DEV_BOOT_USB); } else if (!strcasecmp(name,"dev_boot_legacy")) { - value = VbGetNvStorage(VBNV_DEV_BOOT_LEGACY); + value = vb2_get_nv_storage(VB2_NV_DEV_BOOT_LEGACY); } else if (!strcasecmp(name,"dev_boot_signed_only")) { - value = VbGetNvStorage(VBNV_DEV_BOOT_SIGNED_ONLY); + value = vb2_get_nv_storage(VB2_NV_DEV_BOOT_SIGNED_ONLY); } else if (!strcasecmp(name,"dev_boot_fastboot_full_cap")) { - value = VbGetNvStorage(VBNV_DEV_BOOT_FASTBOOT_FULL_CAP); + value = vb2_get_nv_storage(VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP); } else if (!strcasecmp(name,"oprom_needed")) { - value = VbGetNvStorage(VBNV_OPROM_NEEDED); + value = vb2_get_nv_storage(VB2_NV_OPROM_NEEDED); } else if (!strcasecmp(name,"recovery_subcode")) { - value = VbGetNvStorage(VBNV_RECOVERY_SUBCODE); + value = vb2_get_nv_storage(VB2_NV_RECOVERY_SUBCODE); } else if (!strcasecmp(name,"wipeout_request")) { - value = VbGetNvStorage(VBNV_FW_REQ_WIPEOUT); + value = vb2_get_nv_storage(VB2_NV_REQ_WIPEOUT); } else if (!strcasecmp(name,"kernel_max_rollforward")) { - value = VbGetNvStorage(VBNV_KERNEL_MAX_ROLLFORWARD); + value = vb2_get_nv_storage(VB2_NV_KERNEL_MAX_ROLLFORWARD); } /* Other parameters */ else if (!strcasecmp(name,"cros_debug")) { @@ -550,13 +535,13 @@ int VbGetSystemPropertyInt(const char *name) } else if (!strcasecmp(name,"recovery_reason")) { value = GetVdatInt(VDAT_INT_RECOVERY_REASON); } else if (!strcasecmp(name, "fastboot_unlock_in_fw")) { - value = VbGetNvStorage(VBNV_FASTBOOT_UNLOCK_IN_FW); + value = vb2_get_nv_storage(VB2_NV_FASTBOOT_UNLOCK_IN_FW); } else if (!strcasecmp(name, "boot_on_ac_detect")) { - value = VbGetNvStorage(VBNV_BOOT_ON_AC_DETECT); + value = vb2_get_nv_storage(VB2_NV_BOOT_ON_AC_DETECT); } else if (!strcasecmp(name, "try_ro_sync")) { - value = VbGetNvStorage(VBNV_TRY_RO_SYNC); + value = vb2_get_nv_storage(VB2_NV_TRY_RO_SYNC); } else if (!strcasecmp(name, "battery_cutoff_request")) { - value = VbGetNvStorage(VBNV_BATTERY_CUTOFF_REQUEST); + value = vb2_get_nv_storage(VB2_NV_BATTERY_CUTOFF_REQUEST); } else if (!strcasecmp(name, "inside_vm")) { /* Detect if the host is a VM. If there is no HWID and the * firmware type is "nonchrome", then assume it is a VM. If @@ -604,25 +589,25 @@ const char *VbGetSystemPropertyString(const char *name, char *dest, } else if (!strcasecmp(name, "vdat_lkdebug")) { return GetVdatString(dest, size, VDAT_STRING_LOAD_KERNEL_DEBUG); } else if (!strcasecmp(name, "fw_try_next")) { - return VbGetNvStorage(VBNV_FW_TRY_NEXT) ? "B" : "A"; + return vb2_get_nv_storage(VB2_NV_TRY_NEXT) ? "B" : "A"; } else if (!strcasecmp(name, "fw_tried")) { - return VbGetNvStorage(VBNV_FW_TRIED) ? "B" : "A"; + return vb2_get_nv_storage(VB2_NV_FW_TRIED) ? "B" : "A"; } else if (!strcasecmp(name, "fw_result")) { - int v = VbGetNvStorage(VBNV_FW_RESULT); + int v = vb2_get_nv_storage(VB2_NV_FW_RESULT); if (v < ARRAY_SIZE(fw_results)) return fw_results[v]; else return "unknown"; } else if (!strcasecmp(name, "fw_prev_tried")) { - return VbGetNvStorage(VBNV_FW_PREV_TRIED) ? "B" : "A"; + return vb2_get_nv_storage(VB2_NV_FW_PREV_TRIED) ? "B" : "A"; } else if (!strcasecmp(name, "fw_prev_result")) { - int v = VbGetNvStorage(VBNV_FW_PREV_RESULT); + int v = vb2_get_nv_storage(VB2_NV_FW_PREV_RESULT); if (v < ARRAY_SIZE(fw_results)) return fw_results[v]; else return "unknown"; } else if (!strcasecmp(name,"dev_default_boot")) { - int v = VbGetNvStorage(VBNV_DEV_DEFAULT_BOOT); + int v = vb2_get_nv_storage(VB2_NV_DEV_DEFAULT_BOOT); if (v < ARRAY_SIZE(default_boot)) return default_boot[v]; else @@ -644,82 +629,89 @@ int VbSetSystemPropertyInt(const char *name, int value) if (!strcasecmp(name,"nvram_cleared")) { /* Can only clear this flag; it's set inside the NV storage * library. */ - return VbSetNvStorage(VBNV_KERNEL_SETTINGS_RESET, 0); + return vb2_set_nv_storage(VB2_NV_KERNEL_SETTINGS_RESET, 0); } else if (!strcasecmp(name,"recovery_request")) { - return VbSetNvStorage(VBNV_RECOVERY_REQUEST, value); + return vb2_set_nv_storage(VB2_NV_RECOVERY_REQUEST, value); } else if (!strcasecmp(name,"recovery_subcode")) { - return VbSetNvStorage(VBNV_RECOVERY_SUBCODE, value); + return vb2_set_nv_storage(VB2_NV_RECOVERY_SUBCODE, value); } else if (!strcasecmp(name,"dbg_reset")) { - return VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value); + return vb2_set_nv_storage(VB2_NV_DEBUG_RESET_MODE, value); } else if (!strcasecmp(name,"disable_dev_request")) { - return VbSetNvStorage(VBNV_DISABLE_DEV_REQUEST, value); + return vb2_set_nv_storage(VB2_NV_DISABLE_DEV_REQUEST, value); } else if (!strcasecmp(name,"clear_tpm_owner_request")) { - return VbSetNvStorage(VBNV_CLEAR_TPM_OWNER_REQUEST, value); + return vb2_set_nv_storage(VB2_NV_CLEAR_TPM_OWNER_REQUEST, value); } else if (!strcasecmp(name,"clear_tpm_owner_done")) { /* Can only clear this flag; it's set by firmware. */ - return VbSetNvStorage(VBNV_CLEAR_TPM_OWNER_DONE, 0); - } else if (!strcasecmp(name,"fwb_tries")) { - return VbSetNvStorage(VBNV_TRY_B_COUNT, value); - } else if (!strcasecmp(name,"fw_try_count")) { - return VbSetNvStorage(VBNV_FW_TRY_COUNT, value); + return vb2_set_nv_storage(VB2_NV_CLEAR_TPM_OWNER_DONE, 0); + } else if (!strcasecmp(name,"fwb_tries") || + !strcasecmp(name,"fw_try_count")) { + return vb2_set_nv_storage(VB2_NV_TRY_COUNT, value); } else if (!strcasecmp(name,"oprom_needed")) { - return VbSetNvStorage(VBNV_OPROM_NEEDED, value); + return vb2_set_nv_storage(VB2_NV_OPROM_NEEDED, value); } else if (!strcasecmp(name,"wipeout_request")) { /* Can only clear this flag, set only by firmware. */ - return VbSetNvStorage(VBNV_FW_REQ_WIPEOUT, 0); + return vb2_set_nv_storage(VB2_NV_REQ_WIPEOUT, 0); } else if (!strcasecmp(name,"backup_nvram_request")) { /* Best-effort only, since it requires firmware and TPM * support. */ - return VbSetNvStorage(VBNV_BACKUP_NVRAM_REQUEST, value); + return vb2_set_nv_storage(VB2_NV_BACKUP_NVRAM_REQUEST, value); } else if (!strcasecmp(name,"fwupdate_tries")) { - int kern_nv = VbGetNvStorage(VBNV_KERNEL_FIELD); + int kern_nv = vb2_get_nv_storage(VB2_NV_KERNEL_FIELD); if (kern_nv == -1) return -1; kern_nv &= ~KERN_NV_FWUPDATE_TRIES_MASK; kern_nv |= (value & KERN_NV_FWUPDATE_TRIES_MASK); - return VbSetNvStorage_WithBackup(VBNV_KERNEL_FIELD, kern_nv); + return vb2_set_nv_storage_with_backup(VB2_NV_KERNEL_FIELD, + kern_nv); } else if (!strcasecmp(name,"block_devmode")) { - int kern_nv = VbGetNvStorage(VBNV_KERNEL_FIELD); + int kern_nv = vb2_get_nv_storage(VB2_NV_KERNEL_FIELD); if (kern_nv == -1) return -1; kern_nv &= ~KERN_NV_BLOCK_DEVMODE_FLAG; if (value) kern_nv |= KERN_NV_BLOCK_DEVMODE_FLAG; - return VbSetNvStorage_WithBackup(VBNV_KERNEL_FIELD, kern_nv); + return vb2_set_nv_storage_with_backup(VB2_NV_KERNEL_FIELD, + kern_nv); } else if (!strcasecmp(name,"tpm_attack")) { /* This value should only be read and cleared, but we allow * setting it to 1 for testing. */ - int kern_nv = VbGetNvStorage(VBNV_KERNEL_FIELD); + int kern_nv = vb2_get_nv_storage(VB2_NV_KERNEL_FIELD); if (kern_nv == -1) return -1; kern_nv &= ~KERN_NV_TPM_ATTACK_FLAG; if (value) kern_nv |= KERN_NV_TPM_ATTACK_FLAG; - return VbSetNvStorage_WithBackup(VBNV_KERNEL_FIELD, kern_nv); + return vb2_set_nv_storage_with_backup( + VB2_NV_KERNEL_FIELD, kern_nv); } else if (!strcasecmp(name,"loc_idx")) { - return VbSetNvStorage_WithBackup(VBNV_LOCALIZATION_INDEX, + return vb2_set_nv_storage_with_backup( + VB2_NV_LOCALIZATION_INDEX, value); } else if (!strcasecmp(name,"dev_boot_usb")) { - return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_USB, value); + return vb2_set_nv_storage_with_backup( + VB2_NV_DEV_BOOT_USB, value); } else if (!strcasecmp(name,"dev_boot_legacy")) { - return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_LEGACY, value); + return vb2_set_nv_storage_with_backup( + VB2_NV_DEV_BOOT_LEGACY, value); } else if (!strcasecmp(name,"dev_boot_signed_only")) { - return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_SIGNED_ONLY, - value); + return vb2_set_nv_storage_with_backup( + VB2_NV_DEV_BOOT_SIGNED_ONLY, value); } else if (!strcasecmp(name,"dev_boot_fastboot_full_cap")) { - return VbSetNvStorage_WithBackup( - VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, value); + return vb2_set_nv_storage_with_backup( + VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP, value); } else if (!strcasecmp(name, "fastboot_unlock_in_fw")) { - return VbSetNvStorage_WithBackup(VBNV_FASTBOOT_UNLOCK_IN_FW, - value); + return vb2_set_nv_storage_with_backup( + VB2_NV_FASTBOOT_UNLOCK_IN_FW, value); } else if (!strcasecmp(name, "boot_on_ac_detect")) { - return VbSetNvStorage_WithBackup(VBNV_BOOT_ON_AC_DETECT, value); + return vb2_set_nv_storage_with_backup( + VB2_NV_BOOT_ON_AC_DETECT, value); } else if (!strcasecmp(name, "try_ro_sync")) { - return VbSetNvStorage_WithBackup(VBNV_TRY_RO_SYNC, value); + return vb2_set_nv_storage_with_backup( + VB2_NV_TRY_RO_SYNC, value); } else if (!strcasecmp(name, "battery_cutoff_request")) { - return VbSetNvStorage(VBNV_BATTERY_CUTOFF_REQUEST, value); + return vb2_set_nv_storage(VB2_NV_BATTERY_CUTOFF_REQUEST, value); } else if (!strcasecmp(name,"kernel_max_rollforward")) { - return VbSetNvStorage(VBNV_KERNEL_MAX_ROLLFORWARD, value); + return vb2_set_nv_storage(VB2_NV_KERNEL_MAX_ROLLFORWARD, value); } return -1; @@ -733,9 +725,9 @@ int VbSetSystemPropertyString(const char* name, const char* value) if (!strcasecmp(name, "fw_try_next")) { if (!strcasecmp(value, "A")) - return VbSetNvStorage(VBNV_FW_TRY_NEXT, 0); + return vb2_set_nv_storage(VB2_NV_TRY_NEXT, 0); else if (!strcasecmp(value, "B")) - return VbSetNvStorage(VBNV_FW_TRY_NEXT, 1); + return vb2_set_nv_storage(VB2_NV_TRY_NEXT, 1); else return -1; @@ -744,7 +736,7 @@ int VbSetSystemPropertyString(const char* name, const char* value) for (i = 0; i < ARRAY_SIZE(fw_results); i++) { if (!strcasecmp(value, fw_results[i])) - return VbSetNvStorage(VBNV_FW_RESULT, i); + return vb2_set_nv_storage(VB2_NV_FW_RESULT, i); } return -1; } else if (!strcasecmp(name, "dev_default_boot")) { @@ -752,7 +744,8 @@ int VbSetSystemPropertyString(const char* name, const char* value) for (i = 0; i < ARRAY_SIZE(default_boot); i++) { if (!strcasecmp(value, default_boot[i])) - return VbSetNvStorage(VBNV_DEV_DEFAULT_BOOT, i); + return vb2_set_nv_storage( + VB2_NV_DEV_DEFAULT_BOOT, i); } return -1; } @@ -839,7 +832,7 @@ static int ExecuteMosys(char * const argv[], char *buf, size_t bufsize) return 0; } -int VbReadNvStorage_mosys(VbNvContext *vnc) +int vb2_read_nv_storage_mosys(struct vb2_context *ctx) { char hexstring[VBNV_BLOCK_SIZE * 2 + 32]; /* Reserve extra 32 bytes */ char * const argv[] = { @@ -855,12 +848,12 @@ int VbReadNvStorage_mosys(VbNvContext *vnc) for (i = 0; i < VBNV_BLOCK_SIZE; i++) { hexdigit[0] = hexstring[i * 2]; hexdigit[1] = hexstring[i * 2 + 1]; - vnc->raw[i] = strtol(hexdigit, NULL, 16); + ctx->nvdata[i] = strtol(hexdigit, NULL, 16); } return 0; } -int VbWriteNvStorage_mosys(VbNvContext* vnc) +int vb2_write_nv_storage_mosys(struct vb2_context *ctx) { char hexstring[VBNV_BLOCK_SIZE * 2 + 1]; char * const argv[] = { @@ -870,7 +863,7 @@ int VbWriteNvStorage_mosys(VbNvContext* vnc) int i; for (i = 0; i < VBNV_BLOCK_SIZE; i++) - snprintf(hexstring + i * 2, 3, "%02x", vnc->raw[i]); + snprintf(hexstring + i * 2, 3, "%02x", ctx->nvdata[i]); hexstring[sizeof(hexstring) - 1] = '\0'; if (ExecuteMosys(argv, NULL, 0)) return -1; diff --git a/host/lib/include/crossystem_arch.h b/host/lib/include/crossystem_arch.h index 50198b07..030d9d69 100644 --- a/host/lib/include/crossystem_arch.h +++ b/host/lib/include/crossystem_arch.h @@ -10,7 +10,9 @@ #include <stddef.h> -#include "vboot_nvstorage.h" +#include "2sysincludes.h" +#include "2api.h" +#include "2nvstorage.h" #include "vboot_struct.h" /* Firmware types from BINF.3. Placed in the common file because both x86 and @@ -28,12 +30,12 @@ /* Read an integer property from VbNvStorage. * * Returns the parameter value, or -1 if error. */ -int VbGetNvStorage(VbNvParam param); +int vb2_get_nv_storage(enum vb2_nv_param param); /* Write an integer property to VbNvStorage. * * Returns 0 if success, -1 if error. */ -int VbSetNvStorage(VbNvParam param, int value); +int vb2_set_nv_storage(enum vb2_nv_param param, int value); /* Return true if the FWID starts with the specified string. */ int FwidStartsWith(const char *start); @@ -46,12 +48,12 @@ int VbSharedDataVersion(void); /* Read the non-volatile context from NVRAM. * * Returns 0 if success, -1 if error. */ -int VbReadNvStorage(VbNvContext* vnc); +int vb2_read_nv_storage(struct vb2_context *ctx); /* Write the non-volatile context to NVRAM. * * Returns 0 if success, -1 if error. */ -int VbWriteNvStorage(VbNvContext* vnc); +int vb2_write_nv_storage(struct vb2_context *ctx); /* Read the VbSharedData buffer. * |