1a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * Use of this source code is governed by a BSD-style license that can be 3b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * found in the LICENSE file. 4b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler */ 5b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 6a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* Non-volatile storage routines for verified boot. */ 7b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 8b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler#ifndef VBOOT_REFERENCE_NVSTORAGE_H_ 9b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler#define VBOOT_REFERENCE_NVSTORAGE_H_ 100c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson#include <stdint.h> 11b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 129e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_BLOCK_SIZE 16 /* Size of NV storage block in bytes */ 13b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 14b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglertypedef struct VbNvContext { 15a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Raw NV data. Caller must fill this before calling VbNvSetup(). */ 16a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler uint8_t raw[VBNV_BLOCK_SIZE]; 17a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 18a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Flag indicating whether raw data has changed. Set by VbNvTeardown() 19a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * if the raw data has changed and needs to be stored to the underlying 20a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * non-volatile data store. 21a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 22a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler int raw_changed; 23b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 24a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 25a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Internal data for NV storage routines. Caller should not touch 26a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * these fields. 27a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 28a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler int regenerate_crc; 29b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler} VbNvContext; 30b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 31b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Parameter type for VbNvGet(), VbNvSet(). */ 32b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglertypedef enum VbNvParam { 33a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 34a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Parameter values have been reset to defaults (flag for firmware). 35a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 0=clear; 1=set. 36a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 37a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_FIRMWARE_SETTINGS_RESET = 0, 38a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 39a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Parameter values have been reset to defaults (flag for kernel). 40a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 0=clear; 1=set. 41a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 42a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_KERNEL_SETTINGS_RESET, 43a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Request debug reset on next S3->S0 transition. 0=clear; 1=set. */ 44a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_DEBUG_RESET_MODE, 45a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 46a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Number of times to try booting RW firmware slot B before slot A. 47a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Valid range: 0-15. 489e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler * 499e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler * Vboot2: Number of times to try the firmware in VBNV_FW_TRY_NEXT. 509e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler * 519e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler * These refer to the same field, but have different enum values so 529e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler * case statement don't complain about duplicates. 53a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 54a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_TRY_B_COUNT, 559e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_TRY_COUNT, 56a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 57a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Request recovery mode on next boot; see VBNB_RECOVERY_* below for 58a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * currently defined reason codes. 8-bit value. 59a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 60a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_RECOVERY_REQUEST, 61a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 62a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Localization index for screen bitmaps displayed by firmware. 63a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 8-bit value. 64a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 65a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_LOCALIZATION_INDEX, 66a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Field reserved for kernel/user-mode use; 32-bit value. */ 67a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_KERNEL_FIELD, 68a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Allow booting from USB in developer mode. 0=no, 1=yes. */ 69a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_DEV_BOOT_USB, 70a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Allow booting of legacy OSes in developer mode. 0=no, 1=yes. */ 71a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_DEV_BOOT_LEGACY, 72a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Only boot Google-signed images in developer mode. 0=no, 1=yes. */ 73a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_DEV_BOOT_SIGNED_ONLY, 74a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 75a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Set by userspace to request that RO firmware disable dev-mode on the 76a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * next boot. This is likely only possible if the dev-switch is 77a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * virtual. 78a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 79a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_DISABLE_DEV_REQUEST, 80a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* 81a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Set and cleared by vboot to request that the video Option ROM be 82a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * loaded at boot time, so that BIOS screens can be displayed. 0=no, 83a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 1=yes. 84a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 85a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_OPROM_NEEDED, 86a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Request that the firmware clear the TPM owner on the next boot. */ 87a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_CLEAR_TPM_OWNER_REQUEST, 88a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* Flag that TPM owner was cleared on request. */ 89a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_CLEAR_TPM_OWNER_DONE, 90a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler /* More details on recovery reason */ 91a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler VBNV_RECOVERY_SUBCODE, 92b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson /* Request that NVRAM be backed up at next boot if possible. */ 93b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson VBNV_BACKUP_NVRAM_REQUEST, 949e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler 959e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler /* Vboot2: Firmware slot to try next. 0=A, 1=B */ 969e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_TRY_NEXT, 979e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler /* Vboot2: Firmware slot tried this boot (0=A, 1=B) */ 989e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_TRIED, 999e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler /* Vboot2: Result of trying that firmware (see vb2_fw_result) */ 1009e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_RESULT, 101782300d093a2fbf2ca24e446fb6d65f9f28e56a6Randall Spangler /* Firmware slot tried previous boot (0=A, 1=B) */ 102782300d093a2fbf2ca24e446fb6d65f9f28e56a6Randall Spangler VBNV_FW_PREV_TRIED, 103782300d093a2fbf2ca24e446fb6d65f9f28e56a6Randall Spangler /* Result of trying that firmware (see vb2_fw_result) */ 104782300d093a2fbf2ca24e446fb6d65f9f28e56a6Randall Spangler VBNV_FW_PREV_RESULT, 1059e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler 106b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler} VbNvParam; 107b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 1089e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler/* Result of trying the firmware in VBNV_FW_TRIED */ 1099e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spanglertypedef enum VbFwResult { 1109e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler /* Unknown */ 1119e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_RESULT_UNKNOWN = 0, 1129e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler 1139e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler /* Trying a new slot, but haven't reached success/failure */ 1149e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_RESULT_TRYING = 1, 1159e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler 1169e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler /* Successfully booted to the OS */ 1179e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_RESULT_SUCCESS = 2, 1189e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler 1199e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler /* Known failure */ 1209e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler VBNV_FW_RESULT_FAILURE = 3, 1219e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler 1229e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler} VbFwResult; 1239e1da784487fb8cfbe4e76693e07205b66675bdaRandall Spangler 1249e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* Recovery reason codes for VBNV_RECOVERY_REQUEST */ 1259e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* Recovery not requested. */ 1269e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_NOT_REQUESTED 0x00 127a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* 128a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Recovery requested from legacy utility. (Prior to the NV storage spec, 129a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * recovery mode was a single bitfield; this value is reserved so that scripts 130a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * which wrote 1 to the recovery field are distinguishable from scripts whch 131a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * use the recovery reasons listed here. 132a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 1339e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_LEGACY 0x01 1349e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* User manually requested recovery via recovery button */ 1359e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RO_MANUAL 0x02 1369e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* RW firmware failed signature check (neither RW firmware slot was valid) */ 1379e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RO_INVALID_RW 0x03 1389e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* S3 resume failed */ 1399e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RO_S3_RESUME 0x04 140640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM error in read-only firmware (deprecated) */ 141640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_DEP_RO_TPM_ERROR 0x05 14295c4031ce903258036beeed0705d25c7e9d25da0Randall Spangler/* Shared data error in read-only firmware */ 14395c4031ce903258036beeed0705d25c7e9d25da0Randall Spangler#define VBNV_RECOVERY_RO_SHARED_DATA 0x06 144b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler/* Test error from S3Resume() */ 145b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler#define VBNV_RECOVERY_RO_TEST_S3 0x07 146b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler/* Test error from LoadFirmwareSetup() */ 147b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler#define VBNV_RECOVERY_RO_TEST_LFS 0x08 148b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler/* Test error from LoadFirmware() */ 149b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler#define VBNV_RECOVERY_RO_TEST_LF 0x09 150a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* 151a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * RW firmware failed signature check (neither RW firmware slot was valid). 1529243e616d727c3e57525f8dec2b5f22840900451Randall Spangler * Recovery reason is VBNV_RECOVERY_RO_INVALID_RW_CHECK_MIN + the check value 1539243e616d727c3e57525f8dec2b5f22840900451Randall Spangler * for the slot which came closest to validating; see VBSD_LF_CHECK_* in 154a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * vboot_struct.h. 155a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 1569243e616d727c3e57525f8dec2b5f22840900451Randall Spangler#define VBNV_RECOVERY_RO_INVALID_RW_CHECK_MIN 0x10 1579243e616d727c3e57525f8dec2b5f22840900451Randall Spangler#define VBNV_RECOVERY_RO_INVALID_RW_CHECK_MAX 0x1F 158a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* 159a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Firmware boot failure outside of verified boot (RAM init, missing SSD, 160a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * etc.). 161a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 1629619112a574b975476667545e3a326052fa0c50bRandall Spangler#define VBNV_RECOVERY_RO_FIRMWARE 0x20 163a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* 164a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Recovery mode TPM initialization requires a system reboot. The system was 165a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * already in recovery mode for some other reason when this happened. 166a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 167ad03a439bc97523e03d19aa1dcd568744d60889cRandall Spangler#define VBNV_RECOVERY_RO_TPM_REBOOT 0x21 168584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler/* EC software sync - other error */ 169d4faa060cc6445cf532e3f9c9cd785e0726f1b82Randall Spangler#define VBNV_RECOVERY_EC_SOFTWARE_SYNC 0x22 170584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler/* EC software sync - unable to determine active EC image */ 171d4faa060cc6445cf532e3f9c9cd785e0726f1b82Randall Spangler#define VBNV_RECOVERY_EC_UNKNOWN_IMAGE 0x23 172640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* EC software sync - error obtaining EC image hash (deprecated) */ 173640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_DEP_EC_HASH 0x24 174584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler/* EC software sync - error obtaining expected EC image */ 175584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler#define VBNV_RECOVERY_EC_EXPECTED_IMAGE 0x25 176584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler/* EC software sync - error updating EC */ 177584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler#define VBNV_RECOVERY_EC_UPDATE 0x26 178584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler/* EC software sync - unable to jump to EC-RW */ 179584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler#define VBNV_RECOVERY_EC_JUMP_RW 0x27 180584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler/* EC software sync - unable to protect / unprotect EC-RW */ 181584e0d2070aca1a5e091442cb9bad0726451ad95Randall Spangler#define VBNV_RECOVERY_EC_PROTECT 0x28 1825ca4ea087a3d67c2a639e8b9254f51f076bf85faRandall Spangler/* EC software sync - error obtaining expected EC hash */ 1835ca4ea087a3d67c2a639e8b9254f51f076bf85faRandall Spangler#define VBNV_RECOVERY_EC_EXPECTED_HASH 0x29 1845ca4ea087a3d67c2a639e8b9254f51f076bf85faRandall Spangler/* EC software sync - expected EC image doesn't match hash */ 1855ca4ea087a3d67c2a639e8b9254f51f076bf85faRandall Spangler#define VBNV_RECOVERY_EC_HASH_MISMATCH 0x2A 186dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner/* VB2: Secure data inititalization error */ 187dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner#define VBNV_RECOVERY_VB2_SECDATA_INIT 0x2B 188dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner/* VB2: GBB header is bad */ 189dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner#define VBNV_RECOVERY_VB2_GBB_HEADER 0x2C 190dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner/* VB2: Unable to clear TPM owner */ 191dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner#define VBNV_RECOVERY_VB2_TPM_CLEAR_OWNER 0x2D 192dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner/* VB2: Error determining/updating virtual dev switch */ 193dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner#define VBNV_RECOVERY_VB2_DEV_SWITCH 0x2E 194dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner/* VB2: Error determining firmware slot */ 195dc8ec103c0d0d2a4e930153a4b19c43b51d74b5dJulius Werner#define VBNV_RECOVERY_VB2_FW_SLOT 0x2F 1969e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* Unspecified/unknown error in read-only firmware */ 1979e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RO_UNSPECIFIED 0x3F 198a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* 199a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * User manually requested recovery by pressing a key at developer 200a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * warning screen 201a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 2029e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RW_DEV_SCREEN 0x41 2039e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* No OS kernel detected */ 2049e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RW_NO_OS 0x42 2059e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* OS kernel failed signature check */ 2069e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RW_INVALID_OS 0x43 207640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM error in rewritable firmware (deprecated) */ 208640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_DEP_RW_TPM_ERROR 0x44 209640fb51d866e7ac8a92f61a2f69145bfe6b13699Randall Spangler/* RW firmware in dev mode, but dev switch is off */ 210640fb51d866e7ac8a92f61a2f69145bfe6b13699Randall Spangler#define VBNV_RECOVERY_RW_DEV_MISMATCH 0x45 21195c4031ce903258036beeed0705d25c7e9d25da0Randall Spangler/* Shared data error in rewritable firmware */ 21295c4031ce903258036beeed0705d25c7e9d25da0Randall Spangler#define VBNV_RECOVERY_RW_SHARED_DATA 0x46 213b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler/* Test error from LoadKernel() */ 214b17e8d353c50d46f0e5f29578f6294003692ea1dRandall Spangler#define VBNV_RECOVERY_RW_TEST_LK 0x47 215640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* No bootable disk found (deprecated)*/ 216640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_DEP_RW_NO_DISK 0x48 217d2852eabf6da8bd36ba898c9b375f0480fab02d2Luigi Semenzato/* Rebooting did not correct TPM_E_FAIL or TPM_E_FAILEDSELFTEST */ 218d2852eabf6da8bd36ba898c9b375f0480fab02d2Luigi Semenzato#define VBNV_RECOVERY_TPM_E_FAIL 0x49 219640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM setup error in read-only firmware */ 220640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RO_TPM_S_ERROR 0x50 221640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM write error in read-only firmware */ 222640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RO_TPM_W_ERROR 0x51 223640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM lock error in read-only firmware */ 224640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RO_TPM_L_ERROR 0x52 225640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM update error in read-only firmware */ 226640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RO_TPM_U_ERROR 0x53 227640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM read error in rewritable firmware */ 228640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RW_TPM_R_ERROR 0x54 229640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM write error in rewritable firmware */ 230640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RW_TPM_W_ERROR 0x55 231640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* TPM lock error in rewritable firmware */ 232640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RW_TPM_L_ERROR 0x56 233640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* EC software sync unable to get EC image hash */ 234640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_EC_HASH_FAILED 0x57 235640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* EC software sync invalid image hash size */ 236640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_EC_HASH_SIZE 0x58 237640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* Unspecified error while trying to load kernel */ 238640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_LK_UNSPECIFIED 0x59 239640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* No bootable storage device in system */ 240640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RW_NO_DISK 0x5A 241640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson/* No bootable kernel found on disk */ 242640b1c420748049c796b3f9d59406e38ff8f4774Bill Richardson#define VBNV_RECOVERY_RW_NO_KERNEL 0x5B 2439e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* Unspecified/unknown error in rewritable firmware */ 2449e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_RW_UNSPECIFIED 0x7F 2459e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* DM-verity error */ 2469e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_KE_DM_VERITY 0x81 2479e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* Unspecified/unknown error in kernel */ 2489e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_KE_UNSPECIFIED 0xBF 2499e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* Recovery mode test from user-mode */ 2509e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_US_TEST 0xC1 2519e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler/* Unspecified/unknown error in user-mode */ 2529e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler#define VBNV_RECOVERY_US_UNSPECIFIED 0xFF 2539e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler 254a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/** 255a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Initialize the NV storage library. 256a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 257a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This must be called before any other functions in this library. Returns 0 258a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * if success, non-zero if error. 259b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * 2609e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * Proper calling procedure: 2619e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 1) Allocate a context struct. 2629e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 2) If multi-threaded/multi-process, acquire a lock to prevent 2639e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * other processes from modifying the underlying storage. 2649e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 3) Read underlying storage and fill in context->raw. 2659e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 4) Call VbNvSetup(). 2669e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 267a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * If you have access to global variables, you may want to wrap all that in 268a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * your own VbNvOpen() function. We don't do that in here because there are no 269a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * global variables in UEFI BIOS during the PEI phase (that's also why we have 270a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * to pass around a context pointer). 271a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 272a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglerint VbNvSetup(VbNvContext *context); 273b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 274a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/** 275a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Clean up and flush changes back to the raw data. 276a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 277a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This must be called after other functions in this library. Returns 0 if 278b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * success, non-zero if error. 279b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * 2809e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * Proper calling procedure: 2819e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 1) Call VbNvExit(). 2829e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 2) If context.raw_changed, write data back to underlying storage. 2839e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 3) Release any lock you acquired before calling VbNvSetup(). 2849e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 4) Free the context struct. 2859e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 286b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * If you have access to global variables, you may want to wrap this 287a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * in your own VbNvClose() function. 288a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 289a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglerint VbNvTeardown(VbNvContext *context); 290b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 291a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/** 292a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Read a NV storage parameter into *dest. 2939e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 294a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Returns 0 if success, non-zero if error. 2959e162cdaa7433dff01d3e47ba3a47cb8b39ff3a1Randall Spangler * 296a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This may only be called between VbNvSetup() and VbNvTeardown(). 297a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 298a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglerint VbNvGet(VbNvContext *context, VbNvParam param, uint32_t *dest); 299b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 300a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/** 301a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Set a NV storage param to a new value. 302a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 303a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Returns 0 if success, non-zero if error. 304a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * 305a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This may only be called between VbNvSetup() and VbNvTeardown(). 306a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */ 307a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglerint VbNvSet(VbNvContext *context, VbNvParam param, uint32_t value); 308b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 309b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson/** 310b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * Attempt to restore some fields of a lost VbNvContext from a backup area. 311b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * The rest of the fields are unchanged, so they'd need to be set to their 312b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * appropriate defaults by calling VbNvSetup() first (which is usually how we 313b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * know the fields have been lost). 314b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * 315b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * Returns 0 if success, non-zero if error. 316b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * 317b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * This may only be called between VbNvSetup() and VbNvTeardown(). 318b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson */ 319b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardsonint RestoreNvFromBackup(VbNvContext *vnc); 320b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson 321b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson/** 322b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * Attempt to save some fields of the VbNvContext to a backup area. 323b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * 324b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * Returns 0 if success, non-zero if error. If it succeeds, it will clear the 325b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * VBNV_BACKUP_NVRAM_REQUEST flag in the VbNvContext. 326b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * 327b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson * This may only be called when the backup area is writable. 328b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson */ 329b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardsonint SaveNvToBackup(VbNvContext *vnc); 330b64f097891e697eaf3b2794baae934f8b4d82d14Bill Richardson 331b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler#endif /* VBOOT_REFERENCE_NVSTORAGE_H_ */ 332