Simon Glass | 0a9f426 | 2022-07-30 15:52:32 -0600 | [diff] [blame] | 1 | /* 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 Glass | c221308 | 2025-01-26 11:43:29 -0700 | [diff] [blame] | 13 | #include <linux/types.h> |
| 14 | |
Simon Glass | 0a9f426 | 2022-07-30 15:52:32 -0600 | [diff] [blame] | 15 | /** |
Simon Glass | a72641c | 2022-10-20 18:23:09 -0600 | [diff] [blame] | 16 | * 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 | */ |
| 25 | enum vbe_phase_t { |
| 26 | VBE_PHASE_FIRMWARE, |
| 27 | VBE_PHASE_OS, |
| 28 | }; |
| 29 | |
| 30 | /** |
Simon Glass | c221308 | 2025-01-26 11:43:29 -0700 | [diff] [blame] | 31 | * 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 | */ |
| 37 | enum vbe_pick_t { |
| 38 | VBEP_A, |
| 39 | VBEP_B, |
| 40 | VBEP_RECOVERY, |
| 41 | }; |
| 42 | |
| 43 | /** |
Simon Glass | 9d0042e | 2022-10-20 18:23:18 -0600 | [diff] [blame] | 44 | * struct vbe_handoff - information about VBE progress |
| 45 | * |
Simon Glass | c221308 | 2025-01-26 11:43:29 -0700 | [diff] [blame] | 46 | * @offset: Offset of the FIT to use for SPL onwards |
| 47 | * @size: Size of the area containing the FIT |
Simon Glass | 9d0042e | 2022-10-20 18:23:18 -0600 | [diff] [blame] | 48 | * @phases: Indicates which phases used the VBE bootmeth (1 << PHASE_...) |
Simon Glass | c221308 | 2025-01-26 11:43:29 -0700 | [diff] [blame] | 49 | * @pick: Indicates which firmware pick was used (enum vbe_pick_t) |
Simon Glass | 9d0042e | 2022-10-20 18:23:18 -0600 | [diff] [blame] | 50 | */ |
| 51 | struct vbe_handoff { |
Simon Glass | c221308 | 2025-01-26 11:43:29 -0700 | [diff] [blame] | 52 | ulong offset; |
| 53 | ulong size; |
Simon Glass | 9d0042e | 2022-10-20 18:23:18 -0600 | [diff] [blame] | 54 | u8 phases; |
Simon Glass | c221308 | 2025-01-26 11:43:29 -0700 | [diff] [blame] | 55 | u8 pick; |
Simon Glass | 9d0042e | 2022-10-20 18:23:18 -0600 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /** |
Simon Glass | a72641c | 2022-10-20 18:23:09 -0600 | [diff] [blame] | 59 | * vbe_phase() - get current VBE phase |
| 60 | * |
| 61 | * Returns: Current VBE phase |
| 62 | */ |
| 63 | static inline enum vbe_phase_t vbe_phase(void) |
| 64 | { |
Simon Glass | 209ae76 | 2024-09-29 19:49:49 -0600 | [diff] [blame] | 65 | if (IS_ENABLED(CONFIG_XPL_BUILD)) |
Simon Glass | a72641c | 2022-10-20 18:23:09 -0600 | [diff] [blame] | 66 | return VBE_PHASE_FIRMWARE; |
| 67 | |
| 68 | return VBE_PHASE_OS; |
| 69 | } |
| 70 | |
| 71 | /** |
Simon Glass | 0a9f426 | 2022-07-30 15:52:32 -0600 | [diff] [blame] | 72 | * vbe_list() - List the VBE bootmeths |
| 73 | * |
| 74 | * This shows a list of the VBE bootmeth devices |
| 75 | * |
| 76 | * @return 0 (always) |
| 77 | */ |
| 78 | int 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 | */ |
| 87 | int 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 | */ |
| 95 | int 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 | */ |
| 104 | int vbe_find_next_device(struct udevice **devp); |
| 105 | |
| 106 | #endif |