From: Michael Tretter <m.tretter@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 5/9] PBL: fdt: make minimum fdt size configurable
Date: Wed, 28 May 2025 10:24:01 +0200 [thread overview]
Message-ID: <aDbIIWOQC4GzrUjR@pengutronix.de> (raw)
In-Reply-To: <aDYITmRiE4yL7y90@pengutronix.de>
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.tretter@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
next prev parent reply other threads:[~2025-05-28 8:28 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-26 14:38 [PATCH 0/9] ARM: rockchip: fix dynamic shared memory in OP-TEE Michael Tretter
2025-05-26 14:38 ` [PATCH 1/9] ARM: rockchip: fix formatting Michael Tretter
2025-05-26 17:30 ` Marco Felsch
2025-05-26 14:38 ` [PATCH 2/9] ARM: rockchip: dmc: use RK3588_INT_REG_START for rk3588 Michael Tretter
2025-05-26 17:29 ` Marco Felsch
2025-05-26 14:38 ` [PATCH 3/9] lib: fdt: add fdt_addresses Michael Tretter
2025-05-26 17:29 ` Marco Felsch
2025-05-26 14:38 ` [PATCH 4/9] PBL: fdt: refactor helper for reading nr of cells Michael Tretter
2025-05-26 17:30 ` Marco Felsch
2025-05-26 14:38 ` [PATCH 5/9] PBL: fdt: make minimum fdt size configurable Michael Tretter
2025-05-27 6:41 ` Sascha Hauer
2025-05-27 8:48 ` Michael Tretter
2025-05-27 18:45 ` Sascha Hauer
2025-05-28 8:24 ` Michael Tretter [this message]
2025-05-26 14:38 ` [PATCH 6/9] PBL: fdt: add fdt_fixup_mem to fixup memory nodes Michael Tretter
2025-05-27 6:22 ` Sascha Hauer
2025-05-27 8:34 ` Michael Tretter
2025-05-27 18:51 ` Sascha Hauer
2025-05-26 14:38 ` [PATCH 7/9] ARM: rockchip: dmc: add rk3588_ram_sizes to get full ram size Michael Tretter
2025-05-26 16:33 ` Marco Felsch
2025-05-27 6:25 ` Sascha Hauer
2025-05-27 8:39 ` Michael Tretter
2025-05-27 9:06 ` Marco Felsch
2025-05-26 14:38 ` [PATCH 8/9] ARM: rockchip: pass device tree to TF-A Michael Tretter
2025-05-26 16:37 ` Marco Felsch
2025-05-27 8:03 ` Michael Tretter
2025-05-26 14:38 ` [PATCH 9/9] ARM: rockchip: fixup memory in device tree for TF-A Michael Tretter
2025-05-26 17:25 ` Marco Felsch
2025-05-27 8:16 ` Michael Tretter
2025-05-27 9:40 ` Marco Felsch
2025-05-27 10:19 ` Michael Tretter
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=aDbIIWOQC4GzrUjR@pengutronix.de \
--to=m.tretter@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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