mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/4] ARM: i.MX8M: add option to install OP-TEE
Date: Thu, 9 Mar 2023 12:04:27 +0100	[thread overview]
Message-ID: <20230309110427.GE5784@pengutronix.de> (raw)
In-Reply-To: <20230307093426.1551193-1-a.fatoum@pengutronix.de>

On Tue, Mar 07, 2023 at 10:34:23AM +0100, Ahmad Fatoum wrote:
> While infrastructure for installing OP-TEE was already there, no
> upstream boards made use of it. Let's have OP-TEE installation happen in
> generic code, so it may be enabled for any upstream board.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  arch/arm/mach-imx/atf.c                | 50 ++++++++++++++++++++------
>  arch/arm/mach-imx/include/mach/xload.h | 16 +++++++++
>  firmware/.gitignore                    |  1 +
>  firmware/Kconfig                       | 12 +++++++
>  firmware/Makefile                      |  9 +++--
>  5 files changed, 74 insertions(+), 14 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
> index 2a3e3f53b885..640881afaaca 100644
> --- a/arch/arm/mach-imx/atf.c
> +++ b/arch/arm/mach-imx/atf.c
> @@ -7,6 +7,9 @@
>  #include <mach/generic.h>
>  #include <mach/xload.h>
>  #include <mach/romapi.h>
> +#include <mach/esdctl.h>
> +#include <asm-generic/memory_layout.h>
> +#include <asm/barebox-arm.h>
>  #include <soc/fsl/fsl_udc.h>
>  #include <soc/fsl/caam.h>
>  
> @@ -133,9 +136,17 @@ void imx8mm_load_bl33(void *bl33)
>  
>  __noreturn void imx8mm_load_and_start_image_via_tfa(void)
>  {
> -	imx8mm_save_bootrom_log();
> -	imx8mm_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
> -	imx8mm_load_and_start_tfa(imx8mm_bl31_bin);
> +	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
> +	void *endmem = (void *)MX8M_DDR_CSD1_BASE_ADDR +
> +		imx8m_barebox_earlymem_size(32);
> +
> +	imx8m_save_bootrom_log(__arm_mem_scratch(endmem));
> +	imx8mm_load_bl33(bl33);
> +
> +	if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MM_OPTEE))
> +		imx8m_load_and_start_optee_via_tfa(imx8mm, endmem - OPTEE_SIZE, bl33);
> +	else
> +		imx8mm_load_and_start_tfa(imx8mm_bl31_bin);
>  }
>  
>  void imx8mp_load_bl33(void *bl33)
> @@ -168,13 +179,22 @@ void imx8mp_load_bl33(void *bl33)
>  	memcpy(bl33, __image_start, barebox_pbl_size);
>  }
>  
> -void imx8mp_load_and_start_image_via_tfa(void)
> +__noreturn void imx8mp_load_and_start_image_via_tfa(void)
>  {
> -	imx8mp_save_bootrom_log();
> -	imx8mp_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
> -	imx8mp_load_and_start_tfa(imx8mp_bl31_bin);
> +	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
> +	void *endmem = (void *)MX8M_DDR_CSD1_BASE_ADDR +
> +		imx8m_barebox_earlymem_size(32);
> +
> +	imx8m_save_bootrom_log(__arm_mem_scratch(endmem));
> +	imx8mp_load_bl33(bl33);
> +
> +	if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MP_OPTEE))
> +		imx8m_load_and_start_optee_via_tfa(imx8mp, endmem - OPTEE_SIZE, bl33);
> +	else
> +		imx8mp_load_and_start_tfa(imx8mp_bl31_bin);
>  }
>  
> +
>  void imx8mn_load_bl33(void *bl33)
>  {
>  	enum bootsource src;
> @@ -205,9 +225,17 @@ void imx8mn_load_bl33(void *bl33)
>  	memcpy(bl33, __image_start, barebox_pbl_size);
>  }
>  
> -void imx8mn_load_and_start_image_via_tfa(void)
> +__noreturn void imx8mn_load_and_start_image_via_tfa(void)
>  {
> -	imx8mn_save_bootrom_log();
> -	imx8mn_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
> -	imx8mn_load_and_start_tfa(imx8mn_bl31_bin);
> +	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
> +	void *endmem = (void *)MX8M_DDR_CSD1_BASE_ADDR +
> +		imx8m_barebox_earlymem_size(16);
> +
> +	imx8m_save_bootrom_log(__arm_mem_scratch(endmem));
> +	imx8mn_load_bl33(bl33);
> +
> +	if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MN_OPTEE))
> +		imx8m_load_and_start_optee_via_tfa(imx8mn, endmem - OPTEE_SIZE, bl33);
> +	else
> +		imx8mn_load_and_start_tfa(imx8mn_bl31_bin);
>  }
> diff --git a/arch/arm/mach-imx/include/mach/xload.h b/arch/arm/mach-imx/include/mach/xload.h
> index aa2fa5129a11..713fc1a8fcb7 100644
> --- a/arch/arm/mach-imx/include/mach/xload.h
> +++ b/arch/arm/mach-imx/include/mach/xload.h
> @@ -5,6 +5,7 @@
>  
>  #include <linux/compiler.h>
>  #include <linux/types.h>
> +#include <mach/tzasc.h>
>  
>  int imx53_nand_start_image(void);
>  int imx6_spi_load_image(int instance, unsigned int flash_offset, void *buf, int len);
> @@ -42,4 +43,19 @@ struct imx_scratch_space *__imx8m_scratch_space(int ddr_buswidth);
>  #define imx8mn_scratch_space() __imx8m_scratch_space(16)
>  #define imx8mp_scratch_space() __imx8m_scratch_space(32)
>  
> +#define imx8m_load_and_start_optee_via_tfa(soc, bl32, bl33)	\
> +do {								\
> +	size_t bl32_size;					\
> +	void *bl32_image;					\
> +								\
> +	soc##_tzc380_init();					\
> +	get_builtin_firmware_ext(soc##_bl32_bin,		\
> +				 bl33, &bl32_image,		\
> +				 &bl32_size);			\
> +								\
> +	memcpy(bl32, bl32_image, bl32_size);			\
> +								\
> +	soc##_load_and_start_tfa(soc##_bl31_bin_optee);		\
> +} while (0)
> +
>  #endif /* __MACH_XLOAD_H */
> diff --git a/firmware/.gitignore b/firmware/.gitignore
> index 4f3e56d8b719..8f9a956eb661 100644
> --- a/firmware/.gitignore
> +++ b/firmware/.gitignore
> @@ -1,3 +1,4 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  
>  *.bin
> +*.bin-optee
> diff --git a/firmware/Kconfig b/firmware/Kconfig
> index 1a5e1bf5142a..a12a8f304476 100644
> --- a/firmware/Kconfig
> +++ b/firmware/Kconfig
> @@ -24,6 +24,18 @@ config FIRMWARE_IMX8MP_ATF
>  config FIRMWARE_IMX8MQ_ATF
>  	bool
>  
> +config FIRMWARE_IMX8MM_OPTEE
> +	bool "install OP-TEE on i.MX8MM boards"
> +	depends on FIRMWARE_IMX8MM_ATF && PBL_OPTEE
> +
> +config FIRMWARE_IMX8MN_OPTEE
> +	bool "install OP-TEE on i.MX8MN boards"
> +	depends on FIRMWARE_IMX8MN_ATF && PBL_OPTEE
> +
> +config FIRMWARE_IMX8MP_OPTEE
> +	bool "install OP-TEE on i.MX8MP boards"
> +	depends on FIRMWARE_IMX8MP_ATF && PBL_OPTEE
> +
>  config FIRMWARE_CCBV2_OPTEE
>  	bool
>  	depends on MACH_WEBASTO_CCBV2 && PBL_OPTEE
> diff --git a/firmware/Makefile b/firmware/Makefile
> index da341871d681..984192f030bb 100644
> --- a/firmware/Makefile
> +++ b/firmware/Makefile
> @@ -12,10 +12,13 @@ firmware-$(CONFIG_FIRMWARE_IMX_DDR4_PMU_TRAIN) += \
>  	ddr4_imem_1d.bin \
>  	ddr4_imem_2d.bin
>  
> -firmware-$(CONFIG_FIRMWARE_IMX8MM_ATF) += imx8mm-bl31.bin
> -firmware-$(CONFIG_FIRMWARE_IMX8MN_ATF) += imx8mn-bl31.bin
> -firmware-$(CONFIG_FIRMWARE_IMX8MP_ATF) += imx8mp-bl31.bin
> +firmware-$(CONFIG_FIRMWARE_IMX8MM_ATF) += imx8mm-bl31.bin$(if $(CONFIG_FIRMWARE_IMX8MM_OPTEE),-optee,)
> +firmware-$(CONFIG_FIRMWARE_IMX8MN_ATF) += imx8mn-bl31.bin$(if $(CONFIG_FIRMWARE_IMX8MN_OPTEE),-optee,)
> +firmware-$(CONFIG_FIRMWARE_IMX8MP_ATF) += imx8mp-bl31.bin$(if $(CONFIG_FIRMWARE_IMX8MP_OPTEE),-optee,)
>  firmware-$(CONFIG_FIRMWARE_IMX8MQ_ATF) += imx8mq-bl31.bin
> +fw-external-$(CONFIG_FIRMWARE_IMX8MM_OPTEE) += imx8mm-bl32.bin
> +fw-external-$(CONFIG_FIRMWARE_IMX8MN_OPTEE) += imx8mn-bl32.bin
> +fw-external-$(CONFIG_FIRMWARE_IMX8MP_OPTEE) += imx8mp-bl32.bin
>  firmware-$(CONFIG_ARCH_RK3568) += rk3568-bl31.bin
>  firmware-$(CONFIG_ARCH_RK3568_OPTEE) += rk3568-op-tee.bin
>  firmware-$(CONFIG_ARCH_RK3399) += rk3399-bl31.bin
> -- 
> 2.30.2
> 
> 
> 

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



      parent reply	other threads:[~2023-03-09 11:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07  9:34 Ahmad Fatoum
2023-03-07  9:34 ` [PATCH 2/4] drivers: implement of_optee_fixup helper function Ahmad Fatoum
2023-03-07  9:34 ` [PATCH 3/4] ARM: i.MX8M: fixup op-tee nodes Ahmad Fatoum
2023-03-07  9:34 ` [PATCH 4/4] drivers: drop unneeded CONFIG_CRYPTO_HW guard Ahmad Fatoum
2023-03-09 11:04 ` Sascha Hauer [this message]

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=20230309110427.GE5784@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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