blob: dc7d80bd8518943eddb9150fed3b56abcd7f1b1c [file] [log] [blame]
Simon Glass712bd2d2018-11-15 18:43:50 -07001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * This provides a standard way of passing information between boot phases
4 * (TPL -> SPL -> U-Boot proper.)
5 *
6 * A list of blobs of data, tagged with their owner. The list resides in memory
7 * and can be updated by SPL, U-Boot, etc.
8 *
9 * Copyright 2018 Google, Inc
10 * Written by Simon Glass <sjg@chromium.org>
11 */
12
13#ifndef __BLOBLIST_H
14#define __BLOBLIST_H
15
16enum {
17 BLOBLIST_VERSION = 0,
18 BLOBLIST_MAGIC = 0xb00757a3,
19 BLOBLIST_ALIGN = 16,
20};
21
22enum bloblist_tag_t {
23 BLOBLISTT_NONE = 0,
24
25 /* Vendor-specific tags are permitted here */
26 BLOBLISTT_EC_HOSTEVENT, /* Chromium OS EC host-event mask */
27 BLOBLISTT_SPL_HANDOFF, /* Hand-off info from SPL */
28 BLOBLISTT_VBOOT_CTX, /* Chromium OS verified boot context */
29 BLOBLISTT_VBOOT_HANDOFF, /* Chromium OS internal handoff info */
Simon Glassfdf52632020-09-22 12:44:55 -060030 /*
31 * Advanced Configuration and Power Interface Global Non-Volatile
32 * Sleeping table. This forms part of the ACPI tables passed to Linux.
33 */
34 BLOBLISTT_ACPI_GNVS,
Simon Glass057427c2020-09-22 12:45:03 -060035 BLOBLISTT_INTEL_VBT, /* Intel Video-BIOS table */
Simon Glass272a7032020-09-22 12:45:32 -060036 BLOBLISTT_TPM2_TCG_LOG, /* TPM v2 log space */
Simon Glass712bd2d2018-11-15 18:43:50 -070037};
38
39/**
40 * struct bloblist_hdr - header for the bloblist
41 *
42 * This is stored at the start of the bloblist which is always on a 16-byte
43 * boundary. Records follow this header. The bloblist normally stays in the
44 * same place in memory as SPL and U-Boot execute, but it can be safely moved
45 * around.
46 *
47 * None of the bloblist structures contain pointers but it is possible to put
48 * pointers inside a bloblist record if desired. This is not encouraged,
49 * since it can make part of the bloblist inaccessible if the pointer is
50 * no-longer valid. It is better to just store all the data inside a bloblist
51 * record.
52 *
53 * Each bloblist record is aligned to a 16-byte boundary and follows immediately
54 * from the last.
55 *
56 * @version: BLOBLIST_VERSION
57 * @hdr_size: Size of this header, normally sizeof(struct bloblist_hdr). The
58 * first bloblist_rec starts at this offset from the start of the header
59 * @flags: Space for BLOBLISTF_... flags (none yet)
60 * @magic: BLOBLIST_MAGIC
61 * @size: Total size of all records (non-zero if valid) including this header.
62 * The bloblist extends for this many bytes from the start of this header.
63 * @alloced: Total size allocated for this bloblist. When adding new records,
64 * the bloblist can grow up to this size. This starts out as
65 * sizeof(bloblist_hdr) since we need at least that much space to store a
66 * valid bloblist
67 * @spare: Space space
68 * @chksum: CRC32 for the entire bloblist allocated area. Since any of the
69 * blobs can be altered after being created, this checksum is only valid
70 * when the bloblist is finalised before jumping to the next stage of boot.
71 * Note: @chksum is last to make it easier to exclude it from the checksum
72 * calculation.
73 */
74struct bloblist_hdr {
75 u32 version;
76 u32 hdr_size;
77 u32 flags;
78 u32 magic;
79
80 u32 size;
81 u32 alloced;
82 u32 spare;
83 u32 chksum;
84};
85
86/**
87 * struct bloblist_rec - record for the bloblist
88 *
89 * NOTE: Only exported for testing purposes. Do not use this struct.
90 *
91 * The bloblist contains a number of records each consisting of this record
92 * structure followed by the data contained. Each records is 16-byte aligned.
93 *
94 * @tag: Tag indicating what the record contains
95 * @hdr_size: Size of this header, normally sizeof(struct bloblist_rec). The
96 * record's data starts at this offset from the start of the record
97 * @size: Size of record in bytes, excluding the header size. This does not
98 * need to be aligned (e.g. 3 is OK).
99 * @spare: Spare space for other things
100 */
101struct bloblist_rec {
102 u32 tag;
103 u32 hdr_size;
104 u32 size;
105 u32 spare;
106};
107
108/**
109 * bloblist_find() - Find a blob
110 *
111 * Searches the bloblist and returns the blob with the matching tag
112 *
113 * @tag: Tag to search for (enum bloblist_tag_t)
114 * @size: Expected size of the blob
115 * @return pointer to blob if found, or NULL if not found, or a blob was found
116 * but it is the wrong size
117 */
118void *bloblist_find(uint tag, int size);
119
120/**
121 * bloblist_add() - Add a new blob
122 *
123 * Add a new blob to the bloblist
124 *
125 * This should only be called if you konw there is no existing blob for a
126 * particular tag. It is typically safe to call in the first phase of U-Boot
127 * (e.g. TPL or SPL). After that, bloblist_ensure() should be used instead.
128 *
129 * @tag: Tag to add (enum bloblist_tag_t)
130 * @size: Size of the blob
131 * @return pointer to the newly added block, or NULL if there is not enough
132 * space for the blob
133 */
134void *bloblist_add(uint tag, int size);
135
136/**
137 * bloblist_ensure_size() - Find or add a blob
138 *
139 * Find an existing blob, or add a new one if not found
140 *
141 * @tag: Tag to add (enum bloblist_tag_t)
142 * @size: Size of the blob
143 * @blobp: Returns a pointer to blob on success
144 * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
145 * of space, or -ESPIPE it exists but has the wrong size
146 */
147int bloblist_ensure_size(uint tag, int size, void **blobp);
148
149/**
150 * bloblist_ensure() - Find or add a blob
151 *
152 * Find an existing blob, or add a new one if not found
153 *
154 * @tag: Tag to add (enum bloblist_tag_t)
155 * @size: Size of the blob
156 * @return pointer to blob, or NULL if it is missing and could not be added due
157 * to lack of space, or it exists but has the wrong size
158 */
159void *bloblist_ensure(uint tag, int size);
160
161/**
Simon Glass1e0304e2020-01-27 08:49:50 -0700162 * bloblist_ensure_size_ret() - Find or add a blob
163 *
164 * Find an existing blob, or add a new one if not found
165 *
166 * @tag: Tag to add (enum bloblist_tag_t)
167 * @sizep: Size of the blob to create; returns size of actual blob
168 * @blobp: Returns a pointer to blob on success
169 * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
170 * of space
171 */
172int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp);
173
174/**
Simon Glass712bd2d2018-11-15 18:43:50 -0700175 * bloblist_new() - Create a new, empty bloblist of a given size
176 *
177 * @addr: Address of bloblist
178 * @size: Initial size for bloblist
179 * @flags: Flags to use for bloblist
180 * @return 0 if OK, -EFAULT if addr is not aligned correctly, -ENOSPC is the
181 * area is not large enough
182 */
183int bloblist_new(ulong addr, uint size, uint flags);
184
185/**
186 * bloblist_check() - Check if a bloblist exists
187 *
188 * @addr: Address of bloblist
189 * @size: Expected size of blobsize, or 0 to detect the size
190 * @return 0 if OK, -ENOENT if the magic number doesn't match (indicating that
191 * there problem is no bloblist at the given address), -EPROTONOSUPPORT
192 * if the version does not match, -EIO if the checksum does not match,
Simon Glass32ec7c62020-01-27 08:49:51 -0700193 * -EFBIG if the expected size does not match the detected size, -ENOSPC
194 * if the size is not large enough to hold the headers
Simon Glass712bd2d2018-11-15 18:43:50 -0700195 */
196int bloblist_check(ulong addr, uint size);
197
198/**
199 * bloblist_finish() - Set up the bloblist for the next U-Boot part
200 *
201 * This sets the correct checksum for the bloblist. This ensures that the
202 * bloblist will be detected correctly by the next phase of U-Boot.
203 *
204 * @return 0
205 */
206int bloblist_finish(void);
207
208/**
209 * bloblist_init() - Init the bloblist system with a single bloblist
210 *
211 * This uses CONFIG_BLOBLIST_ADDR and CONFIG_BLOBLIST_SIZE to set up a bloblist
212 * for use by U-Boot.
213 */
214int bloblist_init(void);
215
216#endif /* __BLOBLIST_H */