[PATCH 09/14] ARM: i.MX: add imx6_can_access_tzasc()

Sascha Hauer s.hauer at pengutronix.de
Fri Jun 27 10:39:13 PDT 2025


On Fri, Jun 27, 2025 at 05:33:19PM +0200, Ahmad Fatoum wrote:
> On 6/27/25 16:07, Sascha Hauer wrote:
> > On ARMv7 there is no direct way to detect if we are in the secure or non
> > secure world. Add a imx6_can_access_tzasc() for this purpose. When
> > accessing the TZASC triggers a data abort then we are in the non secure
> > world. This function can be used later to detect if we have to load
> > OP-TEE or not.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  arch/arm/mach-imx/tzasc.c | 16 ++++++++++++++++
> >  include/mach/imx/tzasc.h  |  1 +
> >  2 files changed, 17 insertions(+)
> > 
> > diff --git a/arch/arm/mach-imx/tzasc.c b/arch/arm/mach-imx/tzasc.c
> > index ed20ad8803a2e91b67b5d8c3ab1a4265c4228ec7..63f01cbaa6d4a8fbf47b9683ca840ee64f908cfc 100644
> > --- a/arch/arm/mach-imx/tzasc.c
> > +++ b/arch/arm/mach-imx/tzasc.c
> > @@ -13,6 +13,8 @@
> >  #include <linux/sizes.h>
> >  #include <mach/imx/imx8m-regs.h>
> >  #include <io.h>
> > +#include <abort.h>
> > +#include <asm/barebox-arm.h>
> >  
> >  /*******************************************************************************
> >   *                         TZC380 defines
> > @@ -329,6 +331,20 @@ bool imx6ul_tzc380_is_bypassed(void)
> >  	return !(readl(&gpr[9]) & MX6_GPR_TZASC1_EN);
> >  }
> >  
> 
> How about dropping the panic and just failing the build:
> 
> #ifdef CONFIG_ARM_EXCEPTIONS_PBL
> 
> > +bool imx6_can_access_tzasc(void)
> > +{
> > +	if (!IS_ENABLED(CONFIG_ARM_EXCEPTIONS_PBL))
> > +		panic("%s only works with CONFIG_ARM_EXCEPTIONS_PBL\n", __func__);
> > +
> > +	arm_pbl_init_exceptions();
> > +
> > +	data_abort_mask();
> > +
> > +	readl(IOMEM(MX6_TZASC1_BASE));
> > +
> > +	return !data_abort_unmask();
> > +}
> 
> #else
> 
> bool imx6_can_access_tzasc(void)
> 	__compiletime_error("function called without CONFIG_ARM_EXCEPTIONS_PBL ");
> 
> #endif

At the moment tzasc.c is obj-y, so failing the build would make
CONFIG_ARM_EXCEPTIONS_PBL mandatory for i.MX.

We could introduce a config symbol for the TZASC code and select
CONFIG_ARM_EXCEPTIONS_PBL from there.

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