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 <[email protected]>
---
 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


Reply via email to