bloblist: Load the bloblist from the previous loader

During bloblist initialization, load the bloblist via boot arguments
from the previous loader.
If a valid bloblist exists in boot arguments, relocate it into the
fixed bloblist memory region.
If not, fallback to support BLOBLIST_ADDR or BLOBLIST_ALLOC.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
This commit is contained in:
Raymond Mao 2024-02-03 08:36:26 -08:00 committed by Tom Rini
parent fc61de3ff6
commit 66131310d8
2 changed files with 54 additions and 18 deletions

View File

@ -487,37 +487,57 @@ int bloblist_reloc(void *to, uint to_size)
return 0;
}
/*
* Weak default function for getting bloblist from boot args.
*/
int __weak xferlist_from_boot_arg(ulong __always_unused addr,
ulong __always_unused size)
{
return -ENOENT;
}
int bloblist_init(void)
{
bool fixed = IS_ENABLED(CONFIG_BLOBLIST_FIXED);
int ret = -ENOENT;
ulong addr, size;
bool expected;
/**
* We don't expect to find an existing bloblist in the first phase of
* U-Boot that runs. Also we have no way to receive the address of an
* allocated bloblist from a previous stage, so it must be at a fixed
/*
* If U-Boot is not in the first phase, an existing bloblist must be
* at a fixed address.
*/
bool from_addr = fixed && !u_boot_first_phase();
/*
* If U-Boot is in the first phase that an arch custom routine should
* install the bloblist passed from previous loader to this fixed
* address.
*/
expected = fixed && !u_boot_first_phase();
bool from_boot_arg = fixed && u_boot_first_phase();
if (spl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
expected = false;
from_addr = false;
if (fixed)
addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
CONFIG_BLOBLIST_ADDR);
size = CONFIG_BLOBLIST_SIZE;
if (expected) {
if (from_boot_arg)
ret = xferlist_from_boot_arg(addr, size);
else if (from_addr)
ret = bloblist_check(addr, size);
if (ret) {
log_warning("Expected bloblist at %lx not found (err=%d)\n",
addr, ret);
} else {
/* Get the real size, if it is not what we expected */
size = gd->bloblist->total_size;
}
}
if (ret)
log_warning("Bloblist at %lx not found (err=%d)\n",
addr, ret);
else
/* Get the real size */
size = gd->bloblist->total_size;
if (ret) {
/*
* If we don't have a bloblist from a fixed address, or the one
* in the fixed address is not valid. we must allocate the
* memory for it now.
*/
if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) {
void *ptr = memalign(BLOBLIST_ALIGN, size);
@ -525,7 +545,8 @@ int bloblist_init(void)
return log_msg_ret("alloc", -ENOMEM);
addr = map_to_sysmem(ptr);
} else if (!fixed) {
return log_msg_ret("!fixed", ret);
return log_msg_ret("BLOBLIST_FIXED is not enabled",
ret);
}
log_debug("Creating new bloblist size %lx at %lx\n", size,
addr);
@ -538,6 +559,11 @@ int bloblist_init(void)
return log_msg_ret("ini", ret);
gd->flags |= GD_FLG_BLOBLIST_READY;
#ifdef DEBUG
bloblist_show_stats();
bloblist_show_list();
#endif
return 0;
}

View File

@ -482,4 +482,14 @@ static inline int bloblist_maybe_init(void)
*/
int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig);
/**
* xferlist_from_boot_arg() - Get bloblist from the boot args and relocate it
* to the specified address.
*
* @addr: Address for the bloblist
* @size: Size of space reserved for the bloblist
* Return: 0 if OK, else on error
*/
int xferlist_from_boot_arg(ulong addr, ulong size);
#endif /* __BLOBLIST_H */