[PATCH master v2 5/5] ARM64: place PBL malloc area at start of barebox proper malloc area

Ahmad Fatoum a.fatoum at pengutronix.de
Thu May 28 04:04:55 PDT 2026


Hi,

On 5/27/26 3:12 PM, Alexander Shiyan wrote:
> Tested-by: Alexander Shiyan <eagle.alexander923 at gmail.com>

Unfortunately, I placed the very early malloc area at the wrong place.

I just sent out v3 and would appreciate if you can check if that also
works for you.

Cheers,
Ahmad

> 
> ср, 27 мая 2026 г. в 15:17, Ahmad Fatoum <a.fatoum at pengutronix.de>:
>>
>> The early PBL malloc area used by the Rockchip code overlaps the region
>> used for OP-TEE. Moving it a bit lower would overlap the region occupied
>> by the scratch area.
>>
>> With the switch to CONFIG_BAREBOX_MEMORY_OFFSET, we can compute the start
>> of the malloc area in barebox proper without knowing how big barebox will
>> eventually be, so make use of that and always place the PBL malloc area
>> exactly at the start of the eventual barebox proper memory area.
>>
>> The memory will automatically be reclaimed when the TLSF allocator is
>> instantiated and we will be sure not to overwrite anything by allocating
>> in PBL.
>>
>> Reported-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
>> Fixes: 76b1f31275fe ("ARM: rockchip: initialize PBL malloc")
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  arch/arm/cpu/common.c              |  5 +++++
>>  arch/arm/cpu/uncompress.c          |  4 ++++
>>  arch/arm/include/asm/barebox-arm.h | 10 ++++++----
>>  arch/arm/mach-rockchip/atf.c       |  2 +-
>>  4 files changed, 16 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
>> index 6b82ee8b810c..adb5d6a02bc8 100644
>> --- a/arch/arm/cpu/common.c
>> +++ b/arch/arm/cpu/common.c
>> @@ -114,8 +114,13 @@ void print_pbl_mem_layout(ulong membase, ulong endmem, ulong barebox_base)
>>  #endif
>>         printf("arm_mem_barebox_image = 0x%08lx+0x%08lx\n",
>>                barebox_base, arm_mem_barebox_image_end(endmem) - barebox_base);
>> +#ifdef CONFIG_ARM64
>> +       printf("pbl_malloc area       = 0x%08lx+0x%08x\n",
>> +              barebox_malloc_base(membase, endmem - membase), PBL_MALLOC_SIZE);
>> +#else
>>         printf("arm_mem_early_malloc  = 0x%08lx+0x%08x\n",
>>                barebox_base - PBL_MALLOC_SIZE, PBL_MALLOC_SIZE);
>> +#endif
>>         printf("membase               = 0x%08lx+0x%08lx\n",
>>                membase, endmem - membase);
>>  }
>> diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
>> index 61bcba6e8549..55bbe0019cc4 100644
>> --- a/arch/arm/cpu/uncompress.c
>> +++ b/arch/arm/cpu/uncompress.c
>> @@ -75,7 +75,11 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
>>
>>         handoff_data = (void *)barebox_base + ALIGN(uncompressed_len, 8) + MAX_BSS_SIZE;
>>
>> +#ifdef CONFIG_ARM64
>> +       pbl_malloc_init(barebox_malloc_base(membase, memsize), PBL_MALLOC_SIZE);
>> +#else
>>         pbl_malloc_init(barebox_base - PBL_MALLOC_SIZE, PBL_MALLOC_SIZE);
>> +#endif
>>
>>  #ifdef DEBUG
>>         print_pbl_mem_layout(membase, endmem, barebox_base);
>> diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
>> index 38cceba010ed..f75cddc77243 100644
>> --- a/arch/arm/include/asm/barebox-arm.h
>> +++ b/arch/arm/include/asm/barebox-arm.h
>> @@ -95,10 +95,12 @@ void *barebox_arm_boot_dtb(void);
>>   *                       + BSS) rounded to SZ_1M
>>   *                                   ↓
>>   *  ---------------------- arm_mem_barebox_image() ---------------------
>> - *                                   ↑
>> - *                                SZ_128K
>> - *                                   ↓
>> - *  ------------------------ arm_mem_early_malloc ----------------------
>> + *     ARM32      ↑                  |                ↕         ARM64
>> + *         PBL_MALLOC_SIZE           |------- pbl_malloc area end ------
>> + *                ↓                  |                ↑
>> + *  --- arm_mem_early_malloc --------|         PBL_MALLOC_SIZE
>> + *                                   |                ↓
>> + *                                   ----- pbl_malloc area start -------
>>   */
>>  void print_pbl_mem_layout(ulong membase, ulong endmem, ulong barebox_base);
>>
>> diff --git a/arch/arm/mach-rockchip/atf.c b/arch/arm/mach-rockchip/atf.c
>> index 14797a1e0601..f9dbc8b20c5a 100644
>> --- a/arch/arm/mach-rockchip/atf.c
>> +++ b/arch/arm/mach-rockchip/atf.c
>> @@ -173,7 +173,7 @@ static void rockchip_atf_load_bl31(void *fdt)
>>         unsigned long bl31_ep;
>>
>>         mmu_early_enable(membase[0], memsize[0]);
>> -       pbl_malloc_init(membase[0] + memsize[0] - PBL_MALLOC_SIZE, PBL_MALLOC_SIZE);
>> +       pbl_malloc_init(membase[0], memsize[0]);
>>
>>         bl31_ep = load_elf64_image_phdr(&bl31);
>>
>> --
>> 2.47.3
>>
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




More information about the barebox mailing list