blob: 7d8480548e0214617f08c86c6f02bbbeb04cf134 [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
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 Glass99e555a2020-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 Glassc9cc37d2020-09-22 12:45:03 -060035 BLOBLISTT_INTEL_VBT, /* Intel Video-BIOS table */
Simon Glass9f407d42018-11-15 18:43:50 -070036};
37
38/**
39 * struct bloblist_hdr - header for the bloblist
40 *
41 * This is stored at the start of the bloblist which is always on a 16-byte
42 * boundary. Records follow this header. The bloblist normally stays in the
43 * same place in memory as SPL and U-Boot execute, but it can be safely moved
44 * around.
45 *
46 * None of the bloblist structures contain pointers but it is possible to put
47 * pointers inside a bloblist record if desired. This is not encouraged,
48 * since it can make part of the bloblist inaccessible if the pointer is
49 * no-longer valid. It is better to just store all the data inside a bloblist
50 * record.
51 *
52 * Each bloblist record is aligned to a 16-byte boundary and follows immediately
53 * from the last.
54 *
55 * @version: BLOBLIST_VERSION
56 * @hdr_size: Size of this header, normally sizeof(struct bloblist_hdr). The
57 * first bloblist_rec starts at this offset from the start of the header
58 * @flags: Space for BLOBLISTF_... flags (none yet)
59 * @magic: BLOBLIST_MAGIC
60 * @size: Total size of all records (non-zero if valid) including this header.
61 * The bloblist extends for this many bytes from the start of this header.
62 * @alloced: Total size allocated for this bloblist. When adding new records,
63 * the bloblist can grow up to this size. This starts out as
64 * sizeof(bloblist_hdr) since we need at least that much space to store a
65 * valid bloblist
66 * @spare: Space space
67 * @chksum: CRC32 for the entire bloblist allocated area. Since any of the
68 * blobs can be altered after being created, this checksum is only valid
69 * when the bloblist is finalised before jumping to the next stage of boot.
70 * Note: @chksum is last to make it easier to exclude it from the checksum
71 * calculation.
72 */
73struct bloblist_hdr {
74 u32 version;
75 u32 hdr_size;
76 u32 flags;
77 u32 magic;
78
79 u32 size;
80 u32 alloced;
81 u32 spare;
82 u32 chksum;
83};
84
85/**
86 * struct bloblist_rec - record for the bloblist
87 *
88 * NOTE: Only exported for testing purposes. Do not use this struct.
89 *
90 * The bloblist contains a number of records each consisting of this record
91 * structure followed by the data contained. Each records is 16-byte aligned.
92 *
93 * @tag: Tag indicating what the record contains
94 * @hdr_size: Size of this header, normally sizeof(struct bloblist_rec). The
95 * record's data starts at this offset from the start of the record
96 * @size: Size of record in bytes, excluding the header size. This does not
97 * need to be aligned (e.g. 3 is OK).
98 * @spare: Spare space for other things
99 */
100struct bloblist_rec {
101 u32 tag;
102 u32 hdr_size;
103 u32 size;
104 u32 spare;
105};
106
107/**
108 * bloblist_find() - Find a blob
109 *
110 * Searches the bloblist and returns the blob with the matching tag
111 *
112 * @tag: Tag to search for (enum bloblist_tag_t)
113 * @size: Expected size of the blob
114 * @return pointer to blob if found, or NULL if not found, or a blob was found
115 * but it is the wrong size
116 */
117void *bloblist_find(uint tag, int size);
118
119/**
120 * bloblist_add() - Add a new blob
121 *
122 * Add a new blob to the bloblist
123 *
124 * This should only be called if you konw there is no existing blob for a
125 * particular tag. It is typically safe to call in the first phase of U-Boot
126 * (e.g. TPL or SPL). After that, bloblist_ensure() should be used instead.
127 *
128 * @tag: Tag to add (enum bloblist_tag_t)
129 * @size: Size of the blob
130 * @return pointer to the newly added block, or NULL if there is not enough
131 * space for the blob
132 */
133void *bloblist_add(uint tag, int size);
134
135/**
136 * bloblist_ensure_size() - Find or add a blob
137 *
138 * Find an existing blob, or add a new one if not found
139 *
140 * @tag: Tag to add (enum bloblist_tag_t)
141 * @size: Size of the blob
142 * @blobp: Returns a pointer to blob on success
143 * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
144 * of space, or -ESPIPE it exists but has the wrong size
145 */
146int bloblist_ensure_size(uint tag, int size, void **blobp);
147
148/**
149 * bloblist_ensure() - Find or add a blob
150 *
151 * Find an existing blob, or add a new one if not found
152 *
153 * @tag: Tag to add (enum bloblist_tag_t)
154 * @size: Size of the blob
155 * @return pointer to blob, or NULL if it is missing and could not be added due
156 * to lack of space, or it exists but has the wrong size
157 */
158void *bloblist_ensure(uint tag, int size);
159
160/**
Simon Glass5b044542020-01-27 08:49:50 -0700161 * bloblist_ensure_size_ret() - Find or add a blob
162 *
163 * Find an existing blob, or add a new one if not found
164 *
165 * @tag: Tag to add (enum bloblist_tag_t)
166 * @sizep: Size of the blob to create; returns size of actual blob
167 * @blobp: Returns a pointer to blob on success
168 * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack
169 * of space
170 */
171int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp);
172
173/**
Simon Glass9f407d42018-11-15 18:43:50 -0700174 * bloblist_new() - Create a new, empty bloblist of a given size
175 *
176 * @addr: Address of bloblist
177 * @size: Initial size for bloblist
178 * @flags: Flags to use for bloblist
179 * @return 0 if OK, -EFAULT if addr is not aligned correctly, -ENOSPC is the
180 * area is not large enough
181 */
182int bloblist_new(ulong addr, uint size, uint flags);
183
184/**
185 * bloblist_check() - Check if a bloblist exists
186 *
187 * @addr: Address of bloblist
188 * @size: Expected size of blobsize, or 0 to detect the size
189 * @return 0 if OK, -ENOENT if the magic number doesn't match (indicating that
190 * there problem is no bloblist at the given address), -EPROTONOSUPPORT
191 * if the version does not match, -EIO if the checksum does not match,
Simon Glass02247c12020-01-27 08:49:51 -0700192 * -EFBIG if the expected size does not match the detected size, -ENOSPC
193 * if the size is not large enough to hold the headers
Simon Glass9f407d42018-11-15 18:43:50 -0700194 */
195int bloblist_check(ulong addr, uint size);
196
197/**
198 * bloblist_finish() - Set up the bloblist for the next U-Boot part
199 *
200 * This sets the correct checksum for the bloblist. This ensures that the
201 * bloblist will be detected correctly by the next phase of U-Boot.
202 *
203 * @return 0
204 */
205int bloblist_finish(void);
206
207/**
208 * bloblist_init() - Init the bloblist system with a single bloblist
209 *
210 * This uses CONFIG_BLOBLIST_ADDR and CONFIG_BLOBLIST_SIZE to set up a bloblist
211 * for use by U-Boot.
212 */
213int bloblist_init(void);
214
215#endif /* __BLOBLIST_H */