vboot_api.h revision 8912169231e589b0400debed26f9cedbbe6d9561
1a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * Use of this source code is governed by a BSD-style license that can be
3a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * found in the LICENSE file.
4a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler */
5a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
6a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/* APIs provided by firmware to vboot_reference.
7a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
8a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * General notes:
9a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
10a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * All verified boot functions now start with "Vb" for namespace clarity.  This
11a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * fixes the problem where uboot and vboot both defined assert().
12a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
13a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Verified boot APIs to be implemented by the calling firmware and exported to
14a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * vboot_reference start with "VbEx".
15a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
16a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * TODO: split this file into a vboot_entry_points.h file which contains the
17a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * entry points for the firmware to call vboot_reference, and a
18a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * vboot_firmware_exports.h which contains the APIs to be implemented by the
19a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * calling firmware and exported to vboot_reference.
20a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler */
21a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
22a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#ifndef VBOOT_REFERENCE_VBOOT_API_H_
23a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VBOOT_REFERENCE_VBOOT_API_H_
240c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson#include <stdint.h>
25a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
26a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
27a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Error codes */
28a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
29a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
30a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Functions which return an error all return this type.  This is a 32-bit
31a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * value rather than an int so it's consistent across UEFI, which is 32-bit
32a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * during PEI and 64-bit during DXE/BDS.
33a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
34a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglertypedef uint32_t VbError_t;
35a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
36a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
37a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Predefined error numbers.  Success is 0.  Errors are non-zero, but differ
38a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * between functions.  For example, the TPM functions may pass through TPM
39a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * error codes, some of which may be recoverable.
40a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
411cf77cda5ea2d7549caccb953079263d463feadbRandall Spanglerenum VbErrorPredefined_t {
42a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* No error; function completed successfully. */
43a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_SUCCESS                       = 0,
44a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
45a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
46a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * The verified boot entry points VbInit(), VbSelectFirmware(),
47a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * VbSelectAndLoadKernel() may return the following errors.
48a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
49a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unknown error */
50a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_UNKNOWN                       = 0x10000,
51a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to initialize shared data */
52a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_INIT_SHARED_DATA              = 0x10001,
53a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Error resuming TPM during a S3 resume */
54a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_S3_RESUME                 = 0x10002,
55a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* VbSelectFirmware() failed to find a valid firmware */
56a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_LOAD_FIRMWARE                 = 0x10003,
57a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to write firmware versions to TPM */
58a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_WRITE_FIRMWARE            = 0x10004,
59a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to lock firmware versions in TPM */
60a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_LOCK_FIRMWARE             = 0x10005,
61a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to set boot mode state in TPM */
62a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_SET_BOOT_MODE_STATE       = 0x10006,
63a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* TPM requires reboot */
64a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_REBOOT_REQUIRED           = 0x10007,
65a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to set up TPM */
66a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_FIRMWARE_SETUP            = 0x10008,
67a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to read kernel versions from TPM */
68a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_READ_KERNEL               = 0x10009,
69a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Attempt to load developer-only firmware with developer switch off */
70a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_DEV_FIRMWARE_SWITCH_MISMATCH  = 0x1000A,
71a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to write kernel versions to TPM */
72a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_WRITE_KERNEL              = 0x1000B,
73a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to lock kernel versions in TPM */
74a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_TPM_LOCK_KERNEL               = 0x1000C,
75a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Calling firmware requested shutdown via VbExIsShutdownRequested() */
76a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_SHUTDOWN_REQUESTED            = 0x1000D,
77a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Unable to find a boot device on which to look for a kernel */
78a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_NO_DISK_FOUND                 = 0x1000E,
79a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* No OS kernel found on any boot device */
80a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_NO_KERNEL_FOUND               = 0x1000F,
81a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* All OS kernels found were invalid (corrupt, improperly signed...) */
82a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_INVALID_KERNEL_FOUND          = 0x10010,
83a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* VbSelectAndLoadKernel() requested recovery mode */
84a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_LOAD_KERNEL_RECOVERY          = 0x10011,
85a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Other error inside VbSelectAndLoadKernel() */
86a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_LOAD_KERNEL                   = 0x10012,
87a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Invalid Google binary block */
88a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_INVALID_GBB                   = 0x10013,
89a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Invalid bitmap volume */
90a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_INVALID_BMPFV                 = 0x10014,
91a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Invalid screen index */
92a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_INVALID_SCREEN_INDEX          = 0x10015,
93a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Simulated (test) error */
94a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_SIMULATED                     = 0x10016,
95a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Invalid parameter */
96a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_INVALID_PARAMETER             = 0x10017,
97a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* VbExBeep() can't make sounds at all */
98a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_NO_SOUND                      = 0x10018,
99a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* VbExBeep() can't make sound in the background */
100a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_NO_BACKGROUND_SOUND           = 0x10019,
101a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Developer has requested a BIOS shell */
102a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_BIOS_SHELL_REQUESTED          = 0x10020,
103a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Need VGA and don't have it, or vice-versa */
104a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VBERROR_VGA_OPROM_MISMATCH            = 0x10021,
105a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Need EC to reboot to read-only code */
1065cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler	VBERROR_EC_REBOOT_TO_RO_REQUIRED      = 0x10022,
107527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	/* Invalid region read parameters */
108527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	VBERROR_REGION_READ_INVALID           = 0x10023,
109527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	/* Cannot read from region */
110527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	VBERROR_REGION_READ_FAILED            = 0x10024,
111527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	/* Unsupported region type */
112527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	VBERROR_UNSUPPORTED_REGION            = 0x10025,
113527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	/* No image present (returned from VbGbbReadImage() for missing image) */
114527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	VBERROR_NO_IMAGE_PRESENT              = 0x10026,
1155cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler
1165cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler	/* VbExEcGetExpectedRWHash() may return the following codes */
1175cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler	/* Compute expected RW hash from the EC image; BIOS doesn't have it */
1185cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler	VBERROR_EC_GET_EXPECTED_HASH_FROM_IMAGE = 0x20000,
1191cf77cda5ea2d7549caccb953079263d463feadbRandall Spangler};
120a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
121a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
122a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
123a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Main entry points from firmware into vboot_reference */
124a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
125a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
126a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Minimum and recommended size of shared_data_blob in bytes.  Shared data blob
127a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * is used to communicate data between calls to VbInit(), VbSelectFirmware(),
128a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * the OS.  Minimum size is enough to hold all required data for verified boot
129a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * but may not be able to hold debug output.
130a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
131a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_SHARED_DATA_MIN_SIZE 3072
132a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_SHARED_DATA_REC_SIZE 16384
133a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
134a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
135a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Data passed by firmware to VbInit(), VbSelectFirmware() and
136a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * VbSelectAndLoadKernel().
137a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
138a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Note that in UEFI, these are called by different phases in different
139a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * processor modes (VbInit() and VbSelectFirmware() = 32-bit PEI,
140a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * VbSelectAndLoadKernel() = 64-bit BDS), so the data may be at a different
141a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * location between calls.
142a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
143a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglertypedef struct VbCommonParams {
144a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Pointer to GBB data */
145a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	void *gbb_data;
146a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Size of GBB data in bytes */
147a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t gbb_size;
148a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
149a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
150a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * Shared data blob for data shared between verified boot entry points.
151a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * This should be at least VB_SHARED_DATA_MIN_SIZE bytes long, and
152a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * ideally is VB_SHARED_DATA_REC_SIZE bytes long.
153a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
154a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Pointer to shared data blob buffer */
155a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	void *shared_data_blob;
156a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
157a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * On input, set to size of shared data blob buffer, in bytes.  On
158a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * output, this will contain the actual data size placed into the
159a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * buffer.
160a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
161a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t shared_data_size;
162a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
163a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
164a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * Internal context/data for verified boot, to maintain state during
165a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * calls to other API functions such as VbExHashFirmwareBody().
166a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * Allocated and freed inside the entry point; firmware should not look
167a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * at this.
168a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
169a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	void *vboot_context;
170a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
171a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
172a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * Internal context/data for firmware / VbExHashFirmwareBody().  Needed
173a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * because the PEI phase of UEFI boot runs out of ROM and thus can't
174a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * modify global variables; everything needs to get passed around on
175a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * the stack.
176a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
177a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	void *caller_context;
178527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
179527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	/* For internal use of Vboot - do not examine or modify! */
180527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	struct GoogleBinaryBlockHeader *gbb;
181527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	struct BmpBlockHeader *bmp;
182a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler} VbCommonParams;
183a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
184a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Flags for VbInitParams.flags */
185a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Developer switch was on at boot time. */
186a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_INIT_FLAG_DEV_SWITCH_ON       0x00000001
187a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Recovery button was pressed at boot time. */
188a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_INIT_FLAG_REC_BUTTON_PRESSED  0x00000002
189a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Hardware write protect was enabled at boot time. */
190a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_INIT_FLAG_WP_ENABLED          0x00000004
1911b1998dff0002f20b3f27a21e6e79d8951e64684Randall Spangler/* This is a S3 resume, not a normal boot. */
1921b1998dff0002f20b3f27a21e6e79d8951e64684Randall Spangler#define VB_INIT_FLAG_S3_RESUME           0x00000008
193a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
194a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Previous boot attempt failed for reasons external to verified boot (RAM
195a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * init failure, SSD missing, etc.).
196a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
197a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * TODO: add a field to VbInitParams which holds a reason code, and report
198a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * that via VbSharedData.
199a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
2009619112a574b975476667545e3a326052fa0c50bRandall Spangler#define VB_INIT_FLAG_PREVIOUS_BOOT_FAIL  0x00000010
201a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
202a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Calling firmware supports read only firmware for normal/developer boot path.
203a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
2048bf0d5ff0ff77aaf496507bbe8d65a5f3027c80cRandall Spangler#define VB_INIT_FLAG_RO_NORMAL_SUPPORT   0x00000020
205a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
206a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This platform does not have a physical dev-switch, so we must rely on a
207b75d8adcc01f08cf5a6d87b78aeb1d7cdfcd22afBill Richardson * virtual switch (kept in the TPM) instead. When this flag is set,
208a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * VB_INIT_FLAG_DEV_SWITCH_ON is ignored.
209a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
210b75d8adcc01f08cf5a6d87b78aeb1d7cdfcd22afBill Richardson#define VB_INIT_FLAG_VIRTUAL_DEV_SWITCH  0x00000040
21117b8224ea582b2ba90b30a3e8e2d913e49c7818aBill Richardson/* Set when the VGA Option ROM has been loaded already. */
21217b8224ea582b2ba90b30a3e8e2d913e49c7818aBill Richardson#define VB_INIT_FLAG_OPROM_LOADED        0x00000080
21388d9375f50726fb26f1d4fcb909aa15256e24a17Bill Richardson/* Set if we care about the VGA Option ROM - some platforms don't. */
21488d9375f50726fb26f1d4fcb909aa15256e24a17Bill Richardson#define VB_INIT_FLAG_OPROM_MATTERS       0x00000100
215b2ac7fbbbf05fecfbabd37f6a2e4b268c9ac330fRandall Spangler/* EC on this platform supports EC software sync. */
21688d9375f50726fb26f1d4fcb909aa15256e24a17Bill Richardson#define VB_INIT_FLAG_EC_SOFTWARE_SYNC    0x00000200
217f217520215e7e3d2f5ca006992ab5002927c4f87Bill Richardson/* EC on this platform is slow to update. */
218f217520215e7e3d2f5ca006992ab5002927c4f87Bill Richardson#define VB_INIT_FLAG_EC_SLOW_UPDATE      0x00000400
219a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
220a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Software write protect was enabled at boot time. This is separate from the
221a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * HW write protect. Both must be set for flash write protection to work.
222a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
2239dc62178c97b94e5c308f1c36fd0858c316959e5Bill Richardson#define VB_INIT_FLAG_SW_WP_ENABLED       0x00000800
224a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
225a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
226a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Output flags for VbInitParams.out_flags.  Used to indicate potential boot
227a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * paths and configuration to the calling firmware early in the boot process,
228a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * so that it can properly configure itself for the capabilities subsequently
229a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * required by VbSelectFirmware() and VbSelectAndLoadKernel().
230a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
231a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
232a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Enable recovery path.  Do not rely on any rewritable data (cached RAM
233a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * timings, etc.).  Reliable operation is more important than boot speed.
234a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
235a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_INIT_OUT_ENABLE_RECOVERY      0x00000001
236a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* RAM must be cleared before calling VbSelectFirmware(). */
237a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_INIT_OUT_CLEAR_RAM            0x00000002
238a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
239a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Load display drivers; VbExDisplay*() functions may be called.  If this flag
240a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * is not present, VbExDisplay*() functions will not be called this boot.
241a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
242a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_INIT_OUT_ENABLE_DISPLAY       0x00000004
243a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
244a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Load USB storage drivers; VbExDisk*() functions may be called with the
245a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * VB_DISK_FLAG_REMOVABLE flag.  If this flag is not present, VbExDisk*()
246a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * functions will only be called for fixed disks.
247a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
248a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_INIT_OUT_ENABLE_USB_STORAGE   0x00000008
2491b1998dff0002f20b3f27a21e6e79d8951e64684Randall Spangler/* If this is a S3 resume, do a debug reset boot instead */
2501b1998dff0002f20b3f27a21e6e79d8951e64684Randall Spangler#define VB_INIT_OUT_S3_DEBUG_BOOT        0x00000010
251c8e4ff7c15e6bf5992a578b66bec47d69cde3beaBill Richardson/* BIOS should load any PCI option ROMs it finds, not just internal video */
252c8e4ff7c15e6bf5992a578b66bec47d69cde3beaBill Richardson#define VB_INIT_OUT_ENABLE_OPROM         0x00000020
2530d11efb0dc1d8d2b5eafdd5b65bce82e73fdeeccBill Richardson/* BIOS may be asked to boot something other than ChromeOS */
2540d11efb0dc1d8d2b5eafdd5b65bce82e73fdeeccBill Richardson#define VB_INIT_OUT_ENABLE_ALTERNATE_OS  0x00000040
255dc6b642b47168a09fa1702092961595ab0674c03Che-Liang Chiou/* Enable developer path. */
256dc6b642b47168a09fa1702092961595ab0674c03Che-Liang Chiou#define VB_INIT_OUT_ENABLE_DEVELOPER     0x00000080
257a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
258a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Data only used by VbInit() */
259a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglertypedef struct VbInitParams {
260a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Inputs to VbInit() */
261a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Flags (see VB_INIT_FLAG_*) */
262a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t flags;
263a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
264a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Outputs from VbInit(); valid only if it returns success. */
265a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Output flags for firmware; see VB_INIT_OUT_*) */
266a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t out_flags;
267a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler} VbInitParams;
268a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
269a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
270a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Firmware types for VbHashFirmwareBody() and
271a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * VbSelectFirmwareParams.selected_firmware.  Note that we store these in a
272a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * uint32_t because enum maps to int, which isn't fixed-size.
273a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
274a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglerenum VbSelectFirmware_t {
275a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Recovery mode */
276a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SELECT_FIRMWARE_RECOVERY = 0,
277a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Rewritable firmware A/B for normal or developer path */
278a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SELECT_FIRMWARE_A = 1,
279a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SELECT_FIRMWARE_B = 2,
280a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Read only firmware for normal or developer path. */
281195e4e8b03f98cb4ad841566053324b85b8903eaSimon Glass	VB_SELECT_FIRMWARE_READONLY = 3,
282195e4e8b03f98cb4ad841566053324b85b8903eaSimon Glass        VB_SELECT_FIRMWARE_COUNT,
283a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler};
284a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
285a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Data only used by VbSelectFirmware() */
286a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglertypedef struct VbSelectFirmwareParams {
287a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Inputs to VbSelectFirmware() */
288a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Key block + preamble for firmware A */
289a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	void *verification_block_A;
290a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Key block + preamble for firmware B */
291a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	void *verification_block_B;
292a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Verification block A size in bytes */
293a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t verification_size_A;
294a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Verification block B size in bytes */
295a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t verification_size_B;
296a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
297a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Outputs from VbSelectFirmware(); valid only if it returns success. */
298a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Main firmware to run; see VB_SELECT_FIRMWARE_*. */
299a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t selected_firmware;
300a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler} VbSelectFirmwareParams;
301a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
302a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
303a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * We use disk handles rather than indices.  Using indices causes problems if
304a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * a disk is removed/inserted in the middle of processing.
305a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
306a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglertypedef void *VbExDiskHandle_t;
307a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
308a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Data used only by VbSelectAndLoadKernel() */
309a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglertypedef struct VbSelectAndLoadKernelParams {
310a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Inputs to VbSelectAndLoadKernel() */
311a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Destination buffer for kernel (normally at 0x100000 on x86) */
312a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	void *kernel_buffer;
313a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Size of kernel buffer in bytes */
314a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t kernel_buffer_size;
315a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
316a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
317a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * Outputs from VbSelectAndLoadKernel(); valid only if it returns
318a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * success.
319a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
320a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Handle of disk containing loaded kernel */
321a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VbExDiskHandle_t disk_handle;
322a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Partition number on disk to boot (1...M) */
323a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t partition_number;
324a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Address of bootloader image in RAM */
325a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint64_t bootloader_address;
326a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Size of bootloader image in bytes */
327a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t bootloader_size;
328a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* UniquePartitionGuid for boot partition */
329a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint8_t partition_guid[16];
330a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
331a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * TODO: in H2C, all that pretty much just gets passed to the
332a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * bootloader as KernelBootloaderOptions, though the disk handle is
333a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * passed as an index instead of a handle.  Is that used anymore now
334a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * that we're passing partition_guid?
335a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
336a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler} VbSelectAndLoadKernelParams;
337a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
338a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
339a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Initialize the verified boot library.
340a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
341a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * Returns VBERROR_SUCCESS if success, non-zero if error; on error,
342a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * caller should reboot.
343a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
344a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbInit(VbCommonParams *cparams, VbInitParams *iparams);
345a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
346a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
347a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Select the main firmware.
348a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
349a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * Returns VBERROR_SUCCESS if success, non-zero if error; on error,
350a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * caller should reboot.
351a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
352a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * NOTE: This is now called in all modes, including recovery.  Previously,
353a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * LoadFirmware() was not called in recovery mode, which meant that
354a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * LoadKernel() needed to duplicate the TPM and VbSharedData initialization
355a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * code.
356a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
357a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbSelectFirmware(VbCommonParams *cparams,
358a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler                           VbSelectFirmwareParams *fparams);
359a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
360a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
361a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Update the data hash for the current firmware image, extending it by [size]
362a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * bytes stored in [*data].  This function must only be called inside
363a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * VbExHashFirmwareBody(), which is in turn called by VbSelectFirmware().
364a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
365a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglervoid VbUpdateFirmwareBodyHash(VbCommonParams *cparams,
366a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler                              uint8_t *data, uint32_t size);
367a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
368a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
369a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Select and loads the kernel.
370a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
371a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Returns VBERROR_SUCCESS if success, non-zero if error; on error, caller
372a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * should reboot. */
373a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbSelectAndLoadKernel(VbCommonParams *cparams,
374a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler                                VbSelectAndLoadKernelParams *kparams);
375a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
376a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
377a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Debug output (from utility.h) */
378a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
379a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
380a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Output an error message and quit.  Does not return.  Supports
381a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * printf()-style formatting.
382a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
383a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglervoid VbExError(const char *format, ...);
384a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
385a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
386a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Output a debug message.  Supports printf()-style formatting.
387a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
3887aa250f2db901f523b050ca897237ec1e2be678aVadim Bendeburyvoid VbExDebug(const char *format, ...)
3897aa250f2db901f523b050ca897237ec1e2be678aVadim Bendebury	__attribute__ ((format (__printf__, 1, 2)));
390a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
391a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
392a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Memory (from utility.h) */
393a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
394a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
395a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Allocate [size] bytes and return a pointer to the allocated memory. Abort
396a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * on error; this always either returns a good pointer or never returns.
397a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
398a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * If any of the firmware API implementations require aligned data (for
399a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * example, disk access on ARM), all pointers returned by VbExMalloc() must
400a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * also be aligned.
401a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
402a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglervoid *VbExMalloc(size_t size);
403a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
404a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
405a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Free memory pointed to by [ptr] previously allocated by VbExMalloc().
406a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
407a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spanglervoid VbExFree(void *ptr);
408a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
409a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
410a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Timer and delay (first two from utility.h) */
411a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
412a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
413a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Read a high-resolution timer.  Returns the current timer value in arbitrary
414a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * units.
415a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
416a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This is intended for benchmarking, so this call MUST be fast.  The timer
417a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * frequency must be >1 KHz (preferably >1 MHz), and the timer must not wrap
418a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * around for at least 10 minutes.  It is preferable (but not required) that
419a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * the timer be initialized to 0 at boot.
420a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
421a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * It is assumed that the firmware has some other way of communicating the
422a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * timer frequency to the OS.  For example, on x86 we use TSC, and the OS
423a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * kernel reports the initial TSC value at kernel-start and calculates the
424a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * frequency. */
425a45ee21bb023665b51e09f722555d9e560fab232Randall Spangleruint64_t VbExGetTimer(void);
426a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
427a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
428a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Delay for at least the specified number of milliseconds.  Should be accurate
429a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * to within 10% (a requested delay of 1000 ms should result in an actual delay
430a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * of between 1000 - 1100 ms).
431a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
432a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglervoid VbExSleepMs(uint32_t msec);
433a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
434a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
435a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Play a beep tone of the specified frequency in Hz and duration in msec.
436a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * This is effectively a VbSleep() variant that makes noise.
437a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
4384313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson * If the audio codec can run in the background, then:
4394313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson *   zero frequency means OFF, non-zero frequency means ON
4404313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson *   zero msec means return immediately, non-zero msec means delay (and
4414313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson *     then OFF if needed)
442a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * otherwise,
4434313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson *   non-zero msec and non-zero frequency means ON, delay, OFF, return
4444313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson *   zero msec or zero frequency means do nothing and return immediately
4454313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson *
4464313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson * The return value is used by the caller to determine the capabilities. The
4474313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson * implementation should always do the best it can if it cannot fully support
4484313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson * all features - for example, beeping at a fixed frequency if frequency
4494313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson * support is not available.  At a minimum, it must delay for the specified
4504313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson * non-zero duration.
4514313fba2fb928f662a63b7566f235291dc1455f7Bill Richardson */
4524313fba2fb928f662a63b7566f235291dc1455f7Bill RichardsonVbError_t VbExBeep(uint32_t msec, uint32_t frequency);
453a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
454a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
455a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* TPM (from tlcl_stub.h) */
456a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
457a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
458a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Initialize the stub library. */
459a45ee21bb023665b51e09f722555d9e560fab232Randall SpanglerVbError_t VbExTpmInit(void);
460a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
461a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
462a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Close and open the device.  This is needed for running more complex commands
463a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * at user level, such as TPM_TakeOwnership, since the TPM device can be opened
464a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * only by one process at a time.
465a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
466a45ee21bb023665b51e09f722555d9e560fab232Randall SpanglerVbError_t VbExTpmClose(void);
467a45ee21bb023665b51e09f722555d9e560fab232Randall SpanglerVbError_t VbExTpmOpen(void);
468a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
469a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
470a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Send a request_length-byte request to the TPM and receive a response.  On
471a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * input, response_length is the size of the response buffer in bytes.  On
472a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * exit, response_length is set to the actual received response length in
473a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * bytes. */
474a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExTpmSendReceive(const uint8_t *request, uint32_t request_length,
475a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler                             uint8_t *response, uint32_t *response_length);
476a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
477a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
478a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Non-volatile storage */
479a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
480a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VBNV_BLOCK_SIZE 16  /* Size of NV storage block in bytes */
481a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
482a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
483a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Read the VBNV_BLOCK_SIZE-byte non-volatile storage into buf.
484a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
485a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExNvStorageRead(uint8_t *buf);
486a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
487a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
488a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Write the VBNV_BLOCK_SIZE-byte non-volatile storage from buf.
489a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
490a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExNvStorageWrite(const uint8_t *buf);
491a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
492a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
493a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Firmware / EEPROM access (previously in load_firmware_fw.h) */
494a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
495a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
496a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Calculate the hash of the firmware body data for [firmware_index], which is
497a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * either VB_SELECT_FIRMWARE_A or VB_SELECT_FIRMWARE B.
498a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
499a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This function must call VbUpdateFirmwareBodyHash() before returning, to
500a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * update the secure hash for the firmware image.  For best performance, the
501a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * implementation should call VbUpdateFirmwareBodyHash() periodically during
502a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * the read, so that updating the hash can be pipelined with the read.  If the
503a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * reader cannot update the hash during the read process, it should call
504a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * VbUpdateFirmwareBodyHash() on the entire firmware data after the read,
505a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * before returning.
506a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
507a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * It is recommended that the firmware use this call to copy the requested
508a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * firmware body from EEPROM into RAM, so that it doesn't need to do a second
509a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * slow copy from EEPROM to RAM if this firmware body is selected.
510a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
511a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Note this function doesn't actually pass the firmware body data to verified
512a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * boot, because verified boot doesn't actually need the firmware body, just
513a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * its hash.  This is important on x86, where the firmware is stored
514a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * compressed.  We hash the compressed data, but the BIOS decompresses it
515a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * during read.  Simply updating a hash is compatible with the x86
516a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * read-and-decompress pipeline.
517a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
518a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExHashFirmwareBody(VbCommonParams *cparams,
519a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler                               uint32_t firmware_index);
520a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
521a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
522a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Disk access (previously in boot_device.h) */
523a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
524a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Flags for VbDisk APIs */
525a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Disk is removable.  Example removable disks: SD cards, USB keys.  */
526a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_DISK_FLAG_REMOVABLE 0x00000001
527a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
528a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Disk is fixed.  If this flag is present, disk is internal to the system and
529a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * not removable.  Example fixed disks: internal SATA SSD, eMMC.
530a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
531a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#define VB_DISK_FLAG_FIXED     0x00000002
532a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/*
533a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Note that VB_DISK_FLAG_REMOVABLE and VB_DISK_FLAG_FIXED are
534a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * mutually-exclusive for a single disk.  VbExDiskGetInfo() may specify both
535a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * flags to request disks of both types in a single call.
536a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
537a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * At some point we could specify additional flags, but we don't currently
538a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * have a way to make use of these:
539a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
540a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * USB              Device is known to be attached to USB.  Note that the SD
541a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *                  card reader inside x86 systems is attached to USB so this
542a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *                  isn't super useful.
543a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * SD               Device is known to be a SD card.  Note that external card
544a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *                  readers might not return this information, so also of
545a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *                  questionable use.
546a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * READ_ONLY        Device is known to be read-only.  Could be used by recovery
547a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *                  when processing read-only recovery image.
548a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
549a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
550a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Information on a single disk */
551a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglertypedef struct VbDiskInfo {
552a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Disk handle */
553a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VbExDiskHandle_t handle;
554a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Size of a LBA sector in bytes */
555a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint64_t bytes_per_lba;
556a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Number of LBA sectors on the device */
557a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint64_t lba_count;
558a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Flags (see VB_DISK_FLAG_* constants) */
559a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	uint32_t flags;
560a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/*
561a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * Optional name string, for use in debugging.  May be empty or null if
562a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 * not available.
563a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	 */
564a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	const char *name;
565a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler} VbDiskInfo;
566a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
567a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
568a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Store information into [info] for all disks (storage devices) attached to
569a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * the system which match all of the disk_flags.
570a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
571a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * On output, count indicates how many disks are present, and [infos_ptr]
572a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * points to a [count]-sized array of VbDiskInfo structs with the information
573a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * on those disks; this pointer must be freed by calling VbExDiskFreeInfo().
574a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * If count=0, infos_ptr may point to NULL.  If [infos_ptr] points to NULL
575a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * because count=0 or error, it is not necessary to call VbExDiskFreeInfo().
576a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
577a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * A multi-function device (such as a 4-in-1 card reader) should provide
578a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * multiple disk handles.
579a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
580a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * The firmware must not alter or free the list pointed to by [infos_ptr] until
581a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * VbExDiskFreeInfo() is called.
582a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
583a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExDiskGetInfo(VbDiskInfo **infos_ptr, uint32_t *count,
584a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler                          uint32_t disk_flags);
585a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
586a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
587a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Free a disk information list [infos] previously returned by
588a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * VbExDiskGetInfo().  If [preserve_handle] != NULL, the firmware must ensure
589a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * that handle remains valid after this call; all other handles from the info
590a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * list need not remain valid after this call.
591a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
592a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExDiskFreeInfo(VbDiskInfo *infos,
593a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler                           VbExDiskHandle_t preserve_handle);
594a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
595a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
596a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Read lba_count LBA sectors, starting at sector lba_start, from the disk,
597a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * into the buffer.
598a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
599a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * If the disk handle is invalid (for example, the handle refers to a disk
600a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * which as been removed), the function must return error but must not
601a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * crash.
602a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
603a45ee21bb023665b51e09f722555d9e560fab232Randall SpanglerVbError_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start,
604a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler                       uint64_t lba_count, void *buffer);
605a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
606a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
607a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Write lba_count LBA sectors, starting at sector lba_start, to the disk, from
608a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * the buffer.
609a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
610a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * If the disk handle is invalid (for example, the handle refers to a disk
611a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * which as been removed), the function must return error but must not
612a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * crash.
613a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
614a45ee21bb023665b51e09f722555d9e560fab232Randall SpanglerVbError_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start,
615a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler                        uint64_t lba_count, const void *buffer);
616a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
617a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
618a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Display */
619a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
620a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Predefined (default) screens for VbExDisplayScreen(). */
621a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglerenum VbScreenType_t {
622a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Blank (clear) screen */
623a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_BLANK = 0,
624a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Developer - warning */
625a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_DEVELOPER_WARNING = 0x101,
626a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Developer - easter egg */
627a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_DEVELOPER_EGG     = 0x102,
628a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Recovery - remove inserted devices */
629a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_RECOVERY_REMOVE   = 0x201,
630a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Recovery - insert recovery image */
631a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_RECOVERY_INSERT   = 0x202,
632a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Recovery - inserted image invalid */
633a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_RECOVERY_NO_GOOD  = 0x203,
634a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Recovery - confirm dev mode */
635a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_RECOVERY_TO_DEV   = 0x204,
636a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Developer - confirm normal mode */
637a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_DEVELOPER_TO_NORM = 0x205,
638a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Please wait - programming EC */
639a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_WAIT              = 0x206,
640a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	/* Confirm after DEVELOPER_TO_NORM */
641a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_SCREEN_TO_NORM_CONFIRMED = 0x207,
642a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler};
643a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
644a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
645a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Initialize and clear the display.  Set width and height to the screen
646a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * dimensions in pixels.
647a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
648a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExDisplayInit(uint32_t *width, uint32_t *height);
649a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
650a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
651a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Enable (enable!=0) or disable (enable=0) the display backlight.
652a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
653a45ee21bb023665b51e09f722555d9e560fab232Randall SpanglerVbError_t VbExDisplayBacklight(uint8_t enable);
654a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
655a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
656a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Display a predefined screen; see VB_SCREEN_* for valid screens.
657a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
658a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This is a backup method of screen display, intended for use if the GBB does
659a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * not contain a full set of bitmaps.  It is acceptable for the backup screen
660a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * to be simple ASCII text such as "NO GOOD" or "INSERT"; these screens should
661a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * only be seen during development.
662a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
663a45ee21bb023665b51e09f722555d9e560fab232Randall SpanglerVbError_t VbExDisplayScreen(uint32_t screen_type);
664a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
665a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
666a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Write an image to the display, with the upper left corner at the specified
667b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * pixel coordinates.  The bitmap buffer is a pointer to the platform-dependent
668b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * uncompressed binary blob with dimensions and format specified internally
669b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * (for example, a raw BMP, GIF, PNG, whatever). We pass the size just for
670b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * convenience.
671b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson */
672b1c85a8442fd2d8e05705cdcadfa40865e952975Bill RichardsonVbError_t VbExDisplayImage(uint32_t x, uint32_t y,
673a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler                           void *buffer, uint32_t buffersize);
674a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler
675a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
676a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Display a string containing debug information on the screen, rendered in a
677a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * platform-dependent font.  Should be able to handle newlines '\n' in the
678a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * string.  Firmware must support displaying at least 20 lines of text, where
679a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * each line may be at least 80 characters long.  If the firmware has its own
680a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * debug state, it may display it to the screen below this information.
681a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
682a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * NOTE: This is what we currently display when TAB is pressed.  Some
683a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * information (HWID, recovery reason) is ours; some (CMOS breadcrumbs) is
684a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * platform-specific.  If we decide to soft-render the HWID string
685a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * (chrome-os-partner:3693), we'll need to maintain our own fonts, so we'll
686a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * likely display it via VbExDisplayImage() above.
687a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
688a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall SpanglerVbError_t VbExDisplayDebugInfo(const char *info_str);
689a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
690a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
691a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Keyboard and switches */
692a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
693a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Key codes for required non-printable-ASCII characters. */
694a45ee21bb023665b51e09f722555d9e560fab232Randall Spanglerenum VbKeyCode_t {
695a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_KEY_UP = 0x100,
696a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_KEY_DOWN = 0x101,
697a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_KEY_LEFT = 0x102,
698a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_KEY_RIGHT = 0x103,
699a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler	VB_KEY_CTRL_ENTER = 0x104,
700a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler};
701a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
702a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
703a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Read the next keypress from the keyboard buffer.
704a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
705a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * Returns the keypress, or zero if no keypress is pending or error.
706a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
707a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * The following keys must be returned as ASCII character codes:
708a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x08          Backspace
709a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x09          Tab
710a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x0D          Enter (carriage return)
711a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x01 - 0x1A   Ctrl+A - Ctrl+Z (yes, those alias with backspace/tab/enter)
712a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x1B          Esc
713a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x20          Space
714a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x30 - 0x39   '0' - '9'
715a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    0x60 - 0x7A   'a' - 'z'
716a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
717a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * Some extended keys must also be supported; see the VB_KEY_* defines above.
718a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
719a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * Keys ('/') or key-chords (Fn+Q) not defined above may be handled in any of
720a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * the following ways:
721a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    1. Filter (don't report anything if one of these keys is pressed).
722a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    2. Report as ASCII (if a well-defined ASCII value exists for the key).
723a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *    3. Report as any other value in the range 0x200 - 0x2FF.
724a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * It is not permitted to report a key as a multi-byte code (for example,
725a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * sending an arrow key as the sequence of keys '\x1b', '[', '1', 'A'). */
726a45ee21bb023665b51e09f722555d9e560fab232Randall Spangleruint32_t VbExKeyboardRead(void);
727a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
728a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/*****************************************************************************/
729053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler/* Embedded controller (EC) */
730053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
731a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
732a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * This is called only if the system implements a keyboard-based (virtual)
733053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler * developer switch. It must return true only if the system has an embedded
734053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler * controller which is provably running in its RO firmware at the time the
735a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * function is called.
736a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
737053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spanglerint VbExTrustEC(void);
738053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
739a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
740a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Check if the EC is currently running rewritable code.
741053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler *
742053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler * If the EC is in RO code, sets *in_rw=0.
743053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler * If the EC is in RW code, sets *in_rw non-zero.
744053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler * If the current EC image is unknown, returns error. */
745053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall SpanglerVbError_t VbExEcRunningRW(int *in_rw);
746053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
747a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
748a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Request the EC jump to its rewritable code.  If successful, returns when the
749a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * EC has booting its RW code far enough to respond to subsequent commands.
750a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Does nothing if the EC is already in its rewritable code.
751a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
752053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall SpanglerVbError_t VbExEcJumpToRW(void);
753053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
754a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
7558912169231e589b0400debed26f9cedbbe6d9561Daisuke Nojiri * Tell the EC to refuse another jump until it reboots. Subsequent calls to
7568912169231e589b0400debed26f9cedbbe6d9561Daisuke Nojiri * VbExEcJumpToRW() in this boot will fail.
757a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
7588912169231e589b0400debed26f9cedbbe6d9561Daisuke NojiriVbError_t VbExEcDisableJump(void);
759053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
760a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
761a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Read the SHA-256 hash of the rewriteable EC image.
762a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
763053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall SpanglerVbError_t VbExEcHashRW(const uint8_t **hash, int *hash_size);
764053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
765a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
766a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Get the expected contents of the EC image associated with the main firmware
767a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * specified by the "select" argument.
768a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
769029ae65756993979c22035e3706e2b04049ef9feRandall SpanglerVbError_t VbExEcGetExpectedRW(enum VbSelectFirmware_t select,
770029ae65756993979c22035e3706e2b04049ef9feRandall Spangler                              const uint8_t **image, int *image_size);
771053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
772a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
7735cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler * Read the SHA-256 hash of the expected contents of the EC image associated
7745cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler * with the main firmware specified by the "select" argument.
7755cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler */
7765cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall SpanglerVbError_t VbExEcGetExpectedRWHash(enum VbSelectFirmware_t select,
7775cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler		       const uint8_t **hash, int *hash_size);
7785cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler
7795cfcab54375c93fec3f04cd1cb76ea2f5beaaf97Randall Spangler/**
780a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Update the EC rewritable image.
781a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
782053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall SpanglerVbError_t VbExEcUpdateRW(const uint8_t *image, int image_size);
783053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
784a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
785a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Lock the EC code to prevent updates until the EC is rebooted.
786a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Subsequent calls to VbExEcUpdateRW() this boot will fail.
787a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
788053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall SpanglerVbError_t VbExEcProtectRW(void);
789053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
790e0c55a3238f41ce30d6d592725670766355bed67Bill Richardson/* Args to VbExProtectFlash() */
791e0c55a3238f41ce30d6d592725670766355bed67Bill Richardsonenum VbProtectFlash_t { VBPROTECT_RW_A, VBPROTECT_RW_B, VBPROTECT_RW_DEVKEY };
792e0c55a3238f41ce30d6d592725670766355bed67Bill Richardson
793a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
794a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Lock a section of the BIOS flash address space to prevent updates until the
795e0c55a3238f41ce30d6d592725670766355bed67Bill Richardson * host is rebooted. Subsequent attempts to erase or modify the specified BIOS
796e0c55a3238f41ce30d6d592725670766355bed67Bill Richardson * image will fail. If this function is called more than once each call should
797a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * be cumulative.
798a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
799e0c55a3238f41ce30d6d592725670766355bed67Bill RichardsonVbError_t VbExProtectFlash(enum VbProtectFlash_t region);
800053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler
801053b7b682c60eb7bcf55a079ff7afccccef82fa6Randall Spangler/*****************************************************************************/
802a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler/* Misc */
803a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
804a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
805a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Check if the firmware needs to shut down the system.
806a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler *
807a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler * Returns 1 if a shutdown is being requested (for example, the user has
808a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * pressed the power button or closed the lid), or 0 if a shutdown is not being
809a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * requested.
810a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler *
811a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * NOTE: When we're displaying a screen, pressing the power button should shut
812a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * down the computer.  We need a way to break out of our control loop so this
813a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * can occur cleanly.
814a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
815a45ee21bb023665b51e09f722555d9e560fab232Randall Spangleruint32_t VbExIsShutdownRequested(void);
816a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler
817a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
818a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Expose the BIOS' built-in decompression routine to the vboot wrapper. The
819b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * caller must know how large the uncompressed data will be and must manage
820b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * that memory. The decompression routine just puts the uncompressed data into
821b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * the specified buffer. We pass in the size of the outbuf, and get back the
822b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson * actual size used.
823b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson */
824b1c85a8442fd2d8e05705cdcadfa40865e952975Bill RichardsonVbError_t VbExDecompress(void *inbuf, uint32_t in_size,
825b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson                         uint32_t compression_type,
826b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson                         void *outbuf, uint32_t *out_size);
827b1c85a8442fd2d8e05705cdcadfa40865e952975Bill Richardson
8280c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson/* Constants for compression_type */
8290c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardsonenum {
8300c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	COMPRESS_NONE = 0,
8310c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	COMPRESS_EFIv1,           /* The x86 BIOS only supports this */
8320c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	COMPRESS_LZMA1,           /* The ARM BIOS supports LZMA1 */
8330c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson	MAX_COMPRESS,
8340c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson};
8350c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson
836a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler/**
837a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler * Execute legacy boot option.
838a2db67d204c0dd3d152ff54958bf42c5dbe394ffRandall Spangler */
839a2326ee152ab5b8aee924ccf794cee38d54909bdStefan Reinauerint VbExLegacy(void);
840a2326ee152ab5b8aee924ccf794cee38d54909bdStefan Reinauer
841527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass/* Regions for VbExRegionRead() */
842527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glassenum vb_firmware_region {
843527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	VB_REGION_GBB,	/* Google Binary Block - see gbbheader.h */
844527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
845527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass	VB_REGION_COUNT,
846527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass};
847527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
848527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass/**
849527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * Read data from a region of the firmware image
850527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass *
851527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * Vboot wants access to a region, to read data from it. This function
852527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * reads it (typically from the firmware image such as SPI flash) and
853527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * returns the data.
854527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass *
855527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * cparams is passed so that the boot loader has some context for the
856527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * operation.
857527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass *
858527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * @param cparams	Common parameters, e.g. use member caller_context
859527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass *			to point to useful context data
860527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * @param region	Firmware region to read
861527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * @param offset	Start offset within region
862527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * @param size		Number of bytes to read
863527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * @param buf		Place to put data
864527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass * @return VBERROR_... error, VBERROR_SUCCESS on success,
865527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass */
866527ba810eff4006cf69579f6b96cb4350cb1e189Simon GlassVbError_t VbExRegionRead(VbCommonParams *cparams,
867527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass			 enum vb_firmware_region region, uint32_t offset,
868527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass			 uint32_t size, void *buf);
869527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass
870a45ee21bb023665b51e09f722555d9e560fab232Randall Spangler#endif  /* VBOOT_REFERENCE_VBOOT_API_H_ */
871