xref: /aosp_15_r20/external/vboot_reference/firmware/2lib/include/2info.h (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1 /* Copyright 2022 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  * Helper functions to retrieve vboot firmware information.
6  */
7 
8 #ifndef VBOOT_REFERENCE_2INFO_H_
9 #define VBOOT_REFERENCE_2INFO_H_
10 
11 /* Boot mode decided in vb2api_fw_phase1.
12  *
13  * Boot mode is a constant set by verified boot and may be read (but should not
14  * be set or cleared) by the caller.
15  * The boot modes are mutually exclusive. If a boot fulfill more than one
16  * constraints of the listing boot modes, it will be set to the most important
17  * one. The priority is the same as the listing order.
18  */
19 enum vb2_boot_mode {
20 	/* Undefined, The boot mode is not set. */
21 	VB2_BOOT_MODE_UNDEFINED = 0,
22 
23 	/*
24 	 * Manual recovery boot, regardless of dev mode state.
25 	 *
26 	 * VB2_CONTEXT_RECOVERY_MODE is set and the recovery is physically
27 	 * requested (a.k.a. Manual recovery).  All other recovery requests
28 	 * including manual recovery requested by a (compromised) host will end
29 	 * up with a broken screen.
30 	 */
31 	VB2_BOOT_MODE_MANUAL_RECOVERY = 1,
32 
33 	/*
34 	 * Broken screen.
35 	 *
36 	 * If a recovery boot is not a manual recovery (a.k.a. not requested
37 	 * physically), the recovery is not allowed and will end up with
38 	 * broken screen.
39 	 */
40 	VB2_BOOT_MODE_BROKEN_SCREEN = 2,
41 
42 	/*
43 	 * Diagnostic boot.
44 	 *
45 	 * If diagnostic boot is enabled (a.k.a. vb2api_diagnostic_ui_enabled)
46 	 * and the nvdata contains VB2_NV_DIAG_REQUEST from previous boot, it
47 	 * will boot to diagnostic mode.
48 	 */
49 	VB2_BOOT_MODE_DIAGNOSTICS = 3,
50 
51 	/*
52 	 * Developer boot: self-signed kernel okay.
53 	 *
54 	 * The developer mode switch is set (a.k.a. VB2_CONTEXT_DEVELOPER_MODE)
55 	 * and we are in the developer boot mode.
56 	 */
57 	VB2_BOOT_MODE_DEVELOPER = 4,
58 
59 	/* Normal boot: kernel must be verified. */
60 	VB2_BOOT_MODE_NORMAL = 5,
61 };
62 
63 /* Firmware slot codes */
64 enum vb2_fw_slot {
65 	/* Slot A */
66 	VB2_FW_SLOT_A = 0,
67 
68 	/* Slot B */
69 	VB2_FW_SLOT_B = 1,
70 };
71 
72 /* Firmware result codes for VB2_NV_FW_RESULT and VB2_NV_FW_PREV_RESULT */
73 enum vb2_fw_result {
74 	/* Unknown */
75 	VB2_FW_RESULT_UNKNOWN = 0,
76 
77 	/* Trying a new slot, but haven't reached success/failure */
78 	VB2_FW_RESULT_TRYING = 1,
79 
80 	/* Successfully booted to the OS */
81 	VB2_FW_RESULT_SUCCESS = 2,
82 
83 	/* Known failure */
84 	VB2_FW_RESULT_FAILURE = 3,
85 };
86 
87 /**
88  * Convert Firmware Boot Mode into supported string
89  *
90  * @return char*   firmware boot mode string
91  */
vb2_boot_mode_string(uint8_t boot_mode)92 static inline const char *vb2_boot_mode_string(uint8_t boot_mode)
93 {
94 	switch ((enum vb2_boot_mode)boot_mode) {
95 	/* 0x00 */ case VB2_BOOT_MODE_UNDEFINED:
96 		return "Undefined";
97 	/* 0x01 */ case VB2_BOOT_MODE_MANUAL_RECOVERY:
98 		return "Manual recovery";
99 	/* 0x02 */ case VB2_BOOT_MODE_BROKEN_SCREEN:
100 		return "Broken screen";
101 	/* 0x03 */ case VB2_BOOT_MODE_DIAGNOSTICS:
102 		return "Diagnostic";
103 	/* 0x04 */ case VB2_BOOT_MODE_DEVELOPER:
104 		return "Developer";
105 	/* 0x05 */ case VB2_BOOT_MODE_NORMAL:
106 		return "Secure";
107 	}
108 
109 	return "Unknown";
110 }
111 
112 /**
113  * Convert Firmware Slot result into supported string
114  *
115  * @return char*   firmware slot result string
116  */
vb2_result_string(uint8_t result)117 static inline const char *vb2_result_string(uint8_t result)
118 {
119 	switch ((enum vb2_fw_result)result) {
120 	/* 0x00 */ case VB2_FW_RESULT_UNKNOWN:
121 		return "Unknown";
122 	/* 0x01 */ case VB2_FW_RESULT_TRYING:
123 		return "Trying";
124 	/* 0x02 */ case VB2_FW_RESULT_SUCCESS:
125 		return "Success";
126 	/* 0x03 */ case VB2_FW_RESULT_FAILURE:
127 		return "Failure";
128 	}
129 
130 	return "Unknown";
131 }
132 
133 /**
134  * Convert Firmware Slot into supported string
135  *
136  * @return char*   firmware slot name string
137  */
vb2_slot_string(uint8_t slot)138 static inline const char *vb2_slot_string(uint8_t slot)
139 {
140 	if ((enum vb2_fw_slot)slot == VB2_FW_SLOT_A)
141 	/* 0x00 */ return "A";
142 	else
143 	/* 0x01 */ return "B";
144 }
145 
146 #endif  /* VBOOT_REFERENCE_2INFO_H_ */
147