mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: Michael Tretter <m.tretter@pengutronix.de>
Cc: BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH v2 09/15] ARM: i.MX8M: add support to pass BL3x bl_params
Date: Thu, 5 Feb 2026 23:41:30 +0100	[thread overview]
Message-ID: <20260205224130.pe2fzkyvnuqwwkhu@pengutronix.de> (raw)
In-Reply-To: <aYTNJuyGYsdyoia8@pengutronix.de>

Hi Michael,

On 26-02-05, Michael Tretter wrote:
> On Wed, 04 Feb 2026 21:01:25 +0100, Marco Felsch wrote:
> > Add support to handover the BL32 and BL33 entrypoints via the TF-A
> > struct::bl_params in arg0. This eliminates the requirement to share the
> > different load addresses between multiple binaries to lower the BSP
> > integration effort.
> > 
> > In addition to the entriespoints, this commit also adds the support to
> > pass the builtin barebox DTB to OP-TEE if enabled.
> > 
> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> >  arch/arm/mach-imx/Kconfig | 16 ++++++++++
> >  arch/arm/mach-imx/atf.c   | 80 ++++++++++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 95 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
> > index d244c5758073c0f2c683e500e0d4ed0a6bff2cb5..b3e6e944867e7bd0ce6f15a6d693de44590c809c 100644
> > --- a/arch/arm/mach-imx/Kconfig
> > +++ b/arch/arm/mach-imx/Kconfig
> > @@ -38,6 +38,22 @@ config ARCH_IMX_ATF
> >  	def_bool y
> >  	depends on ARCH_IMX8M || ARCH_IMX9
> >  
> > +config ARCH_IMX_ATF_PASS_BL_PARAMS
> > +	bool "Pass BL3x bl_params as arg0 to TF-A"
> > +	depends on ARCH_IMX_ATF
> > +	select ARM_ATF
> > +	select LIBFDT
> > +	help
> > +	  Enable this option if you are using an upstream TF-A that uses
> > +	  the struct::bl_params to handover all required BL32 and BL33
> > +	  information required to start the BL32 and BL33 image.
> > +
> > +	  Since upstream TF-A v2.12 all i.MX8M support this feature except for
> > +	  the i.MX8MQ.
> > +
> > +	  This option is required if the barebox DT should be passed to the
> > +	  BL32 firmware.
> > +
> >  config ARCH_IMX_ROMAPI
> >  	def_bool y
> >  	depends on ARCH_IMX8M || ARCH_IMX9
> > diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
> > index 11d26607bc2ea449402d9cb8e20fbb44f425989c..34893c3a04616a9fbf2648a58940bec793ae04c8 100644
> > --- a/arch/arm/mach-imx/atf.c
> > +++ b/arch/arm/mach-imx/atf.c
> > @@ -1,5 +1,6 @@
> >  // SPDX-License-Identifier: GPL-2.0-only
> >  
> > +#include <asm/atf_common.h>
> >  #include <asm/sections.h>
> >  #include <common.h>
> >  #include <firmware.h>
> > @@ -18,6 +19,7 @@
> >  #include <mach/imx/ele.h>
> >  #include <mach/imx/xload.h>
> >  #include <mach/imx/snvs.h>
> > +#include <pbl.h>
> >  
> >  static void imx_adjust_optee_memory(void **bl32, void **bl32_image, size_t *bl32_size)
> >  {
> > @@ -37,6 +39,68 @@ static void imx_adjust_optee_memory(void **bl32, void **bl32_image, size_t *bl32
> >  	*bl32_image += sizeof(*hdr);
> >  }
> >  
> > +static __noreturn void bl31_via_bl_params(void *bl31, void *bl32, void *bl33,
> > +					  void *fdt)
> > +{
> > +	struct bl2_to_bl31_params_mem_v2 *params;
> > +
> > +	/* Prepare bl_params for BL32 */
> > +	params = bl2_plat_get_bl31_params_v2((uintptr_t)bl32,
> > +			(uintptr_t)bl33, (uintptr_t)fdt);
> > +
> > +	pr_debug("Jump to BL31 with bl-params (%s BL32-FDT)\n",
> > +		 fdt ? "including" : "excluding");
> > +	/*
> > +	 * Start BL31 without passing the FDT via x1 since the mainline
> > +	 * TF-A doesn't support it yet.
> > +	 */
> > +	bl31_entry_v2((uintptr_t)bl31, &params->bl_params, NULL);
> > +
> > +	__builtin_unreachable();
> > +}
> > +
> > +static __noreturn void start_bl31_via_bl_params(void *bl31, void *bl32,
> > +						void *bl33, void *fdt)
> > +{
> > +	unsigned long mem_base = MX8M_DDR_CSD1_BASE_ADDR;
> > +	unsigned long mem_sz;
> > +	unsigned int bufsz = 0;
> > +	int error;
> > +	u8 *buf;
> > +
> > +	if (!fdt)
> > +		bl31_via_bl_params(bl31, bl32, bl33, NULL);
> > +
> > +	buf = imx_scratch_get_fdt(&bufsz);
> > +	if (IS_ERR_OR_NULL(buf)) {
> > +		if (!buf)
> > +			pr_debug("No FDT scratch mem configured, continue without FDT\n");
> > +		else
> > +			pr_warn("Failed to get FDT scratch mem, continue without FDT\n");
> > +		bl31_via_bl_params(bl31, bl32, bl33, NULL);
> > +	}
> > +
> > +	error = pbl_load_fdt(fdt, buf, bufsz);
> > +	if (error) {
> > +		pr_warn("Failed to load FDT, continue without FDT\n");
> > +		bl31_via_bl_params(bl31, bl32, bl33, NULL);
> > +	}
> > +
> > +	if (cpu_is_mx8mn())
> > +		mem_sz = imx8m_ddrc_sdram_size(16);
> > +	else
> > +		mem_sz = imx8m_ddrc_sdram_size(32);
> > +
> > +	fdt = buf;
> > +	error = fdt_fixup_mem(fdt, &mem_base, &mem_sz, 1);
> 
> On rk3588, I noticed that fdt_fixup_mem() adds a significant delay,
> which depends on the size of the device tree, to boot time. Did you
> notice something similar in your tests?

I noticed a delay as well but didn't debugged the root cause yet since
doing a lot of string parsing doesn't come for free. Thanks for the
heads up, that this function is problematic. On the other hand, we need
to do the fixup to keep the DRAM information only encoded within the
lpddr config file.

> Furthermore, if OP-TEE receives a large device tree, it also seems to
> initialize much slower and add further delay to the boot time.

Good to know! I didn't spent to much time for performance analysis
unfortunately.

> I wonder if it may be better to build a custom device tree during the
> initialization that only contains the necessary nodes rather than
> passing the full device tree with some fixups.

But in that case you need to know which DT nodes are important for
$platform. E.g. for i.MX CAAM devices, the CAAM node is interessting
too, since OP-TEE disables the secure OS used jobring nodes. I don't
know if this scales for all SoCs.

That beeing said, currently we pass the DT only to OP-TEE but it could
be used for TF-A use-cases as well. 

I also don't know if building a custom FDT during runtime is less
effort than using the built-in unmodified DT.

It would be great if we shift "creating the minimal DT" to build time.
U-Boot has this "bootph-all" and CONFIG_OF_SPL_REMOVE_PROPS for the SPL.
But U-Boot uses the custom binman tool to heavily manipulate the DTB
after the DTC.

We could also do something fancy like having a minimal DT for the PBL
(no MMU) and later on barebox-proper loads the rest as overlay (MMU on).
This would require that we split the DT into a DT and DTO. A quick
search showed that we could use '/omit-if-no-ref/' feature to build a
minimal pbl DTB. For PBL DTB builds the build-process needs to handle
adding the property accordingly, so a minimal DT is produced and the
user-impact is minimal. I could imagine something like:

/ {
	barebox,pbl-devices {
  		caam = <&phandle_to_caam>;
		emmc = <&sdhci1>;
		eeprom = <&i2c_eeprom>;
	};
};

The build process could:
 1) add the /omit-if-no-ref/ and later on
 2) follows the phandles listed in barebox,pbl-devices and removes the
    property from each parent recursive.

This way we could implement something similar to the U-Boot "bootph-all"
marking but IMHO more user friendly and only relying on DTC.

However, thanks for your reply :) Of course there is room for
improvements, but this shouldn't stop us from merging this since all
current mainline users are not affected (no boot-time regression).

Regards,
  Marco

> 
> Michael
> 
> > +	if (error) {
> > +		pr_warn("Failed to fixup FDT memory node, continue without FDT\n");
> > +		bl31_via_bl_params(bl31, bl32, bl33, NULL);
> > +	}
> > +
> > +	bl31_via_bl_params(bl31, bl32, bl33, fdt);
> > +}
> > +
> >  /**
> >   * imx8m_tfa_start_bl31 - Load TF-A BL31 blob and transfer control to it
> >   *
> > @@ -122,7 +186,21 @@ imx8m_tfa_start_bl31(const void *tfa_bin, size_t tfa_size, void *tfa_dest,
> >  	asm volatile("msr sp_el2, %0" : :
> >  		     "r" (tfa_dest - 16) :
> >  		     "cc");
> > -	bl31();
> > +
> > +	/*
> > +	 * If enabled the bl_params are passed via x0 to the TF-A, except for
> > +	 * the i.MX8MQ which doesn't support bl_params yet.
> > +	 * Passing the bl_params must be explicit enabled to be backward
> > +	 * compatible with downstream TF-A versions, which may have problems
> > +	 * with the bl_params.
> > +	 */
> > +	if (!IS_ENABLED(CONFIG_ARCH_IMX_ATF_PASS_BL_PARAMS) || cpu_is_mx8mq()) {
> > +		pr_debug("Jump to BL31 without bl-params\n");
> > +		bl31();
> > +	} else {
> > +		start_bl31_via_bl_params(bl31, bl32, bl33, fdt);
> > +	}
> > +
> >  	__builtin_unreachable();
> >  }
> 

-- 
#gernperDu 
#CallMeByMyFirstName

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | https://www.pengutronix.de/ |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-9    |



  reply	other threads:[~2026-02-05 22:42 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04 20:01 [PATCH v2 00/15] Improve OP-TEE handling Marco Felsch
2026-02-04 20:01 ` [PATCH v2 01/15] ARM: i.MX8M: add support to pass DT via lowlevel __imx8m*_load_and_start_image_via_tfa() Marco Felsch
2026-02-06  9:04   ` Ahmad Fatoum
2026-02-04 20:01 ` [PATCH v2 02/15] ARM: i.MX8M: move BL32 setup into imx8m_tfa_start_bl31() Marco Felsch
2026-02-04 20:01 ` [PATCH v2 03/15] ARM: i.MX8M: imx8m_tfa_start_bl31() add support for bl33 and fdt Marco Felsch
2026-02-04 20:01 ` [PATCH v2 04/15] pbl: decomp: add pbl_dtbz_uncompress helper Marco Felsch
2026-02-04 20:01 ` [PATCH v2 05/15] pbl: fdt: add pbl_load_fdt helper Marco Felsch
2026-02-06  9:16   ` Ahmad Fatoum
2026-02-04 20:01 ` [PATCH v2 06/15] ARM: i.MX: scratch: add FDT support Marco Felsch
2026-02-06  9:40   ` Ahmad Fatoum
2026-02-06 10:02     ` Marco Felsch
2026-02-06 13:01       ` Ahmad Fatoum
2026-02-09 20:50         ` Marco Felsch
2026-02-09 20:59           ` Ahmad Fatoum
2026-02-10  9:35             ` Marco Felsch
2026-02-10  9:41               ` Ahmad Fatoum
2026-02-04 20:01 ` [PATCH v2 07/15] ARM: i.MX8M: esdctl: drop ddrc base from imx8m_ddrc_sdram_size Marco Felsch
2026-02-04 20:01 ` [PATCH v2 08/15] ARM: i.MX8M: esdctl: export imx8m_ddrc_sdram_size() Marco Felsch
2026-02-04 20:01 ` [PATCH v2 09/15] ARM: i.MX8M: add support to pass BL3x bl_params Marco Felsch
2026-02-05 17:02   ` Michael Tretter
2026-02-05 22:41     ` Marco Felsch [this message]
2026-02-06 10:20       ` Ahmad Fatoum
2026-02-06 13:46         ` Marco Felsch
2026-02-06 11:55   ` Ahmad Fatoum
2026-02-04 20:01 ` [PATCH v2 10/15] handoff-data: Add TEE_DT_OVL entry Marco Felsch
2026-02-06 11:56   ` Ahmad Fatoum
2026-02-04 20:01 ` [PATCH v2 11/15] security: optee: add optee_handoff_overlay helper Marco Felsch
2026-02-06 12:25   ` Ahmad Fatoum
2026-02-09 20:18     ` Marco Felsch
2026-02-04 20:01 ` [PATCH v2 12/15] security: optee: add helpers to register OF overlays Marco Felsch
2026-02-06 12:09   ` Ahmad Fatoum
2026-02-09 20:17     ` Marco Felsch
2026-02-04 20:01 ` [PATCH v2 13/15] ARM: i.MX8M: Pass optional OP-TEE overlay to barebox Marco Felsch
2026-02-06 12:04   ` Ahmad Fatoum
2026-02-04 20:01 ` [PATCH v2 14/15] of: base: register optional OP-TEE overlay Marco Felsch
2026-02-06 12:05   ` Ahmad Fatoum
2026-02-06 13:24     ` Marco Felsch
2026-02-04 20:01 ` [PATCH v2 15/15] handoff-data: add missing include Marco Felsch
2026-02-06 12:07   ` 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=20260205224130.pe2fzkyvnuqwwkhu@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=m.tretter@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