aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTom Rini2024-04-02 07:03:25 -0400
committerTom Rini2024-04-02 07:03:25 -0400
commitd312d9831f25a8e70d64df46fb2fe9aab2e8c939 (patch)
tree9afa8b258222e66221f8239d8ad51372d63c5ac3 /common
parent25049ad560826f7dc1c4740883b0016014a59789 (diff)
parentbc39e06778168a34bb4e0a34fbee4edbde4414d8 (diff)
Merge branch 'next'
Merge in all changes from the next branch now that the release is out.
Diffstat (limited to 'common')
-rw-r--r--common/autoboot.c3
-rw-r--r--common/bloblist.c85
-rw-r--r--common/board_f.c13
-rw-r--r--common/button_cmd.c2
-rw-r--r--common/cli_readline.c38
-rw-r--r--common/hash.c8
-rw-r--r--common/log.c5
-rw-r--r--common/spl/spl.c3
-rw-r--r--common/spl/spl_fit.c7
9 files changed, 119 insertions, 45 deletions
diff --git a/common/autoboot.c b/common/autoboot.c
index 5d331991c19..6f0aeae6bf3 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -167,6 +167,9 @@ static int passwd_abort_sha256(uint64_t etime)
sha_env_str = AUTOBOOT_STOP_STR_SHA256;
presskey = malloc_cache_aligned(DELAY_STOP_STR_MAX_LENGTH);
+ if (!presskey)
+ return -ENOMEM;
+
c = strstr(sha_env_str, ":");
if (c && (c - sha_env_str < DELAY_STOP_STR_MAX_LENGTH)) {
/* preload presskey with salt */
diff --git a/common/bloblist.c b/common/bloblist.c
index 2d373910b6d..ad06d7a1795 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -384,7 +384,7 @@ int bloblist_check(ulong addr, uint size)
return log_msg_ret("Bad magic", -ENOENT);
if (hdr->version != BLOBLIST_VERSION)
return log_msg_ret("Bad version", -EPROTONOSUPPORT);
- if (!hdr->total_size || (size && hdr->total_size != size))
+ if (!hdr->total_size || (size && hdr->total_size > size))
return log_msg_ret("Bad total size", -EFBIG);
if (hdr->used_size > hdr->total_size)
return log_msg_ret("Bad used size", -ENOENT);
@@ -472,13 +472,28 @@ void bloblist_show_list(void)
}
}
-void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
+int bloblist_reloc(void *to, uint to_size)
{
struct bloblist_hdr *hdr;
- memcpy(to, from, from_size);
+ if (to_size < gd->bloblist->total_size)
+ return -ENOSPC;
+
+ memcpy(to, gd->bloblist, gd->bloblist->total_size);
hdr = to;
hdr->total_size = to_size;
+ gd->bloblist = to;
+
+ 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)
@@ -486,32 +501,43 @@ 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);
@@ -519,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);
@@ -532,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;
}
@@ -542,3 +574,14 @@ int bloblist_maybe_init(void)
return 0;
}
+
+int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig)
+{
+ if (rzero || rsig != (BLOBLIST_MAGIC | BLOBLIST_REGCONV_VER) ||
+ rfdt != (ulong)bloblist_find(BLOBLISTT_CONTROL_FDT, 0)) {
+ gd->bloblist = NULL; /* Reset the gd bloblist pointer */
+ return -EIO;
+ }
+
+ return 0;
+}
diff --git a/common/board_f.c b/common/board_f.c
index 442b8349d08..8bada6ff2ee 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -282,7 +282,9 @@ static int init_func_i2c(void)
static int setup_mon_len(void)
{
-#if defined(__ARM__) || defined(__MICROBLAZE__)
+#if defined(CONFIG_ARCH_NEXELL)
+ gd->mon_len = (ulong)__bss_end - (ulong)__image_copy_start;
+#elif defined(__ARM__) || defined(__MICROBLAZE__)
gd->mon_len = (ulong)__bss_end - (ulong)_start;
#elif defined(CONFIG_SANDBOX) && !defined(__riscv)
gd->mon_len = (ulong)_end - (ulong)_init;
@@ -706,13 +708,10 @@ static int reloc_bloblist(void)
return 0;
}
if (gd->new_bloblist) {
- int size = CONFIG_BLOBLIST_SIZE;
-
debug("Copying bloblist from %p to %p, size %x\n",
- gd->bloblist, gd->new_bloblist, size);
- bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
- gd->bloblist, size);
- gd->bloblist = gd->new_bloblist;
+ gd->bloblist, gd->new_bloblist, gd->bloblist->total_size);
+ return bloblist_reloc(gd->new_bloblist,
+ CONFIG_BLOBLIST_SIZE_RELOC);
}
#endif
diff --git a/common/button_cmd.c b/common/button_cmd.c
index b6a8434d6f2..8642c26735c 100644
--- a/common/button_cmd.c
+++ b/common/button_cmd.c
@@ -33,7 +33,7 @@ struct button_cmd {
static int get_button_cmd(int n, struct button_cmd *cmd)
{
const char *cmd_str;
- struct udevice *btn;
+ struct udevice *btn = NULL;
char buf[24];
snprintf(buf, sizeof(buf), "button_cmd_%d_name", n);
diff --git a/common/cli_readline.c b/common/cli_readline.c
index 2507be22952..cf4339d0e50 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -86,6 +86,9 @@ static int hist_add_idx;
static int hist_cur = -1;
static unsigned hist_num;
+#ifndef CONFIG_CMD_HISTORY_USE_CALLOC
+static char hist_data[HIST_MAX][HIST_SIZE + 1];
+#endif
static char *hist_list[HIST_MAX];
#define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
@@ -100,20 +103,26 @@ static void getcmd_putchars(int count, int ch)
static int hist_init(void)
{
- unsigned char *hist;
int i;
- hist_max = 0;
- hist_add_idx = 0;
- hist_cur = -1;
- hist_num = 0;
-
- hist = calloc(HIST_MAX, HIST_SIZE + 1);
+#ifndef CONFIG_CMD_HISTORY_USE_CALLOC
+ for (i = 0; i < HIST_MAX; i++) {
+ hist_list[i] = hist_data[i];
+ hist_list[i][0] = '\0';
+ }
+#else
+ unsigned char *hist = calloc(HIST_MAX, HIST_SIZE + 1);
if (!hist)
- return -ENOMEM;
+ panic("%s: calloc: out of memory!\n", __func__);
for (i = 0; i < HIST_MAX; i++)
hist_list[i] = hist + (i * (HIST_SIZE + 1));
+#endif
+
+ hist_max = 0;
+ hist_add_idx = 0;
+ hist_cur = -1;
+ hist_num = 0;
return 0;
}
@@ -643,10 +652,15 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer,
static int initted;
/*
- * History uses a global array which is not
- * writable until after relocation to RAM.
- * Revert to non-history version if still
- * running from flash.
+ * Say N to CMD_HISTORY_USE_CALLOC will skip runtime
+ * allocation for the history buffer and directly
+ * use an uninitialized static array as the buffer.
+ * Doing this might have better performance and not
+ * increase the binary file's size, as it only marks
+ * the size. However, the array is only writable after
+ * relocation to RAM. If u-boot is running from ROM
+ * all the time, consider say Y to CMD_HISTORY_USE_CALLOC
+ * or disable CMD_HISTORY.
*/
if (IS_ENABLED(CONFIG_CMDLINE_EDITING) && (gd->flags & GD_FLG_RELOC)) {
if (!initted) {
diff --git a/common/hash.c b/common/hash.c
index e837c56d443..3d6b84de473 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -321,7 +321,8 @@ static struct hash_algo hash_algo[] = {
/* Try to minimize code size for boards that don't want much hashing */
#if CONFIG_IS_ENABLED(SHA256) || IS_ENABLED(CONFIG_CMD_SHA1SUM) || \
CONFIG_IS_ENABLED(CRC32_VERIFY) || IS_ENABLED(CONFIG_CMD_HASH) || \
- CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512)
+ CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512) || \
+ IS_ENABLED(CONFIG_CMD_MD5SUM)
#define multi_hash() 1
#else
#define multi_hash() 0
@@ -404,7 +405,8 @@ int hash_block(const char *algo_name, const void *data, unsigned int len,
}
#if !defined(CONFIG_SPL_BUILD) && (defined(CONFIG_CMD_HASH) || \
- defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32))
+ defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)) || \
+ defined(CONFIG_CMD_MD5SUM)
/**
* store_result: Store the resulting sum to an address or variable
*
@@ -565,7 +567,7 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp,
/* Try to avoid code bloat when verify is not needed */
#if defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_SHA1SUM_VERIFY) || \
- defined(CONFIG_HASH_VERIFY)
+ defined(CONFIG_MD5SUM_VERIFY) || defined(CONFIG_HASH_VERIFY)
if (flags & HASH_FLAG_VERIFY) {
#else
if (0) {
diff --git a/common/log.c b/common/log.c
index b2de57fcb3b..42d35f04b68 100644
--- a/common/log.c
+++ b/common/log.c
@@ -428,6 +428,11 @@ int log_device_set_enable(struct log_driver *drv, bool enable)
return 0;
}
+void log_fixup_for_gd_move(struct global_data *new_gd)
+{
+ new_gd->log_head.prev->next = &new_gd->log_head;
+}
+
int log_init(void)
{
struct log_driver *drv = ll_entry_start(struct log_driver, log_driver);
diff --git a/common/spl/spl.c b/common/spl/spl.c
index b65c439e7aa..e06bc75d36b 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -909,6 +909,9 @@ ulong spl_relocate_stack_gd(void)
#if CONFIG_IS_ENABLED(DM)
dm_fixup_for_gd_move(new_gd);
#endif
+#if CONFIG_IS_ENABLED(LOG)
+ log_fixup_for_gd_move(new_gd);
+#endif
#if !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
gd = new_gd;
#endif
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 872df0c0fe8..e5195d460c4 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -550,7 +550,12 @@ static void *spl_get_fit_load_buffer(size_t size)
buf = malloc_cache_aligned(size);
if (!buf) {
pr_err("Could not get FIT buffer of %lu bytes\n", (ulong)size);
- pr_err("\tcheck CONFIG_SPL_SYS_MALLOC_SIZE\n");
+
+ if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC))
+ pr_err("\tcheck CONFIG_SPL_SYS_MALLOC_SIZE\n");
+ else
+ pr_err("\tcheck CONFIG_SPL_SYS_MALLOC_F_LEN\n");
+
buf = spl_get_load_buffer(0, size);
}
return buf;