mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix ELF image linking into PBL
@ 2026-05-13 13:57 Sascha Hauer
  2026-05-13 13:57 ` [PATCH 1/2] ARM: fix wrong calculation of barebox base Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2026-05-13 13:57 UTC (permalink / raw)
  To: BAREBOX

On ARM and RiscV we now link an ELF image into the PBL. With this PBL
and barebox proper might disagree where the barebox image has been
placed resulting in the malloc area overlapping the barebox image.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Sascha Hauer (2):
      ARM: fix wrong calculation of barebox base
      riscv: fix wrong calculation of barebox base

 arch/arm/include/asm/barebox-arm.h     | 4 ++++
 arch/riscv/include/asm/barebox-riscv.h | 4 ++++
 2 files changed, 8 insertions(+)
---
base-commit: f4da708a0ba2d8489832900b37343ac63dce16f0
change-id: 20260513-pbl-elf-fixes-f400f6c9546b

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] ARM: fix wrong calculation of barebox base
  2026-05-13 13:57 [PATCH 0/2] Fix ELF image linking into PBL Sascha Hauer
@ 2026-05-13 13:57 ` Sascha Hauer
  2026-05-13 13:57 ` [PATCH 2/2] riscv: " Sascha Hauer
  2026-05-15  9:28 ` [PATCH 0/2] Fix ELF image linking into PBL Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2026-05-13 13:57 UTC (permalink / raw)
  To: BAREBOX

We assumed that barebox_image_size matches the size of the uncompressed
barebox proper binary. This was true until dbbca16895, but since then
the uncompressed length of the barebox proper binary includes the ELF
header whereas barebox_image_size does not. With this it can happen
that barebox_base is calculated too high resulting in the malloc area
overlapping the barebox image. For now fix that by using the real
barebox base address from the __image_start linker variable.

Fixes: dbbca16895 ("ARM: link ELF image into PBL")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/include/asm/barebox-arm.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 99f8231194..611b2bb2d6 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -194,11 +194,15 @@ static inline unsigned long arm_mem_barebox_image(unsigned long membase,
 						  unsigned long uncompressed_len,
 						  const struct handoff_data *handoff_data)
 {
+#ifdef __PBL__
 	unsigned long size = uncompressed_len + MAX_BSS_SIZE + __handoff_data_size(handoff_data);
 
 	endmem = arm_mem_ramoops(endmem);
 
 	return ALIGN_DOWN(endmem - size, SZ_1M);
+#else
+	return (unsigned long)__image_start;
+#endif
 }
 
 /*

-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] riscv: fix wrong calculation of barebox base
  2026-05-13 13:57 [PATCH 0/2] Fix ELF image linking into PBL Sascha Hauer
  2026-05-13 13:57 ` [PATCH 1/2] ARM: fix wrong calculation of barebox base Sascha Hauer
@ 2026-05-13 13:57 ` Sascha Hauer
  2026-05-15  9:28 ` [PATCH 0/2] Fix ELF image linking into PBL Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2026-05-13 13:57 UTC (permalink / raw)
  To: BAREBOX

We assumed that barebox_image_size matches the size of the uncompressed
barebox proper binary. This was true until ec8b2ce7c2, but since then
the uncompressed length of the barebox proper binary includes the ELF
header whereas barebox_image_size does not. With this it can happen
that barebox_base is calculated too high resulting in the malloc area
overlapping the barebox image. For now fix that by using the real
barebox base address from the __image_start linker variable.

Fixes: ec8b2ce7c2 ("riscv: link ELF image into PBL")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/riscv/include/asm/barebox-riscv.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/riscv/include/asm/barebox-riscv.h b/arch/riscv/include/asm/barebox-riscv.h
index db6ff0ea71..083889817b 100644
--- a/arch/riscv/include/asm/barebox-riscv.h
+++ b/arch/riscv/include/asm/barebox-riscv.h
@@ -79,9 +79,13 @@ static inline unsigned long riscv_mem_barebox_image(unsigned long membase,
 						    unsigned long endmem,
 						    unsigned long size)
 {
+#ifdef __PBL__
 	endmem = riscv_mem_ramoops(membase, endmem);
 
 	return ALIGN_DOWN(endmem - size, SZ_1M);
+#else
+	return (unsigned long)__image_start;
+#endif
 }
 
 #define ENTRY_FUNCTION(name, arg0, arg1, arg2)                          \

-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Fix ELF image linking into PBL
  2026-05-13 13:57 [PATCH 0/2] Fix ELF image linking into PBL Sascha Hauer
  2026-05-13 13:57 ` [PATCH 1/2] ARM: fix wrong calculation of barebox base Sascha Hauer
  2026-05-13 13:57 ` [PATCH 2/2] riscv: " Sascha Hauer
@ 2026-05-15  9:28 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2026-05-15  9:28 UTC (permalink / raw)
  To: BAREBOX, Sascha Hauer


On Wed, 13 May 2026 15:57:57 +0200, Sascha Hauer wrote:
> On ARM and RiscV we now link an ELF image into the PBL. With this PBL
> and barebox proper might disagree where the barebox image has been
> placed resulting in the malloc area overlapping the barebox image.
> 
> 

Applied, thanks!

[1/2] ARM: fix wrong calculation of barebox base
      https://git.pengutronix.de/cgit/barebox/commit/?id=3ef8ba6540ef (link may not be stable)
[2/2] riscv: fix wrong calculation of barebox base
      https://git.pengutronix.de/cgit/barebox/commit/?id=122f440c6b2f (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-15  9:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-13 13:57 [PATCH 0/2] Fix ELF image linking into PBL Sascha Hauer
2026-05-13 13:57 ` [PATCH 1/2] ARM: fix wrong calculation of barebox base Sascha Hauer
2026-05-13 13:57 ` [PATCH 2/2] riscv: " Sascha Hauer
2026-05-15  9:28 ` [PATCH 0/2] Fix ELF image linking into PBL Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox