Skip to contentSkip to conversation

spl: Ensure final section before BSS is non-empty

PATCH In review Tom Rini 5 participants 10 messages Jan 30 – Feb 9

Subsystems (4)
lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 spl: Ensure final section before BSS is non-empty

As part of ensuring that we make a binary image to append our device tree to and that it will have an 8 byte alignment, one problem was overlooked. That problem is what happens when we have a section that only contains ALIGN statements and linker references, but nothing else. What happens in this case is that we will have a section in the resulting ELF that has is of the NOBITS type. This in turn means that when we use objcopy to turn the ELF in to a binary for further processing, it won't copy anything. This then becomes a problem when we do not have a separate BSS and instead append a "padding" file to act as the BSS, and then append our device tree to that. The solution here is to ensure that the final section in our SPL image is something that will always exist with contents, in this case __u_boot_list.

Fixes 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts")
Fixes f150843499b3 ("riscv: Update linker scripts to ensure appended device tree is aligned")

---
Ilias, if there's anyone else you can get to look at this which understands linker scripts better please do. I think I finally see *how* things go wrong in some cases but I'm less confident in my explanation above. Thanks.

Cc Ilias Apalodimas <[email protected]>
---
 arch/arm/cpu/armv8/u-boot-spl.lds           | 12 ++++++------
 arch/arm/cpu/u-boot-spl.lds                 | 10 +++++-----
 arch/arm/mach-aspeed/ast2600/u-boot-spl.lds | 10 +++++-----
 arch/riscv/cpu/u-boot-spl.lds               | 11 +++++------
 4 files changed, 21 insertions(+), 22 deletions(-)
arch/arm/cpu/armv8/u-boot-spl.lds +6 -6
index b732133ce76d..29252d870f91 100644
@@ -49,12 +49,6 @@ SECTIONS
 	} >.sram
 #endif
 
-	__u_boot_list : {
-		. = ALIGN(8);
-		KEEP(*(SORT(__u_boot_list*)));
-		. = ALIGN(8);
-	} >.sram
-
 	.binman_sym_table : {
 		. = ALIGN(8);
 		__binman_sym_start = .;
@@ -63,6 +57,12 @@ SECTIONS
 		. = ALIGN(8);
 	} > .sram
 
+	__u_boot_list : {
+		. = ALIGN(8);
+		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
+	} >.sram
+
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
arch/arm/cpu/u-boot-spl.lds +5 -5
index c578c3ebf821..5f807323f856 100644
@@ -31,16 +31,16 @@ SECTIONS
 		*(.data*)
 	}
 
-	. = ALIGN(4);
-	__u_boot_list : {
-		KEEP(*(SORT(__u_boot_list*)));
-	}
-
 	. = ALIGN(4);
 	.binman_sym_table : {
 		__binman_sym_start = .;
 		KEEP(*(SORT(.binman_sym*)));
 		__binman_sym_end = .;
+	}
+
+	. = ALIGN(4);
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)));
 		. = ALIGN(8);
 	}
 
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds +5 -5
index 303ace2f61ca..260a0a79dd0a 100644
@@ -39,16 +39,16 @@ SECTIONS
 		*(.data*)
 	} > .nor
 
-	. = ALIGN(4);
-	__u_boot_list : {
-		KEEP(*(SORT(__u_boot_list*)));
-	} > .nor
-
 	. = ALIGN(4);
 	.binman_sym_table : {
 		__binman_sym_start = .;
 		KEEP(*(SORT(.binman_sym*)));
 		__binman_sym_end = .;
+	} > .nor
+
+	. = ALIGN(4);
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)));
 		. = ALIGN(8);
 	} > .nor
 
arch/riscv/cpu/u-boot-spl.lds +5 -6
index 35de28db8f3a..5a65e6653f25 100644
@@ -31,18 +31,17 @@ SECTIONS
 	.data : {
 		*(.data*)
 	} > .spl_mem
-	. = ALIGN(4);
-
-	__u_boot_list : {
-		KEEP(*(SORT(__u_boot_list*)));
-	} > .spl_mem
 
 	. = ALIGN(4);
-
 	.binman_sym_table : {
 		__binman_sym_start = .;
 		KEEP(*(SORT(.binman_sym*)));
 		__binman_sym_end = .;
+	} > .spl_mem
+
+	. = ALIGN(4);
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)));
 		. = ALIGN(8);
 	} > .spl_mem
 
Signature · 1 line
2.43.0
Tested-by on v1 1/1
#1 lore raw
Quoted 77 lines · Tom Rini

As part of ensuring that we make a binary image to append our device tree to and that it will have an 8 byte alignment, one problem was overlooked. That problem is what happens when we have a section that only contains ALIGN statements and linker references, but nothing else. What happens in this case is that we will have a section in the resulting ELF that has is of the NOBITS type. This in turn means that when we use objcopy to turn the ELF in to a binary for further processing, it won't copy anything. This then becomes a problem when we do not have a separate BSS and instead append a "padding" file to act as the BSS, and then append our device tree to that. The solution here is to ensure that the final section in our SPL image is something that will always exist with contents, in this case __u_boot_list.

Fixes 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts")
Fixes f150843499b3 ("riscv: Update linker scripts to ensure appended device tree is aligned")

---
Ilias, if there's anyone else you can get to look at this which understands linker scripts better please do. I think I finally see *how* things go wrong in some cases but I'm less confident in my explanation above. Thanks.

Cc Ilias Apalodimas <[email protected]>
---
 arch/arm/cpu/armv8/u-boot-spl.lds           | 12 ++++++------
 arch/arm/cpu/u-boot-spl.lds                 | 10 +++++-----
 arch/arm/mach-aspeed/ast2600/u-boot-spl.lds | 10 +++++-----
 arch/riscv/cpu/u-boot-spl.lds               | 11 +++++------
 4 files changed, 21 insertions(+), 22 deletions(-)
arch/arm/cpu/armv8/u-boot-spl.lds +6 -6
index b732133ce76d..29252d870f91 100644
@@ -49,12 +49,6 @@ SECTIONS
        } >.sram
 #endif
 
-       __u_boot_list : {
-               . = ALIGN(8);
-               KEEP(*(SORT(__u_boot_list*)));
-               . = ALIGN(8);
-       } >.sram
-
        .binman_sym_table : {
                . = ALIGN(8);
                __binman_sym_start = .;
@@ -63,6 +57,12 @@ SECTIONS
                . = ALIGN(8);
        } > .sram
 
+       __u_boot_list : {
+               . = ALIGN(8);
+               KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
+       } >.sram
+
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
arch/arm/cpu/u-boot-spl.lds +0 -5
index c578c3ebf821..5f807323f856 100644
@@ -31,16 +31,16 @@ SECTIONS
                *(.data*)
        }
 
-       . = ALIGN(4);
-       __u_boot_list : {
-               KEEP(*(SORT(__u_boot_list*)));
-       }
-
        . = ALIGN(4);
        .binman_sym_table : {

arch/arm/cpu/u-boot-spl.lds SECTIONS · line 45

Quoted 10 lines
arch/arm/cpu/u-boot-spl.lds +5 -0
                __binman_sym_start = .;
                KEEP(*(SORT(.binman_sym*)));
                __binman_sym_end = .;
+       }
+
+       . = ALIGN(4);
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)));
                . = ALIGN(8);
        }

For ARM v7 on SoCFPGA GEN5 Cyclone V boards:
AC550
AC501

Quoted 58 lines
arch/arm/mach-aspeed/ast2600/u-boot-spl.lds +5 -5
index 303ace2f61ca..260a0a79dd0a 100644
@@ -39,16 +39,16 @@ SECTIONS
                *(.data*)
        } > .nor
 
-       . = ALIGN(4);
-       __u_boot_list : {
-               KEEP(*(SORT(__u_boot_list*)));
-       } > .nor
-
        . = ALIGN(4);
        .binman_sym_table : {
                __binman_sym_start = .;
                KEEP(*(SORT(.binman_sym*)));
                __binman_sym_end = .;
+       } > .nor
+
+       . = ALIGN(4);
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)));
                . = ALIGN(8);
        } > .nor
 
arch/riscv/cpu/u-boot-spl.lds +5 -7
index 35de28db8f3a..5a65e6653f25 100644
@@ -31,18 +31,17 @@ SECTIONS
        .data : {
                *(.data*)
        } > .spl_mem
-       . = ALIGN(4);
-
-       __u_boot_list : {
-               KEEP(*(SORT(__u_boot_list*)));
-       } > .spl_mem
 
        . = ALIGN(4);
-
        .binman_sym_table : {
                __binman_sym_start = .;
                KEEP(*(SORT(.binman_sym*)));
                __binman_sym_end = .;
+       } > .spl_mem
+
+       . = ALIGN(4);
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)));
                . = ALIGN(8);
        } > .spl_mem
 
--

2.43.0

author
#2 lore raw

PATCH v2 1/1 arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

In reply to Tom Rini

Historically, when we have an appended device tree and also our resulting binary will contain the BSS section, we have ensured that everything will be where it's expected to be by declaring that the BSS is overlayed with a symbol matches the end of the port of the ELF binary that is objcopy'd to the binary we concatenate with. This in turn means that the logic to generate a "pad" file, which is the size found in the __bss_size symbol, will be correct and then we can concatenate the device tree and it will begin at __bss_size at run time.

With commit 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts") we removed this overlay as part of trying to ensure that we met both the requirements of the device tree to be 8 byte aligned as well as that our logic to generate the -pad file would match what ended up in the resulting binary. While it was correct to remove an unused section it did not solve ultimately solve the problem for all cases.

To really fix the problem, we need to do two things. First, our final section prior to _image_binary_end must be 8 byte aligned (for the case of having a separate BSS and so our appended DTB exists at this location). This cannot be '.binman_sym_table' as it may be empty, and in turn the ELF type would be NOBITS and so not copied with objcopy. The __u_boot_list section will never be empty, so it is our final section, and ends with a '. = ALIGN(8)' statement. Second, as this is the end of our copied data it is safe to declare that the BSS starts here, so use the OVERLAY keyword to place the BSS here.

Fixes 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts")

---
Cc: Richard Henderson <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Nobuhiro Iwamatsu <[email protected]>
Cc: Nathan Barrett-Morrison <[email protected]>
Cc: Greg Malysa <[email protected]>
Cc: Ian Roberts <[email protected]>
Cc: Vasileios Bimpikas <[email protected]>
Cc: Utsav Agarwal <[email protected]>
Cc: Arturs Artamonovs <[email protected]>
Cc: [email protected]

So, first, with the exception of:
axm brppt2 imx28_btt3 imx28_xea mk808 taurus work_92105
all platforms using arch/arm/cpu/u-boot-spl.lds do NOT enable CONFIG_SPL_SEPARATE_BSS. And of those, only brppt2 enables SPL_OF_REAL. As an aside, I'm thinking that there is room for a clean-up / merger of arch/arm/cpu/u-boot-spl.lds and arch/arm/mach-omap2/u-boot-spl.lds (*widely* used outside of mach-omap2). But for this patch, that one case is handled correctly, with the first change I explained. All other 32bit platforms are handled with the second.

Which means second, 64bit ARM platforms. With the exception of:
socfpga_agilex7m socfpga_n5x_atf socfpga_n5x_vab socfpga_stratix10_atf all ARM64 SPL_FRAMEWORK using platforms use the arch/arm/cpu/armv8/u-boot-spl.lds explicitly. These other ones set CONFIG_SPL_LDSCRIPT to a non-existant file and then fall back to using arch/arm/cpu/armv8/u-boot-spl.lds. There are only 4 platforms which don't use a separate BSS section and so could trip up the above as well:
r8a779g0_whitehawk r8a779g3_sparrowhawk sc598-som-ezkit-spl sc598-som-ezlite-spl I have inspected the Renesas platforms manually, and I'm a little unsure how this case works on the two sc598 platforms.

---
 arch/arm/cpu/armv8/u-boot-spl.lds | 15 ++++++++-------
 arch/arm/cpu/u-boot-spl.lds       | 12 ++++++------
 2 files changed, 14 insertions(+), 13 deletions(-)
arch/arm/cpu/armv8/u-boot-spl.lds +8 -7
index b732133ce76d..39020a1fddde 100644
@@ -49,12 +49,6 @@ SECTIONS
 	} >.sram
 #endif
 
-	__u_boot_list : {
-		. = ALIGN(8);
-		KEEP(*(SORT(__u_boot_list*)));
-		. = ALIGN(8);
-	} >.sram
-
 	.binman_sym_table : {
 		. = ALIGN(8);
 		__binman_sym_start = .;
@@ -63,6 +57,12 @@ SECTIONS
 		. = ALIGN(8);
 	} > .sram
 
+	__u_boot_list : {
+		. = ALIGN(8);
+		KEEP(*(SORT(__u_boot_list*)));
+		. = ALIGN(8);
+	} >.sram
+
 	__image_copy_end = .;
 	_end = .;
 	_image_binary_end = .;
@@ -75,7 +75,7 @@ SECTIONS
 		__bss_end = .;
 	} >.sdram
 #else
-	.bss (NOLOAD) : {
+	.bss _image_binary_end (OVERLAY) : {
 		__bss_start = .;
 		*(.bss*)
 		 . = ALIGN(8);
@@ -99,5 +99,6 @@ SECTIONS
 
 ASSERT(_image_binary_end % 8 == 0, \
        "_image_binary_end must be 8-byte aligned for device tree");
+
 ASSERT(ADDR(.bss) % 8 == 0, \
        ".bss must be 8-byte aligned");
arch/arm/cpu/u-boot-spl.lds +6 -6
index c578c3ebf821..97083319d39d 100644
@@ -31,16 +31,16 @@ SECTIONS
 		*(.data*)
 	}
 
-	. = ALIGN(4);
-	__u_boot_list : {
-		KEEP(*(SORT(__u_boot_list*)));
-	}
-
 	. = ALIGN(4);
 	.binman_sym_table : {
 		__binman_sym_start = .;
 		KEEP(*(SORT(.binman_sym*)));
 		__binman_sym_end = .;
+	}
+
+	. = ALIGN(4);
+	__u_boot_list : {
+		KEEP(*(SORT(__u_boot_list*)));
 		. = ALIGN(8);
 	}
 
@@ -48,7 +48,7 @@ SECTIONS
 	_image_binary_end = .;
 	_end = .;
 
-	.bss : {
+	.bss _image_binary_end (OVERLAY) : {
 		__bss_start = .;
 		*(.bss*)
 		 . = ALIGN(8);
Signature · 1 line
2.43.0
Tested-by on v2 1/1
#3 lore raw

Re: [PATCH v2] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

Quoted 26 lines · Tom Rini

Historically, when we have an appended device tree and also our resulting binary will contain the BSS section, we have ensured that everything will be where it's expected to be by declaring that the BSS is overlayed with a symbol matches the end of the port of the ELF binary that is objcopy'd to the binary we concatenate with. This in turn means that the logic to generate a "pad" file, which is the size found in the __bss_size symbol, will be correct and then we can concatenate the device tree and it will begin at __bss_size at run time.

With commit 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts") we removed this overlay as part of trying to ensure that we met both the requirements of the device tree to be 8 byte aligned as well as that our logic to generate the -pad file would match what ended up in the resulting binary. While it was correct to remove an unused section it did not solve ultimately solve the problem for all cases.

To really fix the problem, we need to do two things. First, our final section prior to _image_binary_end must be 8 byte aligned (for the case of having a separate BSS and so our appended DTB exists at this location). This cannot be '.binman_sym_table' as it may be empty, and in turn the ELF type would be NOBITS and so not copied with objcopy. The __u_boot_list section will never be empty, so it is our final section, and ends with a '. = ALIGN(8)' statement. Second, as this is the end of our copied data it is safe to declare that the BSS starts here, so use the OVERLAY keyword to place the BSS here.

Quoted 4 lines
Fixes 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts")

On Synology DS414:

Thanks, Tom!

Tested-by on v2 1/1
#4 lore raw

Re: [PATCH v2] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

In reply to Tom Rini
Quoted 109 lines · Tom Rini

Historically, when we have an appended device tree and also our resulting binary will contain the BSS section, we have ensured that everything will be where it's expected to be by declaring that the BSS is overlayed with a symbol matches the end of the port of the ELF binary that is objcopy'd to the binary we concatenate with. This in turn means that the logic to generate a "pad" file, which is the size found in the __bss_size symbol, will be correct and then we can concatenate the device tree and it will begin at __bss_size at run time.

With commit 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts") we removed this overlay as part of trying to ensure that we met both the requirements of the device tree to be 8 byte aligned as well as that our logic to generate the -pad file would match what ended up in the resulting binary. While it was correct to remove an unused section it did not solve ultimately solve the problem for all cases.

To really fix the problem, we need to do two things. First, our final section prior to _image_binary_end must be 8 byte aligned (for the case of having a separate BSS and so our appended DTB exists at this location). This cannot be '.binman_sym_table' as it may be empty, and in turn the ELF type would be NOBITS and so not copied with objcopy. The __u_boot_list section will never be empty, so it is our final section, and ends with a '. = ALIGN(8)' statement. Second, as this is the end of our copied data it is safe to declare that the BSS starts here, so use the OVERLAY keyword to place the BSS here.

Fixes 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts")

---
Cc: Richard Henderson <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Nobuhiro Iwamatsu <[email protected]>
Cc: Nathan Barrett-Morrison <[email protected]>
Cc: Greg Malysa <[email protected]>
Cc: Ian Roberts <[email protected]>
Cc: Vasileios Bimpikas <[email protected]>
Cc: Utsav Agarwal <[email protected]>
Cc: Arturs Artamonovs <[email protected]>
Cc: [email protected]

So, first, with the exception of:
axm brppt2 imx28_btt3 imx28_xea mk808 taurus work_92105
all platforms using arch/arm/cpu/u-boot-spl.lds do NOT enable CONFIG_SPL_SEPARATE_BSS. And of those, only brppt2 enables SPL_OF_REAL. As an aside, I'm thinking that there is room for a clean-up / merger of arch/arm/cpu/u-boot-spl.lds and arch/arm/mach-omap2/u-boot-spl.lds (*widely* used outside of mach-omap2). But for this patch, that one case is handled correctly, with the first change I explained. All other 32bit platforms are handled with the second.

Which means second, 64bit ARM platforms. With the exception of:
socfpga_agilex7m socfpga_n5x_atf socfpga_n5x_vab socfpga_stratix10_atf all ARM64 SPL_FRAMEWORK using platforms use the arch/arm/cpu/armv8/u-boot-spl.lds explicitly. These other ones set CONFIG_SPL_LDSCRIPT to a non-existant file and then fall back to using arch/arm/cpu/armv8/u-boot-spl.lds. There are only 4 platforms which don't use a separate BSS section and so could trip up the above as well:
r8a779g0_whitehawk r8a779g3_sparrowhawk sc598-som-ezkit-spl sc598-som-ezlite-spl I have inspected the Renesas platforms manually, and I'm a little unsure how this case works on the two sc598 platforms.

---
 arch/arm/cpu/armv8/u-boot-spl.lds | 15 ++++++++-------
 arch/arm/cpu/u-boot-spl.lds       | 12 ++++++------
 2 files changed, 14 insertions(+), 13 deletions(-)
arch/arm/cpu/armv8/u-boot-spl.lds +7 -7
index b732133ce76d..39020a1fddde 100644
@@ -49,12 +49,6 @@ SECTIONS
        } >.sram
 #endif
 
-       __u_boot_list : {
-               . = ALIGN(8);
-               KEEP(*(SORT(__u_boot_list*)));
-               . = ALIGN(8);
-       } >.sram
-
        .binman_sym_table : {
                . = ALIGN(8);
                __binman_sym_start = .;
@@ -63,6 +57,12 @@ SECTIONS
                . = ALIGN(8);
        } > .sram
 
+       __u_boot_list : {
+               . = ALIGN(8);
+               KEEP(*(SORT(__u_boot_list*)));
+               . = ALIGN(8);
+       } >.sram
+
        __image_copy_end = .;
        _end = .;
        _image_binary_end = .;
@@ -75,7 +75,7 @@ SECTIONS
                __bss_end = .;
        } >.sdram
 #else
-       .bss (NOLOAD) : {
+       .bss _image_binary_end (OVERLAY) : {
                __bss_start = .;
                *(.bss*)
                 . = ALIGN(8);

arch/arm/cpu/armv8/u-boot-spl.lds SECTIONS · line 104

Quoted 6 lines
arch/arm/cpu/armv8/u-boot-spl.lds +1 -0
@@ -99,5 +99,6 @@ SECTIONS
 
 ASSERT(_image_binary_end % 8 == 0, \
        "_image_binary_end must be 8-byte aligned for device tree");
+
 ASSERT(ADDR(.bss) % 8 == 0, \
        ".bss must be 8-byte aligned");

For ARM v7 on SoCFPGA GEN5 no issue under AC501:

Boot Message as follows:

U-Boot SPL 2026.04-rc1-00154-gb5213bbfdcb1-dirty (Feb 06 2026 - 09:11:02 +0800)

U-Boot 2026.04-rc1-00154-gb5213bbfdcb1-dirty (Feb 06 2026 - 09:11:02 +0800)

CPU:   Altera SoCFPGA Platform
FPGA:  Altera Cyclone V, SE/A2 or SX/C2, version 0x0
BOOT:  SD/MMC Internal Transceiver (3.0V)
DRAM:  1 GiB
Core:  29 devices, 15 uclasses, devicetree: separate
MMC:   dwmmc0@ff704000: 0

Loading Environment from MMC... Card did not respond to voltage select! : -110 *** Warning - No block device, using default environment

In:    serial
Out:   serial
Err:   serial
Model: CoreCourse AC501SoC

Net:
Warning: ethernet@ff702000 (eth0) using random MAC address - 36:e3:3d:93:85:a5
eth0: ethernet@ff702000
Hit any key to stop autoboot: 0

Quoted 38 lines
arch/arm/cpu/u-boot-spl.lds +6 -7
index c578c3ebf821..97083319d39d 100644
@@ -31,16 +31,16 @@ SECTIONS
                *(.data*)
        }
 
-       . = ALIGN(4);
-       __u_boot_list : {
-               KEEP(*(SORT(__u_boot_list*)));
-       }
-
        . = ALIGN(4);
        .binman_sym_table : {
                __binman_sym_start = .;
                KEEP(*(SORT(.binman_sym*)));
                __binman_sym_end = .;
+       }
+
+       . = ALIGN(4);
+       __u_boot_list : {
+               KEEP(*(SORT(__u_boot_list*)));
                . = ALIGN(8);
        }
 
@@ -48,7 +48,7 @@ SECTIONS
        _image_binary_end = .;
        _end = .;
 
-       .bss : {
+       .bss _image_binary_end (OVERLAY) : {
                __bss_start = .;
                *(.bss*)
                 . = ALIGN(8);
--

2.43.0

#5 lore raw

Re: [PATCH v2] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

In reply to Tom Rini
Quoted 4 lines · Tom Rini

Historically, when we have an appended device tree and also our resulting binary will contain the BSS section, we have ensured that everything will be where it's expected to be by declaring that the BSS is overlayed with a symbol matches the end of the port

part ?

Quoted 6 lines

of the ELF binary
that is objcopy'd to the binary we concatenate with. This in turn means that the logic to generate a "pad" file, which is the size found in the __bss_size symbol, will be correct and then we can concatenate the device tree and it will begin at __bss_size at run time.

Quoted 6 lines

With commit 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts") we removed this overlay as part of trying to ensure that we met both the requirements of the device tree to be 8 byte aligned as well as that our logic to generate the -pad file would match what ended up in the resulting binary. While it was correct to remove an unused section it did not solve ultimately solve the problem for all cases.

solve ultimately solve ... one solve is enough

Quoted 6 lines

To really fix the problem, we need to do two things. First, our final section prior to _image_binary_end must be 8 byte aligned (for the case of having a separate BSS and so our appended DTB exists at this location). This cannot be '.binman_sym_table' as it may be empty, and in turn the ELF type would be NOBITS and so not copied with objcopy. The __u_boot_list section will never be empty

How can we be sure of that ?

Quoted 4 lines

, so it is our final section,
and ends with a '. = ALIGN(8)' statement. Second, as this is the end of our copied data it is safe to declare that the BSS starts here, so use the OVERLAY keyword to place the BSS here.

[...]

arch/arm/cpu/armv8/u-boot-spl.lds SECTIONS · line 104

Quoted 7 lines
arch/arm/cpu/armv8/u-boot-spl.lds +1 -0
@@ -99,5 +99,6 @@ SECTIONS
 
  ASSERT(_image_binary_end % 8 == 0, \
         "_image_binary_end must be 8-byte aligned for device tree");
+
  ASSERT(ADDR(.bss) % 8 == 0, \
         ".bss must be 8-byte aligned");

Please drop this extra newline ^ .

author
#6 lore raw

Re: [PATCH v2] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

Quoted 14 lines · Marek Vasut
Quoted 4 lines · Tom Rini

Historically, when we have an appended device tree and also our resulting binary will contain the BSS section, we have ensured that everything will be where it's expected to be by declaring that the BSS is overlayed with a symbol matches the end of the port

part ?

Quoted 6 lines

of the ELF binary
that is objcopy'd to the binary we concatenate with. This in turn means that the logic to generate a "pad" file, which is the size found in the __bss_size symbol, will be correct and then we can concatenate the device tree and it will begin at __bss_size at run time.

Quoted 8 lines
Quoted 6 lines

With commit 5ffc1dcc26d3 ("arm: Remove rel.dyn from SPL linker scripts") we removed this overlay as part of trying to ensure that we met both the requirements of the device tree to be 8 byte aligned as well as that our logic to generate the -pad file would match what ended up in the resulting binary. While it was correct to remove an unused section it did not solve ultimately solve the problem for all cases.

solve ultimately solve ... one solve is enough

Yeah, oops.

Quoted 8 lines
Quoted 6 lines

To really fix the problem, we need to do two things. First, our final section prior to _image_binary_end must be 8 byte aligned (for the case of having a separate BSS and so our appended DTB exists at this location). This cannot be '.binman_sym_table' as it may be empty, and in turn the ELF type would be NOBITS and so not copied with objcopy. The __u_boot_list section will never be empty

How can we be sure of that ?

That __u_boot_list will never be empty? There's too much non-trivial code using it.

Quoted 7 lines
Quoted 4 lines

, so it is our final section,
and ends with a '. = ALIGN(8)' statement. Second, as this is the end of our copied data it is safe to declare that the BSS starts here, so use the OVERLAY keyword to place the BSS here.

[...]

Quoted 7 lines

arch/arm/cpu/armv8/u-boot-spl.lds SECTIONS · line 103

Quoted 6 lines
arch/arm/cpu/armv8/u-boot-spl.lds +1 -0
@@ -99,5 +99,6 @@ SECTIONS
  ASSERT(_image_binary_end % 8 == 0, \
         "_image_binary_end must be 8-byte aligned for device tree");
+
  ASSERT(ADDR(.bss) % 8 == 0, \
         ".bss must be 8-byte aligned");

Please drop this extra newline ^ .

I'll fix that (and the port->part and solve) when applying, assuming no feedback from the toolchain gurus.

Signature · 1 line
Tom
Tested-by on v2 1/1
#7 lore raw

Re: [PATCH v2] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

In reply to Tom Rini

Hi Tom,

Quoted 11 lines · Tom Rini

Which means second, 64bit ARM platforms. With the exception of:
socfpga_agilex7m socfpga_n5x_atf socfpga_n5x_vab socfpga_stratix10_atf all ARM64 SPL_FRAMEWORK using platforms use the arch/arm/cpu/armv8/u-boot-spl.lds explicitly. These other ones set CONFIG_SPL_LDSCRIPT to a non-existant file and then fall back to using arch/arm/cpu/armv8/u-boot-spl.lds. There are only 4 platforms which don't use a separate BSS section and so could trip up the above as well:
r8a779g0_whitehawk r8a779g3_sparrowhawk sc598-som-ezkit-spl sc598-som-ezlite-spl I have inspected the Renesas platforms manually, and I'm a little unsure how this case works on the two sc598 platforms.

Do you recommend using SPL_SEPARATE_BSS on our platform? After power on, the sc598 has 2 MB of SRAM available starting at 0x20000000 which we treat as just a single block of memory to use for all of SPL operation, so we don't have any requirement to do something like a bare bones DDR initialization before using it as our main memory for SPL, so it didn't seem necessary to enable. The boot ROM has some guidelines on where it will place its stack, so we restrict SPL to the first 192 KB currently but this can easily be expanded. I'm not sure if I should admit to it, but some decisions on Kconfigs were made 4 years ago as an arbitrary choice during our initial bringup and then were not reviewed because things were working.

Either way, works for me on the sc598 + ezkit. There's no reason for it to fail on the ezlite in that case either.

Thanks,
Greg

author
#8 lore raw

Re: [PATCH v2] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

Quoted 27 lines · Greg Malysa

Hi Tom,

Quoted 11 lines · Tom Rini

Which means second, 64bit ARM platforms. With the exception of:
socfpga_agilex7m socfpga_n5x_atf socfpga_n5x_vab socfpga_stratix10_atf all ARM64 SPL_FRAMEWORK using platforms use the arch/arm/cpu/armv8/u-boot-spl.lds explicitly. These other ones set CONFIG_SPL_LDSCRIPT to a non-existant file and then fall back to using arch/arm/cpu/armv8/u-boot-spl.lds. There are only 4 platforms which don't use a separate BSS section and so could trip up the above as well:
r8a779g0_whitehawk r8a779g3_sparrowhawk sc598-som-ezkit-spl sc598-som-ezlite-spl I have inspected the Renesas platforms manually, and I'm a little unsure how this case works on the two sc598 platforms.

Do you recommend using SPL_SEPARATE_BSS on our platform? After power on, the sc598 has 2 MB of SRAM available starting at 0x20000000 which we treat as just a single block of memory to use for all of SPL operation, so we don't have any requirement to do something like a bare bones DDR initialization before using it as our main memory for SPL, so it didn't seem necessary to enable. The boot ROM has some guidelines on where it will place its stack, so we restrict SPL to the first 192 KB currently but this can easily be expanded. I'm not sure if I should admit to it, but some decisions on Kconfigs were made 4 years ago as an arbitrary choice during our initial bringup and then were not reviewed because things were working.

Quoted 2 lines

Either way, works for me on the sc598 + ezkit. There's no reason for it to fail on the ezlite in that case either.

So SPL_SEPARATE_BSS is for when the BSS can be easily put in SDRAM instead. It's not better or worse than SRAM, it just depends on the system constraints. I only called these two platforms out because I don't actually see where the dtb comes from and so couldn't check the alignment and location matched.

Signature · 1 line
Tom
author
#9 lore raw

Re: [PATCH v2] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

In reply to Tom Rini
Quoted 10 lines · Tom Rini

Historically, when we have an appended device tree and also our resulting binary will contain the BSS section, we have ensured that everything will be where it's expected to be by declaring that the BSS is overlayed with a symbol matches the end of the port of the ELF binary that is objcopy'd to the binary we concatenate with. This in turn means that the logic to generate a "pad" file, which is the size found in the __bss_size symbol, will be correct and then we can concatenate the device tree and it will begin at __bss_size at run time.

[...]

Applied to u-boot/master, thanks!

[1/1] arm: spl: Ensure 8 byte alignment of appended DTB without separate BSS

      commit: 89965b5eb597d50d052ee79b531f17495cff6f29
Signature · 1 line
Tom