On Tue, 27 May 2025 20:45:34 +0200, Sascha Hauer wrote:
> 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.tret...@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?

fdt_resize() still needs some space for resizing the fdt.

I don't like the reserved space in the binary at all, because it also
increases the size of the binary images.

In v2, I will reserve some extra space in the scratch area (and make its
size configurable), copy the fdt to the scratch area and modify it there
(or create a small new fdt).

This would also solve the issue that the fdt is in a rodata section and
may be compressed. Furthermore, this area could be passed to barebox
proper via handoff data and barebox could apply the dt modifications by
OPTEE to its own device tree.

The drawback of this solution is that the barebox PBL has to copy the
fdt while the mmu is off.

Michael

Reply via email to