blob: 2b4b6696897c11f2ce6d618551314dd1ff7bb95f [file] [log] [blame]
Simon Glass9f407d42018-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
Simon Glass4aed2272020-09-19 18:49:26 -060022/* Supported tags - add new ones to tag_name in bloblist.c */
Simon Glass9f407d42018-11-15 18:43:50 -070023enum bloblist_tag_t {
24 BLOBLISTT_NONE = 0,
25
26 /* Vendor-specific tags are permitted here */
27 BLOBLISTT_EC_HOSTEVENT, /* Chromium OS EC host-event mask */
28 BLOBLISTT_SPL_HANDOFF, /* Hand-off info from SPL */
29 BLOBLISTT_VBOOT_CTX, /* Chromium OS verified boot context */
30 BLOBLISTT_VBOOT_HANDOFF, /* Chromium OS internal handoff info */
Simon Glass99e555a2020-09-22 12:44:55 -060031 /*
32 * Advanced Configuration and Power Interface Global Non-Volatile
33 * Sleeping table. This forms part of the ACPI tables passed to Linux.
34 */
35 BLOBLISTT_ACPI_GNVS,
Simon Glassc9cc37d2020-09-22 12:45:03 -060036 BLOBLISTT_INTEL_VBT, /* Intel Video-BIOS table */
Simon Glass9179c352020-09-22 12:45:32 -060037 BLOBLISTT_TPM2_TCG_LOG, /* TPM v2 log space */
Simon Glass77bb1c62020-09-22 12:45:33 -060038 BLOBLISTT_TCPA_LOG, /* TPM log space */
Simon Glass4aed2272020-09-19 18:49:26 -060039
40 BLOBLISTT_COUNT
Simon Glass9f407d42018-11-15 18:43:50 -070041};
42
43/**
44 * struct bloblist_hdr - header for the bloblist
45 *
46 * This is stored at the start of the bloblist which is always on a 16-byte
47 * boundary. Records follow this header. The bloblist normally stays in the
48 * same place in memory as SPL and U-Boot execute, but it can be safely moved
49 * around.
50 *
51 * None of the bloblist structures contain pointers but it is possible to put
52 * pointers inside a bloblist record if desired. This is not encouraged,
53 * since it can make part of the bloblist inaccessible if the pointer is
54 * no-longer valid. It is better to just store all the data inside a bloblist
55 * record.
56 *
57 * Each bloblist record is aligned to a 16-byte boundary and follows immediately
58 * from the last.
59 *
60 * @version: BLOBLIST_VERSION
61 * @hdr_size: Size of this header, normally sizeof(struct bloblist_hdr). The
62 * first bloblist_rec starts at this offset from the start of the header
63 * @flags: Space for BLOBLISTF_... flags (none yet)
64 * @magic: BLOBLIST_MAGIC
65 * @size: Total size of all records (non-zero if valid) including this header.
66 * The bloblist extends for this many bytes from the start of this header.
67 * @alloced: Total size allocated for this bloblist. When adding new records,
68 * the bloblist can grow up to this size. This starts out as
69 * sizeof(bloblist_hdr) since we need at least that much space to store a
70 * valid bloblist
Simon Glasse9b6b2c2020-09-19 18:49:30 -060071 * @spare: Spare space (for future use)
Simon Glass9f407d42018-11-15 18:43:50 -070072 * @chksum: CRC32 for the entire bloblist allocated area. Since any of the
73 * blobs can be altered after being created, this checksum is only valid
74 * when the bloblist is finalised before jumping to the next stage of boot.
75 * Note: @chksum is last to make it easier to exclude it from the checksum
76 * calculation.
77 */
78struct bloblist_hdr {
79 u32 version;
80 u32 hdr_size;
81 u32 flags;
82 u32 magic;
83
84 u32 size;
85 u32 alloced;
86 u32 spare;
87 u32 chksum;
88};
89
90/**
91 * struct bloblist_rec - record for the bloblist
92 *
93 * NOTE: Only exported for testing purposes. Do not use this struct.
94 *
95 * The bloblist contains a number of records each consisting of this record
96 * structure followed by the data contained. Each records is 16-byte aligned.
97 *
98 * @tag: Tag indicating what the record contains
99 * @hdr_size: Size of this header, normally sizeof(struct bloblist_rec). The
100 * record's data starts at this offset from the start of the record
101 * @size: Size of record in bytes, excluding the header size. This does not
102 * need to be aligned (e.g. 3 is OK).
103 * @spare: Spare space for other things
104 */
105struct bloblist_rec {
106 u32 tag;
107 u32 hdr_size;
108 u32 size;
109 u32 spare;
110};
111
112/**
113 * bloblist_find() - Find a blob
114 *
115 * Searches the bloblist and returns the blob with the matching tag
116 *
117 * @tag: Tag to search for (enum bloblist_tag_t)
Simon Glasse9b6b2c2020-09-19 18:49:30 -0600118 * @size: Expected size of the blob, or 0 for any size
Simon Glass9f407d42018-11-15 18:43:50 -0700119 * @return pointer to blob if found, or NULL if not found, or a blob was found
120 * but it is the wrong size
121 */
122void *bloblist_find(uint tag, int size);
123
124/**
125 * bloblist_add() - Add a new blob
126 *
127 * Add a new blob to the bloblist
128 *
129 * This should only be called if you konw there is no existing blob for a
130 * particular tag. It is typically safe to call in the first phase of U-Boot
131 * (e.g. TPL or SPL). After that, bloblist_ensure() should be used instead.
132 *
133 * @tag: Tag to add (enum bloblist_tag_t)
134 * @size: Size of the blob
Simon Glass4c1497e2020-09-19 18:49:29 -0600135 * @align: Alignment of the blob (in bytes), 0 for default
Simon Glass9f407d42018-11-15 18:43:50 -0700136 * @return pointer to the newly added block, or NULL if there is not enough
137 * space for the blob
138 */
Simon Glass4c1497e2020-09-19 18:49:29 -0600139void *bloblist_add(uint tag, int size, int align);
Simon Glass9f407d42018-11-15 18:43:50 -0700140
141/**
142 * bloblist_ensure_size() - Find or add a blob
143 *
144 * Find an existing blob, or add a new one if not found
145 *
146 * @tag: Tag to add (enum bloblist_tag_t)
147 * @size: Size of the blob
148 * @blobp: Returns a pointer to blob on success
Simon Glass4c1497e2020-09-19 18:49:29 -0600149 * @align: Alignment of the blob (in bytes), 0 for default
Simon Glass9f407d42018-11-15 18:43:50 -0700150 * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
151 * of space, or -ESPIPE it exists but has the wrong size
152 */
Simon Glass4c1497e2020-09-19 18:49:29 -0600153int bloblist_ensure_size(uint tag, int size, int align, void **blobp);
Simon Glass9f407d42018-11-15 18:43:50 -0700154
155/**
156 * bloblist_ensure() - Find or add a blob
157 *
158 * Find an existing blob, or add a new one if not found
159 *
160 * @tag: Tag to add (enum bloblist_tag_t)
161 * @size: Size of the blob
162 * @return pointer to blob, or NULL if it is missing and could not be added due
163 * to lack of space, or it exists but has the wrong size
164 */
165void *bloblist_ensure(uint tag, int size);
166
167/**
Simon Glass5b044542020-01-27 08:49:50 -0700168 * bloblist_ensure_size_ret() - Find or add a blob
169 *
170 * Find an existing blob, or add a new one if not found
171 *
172 * @tag: Tag to add (enum bloblist_tag_t)
173 * @sizep: Size of the blob to create; returns size of actual blob
174 * @blobp: Returns a pointer to blob on success
175 * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
176 * of space
177 */
178int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp);
179
180/**
Simon Glass9f407d42018-11-15 18:43:50 -0700181 * bloblist_new() - Create a new, empty bloblist of a given size
182 *
183 * @addr: Address of bloblist
184 * @size: Initial size for bloblist
185 * @flags: Flags to use for bloblist
186 * @return 0 if OK, -EFAULT if addr is not aligned correctly, -ENOSPC is the
187 * area is not large enough
188 */
189int bloblist_new(ulong addr, uint size, uint flags);
190
191/**
192 * bloblist_check() - Check if a bloblist exists
193 *
194 * @addr: Address of bloblist
195 * @size: Expected size of blobsize, or 0 to detect the size
196 * @return 0 if OK, -ENOENT if the magic number doesn't match (indicating that
197 * there problem is no bloblist at the given address), -EPROTONOSUPPORT
198 * if the version does not match, -EIO if the checksum does not match,
Simon Glass02247c12020-01-27 08:49:51 -0700199 * -EFBIG if the expected size does not match the detected size, -ENOSPC
200 * if the size is not large enough to hold the headers
Simon Glass9f407d42018-11-15 18:43:50 -0700201 */
202int bloblist_check(ulong addr, uint size);
203
204/**
205 * bloblist_finish() - Set up the bloblist for the next U-Boot part
206 *
207 * This sets the correct checksum for the bloblist. This ensures that the
208 * bloblist will be detected correctly by the next phase of U-Boot.
209 *
210 * @return 0
211 */
212int bloblist_finish(void);
213
214/**
Simon Glass4aed2272020-09-19 18:49:26 -0600215 * bloblist_get_stats() - Get information about the bloblist
216 *
217 * This returns useful information about the bloblist
218 */
219void bloblist_get_stats(ulong *basep, ulong *sizep, ulong *allocedp);
220
221/**
222 * bloblist_show_stats() - Show information about the bloblist
223 *
224 * This shows useful information about the bloblist on the console
225 */
226void bloblist_show_stats(void);
227
228/**
229 * bloblist_show_list() - Show a list of blobs in the bloblist
230 *
231 * This shows a list of blobs, showing their address, size and tag.
232 */
233void bloblist_show_list(void);
234
235/**
236 * bloblist_tag_name() - Get the name for a tag
237 *
238 * @tag: Tag to check
239 * @return name of tag, or "invalid" if an invalid tag is provided
240 */
241const char *bloblist_tag_name(enum bloblist_tag_t tag);
242
243/**
Simon Glass9f407d42018-11-15 18:43:50 -0700244 * bloblist_init() - Init the bloblist system with a single bloblist
245 *
246 * This uses CONFIG_BLOBLIST_ADDR and CONFIG_BLOBLIST_SIZE to set up a bloblist
247 * for use by U-Boot.
248 */
249int bloblist_init(void);
250
251#endif /* __BLOBLIST_H */