[PATCH master 3/6] arch: introduce CONFIG_MALLOC_OFFSET

Sascha Hauer s.hauer at pengutronix.de
Mon May 25 23:17:21 PDT 2026


On 2026-05-22 12:53, Ahmad Fatoum wrote:
> +config MALLOC_OFFSET
> +	hex
> +	default 0
> +	prompt "relative malloc base offset (optional)"
> +	depends on ARCH_HAS_MALLOC_OFFSET
> +	help
> +	  Most boards should just leave this at the default zero and barebox
> +	  will dynamically determine the start of its eventual malloc area.
> +	  The currently employed heuristic is:
> +
> +	    - if the prebootloader reports 2GiB of initial memory or more,
> +	      start the malloc area at offset 1GiB from initial memory end.
> +
> +	    - otherwise, start the malloc area at middle of initial memory
> +
> +	  The malloc area is used for dynamic allocations by barebox, e.g.
> +	  to uncompress a kernel. The placement of final boot artifacts happens
> +	  outside of the malloc area and is not restricted to the initial
> +	  memory reported by the prebootloader.
> +
> +	  As this heuristic may not be suitable for devices with tight memory
> +	  constraints, setting a non-zero value here allows customizing the
> +	  offset used to start the malloc area.
> +
> +	  The MALLOC_OFFSET is calculated from end of initial memory to start
> +	  of the malloc area

I read the term offset as something added to the start of something, not
substracted from an end of something.

Maybe MALLOC_OFFSET should be exactly that: The offset between start of
DRAM and start of the malloc area. On a memory constrained hardware with
different DRAM sizes that's also likely the value you want to keep
constant as its given by your Kernel/initrd image size.

Other than that maybe the term we should talk about here is the area
that we use for barebox internal use and the area that's left for
placing the OS. Whether or not we start the malloc area at that boundary
isn't the point.

Something like BAREBOX_MEMORY_OFFSET:

config BAREBOX_MEMORY_OFFSET
        hex "barebox runtime memory offset"
        default 0x0
        help
          Offset from the start of DRAM at which the barebox runtime
          region begins. DRAM below this offset is reserved as the OS
          load region, used for staging the kernel, initrd and device
          tree before boot. barebox itself — the relocated binary, BSS,
          stack and malloc arena — lives at and above this offset and
          will not allocate into the OS load region.

          Set this large enough to hold the biggest OS image you expect
          to boot, plus initrd and DTB.

          A value of 0 selects the default split, which divides DRAM
          into two equal halves: the lower half for the OS load region
          and the upper half for the barebox runtime region. This is
          suitable for most boards with modern DRAM sizes.

Sascha

-- 
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