blob: 63c732973517b663838656e73a37c5f0a40d3c4a [file] [log] [blame]
Simon Glassc2213082025-01-26 11:43:29 -07001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Verified Boot for Embedded (VBE) vbe-abrec common file
4 *
5 * Copyright 2024 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#ifndef __VBE_ABREC_H
10#define __VBE_ABREC_H
11
12#include <vbe.h>
13#include <dm/ofnode_decl.h>
14
15#include "vbe_common.h"
16
17struct bootflow;
18struct udevice;
19
20/**
21 * struct abrec_priv - information read from the device tree
22 *
23 * @area_start: Start offset of the VBE area in the device, in bytes
24 * @area_size: Total size of the VBE area
25 * @skip_offset: Size of an initial part of the device to skip, when using
26 * area_start. This is effectively added to area_start to calculate the
27 * actual start position on the device
28 * @state_offset: Offset from area_start of the VBE state, in bytes
29 * @state_size: Size of the state information
30 * @version_offset: Offset from from area_start of the VBE version info
31 * @version_size: Size of the version info
32 * @storage: Storage device to use, in the form <uclass><devnum>, e.g. "mmc1"
33 */
34struct abrec_priv {
35 u32 area_start;
36 u32 area_size;
37 u32 skip_offset;
38 u32 state_offset;
39 u32 state_size;
40 u32 version_offset;
41 u32 version_size;
42 const char *storage;
43};
44
45/** struct abrec_state - state information read from media
46 *
47 * The state on the media is converted into this more code-friendly structure.
48 *
49 * @fw_version: Firmware version string
50 * @fw_vernum: Firmware version number
51 * @try_count: Number of times the B firmware has been tried
52 * @try_b: true to try B firmware on the next boot
53 * @recovery: true to enter recovery firmware on the next boot
54 * @try_result: Result of trying to boot with the last firmware
55 * @pick: Firmware which was chosen in this boot
56 */
57struct abrec_state {
58 char fw_version[MAX_VERSION_LEN];
59 u32 fw_vernum;
60 u8 try_count;
61 bool try_b;
62 bool recovery;
63 enum vbe_try_result try_result;
64 enum vbe_pick_t pick;
65};
66
67/**
68 * abrec_read_fw_bootflow() - Read a bootflow for firmware
69 *
70 * Locates and loads the firmware image (FIT) needed for the next phase. The FIT
71 * should ideally use external data, to reduce the amount of it that needs to be
72 * read.
73 *
74 * @bdev: bootdev device containing the firmwre
75 * @bflow: Place to put the created bootflow, on success
76 * @return 0 if OK, -ve on error
77 */
78int abrec_read_bootflow_fw(struct udevice *dev, struct bootflow *bflow);
79
80/**
81 * vbe_simple_read_state() - Read the VBE simple state information
82 *
83 * @dev: VBE bootmeth
84 * @state: Place to put the state
85 * @return 0 if OK, -ve on error
86 */
87int abrec_read_state(struct udevice *dev, struct abrec_state *state);
88
89/**
90 * abrec_read_nvdata() - Read non-volatile data from a block device
91 *
92 * Reads the ABrec VBE nvdata from a device. This function reads a single block
93 * from the device, so the nvdata cannot be larger than that.
94 *
95 * @blk: Device to read from
96 * @offset: Offset to read, in bytes
97 * @size: Number of bytes to read
98 * @buf: Buffer to hold the data
99 * Return: 0 if OK, -E2BIG if @size > block size, -EBADF if the offset is not
100 * block-aligned, -EIO if an I/O error occurred, -EPERM if the header version is
101 * incorrect, the header size is invalid or the data fails its CRC check
102 */
103int abrec_read_nvdata(struct abrec_priv *priv, struct udevice *blk,
104 struct abrec_state *state);
105
106/**
107 * abrec_read_priv() - Read info from the devicetree
108 *
109 * @node: Node to read from
110 * @priv: Information to fill in
111 * Return 0 if OK, -EINVAL if something is wrong with the devicetree node
112 */
113int abrec_read_priv(ofnode node, struct abrec_priv *priv);
114
115#endif /* __VBE_ABREC_H */