blob: 168993e0a7b7e242a4960b5b7fcd96c38d81d123 [file] [log] [blame]
Simon Glass6c9e3d12022-01-12 19:26:25 -07001// SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause
Simon Glass9f407d42018-11-15 18:43:50 -07002/*
3 * Copyright 2018 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
Simon Glass1d8bbd72022-01-12 19:26:20 -07007#define LOG_CATEGORY LOGC_BLOBLIST
8
Simon Glass9f407d42018-11-15 18:43:50 -07009#include <common.h>
10#include <bloblist.h>
Simon Glass4e4bf942022-07-31 12:28:48 -060011#include <display_options.h>
Simon Glass9f407d42018-11-15 18:43:50 -070012#include <log.h>
Simon Glassd5b6e912021-11-03 21:09:20 -060013#include <malloc.h>
Simon Glass9f407d42018-11-15 18:43:50 -070014#include <mapmem.h>
15#include <spl.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Simon Glass3db71102019-11-14 12:57:16 -070017#include <u-boot/crc.h>
Simon Glass9f407d42018-11-15 18:43:50 -070018
Simon Glass751b7c72020-09-19 18:49:28 -060019/*
20 * A bloblist is a single contiguous chunk of memory with a header
21 * (struct bloblist_hdr) and a number of blobs in it.
22 *
23 * Each blob starts on a BLOBLIST_ALIGN boundary relative to the start of the
24 * bloblist and consists of a struct bloblist_rec, some padding to the required
25 * alignment for the blog and then the actual data. The padding ensures that the
26 * start address of the data in each blob is aligned as required. Note that
27 * each blob's *data* is aligned to BLOBLIST_ALIGN regardless of the alignment
28 * of the bloblist itself or the blob header.
Simon Glass751b7c72020-09-19 18:49:28 -060029 */
30
Simon Glass9f407d42018-11-15 18:43:50 -070031DECLARE_GLOBAL_DATA_PTR;
32
Simon Glassf16ec772022-01-12 19:26:19 -070033static struct tag_name {
34 enum bloblist_tag_t tag;
35 const char *name;
36} tag_name[] = {
Simon Glasse748e4b2023-12-27 13:06:59 -080037 { BLOBLISTT_VOID, "(void)" },
Simon Glassf16ec772022-01-12 19:26:19 -070038
39 /* BLOBLISTT_AREA_FIRMWARE_TOP */
Simon Glasse748e4b2023-12-27 13:06:59 -080040 { BLOBLISTT_CONTROL_FDT, "Control FDT" },
41 { BLOBLISTT_HOB_BLOCK, "HOB block" },
42 { BLOBLISTT_HOB_LIST, "HOB list" },
43 { BLOBLISTT_ACPI_TABLES, "ACPI tables for x86" },
44 { BLOBLISTT_TPM_EVLOG, "TPM event log defined by TCG EFI" },
45 { BLOBLISTT_TPM_CRB_BASE, "TPM Command Response Buffer address" },
Simon Glassf16ec772022-01-12 19:26:19 -070046
47 /* BLOBLISTT_AREA_FIRMWARE */
Simon Glassf16ec772022-01-12 19:26:19 -070048 { BLOBLISTT_TPM2_TCG_LOG, "TPM v2 log space" },
49 { BLOBLISTT_TCPA_LOG, "TPM log space" },
Simon Glasse748e4b2023-12-27 13:06:59 -080050 { BLOBLISTT_ACPI_GNVS, "ACPI GNVS" },
51
52 /* BLOBLISTT_AREA_TF */
53 { BLOBLISTT_OPTEE_PAGABLE_PART, "OP-TEE pagable part" },
54
55 /* BLOBLISTT_AREA_OTHER */
56 { BLOBLISTT_INTEL_VBT, "Intel Video-BIOS table" },
Simon Glassf16ec772022-01-12 19:26:19 -070057 { BLOBLISTT_SMBIOS_TABLES, "SMBIOS tables for x86" },
58 { BLOBLISTT_VBOOT_CTX, "Chrome OS vboot context" },
59
60 /* BLOBLISTT_PROJECT_AREA */
61 { BLOBLISTT_U_BOOT_SPL_HANDOFF, "SPL hand-off" },
Simon Glass14d9f632023-09-26 08:14:52 -060062 { BLOBLISTT_VBE, "VBE" },
Simon Glass03fe79c2023-07-15 21:38:59 -060063 { BLOBLISTT_U_BOOT_VIDEO, "SPL video handoff" },
Simon Glassf16ec772022-01-12 19:26:19 -070064
65 /* BLOBLISTT_VENDOR_AREA */
Simon Glass4aed2272020-09-19 18:49:26 -060066};
67
68const char *bloblist_tag_name(enum bloblist_tag_t tag)
69{
Simon Glassf16ec772022-01-12 19:26:19 -070070 int i;
Simon Glass4aed2272020-09-19 18:49:26 -060071
Simon Glassf16ec772022-01-12 19:26:19 -070072 for (i = 0; i < ARRAY_SIZE(tag_name); i++) {
73 if (tag_name[i].tag == tag)
74 return tag_name[i].name;
75 }
76
77 return "invalid";
Simon Glass4aed2272020-09-19 18:49:26 -060078}
79
80static struct bloblist_rec *bloblist_first_blob(struct bloblist_hdr *hdr)
Simon Glass9f407d42018-11-15 18:43:50 -070081{
82 if (hdr->alloced <= hdr->hdr_size)
83 return NULL;
84 return (struct bloblist_rec *)((void *)hdr + hdr->hdr_size);
85}
86
Simon Glass1f06ed42023-12-27 13:07:03 -080087static inline uint rec_hdr_size(struct bloblist_rec *rec)
88{
89 return rec->hdr_size;
90}
91
92static inline uint rec_tag(struct bloblist_rec *rec)
93{
94 return rec->tag;
95}
96
Simon Glass1fe59372021-07-05 16:32:53 -060097static ulong bloblist_blob_end_ofs(struct bloblist_hdr *hdr,
98 struct bloblist_rec *rec)
Simon Glass9f407d42018-11-15 18:43:50 -070099{
100 ulong offset;
101
102 offset = (void *)rec - (void *)hdr;
Simon Glass1f06ed42023-12-27 13:07:03 -0800103 offset += rec_hdr_size(rec) + ALIGN(rec->size, BLOBLIST_ALIGN);
Simon Glass1fe59372021-07-05 16:32:53 -0600104
105 return offset;
106}
107
108static struct bloblist_rec *bloblist_next_blob(struct bloblist_hdr *hdr,
109 struct bloblist_rec *rec)
110{
111 ulong offset = bloblist_blob_end_ofs(hdr, rec);
112
Simon Glass9f407d42018-11-15 18:43:50 -0700113 if (offset >= hdr->alloced)
114 return NULL;
115 return (struct bloblist_rec *)((void *)hdr + offset);
116}
117
118#define foreach_rec(_rec, _hdr) \
119 for (_rec = bloblist_first_blob(_hdr); \
120 _rec; \
121 _rec = bloblist_next_blob(_hdr, _rec))
122
123static struct bloblist_rec *bloblist_findrec(uint tag)
124{
125 struct bloblist_hdr *hdr = gd->bloblist;
126 struct bloblist_rec *rec;
127
128 if (!hdr)
129 return NULL;
130
131 foreach_rec(rec, hdr) {
Simon Glass1f06ed42023-12-27 13:07:03 -0800132 if (rec_tag(rec) == tag)
Simon Glass9f407d42018-11-15 18:43:50 -0700133 return rec;
134 }
135
136 return NULL;
137}
138
Simon Glass1a2e02f2023-12-27 13:07:00 -0800139static int bloblist_addrec(uint tag, int size, int align_log2,
Simon Glass4c1497e2020-09-19 18:49:29 -0600140 struct bloblist_rec **recp)
Simon Glass9f407d42018-11-15 18:43:50 -0700141{
142 struct bloblist_hdr *hdr = gd->bloblist;
143 struct bloblist_rec *rec;
Simon Glass751b7c72020-09-19 18:49:28 -0600144 int data_start, new_alloced;
Simon Glass9f407d42018-11-15 18:43:50 -0700145
Simon Glass1a2e02f2023-12-27 13:07:00 -0800146 if (!align_log2)
147 align_log2 = BLOBLIST_ALIGN_LOG2;
Simon Glass4c1497e2020-09-19 18:49:29 -0600148
Simon Glass751b7c72020-09-19 18:49:28 -0600149 /* Figure out where the new data will start */
Simon Glass4c1497e2020-09-19 18:49:29 -0600150 data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec);
151
152 /* Align the address and then calculate the offset from ->alloced */
Simon Glass1a2e02f2023-12-27 13:07:00 -0800153 data_start = ALIGN(data_start, 1U << align_log2) - map_to_sysmem(hdr);
Simon Glass751b7c72020-09-19 18:49:28 -0600154
155 /* Calculate the new allocated total */
Simon Glass1a2e02f2023-12-27 13:07:00 -0800156 new_alloced = data_start + ALIGN(size, 1U << align_log2);
Simon Glass4c1497e2020-09-19 18:49:29 -0600157
Simon Glass1f618d52021-07-05 16:32:55 -0600158 if (new_alloced > hdr->size) {
Simon Glass1d8bbd72022-01-12 19:26:20 -0700159 log_err("Failed to allocate %x bytes size=%x, need size=%x\n",
160 size, hdr->size, new_alloced);
Simon Glass9f407d42018-11-15 18:43:50 -0700161 return log_msg_ret("bloblist add", -ENOSPC);
162 }
163 rec = (void *)hdr + hdr->alloced;
Simon Glass9f407d42018-11-15 18:43:50 -0700164
165 rec->tag = tag;
Simon Glass751b7c72020-09-19 18:49:28 -0600166 rec->hdr_size = data_start - hdr->alloced;
Simon Glass9f407d42018-11-15 18:43:50 -0700167 rec->size = size;
168 rec->spare = 0;
Simon Glassb83994d2020-01-27 08:49:52 -0700169
170 /* Zero the record data */
Simon Glass1f06ed42023-12-27 13:07:03 -0800171 memset((void *)rec + rec_hdr_size(rec), '\0', rec->size);
Simon Glass751b7c72020-09-19 18:49:28 -0600172
173 hdr->alloced = new_alloced;
Simon Glass9f407d42018-11-15 18:43:50 -0700174 *recp = rec;
175
176 return 0;
177}
178
Simon Glass4c1497e2020-09-19 18:49:29 -0600179static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size,
Simon Glass1a2e02f2023-12-27 13:07:00 -0800180 int align_log2)
Simon Glass9f407d42018-11-15 18:43:50 -0700181{
182 struct bloblist_rec *rec;
183
184 rec = bloblist_findrec(tag);
185 if (rec) {
Simon Glass5b044542020-01-27 08:49:50 -0700186 if (size && size != rec->size) {
187 *recp = rec;
Simon Glass9f407d42018-11-15 18:43:50 -0700188 return -ESPIPE;
Simon Glass5b044542020-01-27 08:49:50 -0700189 }
Simon Glass9f407d42018-11-15 18:43:50 -0700190 } else {
191 int ret;
192
Simon Glass1a2e02f2023-12-27 13:07:00 -0800193 ret = bloblist_addrec(tag, size, align_log2, &rec);
Simon Glass9f407d42018-11-15 18:43:50 -0700194 if (ret)
195 return ret;
196 }
197 *recp = rec;
198
199 return 0;
200}
201
202void *bloblist_find(uint tag, int size)
203{
204 struct bloblist_rec *rec;
205
206 rec = bloblist_findrec(tag);
207 if (!rec)
208 return NULL;
209 if (size && size != rec->size)
210 return NULL;
211
Simon Glass1f06ed42023-12-27 13:07:03 -0800212 return (void *)rec + rec_hdr_size(rec);
Simon Glass9f407d42018-11-15 18:43:50 -0700213}
214
Simon Glass1a2e02f2023-12-27 13:07:00 -0800215void *bloblist_add(uint tag, int size, int align_log2)
Simon Glass9f407d42018-11-15 18:43:50 -0700216{
217 struct bloblist_rec *rec;
218
Simon Glass1a2e02f2023-12-27 13:07:00 -0800219 if (bloblist_addrec(tag, size, align_log2, &rec))
Simon Glass9f407d42018-11-15 18:43:50 -0700220 return NULL;
221
Simon Glass1f06ed42023-12-27 13:07:03 -0800222 return (void *)rec + rec_hdr_size(rec);
Simon Glass9f407d42018-11-15 18:43:50 -0700223}
224
Simon Glass1a2e02f2023-12-27 13:07:00 -0800225int bloblist_ensure_size(uint tag, int size, int align_log2, void **blobp)
Simon Glass9f407d42018-11-15 18:43:50 -0700226{
227 struct bloblist_rec *rec;
228 int ret;
229
Simon Glass1a2e02f2023-12-27 13:07:00 -0800230 ret = bloblist_ensurerec(tag, &rec, size, align_log2);
Simon Glass9f407d42018-11-15 18:43:50 -0700231 if (ret)
232 return ret;
Simon Glass1f06ed42023-12-27 13:07:03 -0800233 *blobp = (void *)rec + rec_hdr_size(rec);
Simon Glass9f407d42018-11-15 18:43:50 -0700234
235 return 0;
236}
237
238void *bloblist_ensure(uint tag, int size)
239{
240 struct bloblist_rec *rec;
241
Simon Glass4c1497e2020-09-19 18:49:29 -0600242 if (bloblist_ensurerec(tag, &rec, size, 0))
Simon Glass9f407d42018-11-15 18:43:50 -0700243 return NULL;
244
Simon Glass1f06ed42023-12-27 13:07:03 -0800245 return (void *)rec + rec_hdr_size(rec);
Simon Glass9f407d42018-11-15 18:43:50 -0700246}
247
Simon Glass5b044542020-01-27 08:49:50 -0700248int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp)
249{
250 struct bloblist_rec *rec;
251 int ret;
252
Simon Glass4c1497e2020-09-19 18:49:29 -0600253 ret = bloblist_ensurerec(tag, &rec, *sizep, 0);
Simon Glass5b044542020-01-27 08:49:50 -0700254 if (ret == -ESPIPE)
255 *sizep = rec->size;
256 else if (ret)
257 return ret;
Simon Glass1f06ed42023-12-27 13:07:03 -0800258 *blobp = (void *)rec + rec_hdr_size(rec);
Simon Glass5b044542020-01-27 08:49:50 -0700259
260 return 0;
261}
262
Simon Glass1fe59372021-07-05 16:32:53 -0600263static int bloblist_resize_rec(struct bloblist_hdr *hdr,
264 struct bloblist_rec *rec,
265 int new_size)
266{
267 int expand_by; /* Number of bytes to expand by (-ve to contract) */
268 int new_alloced; /* New value for @hdr->alloced */
269 ulong next_ofs; /* Offset of the record after @rec */
270
271 expand_by = ALIGN(new_size - rec->size, BLOBLIST_ALIGN);
272 new_alloced = ALIGN(hdr->alloced + expand_by, BLOBLIST_ALIGN);
273 if (new_size < 0) {
Simon Glass1d8bbd72022-01-12 19:26:20 -0700274 log_debug("Attempt to shrink blob size below 0 (%x)\n",
275 new_size);
Simon Glass1fe59372021-07-05 16:32:53 -0600276 return log_msg_ret("size", -EINVAL);
277 }
278 if (new_alloced > hdr->size) {
Simon Glass1d8bbd72022-01-12 19:26:20 -0700279 log_err("Failed to allocate %x bytes size=%x, need size=%x\n",
280 new_size, hdr->size, new_alloced);
Simon Glass1fe59372021-07-05 16:32:53 -0600281 return log_msg_ret("alloc", -ENOSPC);
282 }
283
284 /* Move the following blobs up or down, if this is not the last */
285 next_ofs = bloblist_blob_end_ofs(hdr, rec);
286 if (next_ofs != hdr->alloced) {
287 memmove((void *)hdr + next_ofs + expand_by,
288 (void *)hdr + next_ofs, new_alloced - next_ofs);
289 }
290 hdr->alloced = new_alloced;
291
292 /* Zero the new part of the blob */
293 if (expand_by > 0) {
Simon Glass1f06ed42023-12-27 13:07:03 -0800294 memset((void *)rec + rec_hdr_size(rec) + rec->size, '\0',
Simon Glass1fe59372021-07-05 16:32:53 -0600295 new_size - rec->size);
296 }
297
298 /* Update the size of this blob */
299 rec->size = new_size;
300
301 return 0;
302}
303
304int bloblist_resize(uint tag, int new_size)
305{
306 struct bloblist_hdr *hdr = gd->bloblist;
307 struct bloblist_rec *rec;
308 int ret;
309
310 rec = bloblist_findrec(tag);
311 if (!rec)
312 return log_msg_ret("find", -ENOENT);
313 ret = bloblist_resize_rec(hdr, rec, new_size);
314 if (ret)
315 return log_msg_ret("resize", ret);
316
317 return 0;
318}
319
Simon Glass9f407d42018-11-15 18:43:50 -0700320static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr)
321{
322 struct bloblist_rec *rec;
323 u32 chksum;
324
325 chksum = crc32(0, (unsigned char *)hdr,
326 offsetof(struct bloblist_hdr, chksum));
327 foreach_rec(rec, hdr) {
Simon Glass1f06ed42023-12-27 13:07:03 -0800328 chksum = crc32(chksum, (void *)rec, rec_hdr_size(rec));
329 chksum = crc32(chksum, (void *)rec + rec_hdr_size(rec),
330 rec->size);
Simon Glass9f407d42018-11-15 18:43:50 -0700331 }
332
333 return chksum;
334}
335
336int bloblist_new(ulong addr, uint size, uint flags)
337{
338 struct bloblist_hdr *hdr;
339
340 if (size < sizeof(*hdr))
341 return log_ret(-ENOSPC);
342 if (addr & (BLOBLIST_ALIGN - 1))
343 return log_ret(-EFAULT);
344 hdr = map_sysmem(addr, size);
345 memset(hdr, '\0', sizeof(*hdr));
346 hdr->version = BLOBLIST_VERSION;
347 hdr->hdr_size = sizeof(*hdr);
348 hdr->flags = flags;
349 hdr->magic = BLOBLIST_MAGIC;
350 hdr->size = size;
351 hdr->alloced = hdr->hdr_size;
352 hdr->chksum = 0;
353 gd->bloblist = hdr;
354
355 return 0;
356}
357
358int bloblist_check(ulong addr, uint size)
359{
360 struct bloblist_hdr *hdr;
361 u32 chksum;
362
363 hdr = map_sysmem(addr, sizeof(*hdr));
364 if (hdr->magic != BLOBLIST_MAGIC)
365 return log_msg_ret("Bad magic", -ENOENT);
366 if (hdr->version != BLOBLIST_VERSION)
367 return log_msg_ret("Bad version", -EPROTONOSUPPORT);
368 if (size && hdr->size != size)
369 return log_msg_ret("Bad size", -EFBIG);
370 chksum = bloblist_calc_chksum(hdr);
371 if (hdr->chksum != chksum) {
Simon Glass1d8bbd72022-01-12 19:26:20 -0700372 log_err("Checksum %x != %x\n", hdr->chksum, chksum);
Simon Glass9f407d42018-11-15 18:43:50 -0700373 return log_msg_ret("Bad checksum", -EIO);
374 }
375 gd->bloblist = hdr;
376
377 return 0;
378}
379
380int bloblist_finish(void)
381{
382 struct bloblist_hdr *hdr = gd->bloblist;
383
384 hdr->chksum = bloblist_calc_chksum(hdr);
Simon Glass99047f52022-01-12 19:26:22 -0700385 log_debug("Finished bloblist size %lx at %lx\n", (ulong)hdr->size,
386 (ulong)map_to_sysmem(hdr));
Simon Glass9f407d42018-11-15 18:43:50 -0700387
388 return 0;
389}
390
Simon Glasse50a24a2022-01-12 19:26:23 -0700391ulong bloblist_get_base(void)
392{
393 return map_to_sysmem(gd->bloblist);
394}
395
396ulong bloblist_get_size(void)
397{
398 struct bloblist_hdr *hdr = gd->bloblist;
399
400 return hdr->size;
401}
402
Simon Glass4aed2272020-09-19 18:49:26 -0600403void bloblist_get_stats(ulong *basep, ulong *sizep, ulong *allocedp)
404{
405 struct bloblist_hdr *hdr = gd->bloblist;
406
407 *basep = map_to_sysmem(gd->bloblist);
408 *sizep = hdr->size;
409 *allocedp = hdr->alloced;
410}
411
412static void show_value(const char *prompt, ulong value)
413{
414 printf("%s:%*s %-5lx ", prompt, 8 - (int)strlen(prompt), "", value);
415 print_size(value, "\n");
416}
417
418void bloblist_show_stats(void)
419{
420 ulong base, size, alloced;
421
422 bloblist_get_stats(&base, &size, &alloced);
423 printf("base: %lx\n", base);
424 show_value("size", size);
425 show_value("alloced", alloced);
426 show_value("free", size - alloced);
427}
428
429void bloblist_show_list(void)
430{
431 struct bloblist_hdr *hdr = gd->bloblist;
432 struct bloblist_rec *rec;
433
Simon Glassf16ec772022-01-12 19:26:19 -0700434 printf("%-8s %8s Tag Name\n", "Address", "Size");
Simon Glass4aed2272020-09-19 18:49:26 -0600435 for (rec = bloblist_first_blob(hdr); rec;
436 rec = bloblist_next_blob(hdr, rec)) {
Simon Glassf16ec772022-01-12 19:26:19 -0700437 printf("%08lx %8x %4x %s\n",
Simon Glass1f06ed42023-12-27 13:07:03 -0800438 (ulong)map_to_sysmem((void *)rec + rec_hdr_size(rec)),
439 rec->size, rec_tag(rec),
440 bloblist_tag_name(rec_tag(rec)));
Simon Glass4aed2272020-09-19 18:49:26 -0600441 }
442}
443
Simon Glass9fe06462021-01-13 20:29:43 -0700444void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
445{
446 struct bloblist_hdr *hdr;
447
448 memcpy(to, from, from_size);
449 hdr = to;
450 hdr->size = to_size;
451}
452
Simon Glass9f407d42018-11-15 18:43:50 -0700453int bloblist_init(void)
454{
Simon Glassce3e75d2022-01-22 05:07:27 -0700455 bool fixed = IS_ENABLED(CONFIG_BLOBLIST_FIXED);
Simon Glass9f407d42018-11-15 18:43:50 -0700456 int ret = -ENOENT;
Simon Glass99047f52022-01-12 19:26:22 -0700457 ulong addr, size;
458 bool expected;
Simon Glass9f407d42018-11-15 18:43:50 -0700459
460 /**
Simon Glassce3e75d2022-01-22 05:07:27 -0700461 * We don't expect to find an existing bloblist in the first phase of
462 * U-Boot that runs. Also we have no way to receive the address of an
463 * allocated bloblist from a previous stage, so it must be at a fixed
464 * address.
Simon Glass9f407d42018-11-15 18:43:50 -0700465 */
Simon Glassce3e75d2022-01-22 05:07:27 -0700466 expected = fixed && !u_boot_first_phase();
Simon Glass9fe06462021-01-13 20:29:43 -0700467 if (spl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
468 expected = false;
Simon Glassce3e75d2022-01-22 05:07:27 -0700469 if (fixed)
470 addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
471 CONFIG_BLOBLIST_ADDR);
Simon Glass99047f52022-01-12 19:26:22 -0700472 size = CONFIG_BLOBLIST_SIZE;
473 if (expected) {
474 ret = bloblist_check(addr, size);
475 if (ret) {
476 log_warning("Expected bloblist at %lx not found (err=%d)\n",
477 addr, ret);
478 } else {
479 /* Get the real size, if it is not what we expected */
480 size = gd->bloblist->size;
481 }
482 }
Simon Glass9f407d42018-11-15 18:43:50 -0700483 if (ret) {
Simon Glass99047f52022-01-12 19:26:22 -0700484 if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) {
485 void *ptr = memalign(BLOBLIST_ALIGN, size);
Simon Glassd5b6e912021-11-03 21:09:20 -0600486
487 if (!ptr)
488 return log_msg_ret("alloc", -ENOMEM);
489 addr = map_to_sysmem(ptr);
Simon Glassce3e75d2022-01-22 05:07:27 -0700490 } else if (!fixed) {
491 return log_msg_ret("!fixed", ret);
Simon Glassd5b6e912021-11-03 21:09:20 -0600492 }
Simon Glass99047f52022-01-12 19:26:22 -0700493 log_debug("Creating new bloblist size %lx at %lx\n", size,
494 addr);
495 ret = bloblist_new(addr, size, 0);
Simon Glass9f407d42018-11-15 18:43:50 -0700496 } else {
Simon Glass99047f52022-01-12 19:26:22 -0700497 log_debug("Found existing bloblist size %lx at %lx\n", size,
498 addr);
Simon Glass9f407d42018-11-15 18:43:50 -0700499 }
Simon Glass3d653182023-09-26 08:14:51 -0600500 if (ret)
501 return log_msg_ret("ini", ret);
502 gd->flags |= GD_FLG_BLOBLIST_READY;
Simon Glass9f407d42018-11-15 18:43:50 -0700503
Simon Glass3d653182023-09-26 08:14:51 -0600504 return 0;
505}
506
507int bloblist_maybe_init(void)
508{
509 if (CONFIG_IS_ENABLED(BLOBLIST) && !(gd->flags & GD_FLG_BLOBLIST_READY))
510 return bloblist_init();
511
512 return 0;
Simon Glass9f407d42018-11-15 18:43:50 -0700513}