blob: 37a81330325890d9770701a658d557a289c5985a [file] [log] [blame]
Simon Glassfdacd502025-01-15 18:27:03 -07001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Verified Boot for Embedded (VBE) common functions
4 *
5 * Copyright 2024 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#ifndef __VBE_COMMON_H
10#define __VBE_COMMON_H
11
12#include <linux/types.h>
13
14struct udevice;
15
16enum {
17 MAX_VERSION_LEN = 256,
18
19 NVD_HDR_VER_SHIFT = 0,
20 NVD_HDR_VER_MASK = 0xf,
21 NVD_HDR_SIZE_SHIFT = 4,
22 NVD_HDR_SIZE_MASK = 0xf << NVD_HDR_SIZE_SHIFT,
23
24 /* Firmware key-version is in the top 16 bits of fw_ver */
25 FWVER_KEY_SHIFT = 16,
26 FWVER_FW_MASK = 0xffff,
27
28 NVD_HDR_VER_CUR = 1, /* current version */
29};
30
31/**
32 * struct vbe_nvdata - basic storage format for non-volatile data
33 *
34 * This is used for all VBE methods
35 *
36 * @crc8: crc8 for the entire record except @crc8 field itself
37 * @hdr: header size and version (NVD_HDR_...)
38 * @spare1: unused, must be 0
39 * @fw_vernum: version and key version (FWVER_...)
40 * @flags: Flags controlling operation (enum vbe_flags)
41 */
42struct vbe_nvdata {
43 u8 crc8;
44 u8 hdr;
45 u16 spare1;
46 u32 fw_vernum;
47 u32 flags;
48 u8 spare2[0x34];
49};
50
Simon Glass15d320d2025-01-15 18:27:07 -070051/**
52 * vbe_get_blk() - Obtain the block device to use for VBE
53 *
54 * Decodes the string to produce a block device
55 *
56 * @storage: String indicating the device to use, e.g. "mmc1"
57 * @blkp: Returns associated block device, on success
58 * Return 0 if OK, -ENODEV if @storage does not end with a number, -E2BIG if
59 * the device name is more than 15 characters, -ENXIO if the block device could
60 * not be found
61 */
62int vbe_get_blk(const char *storage, struct udevice **blkp);
63
Simon Glass9846e5f2025-01-15 18:27:08 -070064/**
65 * vbe_read_version() - Read version-string from a block device
66 *
67 * Reads the VBE version-string from a device. This function reads a single
68 * block from the device, so the string cannot be larger than that. It uses a
69 * temporary buffer for the read, then copies in up to @size bytes
70 *
71 * @blk: Device to read from
72 * @offset: Offset to read, in bytes
73 * @version: Place to put the string
74 * @max_size: Maximum size of @version
75 * Return: 0 if OK, -E2BIG if @max_size > block size, -EBADF if the offset is
76 * not block-aligned, -EIO if an I/O error occurred
77 */
78int vbe_read_version(struct udevice *blk, ulong offset, char *version,
79 int max_size);
80
Simon Glass72424b82025-01-15 18:27:09 -070081/**
82 * vbe_read_nvdata() - Read non-volatile data from a block device
83 *
84 * Reads the VBE nvdata from a device. This function reads a single block from
85 * the device, so the nvdata cannot be larger than that.
86 *
87 * @blk: Device to read from
88 * @offset: Offset to read, in bytes
89 * @size: Number of bytes to read
90 * @buf: Buffer to hold the data
91 * Return: 0 if OK, -E2BIG if @size > block size, -EBADF if the offset is not
92 * block-aligned, -EIO if an I/O error occurred, -EPERM if the header version is
93 * incorrect, the header size is invalid or the data fails its CRC check
94 */
95int vbe_read_nvdata(struct udevice *blk, ulong offset, ulong size, u8 *buf);
96
Simon Glassfdacd502025-01-15 18:27:03 -070097#endif /* __VBE_ABREC_H */