From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH master 6/6] ARM: place PBL malloc area at start of barebox proper malloc area
Date: Fri, 22 May 2026 12:53:12 +0200 [thread overview]
Message-ID: <20260522105852.2681680-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260522105852.2681680-1-a.fatoum@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_MALLOC_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@gmail.com>
Fixes: 76b1f31275fe ("ARM: rockchip: initialize PBL malloc")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/common.c | 4 ++--
arch/arm/cpu/uncompress.c | 2 +-
arch/arm/include/asm/barebox-arm.h | 6 ++++--
arch/arm/mach-rockchip/atf.c | 2 +-
4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
index 6b82ee8b810c..f03a39cc193a 100644
--- a/arch/arm/cpu/common.c
+++ b/arch/arm/cpu/common.c
@@ -114,8 +114,8 @@ 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);
- printf("arm_mem_early_malloc = 0x%08lx+0x%08x\n",
- barebox_base - PBL_MALLOC_SIZE, PBL_MALLOC_SIZE);
+ printf("pbl_malloc area = 0x%08lx+0x%08x\n",
+ barebox_malloc_base(membase, endmem - membase), PBL_MALLOC_SIZE);
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..2e5d60f6a39d 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -75,7 +75,7 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
handoff_data = (void *)barebox_base + ALIGN(uncompressed_len, 8) + MAX_BSS_SIZE;
- pbl_malloc_init(barebox_base - PBL_MALLOC_SIZE, PBL_MALLOC_SIZE);
+ pbl_malloc_init(barebox_malloc_base(membase, memsize), PBL_MALLOC_SIZE);
#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..f8fe377284f0 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() ---------------------
+ * ↕
+ * ----------------------- pbl_malloc area end ------------------------
* ↑
- * SZ_128K
+ * PBL_MALLOC_SIZE
* ↓
- * ------------------------ arm_mem_early_malloc ----------------------
+ * ----------------------- 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
prev parent reply other threads:[~2026-05-22 11:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 10:53 [PATCH master 0/6] ARM: unify pbl and proper malloc area start Ahmad Fatoum
2026-05-22 10:53 ` [PATCH master 1/6] arch: introduce new CONFIG_ARCH_HAS_MALLOC_SIZE Ahmad Fatoum
2026-05-22 10:53 ` [PATCH master 2/6] ARM: explicitly state CONFIG_MALLOC_SIZE in defconfigs Ahmad Fatoum
2026-05-22 10:53 ` [PATCH master 3/6] arch: introduce CONFIG_MALLOC_OFFSET Ahmad Fatoum
2026-05-22 10:53 ` [PATCH master 4/6] ARM: switch to CONFIG_MALLOC_OFFSET Ahmad Fatoum
2026-05-22 10:53 ` [PATCH master 5/6] ARM: configs: drop CONFIG_MALLOC_SIZE=0x0 as it's now the default Ahmad Fatoum
2026-05-22 10:53 ` Ahmad Fatoum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260522105852.2681680-7-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=eagle.alexander923@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox