[PATCH 6/6] rockchip: ringneck-px30: fix modified boot_targets detection
Kever Yang
kever.yang at rock-chips.com
Thu Nov 9 04:34:09 CET 2023
On 2023/11/8 22:20, Quentin Schulz wrote:
> From: Quentin Schulz <quentin.schulz at theobroma-systems.com>
>
> 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 at 0leil.net>
> Signed-off-by: Quentin Schulz <quentin.schulz at theobroma-systems.com>
Reviewed-by: Kever Yang <kever.yang at rock-chips.com>
Thanks,
- Kever
> ---
> board/theobroma-systems/ringneck_px30/ringneck-px30.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/board/theobroma-systems/ringneck_px30/ringneck-px30.c b/board/theobroma-systems/ringneck_px30/ringneck-px30.c
> index dd711cd05de..2bce8147eeb 100644
> --- a/board/theobroma-systems/ringneck_px30/ringneck-px30.c
> +++ b/board/theobroma-systems/ringneck_px30/ringneck-px30.c
> @@ -39,7 +39,9 @@ static 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",
> @@ -48,7 +50,10 @@ static 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__);
>
More information about the U-Boot
mailing list