xref: /aosp_15_r20/external/vboot_reference/firmware/2lib/include/2nvstorage_fields.h (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1 /* Copyright 2015 The ChromiumOS Authors
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  *
5  * Non-volatile storage bitfields
6  */
7 
8 #ifndef VBOOT_REFERENCE_2NVSTORAGE_FIELDS_H_
9 #define VBOOT_REFERENCE_2NVSTORAGE_FIELDS_H_
10 
11 /*
12  * Constants for NV storage.  We use this rather than structs and bitfields so
13  * the data format is consistent across platforms and compilers.  Total NV
14  * storage size is:
15  *
16  * Version 1: VB2_NVDATA_SIZE = 16 bytes
17  * Version 2: VB2_NVDATA_SIZE_V2 = 64 bytes
18  *
19  * Unused bits/bytes must be set to 0.
20  */
21 
22 enum vb2_nv_offset {
23 	/*** The following fields are present in all versions ***/
24 	VB2_NV_OFFS_HEADER = 0,
25 	VB2_NV_OFFS_BOOT = 1,
26 	VB2_NV_OFFS_RECOVERY = 2,
27 	VB2_NV_OFFS_LOCALIZATION = 3,
28 	VB2_NV_OFFS_DEV = 4,
29 	VB2_NV_OFFS_TPM = 5,
30 	VB2_NV_OFFS_RECOVERY_SUBCODE = 6,
31 	VB2_NV_OFFS_BOOT2 = 7,
32 	VB2_NV_OFFS_MISC = 8,
33 	VB2_NV_OFFS_KERNEL_MAX_ROLLFORWARD1 = 9, /* bits 0-7 of 32 */
34 	VB2_NV_OFFS_KERNEL_MAX_ROLLFORWARD2 = 10, /* bits 8-15 of 32 */
35 	VB2_NV_OFFS_KERNEL1 = 11, /* bits 0-7 of 16 */
36 	VB2_NV_OFFS_KERNEL2 = 12, /* bits 8-15 of 16 */
37 	VB2_NV_OFFS_KERNEL_MAX_ROLLFORWARD3 = 13, /* bits 16-23 of 32 */
38 	VB2_NV_OFFS_KERNEL_MAX_ROLLFORWARD4 = 14, /* bits 24-31 of 32 */
39 
40 	/*
41 	 * CRC_V1 must be last field in V1.  This byte can be reused in later
42 	 * versions.
43 	 */
44 	VB2_NV_OFFS_CRC_V1 = 15,
45 
46 	/* The following fields are only present in V2+ */
47 	VB2_NV_OFFS_RESERVED_V2 = 15, /* Was CRC in V1 (unused = 0xff) */
48 	VB2_NV_OFFS_FW_MAX_ROLLFORWARD1 = 16, /* bits 0-7 of 32 */
49 	VB2_NV_OFFS_FW_MAX_ROLLFORWARD2 = 17, /* bits 8-15 of 32 */
50 	VB2_NV_OFFS_FW_MAX_ROLLFORWARD3 = 18, /* bits 16-23 of 32 */
51 	VB2_NV_OFFS_FW_MAX_ROLLFORWARD4 = 19, /* bits 24-31 of 32 */
52 
53 	/* CRC must be last field */
54 	VB2_NV_OFFS_CRC_V2 = 63,
55 };
56 
57 /* Fields in VB2_NV_OFFS_HEADER (unused = 0x04) */
58 #define VB2_NV_HEADER_WIPEOUT			0x08
59 #define VB2_NV_HEADER_KERNEL_SETTINGS_RESET	0x10
60 #define VB2_NV_HEADER_FW_SETTINGS_RESET		0x20
61 #define VB2_NV_HEADER_SIGNATURE_MASK		0xc3
62 
63 /*
64  * Valid signature values.  Note that V1 readers only looked at mask 0xc0, and
65  * expect it to have value 0x40.  Versions != V1 must have the top two bits !=
66  * 0x40 so old readers will reject the data.  Using all 1-bits or all 0-bits is
67  * also discouraged, because that is indistinguishable from all-erased data on
68  * some platforms.
69  */
70 /* Version 1 = 16-byte record */
71 #define VB2_NV_HEADER_SIGNATURE_V1		0x40
72 /* Version 2 = 64-byte record */
73 #define VB2_NV_HEADER_SIGNATURE_V2		0x03
74 
75 /* Fields in VB2_NV_OFFS_BOOT */
76 #define VB2_NV_BOOT_TRY_COUNT_MASK		0x0f
77 #define VB2_NV_BOOT_BACKUP_NVRAM		0x10
78 #define VB2_NV_BOOT_DISPLAY_REQUEST		0x20
79 #define VB2_NV_BOOT_DISABLE_DEV			0x40
80 #define VB2_NV_BOOT_DEBUG_RESET			0x80
81 
82 /* Fields in VB2_NV_OFFS_BOOT2 */
83 #define VB2_NV_BOOT2_RESULT_MASK		0x03
84 #define VB2_NV_BOOT2_TRIED			0x04
85 #define VB2_NV_BOOT2_TRY_NEXT			0x08
86 #define VB2_NV_BOOT2_PREV_RESULT_MASK		0x30
87 #define VB2_NV_BOOT2_PREV_RESULT_SHIFT 4  /* Number of bits to shift result */
88 #define VB2_NV_BOOT2_PREV_TRIED			0x40
89 #define VB2_NV_BOOT2_REQ_DIAG			0x80
90 
91 /* Fields in VB2_NV_OFFS_DEV (unused = 0x80) */
92 #define VB2_NV_DEV_FLAG_EXTERNAL		0x01
93 #define VB2_NV_DEV_FLAG_SIGNED_ONLY		0x02
94 #define VB2_NV_DEV_FLAG_LEGACY			0x04
95 #define VB2_NV_DEV_FLAG_DEPRECATED_FASTBOOT_FULL_CAP	0x08
96 #define VB2_NV_DEV_FLAG_DEFAULT_BOOT		0x30
97 #define VB2_NV_DEV_DEFAULT_BOOT_SHIFT 4  /* Number of bits to shift */
98 #define VB2_NV_DEV_FLAG_UDC			0x40
99 
100 /* Fields in VB2_NV_OFFS_TPM (unused = 0xf8) */
101 #define VB2_NV_TPM_CLEAR_OWNER_REQUEST		0x01
102 #define VB2_NV_TPM_CLEAR_OWNER_DONE		0x02
103 #define VB2_NV_TPM_REBOOTED			0x04
104 
105 /* Fields in VB2_NV_OFFS_MISC (unused = 0xa0) */
106 #define VB2_NV_MISC_DEPRECATED_UNLOCK_FASTBOOT	0x01
107 #define VB2_NV_MISC_BOOT_ON_AC_DETECT		0x02
108 #define VB2_NV_MISC_TRY_RO_SYNC			0x04
109 #define VB2_NV_MISC_BATTERY_CUTOFF		0x08
110 #define VB2_NV_MISC_MINIOS_PRIORITY		0x10
111 #define VB2_NV_MISC_POST_EC_SYNC_DELAY		0x40
112 
113 #endif  /* VBOOT_REFERENCE_2NVSTORAGE_FIELDS_H_ */
114