In preparation for using the barebox proper malloc area in PBL too,
switch over ARM64 to CONFIG_BAREBOX_MEMORY_OFFSET as this allows
calculating the malloc area start without needing to know the eventual
size of barebox proper itself.

The switch for ARM32 is more involved, so that's omitted for now without
a comment explaining why. Once we have migrated the xload code to not
use the malloc area for second stage placement and weeded out the
bugs[1], we should be good to go[1].

[1]: On a Beagle Bone Black, despite first stage being moved out of
malloc area, I get a data abort before barebox_pbl_start...

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 arch/arm/Kconfig     |  3 ++-
 arch/arm/cpu/start.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 53bddd55e179..c7a883338b0b 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -20,7 +20,6 @@ config ARM
        select ARCH_HAS_DMA_WRITE_COMBINE
        select HAVE_EFI_LOADER if MMU # for payload unaligned accesses
        select PBL_IMAGE_ELF
-       select ARCH_HAS_MALLOC_SIZE
        default y
 
 config ARCH_LINUX_NAME
@@ -34,10 +33,12 @@ config ARCH_MKIMAGE_NAME
 
 config ARM32
        def_bool CPU_32
+       select ARCH_HAS_MALLOC_SIZE
 
 config ARM64
        def_bool CPU_64
        select ARCH_HAS_RELR
+       select ARCH_HAS_BAREBOX_MEMORY_OFFSET
 
 config ARCH_TEXT_BASE
        hex
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index bbcf465be4db..6a9941275c12 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -156,6 +156,15 @@ __noreturn void barebox_non_pbl_start(unsigned long 
membase,
                armv7r_mpu_init_coherent(malloc_end, REGION_8MB);
        }
 
+#ifdef CONFIG_ARM64
+       malloc_start = barebox_malloc_base(membase, memsize);
+#else
+       /* TODO: migrate ARM32 to barebox_malloc_base(), once legacy xload
+        * code has been migrated to loadables; On boards like the beaglebone,
+        * a separate first stage barebox loads the second stage into RAM
+        * and executes it from there, so reusing the malloc area in second
+        * stage PBL will mangle the second stage code.
+        */
        /*
         * Maximum malloc space is the Kconfig value if given
         * or 1GB.
@@ -169,6 +178,7 @@ __noreturn void barebox_non_pbl_start(unsigned long membase,
                if (malloc_end - malloc_start > SZ_1G)
                        malloc_start = malloc_end - SZ_1G;
        }
+#endif
 
        pr_debug("initializing malloc pool at 0x%08lx (size 0x%08lx)\n",
                        malloc_start, malloc_end - malloc_start);
-- 
2.47.3


Reply via email to