Hi,

> From: Heinrich Schuchardt <xypron.g...@gmx.de>
> Sent: Thursday, February 20, 2025 9:22 AM
> 
> On 2/20/25 07:58, Ilias Apalodimas wrote:
> > On Mon, 10 Feb 2025 at 18:07, Pawel Kochanowski <pkochanow...@sii.pl>
> wrote:
> >>
> >> From: Gabriel Nesteruk <gneste...@sii.pl>
> >>
> >> U-Boot currently reserves only 0x3000 bytes when copying the FDT in
> >> `copy_fdt()`, which may not be sufficient if additional nodes (such
> >> as FMAN firmware) are added later.
> >>
> >> This patch introduces a new `CONFIG_FDT_EXTRA_SPACE` Kconfig option
> >> to allow users to define the amount of extra space reserved for FDT
> >> expansion. The default remains 0x3000.
> >>
> >> This change prevents potential corruption when resizing FDT after EFI
> >> boot, especially when firmware like FMAN requires additional space.
> >>
> >> Signed-off-by: Gabriel Nesteruk <gneste...@sii.pl>
> >> Signed-off-by: Pawel Kochanowski <pkochanow...@sii.pl>
> >> ---
> >>   lib/efi_loader/Kconfig      | 9 +++++++++
> >>   lib/efi_loader/efi_helper.c | 2 +-
> >>   2 files changed, 10 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index
> >> d4f6b56afaa..bd2cbe995c9 100644
> >> --- a/lib/efi_loader/Kconfig
> >> +++ b/lib/efi_loader/Kconfig
> >> @@ -586,6 +586,15 @@ config BOOTEFI_TESTAPP_COMPILE
> >>            No additional space will be required in the resulting U-Boot 
> >> binary
> >>            when this option is enabled.
> >>
> >> +config EFI_FDT_EXTRA_SPACE
> >> +    hex "Extra space to allocate for FDT expansion"
> 
> Hello Pawel,
> 
> Is this problem really EFI specific? Wouldn't you have a similar problem when
> booting via booti?
> 
Yes it seems that this problem occurs only in EFI as this FDT relocation is 
done with
hardcoded size. In other cases the boot_relocate_fdt() is used and 
CONFIG_SYS_FDT_PAD bytes are added instead.

Would it make sense to simply use the config SYS_FDT_PAD also here?
It already has increased padding size in case FMAN_ENET option is used.

> >> +    default 0x3000
> >> +    help
> >> +      Defines additional space (in bytes) reserved for expanding the
> >> +      Flattened Device Tree (FDT) when passed to the EFI system.
> >> +      Increase this value if your firmware (e.g., FMAN) needs to add
> >> +      more data to the device tree after U-Boot relocation.
> >> +
> >>   endif
> >>
> >>   source "lib/efi/Kconfig"
> >> diff --git a/lib/efi_loader/efi_helper.c
> >> b/lib/efi_loader/efi_helper.c index 04b2efc4a3b..91b2a5b8653 100644
> >> --- a/lib/efi_loader/efi_helper.c
> >> +++ b/lib/efi_loader/efi_helper.c
> >> @@ -477,7 +477,7 @@ static efi_status_t copy_fdt(void **fdtp)
> >>           * needs to be expanded later.
> >>           */
> >>          fdt = *fdtp;
> >> -       fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000);
> >> +       fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) +
> >> + CONFIG_EFI_FDT_EXTRA_SPACE);
> 
> This is not the only place where the configuration value needs to be
> considered:
> 
> lib/efi_loader/efi_dt_fixup.c:171:
>                                0x3000;
> 
> Could you, please, send a new revision of your patch.
> 
> Best regards
> 
> Heinrich

Please let me know if the initially proposed EFI_FDT_EXTRA_SPACE or the 
global SYS_FDT_PAD should be used and I will prepare and test new patch.

BR,
Pawel
> 
> >>          fdt_size = fdt_pages << EFI_PAGE_SHIFT;
> >>
> >>          ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
> >> --
> >> 2.43.0
> >>
> >
> > Reviewed-by: Ilias Apalodimas <ilias.apalodi...@linaro.org>

Reply via email to