[PATCH 5/9] PBL: fdt: make minimum fdt size configurable

Sascha Hauer s.hauer at pengutronix.de
Tue May 27 11:45:34 PDT 2025


On Tue, May 27, 2025 at 10:48:02AM +0200, Michael Tretter wrote:
> On Tue, 27 May 2025 08:41:16 +0200, Sascha Hauer wrote:
> > On Mon, May 26, 2025 at 04:38:11PM +0200, Michael Tretter wrote:
> > > Adding or modifying nodes in the fdt may change the size of the fdt.
> > > This needs some reserved space in the fdt to avoid overriding memory
> > > that comes after the fdt and is already used.
> > > 
> > > Signed-off-by: Michael Tretter <m.tretter at pengutronix.de>
> > > ---
> > >  pbl/Kconfig          | 11 +++++++++++
> > >  scripts/Makefile.lib |  2 ++
> > >  2 files changed, 13 insertions(+)
> > > 
> > > diff --git a/pbl/Kconfig b/pbl/Kconfig
> > > index 6e3581829d589c7b06ed878b09bf74e16a0c3086..489b2001a855d62e11a2159311332b0e67f3a754 100644
> > > --- a/pbl/Kconfig
> > > +++ b/pbl/Kconfig
> > > @@ -60,6 +60,17 @@ config PBL_VERIFY_PIGGY
> > >  config PBL_CLOCKSOURCE
> > >  	bool
> > >  
> > > +config PBL_FDT_MIN_SIZE
> > > +	hex
> > > +	default 0x0
> > > +	prompt "Minimum size of the FDT blob"
> > > +	help
> > > +	  The TF-A or OP-TEE may modify the FDT or add nodes to the FDT. This
> > > +	  may increases the size of the device tree. This may override the
> > > +	  barebox binary.
> > > +
> > > +	  The minimum size should be at least CFG_DTB_MAX_SIZE for OP-TEE.
> > > +
> > >  config BOARD_GENERIC_DT
> > >  	bool
> > >  	select LIBFDT
> > > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> > > index b10119797686ea31fe927d29a7849ad525c8c835..f50006f57200a76a86c7e29175dd7e35ab138e26 100644
> > > --- a/scripts/Makefile.lib
> > > +++ b/scripts/Makefile.lib
> > > @@ -396,6 +396,8 @@ ifeq ($(CONFIG_OF_OVERLAY_LIVE), y)
> > >  DTC_FLAGS.dtb += -@
> > >  endif
> > >  
> > > +DTC_FLAGS.dtb += --space $(CONFIG_PBL_FDT_MIN_SIZE)
> > 
> > --space sets the minimum fdt size. The fdt size will vary over time and
> > different boards. Isn't --pad more suitable for what you want to
> > archieve?
> 
> --pad would be more appropriate if it is used to reserve extra space for
> the memory nodes added by barebox.
> 
> However, OP-TEE also adds properties and nodes to the passed fdt. During
> initialization it does a fdt_open_into() with size CFG_DTB_MAX_SIZE on
> the blob. This allows OP-TEE to write up to CFG_DTB_MAX_SIZE into the
> blob.
> 
> Using --space with the same value as CFG_DTB_MAX_SIZE ensures that
> barebox reserves enough space that a properly configured OP-TEE is not
> able to accidentally override anything else by modifying the device
> tree.

Makes sense. What's not so nice is that this --space option inflates all
dtbs from all boards of the current config.

Would fdt_resize() be an option?

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