[PATCH v2] bootm: Fix bmi->images pointer not initialized in some cases

Simon Glass sjg at chromium.org
Fri May 23 15:48:15 CEST 2025


Hi Benjamin,

On Tue, 20 May 2025 at 22:35, Benjamin ROBIN <dev at benjarobin.fr> wrote:
>
> When building with only bootz command, without bootm, images pointer
> inside bootm_info structure is not initialized. And since this structure
> is stored in stack, the generated error is kind of random, but most of
> the time this will generate: "ramdisk - allocation error".
>
> Also, after analysis, this problem could occur with the command booti,
> if the command bootm is disabled.
>
> Currently bootm_init() is called by: do_bootz(), do_bootm(), do_booti()
> and by do_stm32prog(). And all of these commands execute bootm_run_states()
> which access the images pointer stored into bootm_info structure.
>
> So, to fix this issue, just do the assignment unconditionally.
>
> Fixes: c2211ff65136 ("bootm: Add more fields to bootm_info")
> Signed-off-by: Benjamin ROBIN <dev at benjarobin.fr>
> ---
>  boot/bootm.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/boot/bootm.c b/boot/bootm.c
> index f6aa32746b7e..108ca7fb472e 100644
> --- a/boot/bootm.c
> +++ b/boot/bootm.c
> @@ -1169,8 +1169,7 @@ void bootm_init(struct bootm_info *bmi)
>  {
>         memset(bmi, '\0', sizeof(struct bootm_info));
>         bmi->boot_progress = true;
> -       if (IS_ENABLED(CONFIG_CMD_BOOTM))
> -               bmi->images = &images;
> +       bmi->images = &images;

In my tree I have:

if (IS_ENABLED(CONFIG_CMD_BOOTM) || IS_ENABLED(CONFIG_CMD_BOOTZ) ||
    IS_ENABLED(CONFIG_CMD_BOOTI) || IS_ENABLED(CONFIG_PXE_UTILS))

but it seems that the few boards that didn't include boot/bootm.c have
been dropped, so your patch is fine.

>  }
>
>  /**
> --
> 2.49.0
>

Regards,
Simon


More information about the U-Boot mailing list