Skip to contentSkip to conversation

efi: Make FDT extra space configurable

PATCH In review Pawel Kochanowski 3 participants 3 messages Mar 18, 2025 – Apr 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi: Make FDT extra space configurable

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 uses the exisitng SYS_FDT_PAD to reserve space for FDT fixup instead of hardcoded value.

This change prevents potential corruption when resizing FDT after EFI boot, especially when firmware like FMAN requires additional space.

---
Changes since version 1:
- Removed custom CONFIG_FDT_EXTRA_SPACE in favor of already present SYS_FDT_PAD
- Use the define also in efi_dt_fixup.c

 lib/efi_loader/efi_dt_fixup.c | 2 +-
 lib/efi_loader/efi_helper.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
lib/efi_loader/efi_dt_fixup.c +1 -1
index 26928cfc454..544e1aa9808 100644
@@ -168,7 +168,7 @@ efi_dt_fixup(struct efi_dt_fixup_protocol *this, void *dtb,
 		/* Check size */
 		required_size = fdt_off_dt_strings(dtb) +
 				fdt_size_dt_strings(dtb) +
-				0x3000;
+				CONFIG_SYS_FDT_PAD;
 		total_size = fdt_totalsize(dtb);
 		if (required_size < total_size)
 			required_size = total_size;
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..40e5d31575a 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_SYS_FDT_PAD);
 	fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
 	ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Pawel Kochanowski

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 uses the exisitng SYS_FDT_PAD to reserve space for FDT fixup instead of hardcoded value.

Quoted 6 lines

This change prevents potential corruption when resizing FDT after EFI boot, especially when firmware like FMAN requires additional space.

Quoted 35 lines

---
Changes since version 1:
- Removed custom CONFIG_FDT_EXTRA_SPACE in favor of already present SYS_FDT_PAD
- Use the define also in efi_dt_fixup.c

  lib/efi_loader/efi_dt_fixup.c | 2 +-
  lib/efi_loader/efi_helper.c   | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
lib/efi_loader/efi_dt_fixup.c +1 -1
index 26928cfc454..544e1aa9808 100644
@@ -168,7 +168,7 @@ efi_dt_fixup(struct efi_dt_fixup_protocol *this, void *dtb,
  		/* Check size */
  		required_size = fdt_off_dt_strings(dtb) +
  				fdt_size_dt_strings(dtb) +
-				0x3000;
+				CONFIG_SYS_FDT_PAD;
  		total_size = fdt_totalsize(dtb);
  		if (required_size < total_size)
  			required_size = total_size;
lib/efi_loader/efi_helper.c +1 -1
index 04b2efc4a3b..40e5d31575a 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_SYS_FDT_PAD);
  	fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
  	ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
Reviewed-by on v2 1/1
#2 lore raw
In reply to Pawel Kochanowski
Quoted 50 lines · Pawel Kochanowski

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 uses the exisitng SYS_FDT_PAD to reserve space for FDT fixup instead of hardcoded value.

This change prevents potential corruption when resizing FDT after EFI boot, especially when firmware like FMAN requires additional space.

---
Changes since version 1:
- Removed custom CONFIG_FDT_EXTRA_SPACE in favor of already present SYS_FDT_PAD
- Use the define also in efi_dt_fixup.c

 lib/efi_loader/efi_dt_fixup.c | 2 +-
 lib/efi_loader/efi_helper.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
lib/efi_loader/efi_dt_fixup.c +1 -1
index 26928cfc454..544e1aa9808 100644
@@ -168,7 +168,7 @@ efi_dt_fixup(struct efi_dt_fixup_protocol *this, void *dtb,
                /* Check size */
                required_size = fdt_off_dt_strings(dtb) +
                                fdt_size_dt_strings(dtb) +
-                               0x3000;
+                               CONFIG_SYS_FDT_PAD;
                total_size = fdt_totalsize(dtb);
                if (required_size < total_size)
                        required_size = total_size;
lib/efi_loader/efi_helper.c +1 -2
index 04b2efc4a3b..40e5d31575a 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_SYS_FDT_PAD);
        fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 
        ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--
Quoted 2 lines

2.43.0