vboot_nvstorage.h revision b944534edd3799b3353f73bcb8ee90161d640c2b
1b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Copyright (c) 2011 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 6b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Non-volatile storage routines. 7b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler */ 8b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 9b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler#ifndef VBOOT_REFERENCE_NVSTORAGE_H_ 10b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler#define VBOOT_REFERENCE_NVSTORAGE_H_ 11b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 12b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler#define NV_BLOCK_SIZE 16 /* Size of NV storage block in bytes */ 13b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 14b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglertypedef struct VbNvContext { 15b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler /* Raw NV data. Caller must fill this before calling VbNvSetup(). */ 16b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler uint8_t raw[NV_BLOCK_SIZE]; 17b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler /* Flag indicating whether raw data has changed. Set by VbNvTeardown() if 18b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * the raw data has changed and needs to be stored to the underlying 19b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * non-volatile data store. */ 20b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler int raw_changed; 21b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 22b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler /* Internal data for NV storage routines. Caller should not touch 23b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * these fields. */ 24b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler int regenerate_crc; 25b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 26b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler} VbNvContext; 27b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 28b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 29b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Parameter type for VbNvGet(), VbNvSet(). */ 30b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglertypedef enum VbNvParam { 31b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler VBNV_FIRMWARE_SETTINGS_RESET = 0, 32b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler VBNV_KERNEL_SETTINGS_RESET, 33b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler VBNV_DEBUG_RESET_MODE, 34b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler VBNV_TRY_B_COUNT, 35b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler VBNV_RECOVERY_REQUEST, 36b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler VBNV_LOCALIZATION_INDEX, 37b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler VBNV_KERNEL_FIELD, 38b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler} VbNvParam; 39b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 40b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 41b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Initialize the NV storage library. This must be called before any 42b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * other functions in this library. Returns 0 if success, non-zero if 43b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * error. 44b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * 45b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * If you have access to global variables, you may want to wrap this 46b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * in your own VbNvOpen() function which allocates a context, acquires 47b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * a lock to prevent race conditions accessing the underlying storage, 48b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * reads the raw data from underlying storage, and calls VbNvSetup(). 49b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * We don't do that in here because there are no global variables in 50b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * UEFI BIOS during PEI phase. */ 51b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglerint VbNvSetup(VbNvContext* context); 52b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 53b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Clean up and flush changes back to the raw data. This must be 54b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * called after other functions in this library. Caller must check 55b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * context.raw_changed after calling this function. Returns 0 if 56b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * success, non-zero if error. 57b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * 58b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * If you have access to global variables, you may want to wrap this 59b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * in your own VbNvClose() function which calls VbNvTeardown(), writes 60b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * the underlying storage if context.raw_changed, releases the lock 61b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * acquired in VbNvOpen, and frees the context. */ 62b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglerint VbNvTeardown(VbNvContext* context); 63b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 64b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Read a NV storage parameter into *dest. Returns 0 if success, 65b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * non-zero if error. */ 66b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglerint VbNvGet(VbNvContext* context, VbNvParam param, uint32_t* dest); 67b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 68b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler/* Set a NV storage param to a new value. Returns 0 if success, 69b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler * non-zero if error. */ 70b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spanglerint VbNvSet(VbNvContext* context, VbNvParam param, uint32_t value); 71b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 72b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler 73b944534edd3799b3353f73bcb8ee90161d640c2bRandall Spangler#endif /* VBOOT_REFERENCE_NVSTORAGE_H_ */ 74