aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Schulz <quentin.schulz@theobroma-systems.com>2024-01-17 18:59:13 +0100
committerKever Yang <kever.yang@rock-chips.com>2024-01-19 10:57:36 +0800
commitd2c90bfc4c56b8366b3c4c6ed298b0d81846fc7e (patch)
treef2de0ad75847476f6915b3b101aa4034b01b6325
parent87d3c472a266261642ad26a3d4b040de09edac71 (diff)
downloadu-boot-d2c90bfc4c56b8366b3c4c6ed298b0d81846fc7e.zip
u-boot-d2c90bfc4c56b8366b3c4c6ed298b0d81846fc7e.tar.gz
u-boot-d2c90bfc4c56b8366b3c4c6ed298b0d81846fc7e.tar.bz2
rockchip: theobroma-systems: fix modified boot_targets detection
U-Boot proper automatically modifies boot_targets to swap the order in which MMC storage media are used for standard boot based on which MMC storage medium was used to load U-Boot proper. This is however only done if the user has not changed it manually, therefore a check between the default and current value is done. This used to work fine until the migration to standard boot where boot_targets value size in the default environment went above the 32 characters that env_get_default function can return, thus resulting in a truncated variable. Therefore the check between default and current value would always fail. By using the newly added env_get_default_into function, a buffer of the appropriate size can be allocated on the stack to get the whole value of boot_targets in the default environment and thus fixing the check. Cc: Quentin Schulz <foss+uboot@0leil.net> Reviewed-by: Kever Yang <kever.yang@rock-chips.com> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
-rw-r--r--board/theobroma-systems/common/common.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/board/theobroma-systems/common/common.c b/board/theobroma-systems/common/common.c
index eb21d4c..864bcdd 100644
--- a/board/theobroma-systems/common/common.c
+++ b/board/theobroma-systems/common/common.c
@@ -21,7 +21,9 @@ int setup_boottargets(void)
{
const char *boot_device =
ofnode_read_chosen_string("u-boot,spl-boot-device");
- char *env_default, *env;
+ char env_default[sizeof(BOOT_TARGETS)];
+ char *env;
+ int ret;
if (!boot_device) {
debug("%s: /chosen/u-boot,spl-boot-device not set\n",
@@ -30,7 +32,9 @@ int setup_boottargets(void)
}
debug("%s: booted from %s\n", __func__, boot_device);
- env_default = env_get_default("boot_targets");
+ ret = env_get_default_into("boot_targets", env_default, sizeof(env_default));
+ if (ret < 0)
+ env_default[0] = '\0';
env = env_get("boot_targets");
if (!env) {
debug("%s: boot_targets does not exist\n", __func__);