const char* VbGetSystemPropertyString(const char* name, char* dest, size_t size) { /* Check architecture-dependent properties first */ if (VbGetArchPropertyString(name, dest, size)) return dest; if (!strcasecmp(name,"kernkey_vfy")) { switch(GetVdatInt(VDAT_INT_KERNEL_KEY_VERIFIED)) { case 0: return "hash"; case 1: return "sig"; default: return NULL; } } else if (!strcasecmp(name, "mainfw_act")) { return GetVdatString(dest, size, VDAT_STRING_MAINFW_ACT); } else if (!strcasecmp(name, "vdat_timers")) { return GetVdatString(dest, size, VDAT_STRING_TIMERS); } else if (!strcasecmp(name, "vdat_lfdebug")) { return GetVdatString(dest, size, VDAT_STRING_LOAD_FIRMWARE_DEBUG); } 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"; } else if (!strcasecmp(name, "fw_tried")) { return VbGetNvStorage(VBNV_FW_TRIED) ? "B" : "A"; } else if (!strcasecmp(name, "fw_result")) { int v = VbGetNvStorage(VBNV_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"; } else if (!strcasecmp(name, "fw_prev_result")) { int v = VbGetNvStorage(VBNV_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); if (v < ARRAY_SIZE(default_boot)) return default_boot[v]; else return "unknown"; } return NULL; }
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)) return 0; return VbSetCmosRebootField(CMOSRF_RECOVERY, value); } else if (!strcasecmp(name,"dbg_reset")) { if (0 == VbSetNvStorage(VBNV_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)) return 0; return VbSetCmosRebootField(CMOSRF_TRY_B, value); } /* Firmware update tries is now stored in the kernel field. On * 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)) return -1; /* NvStorage supported; fail through arch-specific * implementation to normal implementation */ if (value) { char buf[32]; snprintf(buf, sizeof(buf), "%d", value); return WriteFile(NEED_FWUPDATE_PATH, buf, strlen(buf)); } else { /* No update tries, so remove file if it exists. */ unlink(NEED_FWUPDATE_PATH); return 0; } } return -1; }
int VbGetArchPropertyInt(const char* name) { int value = -1; /* Values from ACPI */ if (!strcasecmp(name,"fmap_base")) { unsigned fmap_base; if (ReadFileInt(ACPI_FMAP_PATH, &fmap_base) < 0) return -1; else value = (int)fmap_base; } /* Switch positions */ if (!strcasecmp(name,"devsw_cur")) { /* Systems with virtual developer switches return at-boot value */ int flags = VbGetSystemPropertyInt("vdat_flags"); if ((flags != -1) && (flags & VBSD_HONOR_VIRT_DEV_SWITCH)) value = VbGetSystemPropertyInt("devsw_boot"); else value = ReadGpio(GPIO_SIGNAL_TYPE_DEV); } else if (!strcasecmp(name,"recoverysw_cur")) { value = ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY); } else if (!strcasecmp(name,"wpsw_cur")) { value = ReadGpio(GPIO_SIGNAL_TYPE_WP); if (-1 != value && FwidStartsWith("Mario.")) value = 1 - value; /* Mario reports this backwards */ } else if (!strcasecmp(name,"recoverysw_ec_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT); } /* Fields for old systems which don't have VbSharedData */ if (VbSharedDataVersion() < 2) { if (!strcasecmp(name,"recovery_reason")) { value = VbGetRecoveryReason(); } else if (!strcasecmp(name,"devsw_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT); } else if (!strcasecmp(name,"recoverysw_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT); } else if (!strcasecmp(name,"wpsw_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT); if (-1 != value && FwidStartsWith("Mario.")) value = 1 - value; /* Mario reports this backwards */ } } /* Saved memory is at a fixed location for all H2C BIOS. If the CHSW * path exists in sysfs, it's a H2C BIOS. */ if (!strcasecmp(name,"savedmem_base")) { unsigned savedmem_base; if (ReadFileInt(ACPI_CHSW_PATH, &savedmem_base) < 0) return -1; else return 0x00F00000; } else if (!strcasecmp(name,"savedmem_size")) { unsigned savedmem_size; if (ReadFileInt(ACPI_CHSW_PATH, &savedmem_size) < 0) return -1; else return 0x00100000; } /* 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); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_RECOVERY); } else if (!strcasecmp(name,"dbg_reset")) { value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_DEBUG_RESET); } else if (!strcasecmp(name,"fwb_tries")) { value = VbGetNvStorage(VBNV_TRY_B_COUNT); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_TRY_B); } /* Firmware update tries is now stored in the kernel field. On * older systems where it's not, it was stored in a file in the * stateful partition. */ if (!strcasecmp(name,"fwupdate_tries")) { unsigned fwupdate_value; if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) return -1; /* NvStorage supported; fail through arch-specific * implementation to normal implementation. */ /* Read value from file; missing file means value=0. */ if (ReadFileInt(NEED_FWUPDATE_PATH, &fwupdate_value) < 0) value = 0; else value = (int)fwupdate_value; } return value; }
int VbSetSystemPropertyInt(const char* name, int value) { /* Check architecture-dependent properties first */ if (0 == VbSetArchPropertyInt(name, value)) return 0; /* NV storage values */ 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); } else if (!strcasecmp(name,"recovery_request")) { return VbSetNvStorage(VBNV_RECOVERY_REQUEST, value); } else if (!strcasecmp(name,"recovery_subcode")) { return VbSetNvStorage(VBNV_RECOVERY_SUBCODE, value); } else if (!strcasecmp(name,"dbg_reset")) { return VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value); } else if (!strcasecmp(name,"disable_dev_request")) { return VbSetNvStorage(VBNV_DISABLE_DEV_REQUEST, value); } else if (!strcasecmp(name,"clear_tpm_owner_request")) { return VbSetNvStorage(VBNV_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); } else if (!strcasecmp(name,"oprom_needed")) { return VbSetNvStorage(VBNV_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); } else if (!strcasecmp(name,"backup_nvram_request")) { /* Best-effort only, since it requires firmware and TPM support. */ return VbSetNvStorage(VBNV_BACKUP_NVRAM_REQUEST, value); } else if (!strcasecmp(name,"fwupdate_tries")) { int kern_nv = VbGetNvStorage(VBNV_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); } else if (!strcasecmp(name,"block_devmode")) { int kern_nv = VbGetNvStorage(VBNV_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); } 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); 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); } else if (!strcasecmp(name,"loc_idx")) { return VbSetNvStorage_WithBackup(VBNV_LOCALIZATION_INDEX, value); } else if (!strcasecmp(name,"dev_boot_usb")) { return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_USB, value); } else if (!strcasecmp(name,"dev_boot_legacy")) { return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_LEGACY, value); } else if (!strcasecmp(name,"dev_boot_signed_only")) { return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_SIGNED_ONLY, value); } else if (!strcasecmp(name,"dev_boot_fastboot_full_cap")) { return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, value); } else if (!strcasecmp(name, "fastboot_unlock_in_fw")) { return VbSetNvStorage_WithBackup(VBNV_FASTBOOT_UNLOCK_IN_FW, value); } else if (!strcasecmp(name, "boot_on_ac_detect")) { return VbSetNvStorage_WithBackup(VBNV_BOOT_ON_AC_DETECT, value); } else if (!strcasecmp(name, "try_ro_sync")) { return VbSetNvStorage_WithBackup(VBNV_TRY_RO_SYNC, value); } return -1; }
int VbGetSystemPropertyInt(const char* name) { int value = -1; /* Check architecture-dependent properties first */ value = VbGetArchPropertyInt(name); if (-1 != value) return value; /* NV storage values */ else if (!strcasecmp(name,"kern_nv")) { value = VbGetNvStorage(VBNV_KERNEL_FIELD); } else if (!strcasecmp(name,"nvram_cleared")) { value = VbGetNvStorage(VBNV_KERNEL_SETTINGS_RESET); } else if (!strcasecmp(name,"recovery_request")) { value = VbGetNvStorage(VBNV_RECOVERY_REQUEST); } else if (!strcasecmp(name,"dbg_reset")) { value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); } else if (!strcasecmp(name,"disable_dev_request")) { value = VbGetNvStorage(VBNV_DISABLE_DEV_REQUEST); } else if (!strcasecmp(name,"clear_tpm_owner_request")) { value = VbGetNvStorage(VBNV_CLEAR_TPM_OWNER_REQUEST); } else if (!strcasecmp(name,"clear_tpm_owner_done")) { value = VbGetNvStorage(VBNV_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); } 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); if (value != -1) value &= KERN_NV_FWUPDATE_TRIES_MASK; } else if (!strcasecmp(name,"block_devmode")) { value = VbGetNvStorage(VBNV_KERNEL_FIELD); if (value != -1) { value &= KERN_NV_BLOCK_DEVMODE_FLAG; value = !!value; } } else if (!strcasecmp(name,"tpm_attack")) { value = VbGetNvStorage(VBNV_KERNEL_FIELD); if (value != -1) { value &= KERN_NV_TPM_ATTACK_FLAG; value = !!value; } } else if (!strcasecmp(name,"loc_idx")) { value = VbGetNvStorage(VBNV_LOCALIZATION_INDEX); } else if (!strcasecmp(name,"backup_nvram_request")) { value = VbGetNvStorage(VBNV_BACKUP_NVRAM_REQUEST); } else if (!strcasecmp(name,"dev_boot_usb")) { value = VbGetNvStorage(VBNV_DEV_BOOT_USB); } else if (!strcasecmp(name,"dev_boot_legacy")) { value = VbGetNvStorage(VBNV_DEV_BOOT_LEGACY); } else if (!strcasecmp(name,"dev_boot_signed_only")) { value = VbGetNvStorage(VBNV_DEV_BOOT_SIGNED_ONLY); } else if (!strcasecmp(name,"dev_boot_fastboot_full_cap")) { value = VbGetNvStorage(VBNV_DEV_BOOT_FASTBOOT_FULL_CAP); } else if (!strcasecmp(name,"oprom_needed")) { value = VbGetNvStorage(VBNV_OPROM_NEEDED); } else if (!strcasecmp(name,"recovery_subcode")) { value = VbGetNvStorage(VBNV_RECOVERY_SUBCODE); } else if (!strcasecmp(name,"wipeout_request")) { value = VbGetNvStorage(VBNV_FW_REQ_WIPEOUT); } /* Other parameters */ else if (!strcasecmp(name,"cros_debug")) { value = VbGetCrosDebug(); } else if (!strcasecmp(name,"debug_build")) { value = VbGetDebugBuild(); } else if (!strcasecmp(name,"devsw_boot")) { value = GetVdatInt(VDAT_INT_DEVSW_BOOT); } else if (!strcasecmp(name,"devsw_virtual")) { value = GetVdatInt(VDAT_INT_DEVSW_VIRTUAL); } else if (!strcasecmp(name, "recoverysw_boot")) { value = GetVdatInt(VDAT_INT_RECSW_BOOT); } else if (!strcasecmp(name, "wpsw_boot")) { value = GetVdatInt(VDAT_INT_HW_WPSW_BOOT); } else if (!strcasecmp(name, "sw_wpsw_boot")) { value = GetVdatInt(VDAT_INT_SW_WPSW_BOOT); } else if (!strcasecmp(name,"vdat_flags")) { value = GetVdatInt(VDAT_INT_FLAGS); } else if (!strcasecmp(name,"tpm_fwver")) { value = GetVdatInt(VDAT_INT_FW_VERSION_TPM); } else if (!strcasecmp(name,"tpm_kernver")) { value = GetVdatInt(VDAT_INT_KERNEL_VERSION_TPM); } else if (!strcasecmp(name,"tried_fwb")) { value = GetVdatInt(VDAT_INT_TRIED_FIRMWARE_B); } 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); } else if (!strcasecmp(name, "boot_on_ac_detect")) { value = VbGetNvStorage(VBNV_BOOT_ON_AC_DETECT); } else if (!strcasecmp(name, "try_ro_sync")) { value = VbGetNvStorage(VBNV_TRY_RO_SYNC); } return value; }