blob: 61bfa0e557d0945f3668cb8c8b2af374a5b79416 [file] [log] [blame]
Simon Glass0a9f4262022-07-30 15:52:32 -06001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Verified Boot for Embedded (VBE) support
4 * See doc/develop/vbe.rst
5 *
6 * Copyright 2022 Google LLC
7 * Written by Simon Glass <sjg@chromium.org>
8 */
9
10#ifndef __VBE_H
11#define __VBE_H
12
Simon Glassc2213082025-01-26 11:43:29 -070013#include <linux/types.h>
14
Simon Glass0a9f4262022-07-30 15:52:32 -060015/**
Simon Glassa72641c2022-10-20 18:23:09 -060016 * enum vbe_phase_t - current phase of VBE
17 *
18 * VBE operates in two distinct phases. In VPL it has to choose which firmware
19 * to run (SPL, U-Boot, OP-TEE, etc.). It then carries on running until it gets
20 * to U-Boot, where it decides which OS to run
21 *
22 * @VBE_PHASE_FIRMWARE: Selecting the firmware to run
23 * @VBE_PHASE_OS: Selecting the Operating System to run
24 */
25enum vbe_phase_t {
26 VBE_PHASE_FIRMWARE,
27 VBE_PHASE_OS,
28};
29
30/**
Simon Glassc2213082025-01-26 11:43:29 -070031 * enum vbe_pick_t - indicates which firmware is picked
32 *
33 * @VBEFT_A: Firmware A
34 * @VBEFT_B: Firmware B
35 * @VBEFT_RECOVERY: Recovery firmware
36 */
37enum vbe_pick_t {
38 VBEP_A,
39 VBEP_B,
40 VBEP_RECOVERY,
41};
42
43/**
Simon Glass9d0042e2022-10-20 18:23:18 -060044 * struct vbe_handoff - information about VBE progress
45 *
Simon Glassc2213082025-01-26 11:43:29 -070046 * @offset: Offset of the FIT to use for SPL onwards
47 * @size: Size of the area containing the FIT
Simon Glass9d0042e2022-10-20 18:23:18 -060048 * @phases: Indicates which phases used the VBE bootmeth (1 << PHASE_...)
Simon Glassc2213082025-01-26 11:43:29 -070049 * @pick: Indicates which firmware pick was used (enum vbe_pick_t)
Simon Glass9d0042e2022-10-20 18:23:18 -060050 */
51struct vbe_handoff {
Simon Glassc2213082025-01-26 11:43:29 -070052 ulong offset;
53 ulong size;
Simon Glass9d0042e2022-10-20 18:23:18 -060054 u8 phases;
Simon Glassc2213082025-01-26 11:43:29 -070055 u8 pick;
Simon Glass9d0042e2022-10-20 18:23:18 -060056};
57
58/**
Simon Glassa72641c2022-10-20 18:23:09 -060059 * vbe_phase() - get current VBE phase
60 *
61 * Returns: Current VBE phase
62 */
63static inline enum vbe_phase_t vbe_phase(void)
64{
Simon Glass209ae762024-09-29 19:49:49 -060065 if (IS_ENABLED(CONFIG_XPL_BUILD))
Simon Glassa72641c2022-10-20 18:23:09 -060066 return VBE_PHASE_FIRMWARE;
67
68 return VBE_PHASE_OS;
69}
70
71/**
Simon Glass0a9f4262022-07-30 15:52:32 -060072 * vbe_list() - List the VBE bootmeths
73 *
74 * This shows a list of the VBE bootmeth devices
75 *
76 * @return 0 (always)
77 */
78int vbe_list(void);
79
80/**
81 * vbe_find_by_any() - Find a VBE bootmeth by name or sequence
82 *
83 * @name: name (e.g. "vbe-simple"), or sequence ("2") to find
84 * @devp: returns the device found, on success
85 * Return: 0 if OK, -ve on error
86 */
87int vbe_find_by_any(const char *name, struct udevice **devp);
88
89/**
90 * vbe_find_first_device() - Find the first VBE bootmeth
91 *
92 * @devp: Returns first available VBE bootmeth, or NULL if none
93 * Returns: 0 (always)
94 */
95int vbe_find_first_device(struct udevice **devp);
96
97/**
98 * vbe_find_next_device() - Find the next available VBE bootmeth
99 *
100 * @devp: Previous device to start from. Returns next available VBE bootmeth,
101 * or NULL if none
102 * Returns: 0 (always)
103 */
104int vbe_find_next_device(struct udevice **devp);
105
106#endif