rockchip: px30: Fix TPL_STACK overflow into BootROM reserved region
Subsystems (3)
PATCH v3 1/1 rockchip: px30: Fix TPL_STACK overflow into BootROM reserved region
The PX30/RK3326 has 16 KiB SRAM at [0xff0e0000, 0xff0e4000), with the initial 4 KiB at [0xff0e0000, 0xff0e1000) reserved for BootROM at boot.
SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a TPL_STACK at 0xff0e4ff0 (16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.
TPL on PX30/RK3326 does not have any use for the malloc area, the generated GD_SIZE is typically around 304 bytes and BSS around 72 bytes.
Current memory layout possibly looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM
[0xff0e0000, 0xff0e1000) 4 KiB BROM area
[..., 0xff0e08c0) stack area
[0xff0e08c0] stack pointer
[0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed)
[0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched)
[0xff0e1000, 0xff0e4000) 12 KiB TPL area
[0xff0e1000, 0xff0e3800) 10 KiB code
[0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved TPL_SYS_MALLOC_F_LEN bytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to TPL_STACK, TPL_SYS_MALLOC_F_LEN or code could theoretically change this and cause issues for BootROM.
Update TPL_STACK to use the top of SRAM address and reduce MALLOC_F_LEN to 0x200 to avoid overflowing global data, malloc area and stack into the BootROM reserved region.
With these changes the memory layout looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM
[0xff0e0000, 0xff0e1000) 4 KiB BROM area
[0xff0e1000, 0xff0e4000) 12 KiB TPL area
[0xff0e1000, 0xff0e3800) 10 KiB code
[0xff0e3800, 0xff0e3848) 72 bytes BSS
[0xff0e3848, 0xff0e3cd0) 1160 bytes stack area
[0xff0e3cd0] stack pointer
[0xff0e3cd0, 0xff0e3e00) 304 bytes global data
[0xff0e3e00, 0xff0e4000) 512 bytes malloc area (unused)---
The overflow/wrapping was runtime validated on a RK3326 ODROID-GO Super by printing out content of [0xff0e0000, 0xff0e5000] and comparing the initial 4 KiB with the 16-20 KiB and the data matched 1:1.
Changes in v3:
- Drop TPL_MAX_SIZE change
- Keep a small 512 byte malloc area
- Update commit message to reflect changes
Changes in v2:
- Mention BSS in commit message
- Update spelling in commit message
- Collect r-b tag
--- arch/arm/mach-rockchip/px30/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-rockchip/px30/Kconfig +2 -2
@@ -81,10 +81,10 @@ config TPL_TEXT_BASE default 0xff0e1000 config TPL_STACK - default 0xff0e4fff + default 0xff0e4000 config TPL_SYS_MALLOC_F_LEN - default 0x600 + default 0x200 config DEBUG_UART_CHANNEL int "Mux channel to use for debug UART2/UART3"
Signature · 1 line
2.55.0
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 25 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[
0xff0e0000,0xff0e4000) 16 KiB SRAM[0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSS
Quoted 8 lines
TPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.
Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct? As code size itself is checked against TPL_MAX_SIZE at build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal against TPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?
With the new layout the check should be:
code size + BSS + GD_SIZE + TPL_SYS_MALLOC_F_LEN + <min_stack> <= 12 KiB
[1] https://github.com/u-boot/u-boot/blob/main/arch/arm/mach-rockchip/u-boot-tpl-v8.lds
Quoted 4 lines
Update
TPL_STACKto use the top of SRAM address and reduceMALLOC_F_LENto0x200to avoid overflowing global data, malloc area and stack into the BootROM reserved region.
The new layout is certainly safer, but I wonder if we are losing the opportunity for TPL to have approximately 2 extra KiB as they are not used by BootROM once TPL returns to it. I mean, it would be useful to know where initial values of TPL_STACK and TPL_SYS_MALLOC_F_LEN came from, and the rationales behind them. If Rockchip were to assure that preserving only the first 2 KiB of SRAM is enough for SPL loading, keeping these 2 extra KiB on the radar could be useful for future TPL development and/or maintenance.
Regards,
Massimo
Quoted 53 lines
With these changes the memory layout looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSS [0xff0e3848, 0xff0e3cd0) 1160 bytes stack area [0xff0e3cd0] stack pointer [0xff0e3cd0, 0xff0e3e00) 304 bytes global data [0xff0e3e00, 0xff0e4000) 512 bytes malloc area (unused)Signed-off-by Jonas Karlman <[email protected]>Reviewed-by Simon Glass <[email protected]>---
The overflow/wrapping was runtime validated on a RK3326 ODROID-GO Super by printing out content of [0xff0e0000,0xff0e5000] and comparing the initial 4 KiB with the 16-20 KiB and the data matched 1:1.Changes in v3:
- DropTPL_MAX_SIZEchange
- Keep a small 512 byte malloc area
- Update commit message to reflect changesChanges in v2:
- Mention BSS in commit message
- Update spelling in commit message
- Collect r-b tag--- arch/arm/mach-rockchip/px30/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm/mach-rockchip/px30/Kconfig +2
-3@@ -81,10 +81,10 @@ config TPL_TEXT_BASE default 0xff0e1000 config TPL_STACK - default 0xff0e4fff + default 0xff0e4000 config TPL_SYS_MALLOC_F_LEN - default 0x600 + default 0x200 config DEBUG_UART_CHANNEL int "Mux channel to use for debug UART2/UART3" --2.55.0
Hi Massimo,
Quoted 33 lines · Massimo Pegorer
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 29 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[
0xff0e0000,0xff0e4000) 16 KiB SRAM[0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.
Quoted 7 lines
Quoted 4 lines
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct?
Not only, the change to TPL_STACK, TPL_SYS_MALLOC_F_LEN or 'struct global_data' would affect where the TPL stack ends up. However, and any change to the code may change how the stack is used and thus possible write to more/less/other data inside the BootROM area.
Quoted 7 lines
As code size itself is checked against
TPL_MAX_SIZEat build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal againstTPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?
Correct, this was also briefly discussed/mentioned in the v2 thread. However, this patch only tries to address the issue with TPL stack being placed inside BootROM reserved area.
Quoted 11 lines
With the new layout the check should be:
code size + BSS +GD_SIZE+TPL_SYS_MALLOC_F_LEN+ <min_stack> <= 12 KiB[1] https://github.com/u-boot/u-boot/blob/main/arch/arm/mach-rockchip/u-boot-tpl-v8.lds
Quoted 4 lines
Update
TPL_STACKto use the top of SRAM address and reduceMALLOC_F_LENto0x200to avoid overflowing global data, malloc area and stack into the BootROM reserved region.
Quoted 7 lines
The new layout is certainly safer, but I wonder if we are losing the opportunity for TPL to have approximately 2 extra KiB as they are not used by BootROM once TPL returns to it. I mean, it would be useful to know where initial values of
TPL_STACKandTPL_SYS_MALLOC_F_LENcame from, and the rationales behind them. If Rockchip were to assure that preserving only the first 2 KiB of SRAM is enough for SPL loading, keeping these 2 extra KiB on the radar could be useful for future TPL development and/or maintenance.
Please look at v1/v2, they safely allowed for up to 11 KiB TPL. However, that change should be handled in a separate patch/series.
Some of vendor ddr blobs continue to use the BootROM stack, and others setup a dedicated stack at end of SRAM. Mainline U-Boot use a dedicated stack, and it is placed at end of SRAM for all other Rockchip SoCs.
This patch tries to align PX30/RK3326 to use TPL stack at end of SRAM, ahead of a future pending TPL consolidation/refactor series, see [2] or deep in my work-in-progress branch at [3].
[2] https://git.u-boot-project.org/u-boot/contributors/kwiboo/u-boot/-/commits/tpl
[3] https://git.u-boot-project.org/u-boot/contributors/kwiboo/u-boot/-/commits/rk3562
Regards,
Jonas
Quoted 57 lines
Regards,
MassimoQuoted 53 lines
With these changes the memory layout looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSS [0xff0e3848, 0xff0e3cd0) 1160 bytes stack area [0xff0e3cd0] stack pointer [0xff0e3cd0, 0xff0e3e00) 304 bytes global data [0xff0e3e00, 0xff0e4000) 512 bytes malloc area (unused)Signed-off-by Jonas Karlman <[email protected]>Reviewed-by Simon Glass <[email protected]>---
The overflow/wrapping was runtime validated on a RK3326 ODROID-GO Super by printing out content of [0xff0e0000,0xff0e5000] and comparing the initial 4 KiB with the 16-20 KiB and the data matched 1:1.Changes in v3:
- DropTPL_MAX_SIZEchange
- Keep a small 512 byte malloc area
- Update commit message to reflect changesChanges in v2:
- Mention BSS in commit message
- Update spelling in commit message
- Collect r-b tag--- arch/arm/mach-rockchip/px30/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm/mach-rockchip/px30/Kconfig +2
-3@@ -81,10 +81,10 @@ config TPL_TEXT_BASE default 0xff0e1000 config TPL_STACK - default 0xff0e4fff + default 0xff0e4000 config TPL_SYS_MALLOC_F_LEN - default 0x600 + default 0x200 config DEBUG_UART_CHANNEL int "Mux channel to use for debug UART2/UART3" --2.55.0
Massimo Pegorer
Tested-byHi Jonas,
Il giorno mar 22 set 2026 alle ore 15:28 Jonas Karlman ha scritto:
Quoted 58 lines
Hi Massimo,
Quoted 33 lines · Massimo Pegorer
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 29 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[
0xff0e0000,0xff0e4000) 16 KiB SRAM[0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Quoted 7 lines
Quoted 4 lines
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct?
Not only, the change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor 'structglobal_data' would affect where the TPL stack ends up. However, and any change to the code may change how the stack is used and thus possible write to more/less/other data inside the BootROM area.Quoted 7 lines
As code size itself is checked against
TPL_MAX_SIZEat build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal againstTPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?
Quoted 3 lines
Correct, this was also briefly discussed/mentioned in the v2 thread. However, this patch only tries to address the issue with TPL stack being placed inside BootROM reserved area.
Indeed. I was just wondering if in a future patch we should avoid TPL_MAX_SIZE configuration, and instead have just TPL_MAX_FOOTPRINT configured to 0x3000 adding GD_SIZE and TPL_SYS_MALLOC_F_LEN in the linker check.
Quoted 20 lines
Quoted 12 lines
With the new layout the check should be:
code size + BSS +GD_SIZE+TPL_SYS_MALLOC_F_LEN+ <min_stack> <= 12 KiB[1] https://github.com/u-boot/u-boot/blob/main/arch/arm/mach-rockchip/u-boot-tpl-v8.lds
Quoted 4 lines
Update
TPL_STACKto use the top of SRAM address and reduceMALLOC_F_LENto0x200to avoid overflowing global data, malloc area and stack into the BootROM reserved region.Quoted 7 lines
The new layout is certainly safer, but I wonder if we are losing the opportunity for TPL to have approximately 2 extra KiB as they are not used by BootROM once TPL returns to it. I mean, it would be useful to know where initial values of
TPL_STACKandTPL_SYS_MALLOC_F_LENcame from, and the rationales behind them. If Rockchip were to assure that preserving only the first 2 KiB of SRAM is enough for SPL loading, keeping these 2 extra KiB on the radar could be useful for future TPL development and/or maintenance.
Quoted 2 lines
Please look at v1/v2, they safely allowed for up to 11 KiB TPL. However, that change should be handled in a separate patch/series.
I had looked at them, and I agree on a separate patch/series. But here I mean the 2 KiB that (maybe?) can be used in the 4 KiB BROM SRAM area, in addition to memory in the 12 KiB TPL SRAM area.
Quoted 4 lines
Some of vendor ddr blobs continue to use the BootROM stack, and others setup a dedicated stack at end of SRAM. Mainline U-Boot use a dedicated stack, and it is placed at end of SRAM for all other Rockchip SoCs.
I totally agree on following a common approach over more SoCs when possible.
Not a relevant contribution, anyway that is my:
Regards,
Massimo
Quoted 69 lines
This patch tries to align PX30/RK3326 to use TPL stack at end of SRAM, ahead of a future pending TPL consolidation/refactor series, see [2] or deep in my work-in-progress branch at [3].
[2] https://git.u-boot-project.org/u-boot/contributors/kwiboo/u-boot/-/commits/tpl
[3] https://git.u-boot-project.org/u-boot/contributors/kwiboo/u-boot/-/commits/rk3562Regards,
JonasQuoted 57 lines
Regards,
MassimoQuoted 53 lines
With these changes the memory layout looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSS [0xff0e3848, 0xff0e3cd0) 1160 bytes stack area [0xff0e3cd0] stack pointer [0xff0e3cd0, 0xff0e3e00) 304 bytes global data [0xff0e3e00, 0xff0e4000) 512 bytes malloc area (unused)Signed-off-by Jonas Karlman <[email protected]>Reviewed-by Simon Glass <[email protected]>---
The overflow/wrapping was runtime validated on a RK3326 ODROID-GO Super by printing out content of [0xff0e0000,0xff0e5000] and comparing the initial 4 KiB with the 16-20 KiB and the data matched 1:1.Changes in v3:
- DropTPL_MAX_SIZEchange
- Keep a small 512 byte malloc area
- Update commit message to reflect changesChanges in v2:
- Mention BSS in commit message
- Update spelling in commit message
- Collect r-b tag--- arch/arm/mach-rockchip/px30/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm/mach-rockchip/px30/Kconfig +2
-3@@ -81,10 +81,10 @@ config TPL_TEXT_BASE default 0xff0e1000 config TPL_STACK - default 0xff0e4fff + default 0xff0e4000 config TPL_SYS_MALLOC_F_LEN - default 0x600 + default 0x200 config DEBUG_UART_CHANNEL int "Mux channel to use for debug UART2/UART3" --2.55.0
Hi Massimo,
Quoted 61 lines · Massimo Pegorer
Hi Jonas,
Il giorno mar 22 set 2026 alle ore 15:28 Jonas Karlman ha scritto:
Quoted 58 lines
Hi Massimo,
Quoted 33 lines · Massimo Pegorer
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 29 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Quoted 7 lines
Quoted 4 lines
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct?
Not only, the change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor 'structglobal_data' would affect where the TPL stack ends up. However, and any change to the code may change how the stack is used and thus possible write to more/less/other data inside the BootROM area.Quoted 7 lines
As code size itself is checked against
TPL_MAX_SIZEat build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal againstTPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?
Quoted 8 lines
Quoted 3 lines
Correct, this was also briefly discussed/mentioned in the v2 thread. However, this patch only tries to address the issue with TPL stack being placed inside BootROM reserved area.
Indeed. I was just wondering if in a future patch we should avoid
TPL_MAX_SIZEconfiguration, and instead have justTPL_MAX_FOOTPRINTconfigured to0x3000addingGD_SIZEandTPL_SYS_MALLOC_F_LENin the linker check.
I had never heard of that symbol before and went checking. It has never been used (there isn't even a Kconfig symbol for it!) so we would need a bit of work to make this work (probably not a crazy amount though :) ).
I'm not sure we still need arch/arm/mach-rockchip/u-boot-tpl-v8.lds though. It's only used for evb-px5_defconfig, all PX30, all RK3328, all RK3399 and RV1126.
I think it was necessary when added back in 2019 because arch/arm/cpu/armv8/u-boot-spl.lds didn't allow yet to remove the SDRAM part in it (c.f. 3cbec0ad090f ("rockchip: add u-boot-tpl-v8.lds") which claims "we don't have both SRAM and SDRAM in TPL" but we have SRAM access in TPL, don't we?), but that has changed since 2024. They are a bit different though and I have no experience with linker scripts so no clue if it makes sense to merge them (if at all possible). I'm guessing the additional asserts would make sense for everybody anyway.
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
With the new layout the check should be:
code size + BSS +GD_SIZE+TPL_SYS_MALLOC_F_LEN+ <min_stack> <= 12 KiB[1] https://github.com/u-boot/u-boot/blob/main/arch/arm/mach-rockchip/u-boot-tpl-v8.lds
Quoted 4 lines
Update
TPL_STACKto use the top of SRAM address and reduceMALLOC_F_LENto0x200to avoid overflowing global data, malloc area and stack into the BootROM reserved region.The new layout is certainly safer, but I wonder if we are losing the opportunity for TPL to have approximately 2 extra KiB as they are not used by BootROM once TPL returns to it. I mean, it would be useful to know where initial values of
TPL_STACKandTPL_SYS_MALLOC_F_LENcame from, and the rationales behind them. If Rockchip were to assure that preserving only the first 2 KiB of SRAM is enough for SPL loading, keeping these 2 extra KiB on the radar could be useful for future TPL development and/or maintenance.
Quoted 7 lines
Quoted 2 lines
Please look at v1/v2, they safely allowed for up to 11 KiB TPL. However, that change should be handled in a separate patch/series.
I had looked at them, and I agree on a separate patch/series. But here I mean the 2 KiB that (maybe?) can be used in the 4 KiB BROM SRAM area, in addition to memory in the 12 KiB TPL SRAM area.
I.. would rather not. While I don't expect Rockchip to change the BootROM without changing the SoC official name, it's not impossible. I would err on the side of what Rockchip is doing in their fork and trust that they get this early init stuff right, hopefully *they* know what's happening in the BootROM for their own SoCs :)
Quoted 8 lines
Quoted 4 lines
Some of vendor ddr blobs continue to use the BootROM stack, and others setup a dedicated stack at end of SRAM. Mainline U-Boot use a dedicated stack, and it is placed at end of SRAM for all other Rockchip SoCs.
I totally agree on following a common approach over more SoCs when possible.
Not a relevant contribution, anyway that is my:
Review is relevant contribution, so thanks for doing it!
Cheers,
Quentin
A message that is not in the archive (sent off-list or not yet received): CAC928HYf7zobjKPt+qQA3=fQSzuvfKqM7LvD-kG5tPBM=+Y1Gw@mail.gmail.com
Hi Massimo,
Quoted 92 lines · Massimo Pegorer
Hi Quentin,
Quoted 77 lines · Quentin Schulz
Hi Massimo,
Quoted 61 lines · Massimo Pegorer
Hi Jonas,
Il giorno mar 22 set 2026 alle ore 15:28 Jonas Karlman ha scritto:
Quoted 58 lines
Hi Massimo,
Quoted 33 lines · Massimo Pegorer
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 29 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Quoted 7 lines
Quoted 4 lines
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct?
Not only, the change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor 'structglobal_data' would affect where the TPL stack ends up. However, and any change to the code may change how the stack is used and thus possible write to more/less/other data inside the BootROM area.Quoted 7 lines
As code size itself is checked against
TPL_MAX_SIZEat build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal againstTPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?Quoted 8 lines
Quoted 3 lines
Correct, this was also briefly discussed/mentioned in the v2 thread. However, this patch only tries to address the issue with TPL stack being placed inside BootROM reserved area.
Indeed. I was just wondering if in a future patch we should avoid
TPL_MAX_SIZEconfiguration, and instead have justTPL_MAX_FOOTPRINTconfigured to0x3000addingGD_SIZEandTPL_SYS_MALLOC_F_LENin the linker check.I had never heard of that symbol before and went checking. It has never been used (there isn't even a
Kconfigsymbol for it!) so we would need a bit of work to make this work (probably not a crazy amount though :) ).Quoted 11 lines
I'm not sure we still need
arch/arm/mach-rockchip/u-boot-tpl-v8.ldsthough. It's only used for evb-px5_defconfig, all PX30, all RK3328, all RK3399 and RV1126.
I think it was necessary when added back in 2019 becausearch/arm/cpu/armv8/u-boot-spl.ldsdidn't allow yet to remove the SDRAM part in it (c.f.3cbec0ad090f("rockchip: addu-boot-tpl-v8.lds") which claims "we don't have both SRAM and SDRAM in TPL" but we have SRAM access in TPL, don't we?), but that has changed since 2024. They are a bit different though and I have no experience with linker scripts so no clue if it makes sense to merge them (if at all possible). I'm guessing the additional asserts would make sense for everybody anyway.
Quoted 5 lines
Me too, almost no experience with linker scripts. Anyway, I had a quick look at
arch/arm/cpu/armv8/u-boot-spl.ldsfor TPL building purpose, and IMO it's broken by design because of SPL specific configuration options dependencies:SPL_SEPARATE_BSSandSPL_RECOVER_DATA_SECTION. I will check more in depth.
We can always migrate those to CONFIG_IS_ENABLED(SEPARATE_BSS), CONFIG_IS_ENABLED(RECOVER_DATA_SECTION), CONFIG_VAL(BSS_START_ADDR), CONFIG_VAL(BSS_MAX_SIZE), etc., if needed.
Quoted 5 lines
BTW, the .sram MEMORY segment definition in the script would do the game: here the size that linker would check against
TPL_MAX_SIZEincludes BSS (consider the caseSPL_SEPARATE_BSSnot defined, of course), whileu-boot-tpl-v8.ldschecks size without BSS againstTPL_MAX_SIZE.
We would have the same behavior of size checking if we had TPL_SEPARATE_BSS enabled I believe. But if we had TPL_SEPARATE_BSS enabled, then we would have an .sdram section too, which is the reason for having a separate linker script in the first place.
I'm also not sure about IMAGE_TEXT_BASE (set by CONFIG_TEXT_BASE) only used in the armv8 linker script and the first
. = 0x00000000;
in Rockchip's TPL linker script.
But maybe we should really have BSS part of the size check.
I'm out of my depth here though, no clue what would be proper.
Cheers,
Quentin
Hi Quentin and Massimo,
Quoted 101 lines · Quentin Schulz
Hi Massimo,
Quoted 92 lines · Massimo Pegorer
Hi Quentin,
Quoted 77 lines · Quentin Schulz
Hi Massimo,
Quoted 61 lines · Massimo Pegorer
Hi Jonas,
Il giorno mar 22 set 2026 alle ore 15:28 Jonas Karlman ha scritto:
Quoted 58 lines
Hi Massimo,
Quoted 33 lines · Massimo Pegorer
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 29 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Quoted 7 lines
Quoted 4 lines
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct?
Not only, the change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor 'structglobal_data' would affect where the TPL stack ends up. However, and any change to the code may change how the stack is used and thus possible write to more/less/other data inside the BootROM area.Quoted 7 lines
As code size itself is checked against
TPL_MAX_SIZEat build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal againstTPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?Quoted 8 lines
Quoted 3 lines
Correct, this was also briefly discussed/mentioned in the v2 thread. However, this patch only tries to address the issue with TPL stack being placed inside BootROM reserved area.
Indeed. I was just wondering if in a future patch we should avoid
TPL_MAX_SIZEconfiguration, and instead have justTPL_MAX_FOOTPRINTconfigured to0x3000addingGD_SIZEandTPL_SYS_MALLOC_F_LENin the linker check.I had never heard of that symbol before and went checking. It has never been used (there isn't even a
Kconfigsymbol for it!) so we would need a bit of work to make this work (probably not a crazy amount though :) ).Quoted 11 lines
I'm not sure we still need
arch/arm/mach-rockchip/u-boot-tpl-v8.ldsthough. It's only used for evb-px5_defconfig, all PX30, all RK3328, all RK3399 and RV1126.
I think it was necessary when added back in 2019 becausearch/arm/cpu/armv8/u-boot-spl.ldsdidn't allow yet to remove the SDRAM part in it (c.f.3cbec0ad090f("rockchip: addu-boot-tpl-v8.lds") which claims "we don't have both SRAM and SDRAM in TPL" but we have SRAM access in TPL, don't we?), but that has changed since 2024. They are a bit different though and I have no experience with linker scripts so no clue if it makes sense to merge them (if at all possible). I'm guessing the additional asserts would make sense for everybody anyway.Quoted 5 lines
Me too, almost no experience with linker scripts. Anyway, I had a quick look at
arch/arm/cpu/armv8/u-boot-spl.ldsfor TPL building purpose, and IMO it's broken by design because of SPL specific configuration options dependencies:SPL_SEPARATE_BSSandSPL_RECOVER_DATA_SECTION. I will check more in depth.
Quoted 3 lines
We can always migrate those to
CONFIG_IS_ENABLED(SEPARATE_BSS),CONFIG_IS_ENABLED(RECOVER_DATA_SECTION),CONFIG_VAL(BSS_START_ADDR),CONFIG_VAL(BSS_MAX_SIZE), etc., if needed.
I did a quick test with my TPL stubs on RK3568 and RK3528 and we can likely use arch/arm/cpu/armv8/u-boot-spl.lds after your suggested changes.
However, we must also ensure to disable TPL_SEPARATE_BSS and not let it use the default TPL_SEPARATE_BSS=SPL_SEPARATE_BSS, and also ensure that TPL_MAX_SIZE is defined, as it will define the LENGTH of the MEMORY, i.e. work as a built in size check that image+bss fit inside .sram.
And then we possible could to add a new size check, or possible manually just ensure that TPL_MAX_SIZE is reduced by GD_SIZE, TPL_SYS_MALLOC_F_LEN and a guestimated usage need for the runtime stack.
Quoted 11 lines
Quoted 6 lines
BTW, the .sram MEMORY segment definition in the script would do the game: here the size that linker would check against
TPL_MAX_SIZEincludes BSS (consider the caseSPL_SEPARATE_BSSnot defined, of course), whileu-boot-tpl-v8.ldschecks size without BSS againstTPL_MAX_SIZE.We would have the same behavior of size checking if we had
TPL_SEPARATE_BSSenabled I believe. But if we hadTPL_SEPARATE_BSSenabled, then we would have an .sdram section too, which is the reason for having a separate linker script in the first place.
Correct, we should use TPL_SEPARATE_BSS=n if we want to replace the custom rockchip tpl armv8 linker script and keep current behavior.
Quoted 7 lines
I'm also not sure about
IMAGE_TEXT_BASE(set byCONFIG_TEXT_BASE) only used in the armv8 linker script and the first. =
0x00000000;in Rockchip's TPL linker script.
It does not seem like this line is needed in the linker script.
Quoted 2 lines
But maybe we should really have BSS part of the size check.
As mentioned above, with a TPL_MAX_SIZE the .sram LENGTH is assigned and we get a built in size check, e.g. using TPL_MAX_SIZE=0x100 stop build:
LD tpl/u-boot-tpl
/usr/bin/aarch64-linux-gnu-ld.bfd: address 0xfe481570 of u-boot-tpl section .text' is not within region .sram' /usr/bin/aarch64-linux-gnu-ld.bfd: u-boot-tpl section .rodata' will not fit in region .sram' /usr/bin/aarch64-linux-gnu-ld.bfd: address 0xfe481570 of u-boot-tpl section .text' is not within region .sram' /usr/bin/aarch64-linux-gnu-ld.bfd: address 0xfe481570 of u-boot-tpl section .text' is not within region .sram' /usr/bin/aarch64-linux-gnu-ld.bfd: region `.sram' overflowed by 1464 bytes
make[2]: *** [scripts/Makefile.xpl:546: tpl/u-boot-tpl] Error 1
Quoted 2 lines
I'm out of my depth here though, no clue what would be proper.
For my forth coming TPL refactor series I tried to sync a few changes into the Rockchip custom linker script, probably better to try and drop it instead.
On a side note, the TPL stub runtime tests on RK3568 and RK3528 revealed that in special cases we possible could use the BootROM stack, but I still think that can be risky and that it is safer that we keep U-Boot TPL stack and malloc area separate from the BootROM stack.
Test run of TPL stub on RK3528:
U-Boot TPL 2026.10-rc5 (Sep 28 2026 - 20:23:41)
x0: fe480458
x1: 00000008
x2: fe481000
sp: fe480ef0
DRAM init failed
Test run of TPL stub on RK3568:
U-Boot TPL 2026.10-rc5 (Sep 28 2026 - 20:22:26)
x0: fdcc0098
x1: 00000008
x2: fdcc1000
sp: fdcc0f30
DRAM init failed
Above is the values x0, x1, x2 and sp register had when BootROM called the TPL code.
The stack pointer seem to be near the end of the BootROM reserved area. Not sure what x0 or x1 values could be, but x2 seem to match TPL_TEXT_BASE, so possible the address BootROM called/jumped to.
Also x3-x7 did not seem to have any useful values or they changed each board reset.
What I take away from all above is that I will shortly update my rk3562 work-in-progress branch to also define TPL_MAX_SIZE to be the result of TPL_STACK-TPL_TEXT_BASE for all added TPL stubs.
Regards,
Jonas
Quoted 3 lines
Cheers,
Quentin
Hi again,
Quoted 190 lines · Jonas Karlman
Hi Quentin and Massimo,
Quoted 101 lines · Quentin Schulz
Hi Massimo,
Quoted 92 lines · Massimo Pegorer
Hi Quentin,
Quoted 77 lines · Quentin Schulz
Hi Massimo,
Quoted 61 lines · Massimo Pegorer
Hi Jonas,
Il giorno mar 22 set 2026 alle ore 15:28 Jonas Karlman ha scritto:
Quoted 58 lines
Hi Massimo,
Quoted 33 lines · Massimo Pegorer
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 29 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Quoted 7 lines
Quoted 4 lines
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct?
Not only, the change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor 'structglobal_data' would affect where the TPL stack ends up. However, and any change to the code may change how the stack is used and thus possible write to more/less/other data inside the BootROM area.Quoted 7 lines
As code size itself is checked against
TPL_MAX_SIZEat build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal againstTPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?Quoted 8 lines
Quoted 3 lines
Correct, this was also briefly discussed/mentioned in the v2 thread. However, this patch only tries to address the issue with TPL stack being placed inside BootROM reserved area.
Indeed. I was just wondering if in a future patch we should avoid
TPL_MAX_SIZEconfiguration, and instead have justTPL_MAX_FOOTPRINTconfigured to0x3000addingGD_SIZEandTPL_SYS_MALLOC_F_LENin the linker check.I had never heard of that symbol before and went checking. It has never been used (there isn't even a
Kconfigsymbol for it!) so we would need a bit of work to make this work (probably not a crazy amount though :) ).Quoted 11 lines
I'm not sure we still need
arch/arm/mach-rockchip/u-boot-tpl-v8.ldsthough. It's only used for evb-px5_defconfig, all PX30, all RK3328, all RK3399 and RV1126.
I think it was necessary when added back in 2019 becausearch/arm/cpu/armv8/u-boot-spl.ldsdidn't allow yet to remove the SDRAM part in it (c.f.3cbec0ad090f("rockchip: addu-boot-tpl-v8.lds") which claims "we don't have both SRAM and SDRAM in TPL" but we have SRAM access in TPL, don't we?), but that has changed since 2024. They are a bit different though and I have no experience with linker scripts so no clue if it makes sense to merge them (if at all possible). I'm guessing the additional asserts would make sense for everybody anyway.Quoted 5 lines
Me too, almost no experience with linker scripts. Anyway, I had a quick look at
arch/arm/cpu/armv8/u-boot-spl.ldsfor TPL building purpose, and IMO it's broken by design because of SPL specific configuration options dependencies:SPL_SEPARATE_BSSandSPL_RECOVER_DATA_SECTION. I will check more in depth.Quoted 3 lines
We can always migrate those to
CONFIG_IS_ENABLED(SEPARATE_BSS),CONFIG_IS_ENABLED(RECOVER_DATA_SECTION),CONFIG_VAL(BSS_START_ADDR),CONFIG_VAL(BSS_MAX_SIZE), etc., if needed.I did a quick test with my TPL stubs on RK3568 and RK3528 and we can likely use
arch/arm/cpu/armv8/u-boot-spl.ldsafter your suggested changes.However, we must also ensure to disable
TPL_SEPARATE_BSSand not let it use the default TPL_SEPARATE_BSS=SPL_SEPARATE_BSS, and also ensure thatTPL_MAX_SIZEis defined, as it will define the LENGTH of the MEMORY, i.e. work as a built in size check that image+bss fit inside .sram.And then we possible could to add a new size check, or possible manually just ensure that
TPL_MAX_SIZEis reduced byGD_SIZE,TPL_SYS_MALLOC_F_LENand a guestimated usage need for the runtime stack.Quoted 11 lines
Quoted 6 lines
BTW, the .sram MEMORY segment definition in the script would do the game: here the size that linker would check against
TPL_MAX_SIZEincludes BSS (consider the caseSPL_SEPARATE_BSSnot defined, of course), whileu-boot-tpl-v8.ldschecks size without BSS againstTPL_MAX_SIZE.We would have the same behavior of size checking if we had
TPL_SEPARATE_BSSenabled I believe. But if we hadTPL_SEPARATE_BSSenabled, then we would have an .sdram section too, which is the reason for having a separate linker script in the first place.Correct, we should use TPL_SEPARATE_BSS=n if we want to replace the custom rockchip tpl armv8 linker script and keep current behavior.
Quoted 7 lines
I'm also not sure about
IMAGE_TEXT_BASE(set byCONFIG_TEXT_BASE) only used in the armv8 linker script and the first. =
0x00000000;in Rockchip's TPL linker script.
It does not seem like this line is needed in the linker script.
Quoted 2 lines
But maybe we should really have BSS part of the size check.
As mentioned above, with a
TPL_MAX_SIZEthe .sram LENGTH is assigned and we get a built in size check, e.g. using TPL_MAX_SIZE=0x100 stop build:LD tpl/u-boot-tpl
/usr/bin/aarch64-linux-gnu-ld.bfd: address0xfe481570of u-boot-tpl section.text' is not within region.sram'/usr/bin/aarch64-linux-gnu-ld.bfd: u-boot-tpl section.rodata' will not fit in region.sram'/usr/bin/aarch64-linux-gnu-ld.bfd: address0xfe481570of u-boot-tpl section.text' is not within region.sram'/usr/bin/aarch64-linux-gnu-ld.bfd: address0xfe481570of u-boot-tpl section.text' is not within region.sram'/usr/bin/aarch64-linux-gnu-ld.bfd: region `.sram' overflowed by 1464 bytes
make[2]: *** [scripts/Makefile.xpl:546: tpl/u-boot-tpl] Error 1Quoted 2 lines
I'm out of my depth here though, no clue what would be proper.
For my forth coming TPL refactor series I tried to sync a few changes into the Rockchip custom linker script, probably better to try and drop it instead.
On a side note, the TPL stub runtime tests on RK3568 and RK3528 revealed that in special cases we possible could use the BootROM stack, but I still think that can be risky and that it is safer that we keep U-Boot TPL stack and malloc area separate from the BootROM stack.
Test run of TPL stub on RK3528:
U-Boot TPL 2026.10-rc5 (Sep 28 2026 - 20:23:41)
x0:fe480458
x1: 00000008
x2:fe481000
sp:fe480ef0
DRAM init failedTest run of TPL stub on RK3568:
U-Boot TPL 2026.10-rc5 (Sep 28 2026 - 20:22:26)
x0:fdcc0098
x1: 00000008
x2:fdcc1000
sp:fdcc0f30
DRAM init failed
Quoted 6 lines
Above is the values x0, x1, x2 and sp register had when BootROM called the TPL code.
The stack pointer seem to be near the end of the BootROM reserved area. Not sure what x0 or x1 values could be, but x2 seem to match
TPL_TEXT_BASE, so possible the address BootROM called/jumped to.
I did similar testing on a RK3288 TinkerBoard-S, it seem to reveal that we are currently limiting TPL size to 32 KiB, however using the entire 96 KiB SRAM on RK3288 seems to be working.
With u-boot-tpl.bin that is 0x878 bytes:
U-Boot TPL 2026.10-rc5 (Sep 29 2026 - 07:32:40)
0: 32334b52 ("RK32")
1: eaffffff
2: ffffffff
3: ff704882 (payload size?, 0x878 vs 0x882)
4: ff702964
5: 00000002
6: 00000000
7: ff703790 (sp)
DRAM init failed
and with u-boot-tpl.bin that is 0x13878 bytes (.space 0x13000 padding before reset symbol):
U-Boot TPL 2026.10-rc5 (Sep 29 2026 - 07:38:06)
0: 32334b52 ("RK32")
1: eaffffff
2: ffffffff
3: ff717882 (payload size?, 0x13878 vs 0x17882)
4: ff702964
5: 00000002
6: 00000000
7: ff703790 (sp)
DRAM init failed
I will try to run similar tests on my other RK SoCs to see how they behave and to verify rkcommon.c limit matches actual limits.
Regards,
Jonas
Quoted 15 lines
Also x3-x7 did not seem to have any useful values or they changed each board reset.
What I take away from all above is that I will shortly update my rk3562 work-in-progress branch to also define
TPL_MAX_SIZEto be the result of TPL_STACK-TPL_TEXT_BASE for all added TPL stubs.Regards,
JonasQuoted 3 lines
Cheers,
Quentin
Hi Quentin,
Il giorno lun 28 set 2026 alle ore 11:10 Quentin Schulz <[email protected]> ha scritto:
Quoted 102 lines
Hi Massimo,
Quoted 92 lines · Massimo Pegorer
Hi Quentin,
Quoted 77 lines · Quentin Schulz
Hi Massimo,
Quoted 61 lines · Massimo Pegorer
Hi Jonas,
Il giorno mar 22 set 2026 alle ore 15:28 Jonas Karlman ha scritto:
Quoted 58 lines
Hi Massimo,
Quoted 33 lines · Massimo Pegorer
Hi Jonas,
Il giorno dom 20 set 2026 alle ore 18:19 Jonas Karlman <[email protected]> ha scritto:
Quoted 29 lines
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Quoted 7 lines
Quoted 4 lines
Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Here with "any change to [...] code" I suppose you mean any change of global data and/or BSS sizes, correct?
Not only, the change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor 'structglobal_data' would affect where the TPL stack ends up. However, and any change to the code may change how the stack is used and thus possible write to more/less/other data inside the BootROM area.Quoted 7 lines
As code size itself is checked against
TPL_MAX_SIZEat build time. Regarding build time checks, I have a couple of doubts about [1]:
- shouldn't we check for less than or equal againstTPL_MAX_SIZE, instead of strictly less than?
- shouldn't be more correct to check the TPL "footprint" size against the 10 (or 11 or 12) KiB limit, instead only the code size?Quoted 8 lines
Quoted 3 lines
Correct, this was also briefly discussed/mentioned in the v2 thread. However, this patch only tries to address the issue with TPL stack being placed inside BootROM reserved area.
Indeed. I was just wondering if in a future patch we should avoid
TPL_MAX_SIZEconfiguration, and instead have justTPL_MAX_FOOTPRINTconfigured to0x3000addingGD_SIZEandTPL_SYS_MALLOC_F_LENin the linker check.I had never heard of that symbol before and went checking. It has never been used (there isn't even a
Kconfigsymbol for it!) so we would need a bit of work to make this work (probably not a crazy amount though :) ).Quoted 11 lines
I'm not sure we still need
arch/arm/mach-rockchip/u-boot-tpl-v8.ldsthough. It's only used for evb-px5_defconfig, all PX30, all RK3328, all RK3399 and RV1126.
I think it was necessary when added back in 2019 becausearch/arm/cpu/armv8/u-boot-spl.ldsdidn't allow yet to remove the SDRAM part in it (c.f.3cbec0ad090f("rockchip: addu-boot-tpl-v8.lds") which claims "we don't have both SRAM and SDRAM in TPL" but we have SRAM access in TPL, don't we?), but that has changed since 2024. They are a bit different though and I have no experience with linker scripts so no clue if it makes sense to merge them (if at all possible). I'm guessing the additional asserts would make sense for everybody anyway.Quoted 5 lines
Me too, almost no experience with linker scripts. Anyway, I had a quick look at
arch/arm/cpu/armv8/u-boot-spl.ldsfor TPL building purpose, and IMO it's broken by design because of SPL specific configuration options dependencies:SPL_SEPARATE_BSSandSPL_RECOVER_DATA_SECTION. I will check more in depth.
Quoted 3 lines
We can always migrate those to
CONFIG_IS_ENABLED(SEPARATE_BSS),CONFIG_IS_ENABLED(RECOVER_DATA_SECTION),CONFIG_VAL(BSS_START_ADDR),CONFIG_VAL(BSS_MAX_SIZE), etc., if needed.
Thanks for the suggestion. I will run some tests and then try to send a patch to fix the usage of u-boot-spl.lds for generic XPL cases, as a first step to eventually drop u-boot-tpl-v8.lds later on, if possibile.
Quoted 25 lines
Quoted 6 lines
BTW, the .sram MEMORY segment definition in the script would do the game: here the size that linker would check against
TPL_MAX_SIZEincludes BSS (consider the caseSPL_SEPARATE_BSSnot defined, of course), whileu-boot-tpl-v8.ldschecks size without BSS againstTPL_MAX_SIZE.We would have the same behavior of size checking if we had
TPL_SEPARATE_BSSenabled I believe. But if we hadTPL_SEPARATE_BSSenabled, then we would have an .sdram section too, which is the reason for having a separate linker script in the first place.I'm also not sure about
IMAGE_TEXT_BASE(set byCONFIG_TEXT_BASE) only used in the armv8 linker script and the first. =
0x00000000;in Rockchip's TPL linker script.
But maybe we should really have BSS part of the size check.
I'm out of my depth here though, no clue what would be proper.
Cheers,
Quentin
Hi Jonas,
Quoted 49 lines · Jonas Karlman
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.TPL on PX30/RK3326 does not have any use for the malloc area, the generated
GD_SIZEis typically around 304 bytes and BSS around 72 bytes.Current memory layout possibly looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [..., 0xff0e08c0) stack area [0xff0e08c0] stack pointer [0xff0e08c0, 0xff0e09f0) 304 bytes global data (zeroed) [0xff0e09f0, 0xff0e0ff0) 1536 bytes malloc area (untouched) [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSSTPL currently does not touch the malloc area, instead the reserved
TPL_SYS_MALLOC_F_LENbytes help push the zeroed global data struct and the TPL stack addresses deeper into the BootROM reserved area.Using current offsets for global data and stack does not seem to cause any known issue for BootROM after TPL returns to BootROM to load SPL into DRAM, however any change to
TPL_STACK,TPL_SYS_MALLOC_F_LENor code could theoretically change this and cause issues for BootROM.Update
TPL_STACKto use the top of SRAM address and reduceMALLOC_F_LENto0x200to avoid overflowing global data, malloc area and stack into the BootROM reserved region.With these changes the memory layout looks something like:
[0xff0e0000, 0xff0e4000) 16 KiB SRAM [0xff0e0000, 0xff0e1000) 4 KiB BROM area [0xff0e1000, 0xff0e4000) 12 KiB TPL area [0xff0e1000, 0xff0e3800) 10 KiB code [0xff0e3800, 0xff0e3848) 72 bytes BSS [0xff0e3848, 0xff0e3cd0) 1160 bytes stack area [0xff0e3cd0] stack pointer [0xff0e3cd0, 0xff0e3e00) 304 bytes global data [0xff0e3e00, 0xff0e4000) 512 bytes malloc area (unused)
Quoted 2 lines
Signed-off-by Jonas Karlman <[email protected]>Reviewed-by Simon Glass <[email protected]>
I intend to take this for 2027.01. We've lived with this mistake since forever and I would like to avoid changes with potentially big consequences like this one here so late in the development cycle.
Looking forward for what was split from v2 into other patches (specifically bumping TPL_MAX_SIZE to the one used in downstream).
Thanks!
Quentin
Quoted 10 lines · Jonas Karlman
The PX30/RK3326 has 16 KiB SRAM at [
0xff0e0000,0xff0e4000), with the initial 4 KiB at [0xff0e0000,0xff0e1000) reserved for BootROM at boot.SRAM addressing only seems to use 14 bits, meaning that reading from 0xff0e4000+ wraps around and instead reads back data at 0xff0e0000+.
Using a
TPL_STACKat0xff0e4ff0(16-bytes aligned) means TPL use BootROM reserved region for its global data, malloc area and runtime stack.[...]
Applied to https://git.u-boot-project.org/u-boot/custodians/u-boot-rockchip (u-boot-rockchip-2027.01), thanks!
[1/1] rockchip: px30: Fix TPL_STACK overflow into BootROM reserved region
https://git.u-boot-project.org/u-boot/custodians/u-boot-rockchip/-/commit/b177b194d9e4af7631a23b2a9227edfcf937f8b7
Best regards,
Signature · 1 line
Quentin Schulz <[email protected]>