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

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Jun 27 08:33:19 PDT 2025


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

> +
>  void imx8m_tzc380_init(void)
>  {
>  	u32 __iomem *gpr = IOMEM(MX8M_IOMUXC_GPR_BASE_ADDR);
> diff --git a/include/mach/imx/tzasc.h b/include/mach/imx/tzasc.h
> index 0fbcdc2150e63864366a8dddeed2d1b97685903d..ca85704a8f459ab6e0cdc975940d855929f3d6f7 100644
> --- a/include/mach/imx/tzasc.h
> +++ b/include/mach/imx/tzasc.h
> @@ -10,6 +10,7 @@ void imx6q_tzc380_early_ns_region1(void);
>  void imx6ul_tzc380_early_ns_region1(void);
>  bool imx6q_tzc380_is_bypassed(void);
>  bool imx6ul_tzc380_is_bypassed(void);
> +bool imx6_can_access_tzasc(void);
>  void imx8m_tzc380_init(void);
>  bool imx8m_tzc380_is_enabled(void);
>  
> 

-- 
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