Skip to contentSkip to conversation

efi: Make FDT extra space configurable

PATCH Superseded Pawel Kochanowski 4 participants 10 messages Feb 10, 2025 – Mar 2, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: Make FDT extra space configurable

From: Gabriel Nesteruk <[email protected]>

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.

---
 lib/efi_loader/Kconfig      | 9 +++++++++
 lib/efi_loader/efi_helper.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +9 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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"
+    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"
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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);
 	fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
 	ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 56 lines · Pawel Kochanowski

From: Gabriel Nesteruk <[email protected]>

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.

---
 lib/efi_loader/Kconfig      | 9 +++++++++
 lib/efi_loader/efi_helper.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +9 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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"
+    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"
lib/efi_loader/efi_helper.c +1 -2
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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);
        fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
        ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--
Quoted 2 lines

2.43.0

#2 lore raw
Quoted 31 lines · Ilias Apalodimas
Quoted 30 lines · Pawel Kochanowski

From: Gabriel Nesteruk <[email protected]>

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.

---
  lib/efi_loader/Kconfig      | 9 +++++++++
  lib/efi_loader/efi_helper.c | 2 +-
  2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +0 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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.
 
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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?

Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 11 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 480

Quoted 11 lines
lib/efi_loader/Kconfig +0 -0
  source "lib/efi/Kconfig"
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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

Quoted 8 lines
Quoted 6 lines
lib/efi_loader/efi_helper.c +0 -1
         fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
         ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0

#3 lore raw

Hi,

Quoted 65 lines · Heinrich Schuchardt
Quoted 31 lines · Ilias Apalodimas
Quoted 30 lines · Pawel Kochanowski

From: Gabriel Nesteruk <[email protected]>

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.

---
  lib/efi_loader/Kconfig      | 9 +++++++++
  lib/efi_loader/efi_helper.c | 2 +-
  2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +0 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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.
 
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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?

Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 11 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 480

Quoted 11 lines
lib/efi_loader/Kconfig +0 -0
  source "lib/efi/Kconfig"
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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:

Quoted 18 lines

lib/efi_loader/efi_dt_fixup.c:171:

                               0x3000;

Could you, please, send a new revision of your patch.

Best regards

Heinrich

Quoted 8 lines
Quoted 6 lines
lib/efi_loader/efi_helper.c +0 -1
         fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
         ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0

Let's do this instead, as it is generic:

https://lore.kernel.org/u-boot/[email protected]/

I believe the copy_fdt() function can just be removed, as the FDT is already in reserved memory. Putting it in the ACPI_RECLAIM region is wrong, too, as it is not an ACPI region.

Regards,
Simon

#4 lore raw
Quoted 87 lines · Simon Glass

Hi,

Quoted 65 lines · Heinrich Schuchardt
Quoted 31 lines · Ilias Apalodimas
Quoted 30 lines · Pawel Kochanowski

From: Gabriel Nesteruk <[email protected]>

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.

---
   lib/efi_loader/Kconfig      | 9 +++++++++
   lib/efi_loader/efi_helper.c | 2 +-
   2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +0 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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.
 
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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?

Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 11 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 480

Quoted 11 lines
lib/efi_loader/Kconfig +0 -0
   source "lib/efi/Kconfig"
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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:

Quoted 18 lines

lib/efi_loader/efi_dt_fixup.c:171:

                                0x3000;

Could you, please, send a new revision of your patch.

Best regards

Heinrich

Quoted 8 lines
Quoted 6 lines
lib/efi_loader/efi_helper.c +0 -1
          fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
          ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0

Quoted 7 lines

Let's do this instead, as it is generic:

https://lore.kernel.org/u-boot/[email protected]/

I believe the copy_fdt() function can just be removed, as the FDT is already in reserved memory. Putting it in the ACPI_RECLAIM region is wrong, too, as it is not an ACPI region.

Hello Simon,

UEFI specification 2.11:

4.6.1.3 Devicetree Tables
The DTB must be contained in memory of type EfiACPIReclaimMemory.

EBBR:

The DTB must be contained in memory of type EfiACPIReclaimMemory.
https://github.com/ARM-software/ebbr/blob/75112a58a5eacdfee758ce1b93ef3692b225fc36/source/chapter2-uefi.rst?plain=1#L396

We need the copy as the original device-tree which may be at $fdtcontroladdr will not have the required space for expansion.

Best regards

Heinrich

#5 lore raw

Hi Heinrich,

Quoted 101 lines · Heinrich Schuchardt
Quoted 87 lines · Simon Glass

Hi,

Quoted 65 lines · Heinrich Schuchardt
Quoted 31 lines · Ilias Apalodimas
Quoted 30 lines · Pawel Kochanowski

From: Gabriel Nesteruk <[email protected]>

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.

---
   lib/efi_loader/Kconfig      | 9 +++++++++
   lib/efi_loader/efi_helper.c | 2 +-
   2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +0 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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.
 
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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?

Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 11 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 480

Quoted 11 lines
lib/efi_loader/Kconfig +0 -0
   source "lib/efi/Kconfig"
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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:

Quoted 18 lines

lib/efi_loader/efi_dt_fixup.c:171:

                                0x3000;

Could you, please, send a new revision of your patch.

Best regards

Heinrich

Quoted 8 lines
Quoted 6 lines
lib/efi_loader/efi_helper.c +0 -1
          fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
          ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0

Quoted 7 lines

Let's do this instead, as it is generic:

https://lore.kernel.org/u-boot/[email protected]/

I believe the copy_fdt() function can just be removed, as the FDT is already in reserved memory. Putting it in the ACPI_RECLAIM region is wrong, too, as it is not an ACPI region.

Hello Simon,

UEFI specification 2.11:

Quoted 7 lines

4.6.1.3 Devicetree Tables
The DTB must be contained in memory of type EfiACPIReclaimMemory.

EBBR:

The DTB must be contained in memory of type EfiACPIReclaimMemory.
https://github.com/ARM-software/ebbr/blob/75112a58a5eacdfee758ce1b93ef3692b225fc36/source/chapter2-uefi.rst?plain=1#L396

Ah, I see, thanks. Confusing.

Quoted 3 lines

We need the copy as the original device-tree which may be at $fdtcontroladdr will not have the required space for expansion.

That's the subject of the patch I linked.

It would be nice if EFI could use common code to update the FDT *e.g. image_setup_linux()), then copy it into the new 'ACPI' region after that.

Regards,
Simon

#6 lore raw
In reply to Simon Glass

Hi Simon,

Quoted 88 lines · Simon Glass

Hi,

Quoted 65 lines · Heinrich Schuchardt
Quoted 31 lines · Ilias Apalodimas
Quoted 30 lines · Pawel Kochanowski

From: Gabriel Nesteruk <[email protected]>

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.

---
  lib/efi_loader/Kconfig      | 9 +++++++++
  lib/efi_loader/efi_helper.c | 2 +-
  2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +0 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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.
 
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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?

Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 11 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 480

Quoted 11 lines
lib/efi_loader/Kconfig +0 -0
  source "lib/efi/Kconfig"
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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:

Quoted 18 lines

lib/efi_loader/efi_dt_fixup.c:171:

                               0x3000;

Could you, please, send a new revision of your patch.

Best regards

Heinrich

Quoted 8 lines
Quoted 6 lines
lib/efi_loader/efi_helper.c +0 -1
         fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
         ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0

Quoted 7 lines

Let's do this instead, as it is generic:

https://lore.kernel.org/u-boot/[email protected]/

I believe the copy_fdt() function can just be removed, as the FDT is already in reserved memory. Putting it in the ACPI_RECLAIM region is wrong, too, as it is not an ACPI region.

That's not true. The EFI specification explicitly requests is as such. ACPI_RECLAIM is a bit of an unfortunate misnomer, but it's memory the OS can reclaim if it wants. IIRC Linux doesn't currently

/Ilias

Quoted 3 lines

Regards,
Simon

#7 lore raw

Hi Ilias,

Quoted 96 lines · Ilias Apalodimas

Hi Simon,

Quoted 92 lines · Simon Glass

Hi,

Quoted 65 lines · Heinrich Schuchardt
Quoted 31 lines · Ilias Apalodimas
Quoted 30 lines · Pawel Kochanowski

From: Gabriel Nesteruk <[email protected]>

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.

---
  lib/efi_loader/Kconfig      | 9 +++++++++
  lib/efi_loader/efi_helper.c | 2 +-
  2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +0 -0
index d4f6b56afaa..bd2cbe995c9 100644
@@ -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.
 
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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?

Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 11 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 480

Quoted 11 lines
lib/efi_loader/Kconfig +0 -0
  source "lib/efi/Kconfig"
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..91b2a5b8653 100644
@@ -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:

Quoted 18 lines

lib/efi_loader/efi_dt_fixup.c:171:

                               0x3000;

Could you, please, send a new revision of your patch.

Best regards

Heinrich

Quoted 8 lines
Quoted 6 lines
lib/efi_loader/efi_helper.c +0 -1
         fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
         ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0

Let's do this instead, as it is generic:

https://lore.kernel.org/u-boot/[email protected]/

Quoted 7 lines
Quoted 3 lines

I believe the copy_fdt() function can just be removed, as the FDT is already in reserved memory. Putting it in the ACPI_RECLAIM region is wrong, too, as it is not an ACPI region.

That's not true. The EFI specification explicitly requests is as such. ACPI_RECLAIM is a bit of an unfortunate misnomer, but it's memory the OS can reclaim if it wants. IIRC Linux doesn't currently

Got it. Yes it looks like Linux doesn't reclaim it.

Regards,
Simon

#8 lore raw
In reply to Heinrich Schuchardt

Hi,

Quoted 35 lines

From: Heinrich Schuchardt <[email protected]>
Sent: Thursday, February 20, 2025 9:22 AM

Quoted 1 line · Ilias Apalodimas

On Mon, 10 Feb 2025 at 18:07, Pawel Kochanowski <[email protected]>

Quoted 29 lines · wrote:
Quoted 29 lines

From: Gabriel Nesteruk <[email protected]>

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.

---
  lib/efi_loader/Kconfig      | 9 +++++++++
  lib/efi_loader/efi_helper.c | 2 +-
  2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig index renamed from lib/efi_loader/Kconfig +0 -0

d4f6b56afaa..bd2cbe995c9 100644

lib/efi_loader/Kconfig +0 -0
@@ -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.
 
Quoted 8 lines
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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.

Quoted 25 lines
Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 12 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 481

Quoted 12 lines
lib/efi_loader/Kconfig +0 -0
  source "lib/efi/Kconfig"
(quoted diff) +0 -0

b/lib/efi_loader/efi_helper.c index 04b2efc4a3b..91b2a5b8653 100644

lib/efi_loader/efi_helper.c +2 -1
@@ -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:

Quoted 8 lines

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

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
lib/efi_loader/efi_helper.c +0 -1
         fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
         ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0

#9 lore raw
Quoted 80 lines · Paweł Kochanowski

Hi,

Quoted 35 lines

From: Heinrich Schuchardt <[email protected]>
Sent: Thursday, February 20, 2025 9:22 AM

Quoted 1 line · Ilias Apalodimas

On Mon, 10 Feb 2025 at 18:07, Pawel Kochanowski <[email protected]>

Quoted 29 lines · wrote:
Quoted 29 lines

From: Gabriel Nesteruk <[email protected]>

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.

---
   lib/efi_loader/Kconfig      | 9 +++++++++
   lib/efi_loader/efi_helper.c | 2 +-
   2 files changed, 10 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig index renamed from lib/efi_loader/Kconfig +0 -0

d4f6b56afaa..bd2cbe995c9 100644

lib/efi_loader/Kconfig +0 -0
@@ -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.
 
Quoted 8 lines
Quoted 2 lines

lib/efi_loader/Kconfig config BOOTEFI_TESTAPP_COMPILE · line 590

Quoted 2 lines
lib/efi_loader/Kconfig +2 -0
+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.

Quoted 28 lines
Quoted 9 lines
Quoted 9 lines
lib/efi_loader/Kconfig +7 -0
+    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
 
Quoted 12 lines

lib/efi_loader/efi_helper.c static efi_status_t copy_fdt(void **fdtp) · line 481

Quoted 12 lines
lib/efi_loader/Kconfig +0 -0
   source "lib/efi/Kconfig"
(quoted diff) +0 -0

b/lib/efi_loader/efi_helper.c index 04b2efc4a3b..91b2a5b8653 100644

lib/efi_loader/efi_helper.c +2 -1
@@ -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;
Quoted 8 lines
Quoted 5 lines

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.

Yes, we should use the same Kconfig variable.

The description in

lib/Kconfig:1010:config SYS_FDT_PAD

seems not to match the usage. I have sent
https://lore.kernel.org/u-boot/[email protected]/T/#u

Best regards

Heinrich

Quoted 13 lines

BR,
Pawel

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
lib/efi_loader/efi_helper.c +0 -1
          fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
          ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--

2.43.0