mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 0/6] ARM: unify pbl and proper malloc area start
Date: Fri, 22 May 2026 12:53:06 +0200	[thread overview]
Message-ID: <20260522105852.2681680-1-a.fatoum@pengutronix.de> (raw)

With the most recent changes to the PBL rockchip code, barebox gained an
additional very early malloc pool:

- very early on, it reserves some space at the end of RAM for extracting
  compressed TF-A/OP-TEE blobs.

- a bit later, but still in PBL, it reserve some space directly under
  the start of the barebox area at end of RAM as before.

- In barebox proper, it reserves a large malloc area that ends also
  at the start of the barebox area at end of RAM.

Nothing allocated in these different pools needs to survive after the
next pool is instantiated, so reusing the memory is fine.

The new pool at the start causes a regression for Rockchip boards with
OP-TEE as the OP-TEE region overlapped that very early malloc area.

The clean resolution of this is if we could just use the same malloc
area used later in barebox proper in PBL, whether very early or just
before barebox proper decompression.

There's a problem though:

 - The end of the malloc region is relative to barebox area, which means
   we must know how big barebox is, which we can't very early on as it
   contains handoff data not yet allocated and may not even be possible
   at all if we have separate first and second stages

- The start of the malloc region is relative to the end of the malloc
  region


This mess has been a fertile ground for bugs, so in interest of avoiding
more bugs in future, this series changes the calculation of the malloc
area on ARM:


 - The end continues to be relative to the barebox area
 - The start of the malloc area is relative to the end of the initial
   memory without regard to the barebox area

For the common case of the malloc area being dynamic anyway, the malloc
area will change in size by few megabytes, which doesn't matter much.

For the uncommon case, CONFIG_MALLOC_OFFSET would need to be set
appropriately. The migration notes are extended to describe how to
determine the value.

An extra benefit is that CONFIG_MALLOC_OFFSET=0 becomes the default now
instead of CONFIG_MALLOC_SIZE=4M, which most boards were overriding
anyway.

A future change that can be built on top of this is saving handoff
_before_ the barebox executable on memory, not before it.

This could further simplify the code. This is not implemented here as
this is meant for master to fix the regression for Rockchip.

This passes the DistroKit pre-release tests and the Github Actions CI.
@Alexander, could you test on your OP-TEE enabled RK35xx?

Ahmad Fatoum (6):
  arch: introduce new CONFIG_ARCH_HAS_MALLOC_SIZE
  ARM: explicitly state CONFIG_MALLOC_SIZE in defconfigs
  arch: introduce CONFIG_MALLOC_OFFSET
  ARM: switch to CONFIG_MALLOC_OFFSET
  ARM: configs: drop CONFIG_MALLOC_SIZE=0x0 as it's now the default
  ARM: place PBL malloc area at start of barebox proper malloc area

 arch/Kconfig                                  | 20 +++++++++
 arch/arm/Kconfig                              |  1 +
 arch/arm/configs/am335x_mlo_defconfig         |  1 -
 .../arm/configs/am35xx_pfc200_xload_defconfig |  1 -
 arch/arm/configs/animeo_ip_defconfig          |  1 +
 arch/arm/configs/at91_multi_defconfig         |  1 -
 arch/arm/configs/at91rm9200ek_defconfig       |  1 +
 arch/arm/configs/at91sam9260ek_defconfig      |  1 +
 .../configs/at91sam9261ek_bootstrap_defconfig |  1 +
 arch/arm/configs/at91sam9261ek_defconfig      |  1 +
 arch/arm/configs/at91sam9g10ek_defconfig      |  1 +
 arch/arm/configs/at91sam9g20ek_defconfig      |  1 +
 arch/arm/configs/at91sam9m10g45ek_defconfig   |  2 +-
 arch/arm/configs/at91sam9m10ihd_defconfig     |  2 +-
 arch/arm/configs/at91sam9n12ek_defconfig      |  2 +-
 arch/arm/configs/clps711x_defconfig           |  1 +
 arch/arm/configs/dss11_defconfig              |  1 +
 arch/arm/configs/efi_v8_defconfig             |  1 -
 arch/arm/configs/haba_knx_lite_defconfig      |  1 +
 arch/arm/configs/imx23_defconfig              |  1 -
 arch/arm/configs/imx28_defconfig              |  1 -
 arch/arm/configs/imx_v7_defconfig             |  1 -
 arch/arm/configs/imx_v8_defconfig             |  1 -
 arch/arm/configs/k3-r5_defconfig              |  1 -
 arch/arm/configs/kindle-gen-6-7_defconfig     |  1 -
 arch/arm/configs/kindle-mx50_defconfig        |  1 -
 arch/arm/configs/layerscape_defconfig         |  1 -
 arch/arm/configs/layerscape_v7_defconfig      |  1 -
 arch/arm/configs/modules32_defconfig          |  1 -
 arch/arm/configs/multi_v5_v6_defconfig        |  1 -
 arch/arm/configs/multi_v7_defconfig           |  1 -
 arch/arm/configs/multi_v8_defconfig           |  1 -
 arch/arm/configs/mvebu_defconfig              |  1 -
 arch/arm/configs/omap_defconfig               |  1 -
 arch/arm/configs/pm9261_defconfig             |  1 +
 arch/arm/configs/pm9263_defconfig             |  1 +
 arch/arm/configs/pm9g45_defconfig             |  1 +
 arch/arm/configs/qil_a9260_defconfig          |  1 +
 arch/arm/configs/qil_a9g20_defconfig          |  1 +
 arch/arm/configs/rockchip_v7a_defconfig       |  1 -
 arch/arm/configs/rockchip_v8_defconfig        |  1 -
 arch/arm/configs/rpi_defconfig                |  1 -
 arch/arm/configs/rpi_v8a_defconfig            |  3 +-
 arch/arm/configs/socfpga-agilex5_defconfig    |  1 -
 arch/arm/configs/socfpga-arria10_defconfig    |  1 -
 arch/arm/configs/socfpga-xload_defconfig      |  1 -
 arch/arm/configs/socfpga_defconfig            |  1 -
 arch/arm/configs/stm32mp_defconfig            |  1 -
 arch/arm/configs/tegra_v7_defconfig           |  1 -
 arch/arm/configs/telit_evk_pro3_defconfig     |  1 +
 arch/arm/configs/tny_a9260_defconfig          |  1 +
 .../arm/configs/tny_a9263_bootstrap_defconfig |  1 +
 arch/arm/configs/tny_a9263_defconfig          |  1 +
 arch/arm/configs/tny_a9g20_defconfig          |  1 +
 arch/arm/configs/usb_a9260_defconfig          |  1 +
 .../arm/configs/usb_a9263_bootstrap_defconfig |  1 +
 arch/arm/configs/usb_a9263_defconfig          |  1 +
 arch/arm/configs/usb_a9g20_defconfig          |  2 +-
 arch/arm/configs/virt32_secure_defconfig      |  1 -
 arch/arm/configs/zii_vf610_dev_defconfig      |  1 -
 arch/arm/configs/zynq_defconfig               |  2 +-
 arch/arm/configs/zynqmp_defconfig             |  1 -
 arch/arm/cpu/common.c                         |  4 +-
 arch/arm/cpu/start.c                          | 14 +------
 arch/arm/cpu/uncompress.c                     |  2 +-
 arch/arm/include/asm/barebox-arm.h            |  6 ++-
 arch/arm/mach-rockchip/atf.c                  |  2 +-
 arch/mips/Kconfig                             |  1 +
 arch/openrisc/Kconfig                         |  1 +
 arch/powerpc/Kconfig                          |  1 +
 arch/riscv/Kconfig                            |  1 +
 arch/sandbox/Kconfig                          |  1 +
 common/Kconfig                                | 41 ++++++++++++++++++-
 include/asm-generic/memory_layout.h           | 20 +++++++++
 74 files changed, 123 insertions(+), 59 deletions(-)

-- 
2.47.3




             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 Ahmad Fatoum [this message]
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 ` [PATCH master 6/6] ARM: place PBL malloc area at start of barebox proper malloc area Ahmad Fatoum

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-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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