mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: i.MX8MM: Consolidate common code to load image and jump to it via TF-A
@ 2022-07-06  8:12 Uwe Kleine-König
  2022-07-06 12:01 ` Marco Felsch
  2022-07-11 10:51 ` Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2022-07-06  8:12 UTC (permalink / raw)
  To: barebox; +Cc: David Jander

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/boards/nxp-imx8mm-evk/lowlevel.c     | 41 +----------------
 .../boards/protonic-imx8m/lowlevel-prt8mm.c   | 35 +--------------
 arch/arm/mach-imx/atf.c                       | 44 +++++++++++++++++++
 include/soc/imx8m.h                           |  8 ++++
 4 files changed, 56 insertions(+), 72 deletions(-)
 create mode 100644 include/soc/imx8m.h

diff --git a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
index c2f6206cfd8e..d67bc157e261 100644
--- a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
@@ -3,24 +3,20 @@
 #include <io.h>
 #include <common.h>
 #include <debug_ll.h>
-#include <firmware.h>
 #include <asm/mmu.h>
 #include <asm/cache.h>
-#include <asm/sections.h>
 #include <asm/barebox-arm.h>
 #include <asm/barebox-arm-head.h>
 #include <i2c/i2c-early.h>
 #include <linux/sizes.h>
-#include <mach/atf.h>
-#include <mach/xload.h>
 #include <mach/esdctl.h>
 #include <mach/generic.h>
 #include <mach/imx8mm-regs.h>
 #include <mach/iomux-mx8mm.h>
 #include <mach/imx8m-ccm-regs.h>
 #include <mfd/bd71837.h>
+#include <soc/imx8m.h>
 #include <soc/imx8m/ddr.h>
-#include <soc/fsl/fsl_udc.h>
 #include <image-metadata.h>
 
 extern char __dtb_imx8mm_evk_start[];
@@ -96,11 +92,6 @@ extern struct dram_timing_info imx8mm_evk_dram_timing;
 
 static void start_atf(void)
 {
-	size_t bl31_size;
-	const u8 *bl31;
-	enum bootsource src;
-	int instance;
-
 	/*
 	 * If we are in EL3 we are running for the first time and need to
 	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
@@ -112,35 +103,7 @@ static void start_atf(void)
 	power_init_board();
 	imx8mm_ddr_init(&imx8mm_evk_dram_timing);
 
-	imx8mm_get_boot_source(&src, &instance);
-	switch (src) {
-	case BOOTSOURCE_MMC:
-		imx8m_esdhc_load_image(instance, false);
-		break;
-	case BOOTSOURCE_SERIAL:
-		imx8mm_barebox_load_usb((void *)MX8M_ATF_BL33_BASE_ADDR);
-	break;
-	default:
-		printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
-		hang();
-	}
-
-	/*
-	 * On completion the TF-A will jump to MX8M_ATF_BL33_BASE_ADDR
-	 * in EL2. Copy the image there, but replace the PBL part of
-	 * that image with ourselves. On a high assurance boot only the
-	 * currently running code is validated and contains the checksum
-	 * for the piggy data, so we need to ensure that we are running
-	 * the same code in DRAM.
-	 */
-	memcpy((void *)MX8M_ATF_BL33_BASE_ADDR,
-	       __image_start, barebox_pbl_size);
-
-	get_builtin_firmware(imx8mm_bl31_bin, &bl31, &bl31_size);
-
-	imx8mm_atf_load_bl31(bl31, bl31_size);
-
-	/* not reached */
+	imx8mm_load_and_start_image_via_tfa();
 }
 
 /*
diff --git a/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c b/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
index 24d98fe6c993..95d062d0b575 100644
--- a/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
+++ b/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
@@ -14,6 +14,7 @@
 #include <mach/xload.h>
 #include <soc/fsl/fsl_udc.h>
 #include <soc/imx8m/ddr.h>
+#include <soc/imx8m.h>
 
 extern char __dtb_imx8mm_prt8mm_start[];
 
@@ -37,11 +38,6 @@ extern struct dram_timing_info prt8mm_dram_timing;
 
 static void start_atf(void)
 {
-	size_t bl31_size;
-	const u8 *bl31;
-	enum bootsource src;
-	int instance;
-
 	/*
 	 * If we are in EL3 we are running for the first time and need to
 	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
@@ -54,34 +50,7 @@ static void start_atf(void)
 
 	imx8mm_ddr_init(&prt8mm_dram_timing);
 
-	imx8mm_get_boot_source(&src, &instance);
-	switch (src) {
-	case BOOTSOURCE_MMC:
-		imx8m_esdhc_load_image(instance, false);
-		break;
-	case BOOTSOURCE_SERIAL:
-		imx8mm_barebox_load_usb((void *)MX8M_ATF_BL33_BASE_ADDR);
-		break;
-	default:
-		printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
-		hang();
-	}
-
-	/*
-	 * On completion the TF-A will jump to MX8M_ATF_BL33_BASE_ADDR
-	 * in EL2. Copy the image there, but replace the PBL part of
-	 * that image with ourselves. On a high assurance boot only the
-	 * currently running code is validated and contains the checksum
-	 * for the piggy data, so we need to ensure that we are running
-	 * the same code in DRAM.
-	 */
-	memcpy((void *)MX8MM_ATF_BL33_BASE_ADDR,
-	       __image_start, barebox_pbl_size);
-
-	get_builtin_firmware(imx8mm_bl31_bin, &bl31, &bl31_size);
-	imx8mm_atf_load_bl31(bl31, bl31_size);
-
-	/* not reached */
+	imx8mm_load_and_start_image_via_tfa();
 }
 
 /*
diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
index 9ab9ddd20385..709620e5df26 100644
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -1,7 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#include <asm/sections.h>
 #include <common.h>
+#include <firmware.h>
 #include <mach/atf.h>
+#include <mach/generic.h>
+#include <mach/xload.h>
+#include <soc/imx8m.h>
+#include <soc/fsl/fsl_udc.h>
 
 /**
  * imx8m_atf_load_bl31 - Load ATF BL31 blob and transfer control to it
@@ -63,3 +69,41 @@ void imx8mq_atf_load_bl31(const void *fw, size_t fw_size)
 {
 	imx8m_atf_load_bl31(fw, fw_size, (void *)MX8MQ_ATF_BL31_BASE_ADDR);
 }
+
+void imx8mm_load_and_start_image_via_tfa(void)
+{
+	size_t bl31_size;
+	const u8 *bl31;
+	enum bootsource src;
+	int instance;
+
+	imx8mm_get_boot_source(&src, &instance);
+	switch (src) {
+	case BOOTSOURCE_MMC:
+		imx8m_esdhc_load_image(instance, false);
+		break;
+	case BOOTSOURCE_SERIAL:
+		imx8mm_barebox_load_usb((void *)MX8M_ATF_BL33_BASE_ADDR);
+		break;
+	default:
+		printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
+		hang();
+	}
+
+	/*
+	 * On completion the TF-A will jump to MX8M_ATF_BL33_BASE_ADDR
+	 * in EL2. Copy the image there, but replace the PBL part of
+	 * that image with ourselves. On a high assurance boot only the
+	 * currently running code is validated and contains the checksum
+	 * for the piggy data, so we need to ensure that we are running
+	 * the same code in DRAM.
+	 */
+	memcpy((void *)MX8M_ATF_BL33_BASE_ADDR,
+	       __image_start, barebox_pbl_size);
+
+	get_builtin_firmware(imx8mm_bl31_bin, &bl31, &bl31_size);
+
+	imx8mm_atf_load_bl31(bl31, bl31_size);
+
+	/* not reached */
+}
diff --git a/include/soc/imx8m.h b/include/soc/imx8m.h
new file mode 100644
index 000000000000..03b9b59b0b44
--- /dev/null
+++ b/include/soc/imx8m.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __MACH_IMX8M_H__
+#define __MACH_IMX8M_H__
+
+void imx8mm_load_and_start_image_via_tfa(void);
+
+#endif
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ARM: i.MX8MM: Consolidate common code to load image and jump to it via TF-A
  2022-07-06  8:12 [PATCH] ARM: i.MX8MM: Consolidate common code to load image and jump to it via TF-A Uwe Kleine-König
@ 2022-07-06 12:01 ` Marco Felsch
  2022-07-06 14:48   ` Uwe Kleine-König
  2022-07-11 10:51 ` Sascha Hauer
  1 sibling, 1 reply; 4+ messages in thread
From: Marco Felsch @ 2022-07-06 12:01 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox, David Jander

Hi Uwe,

thanks for the patch.

On 22-07-06, Uwe Kleine-König wrote:

...

> @@ -96,11 +92,6 @@ extern struct dram_timing_info imx8mm_evk_dram_timing;
>  
>  static void start_atf(void)
>  {
> -	size_t bl31_size;
> -	const u8 *bl31;
> -	enum bootsource src;
> -	int instance;
> -
>  	/*
>  	 * If we are in EL3 we are running for the first time and need to
>  	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
> @@ -112,35 +103,7 @@ static void start_atf(void)
>  	power_init_board();
>  	imx8mm_ddr_init(&imx8mm_evk_dram_timing);

I would move the imx8mm_ddr_init() into your helper
imx8mm_load_and_start_image_via_tfa() and pass the timing as argument.
So your helper doesn't depend on the 'hopefully' intialized DRAM. Else I
would add a comment above your helper, that the DRAM must be initialized
before calling this function.

Regards,
  Marco



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ARM: i.MX8MM: Consolidate common code to load image and jump to it via TF-A
  2022-07-06 12:01 ` Marco Felsch
@ 2022-07-06 14:48   ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2022-07-06 14:48 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox, David Jander

[-- Attachment #1: Type: text/plain, Size: 1633 bytes --]

On Wed, Jul 06, 2022 at 02:01:35PM +0200, Marco Felsch wrote:
> Hi Uwe,
> 
> thanks for the patch.
> 
> On 22-07-06, Uwe Kleine-König wrote:
> 
> ...
> 
> > @@ -96,11 +92,6 @@ extern struct dram_timing_info imx8mm_evk_dram_timing;
> >  
> >  static void start_atf(void)
> >  {
> > -	size_t bl31_size;
> > -	const u8 *bl31;
> > -	enum bootsource src;
> > -	int instance;
> > -
> >  	/*
> >  	 * If we are in EL3 we are running for the first time and need to
> >  	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
> > @@ -112,35 +103,7 @@ static void start_atf(void)
> >  	power_init_board();
> >  	imx8mm_ddr_init(&imx8mm_evk_dram_timing);
> 
> I would move the imx8mm_ddr_init() into your helper
> imx8mm_load_and_start_image_via_tfa() and pass the timing as argument.

I thought about that, but didn't find a nice function name for that.
imx8mm_ddr_init_load_and_start_image_via_tfa_prepare_coffee() is a bit
long ... :-) Also while these things are "normal" in this order in the
PBL board code, mixing too many things in a single function isn't only
advantageous. I like it to have memory initialisation and image loading
in separate steps---my subjective view.

> So your helper doesn't depend on the 'hopefully' intialized DRAM. Else I
> would add a comment above your helper, that the DRAM must be initialized
> before calling this function.

Several functions depend on initialized DRAM.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ARM: i.MX8MM: Consolidate common code to load image and jump to it via TF-A
  2022-07-06  8:12 [PATCH] ARM: i.MX8MM: Consolidate common code to load image and jump to it via TF-A Uwe Kleine-König
  2022-07-06 12:01 ` Marco Felsch
@ 2022-07-11 10:51 ` Sascha Hauer
  1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2022-07-11 10:51 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox, David Jander

On Wed, Jul 06, 2022 at 10:12:36AM +0200, Uwe Kleine-König wrote:
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  arch/arm/boards/nxp-imx8mm-evk/lowlevel.c     | 41 +----------------
>  .../boards/protonic-imx8m/lowlevel-prt8mm.c   | 35 +--------------
>  arch/arm/mach-imx/atf.c                       | 44 +++++++++++++++++++
>  include/soc/imx8m.h                           |  8 ++++
>  4 files changed, 56 insertions(+), 72 deletions(-)
>  create mode 100644 include/soc/imx8m.h

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
> index c2f6206cfd8e..d67bc157e261 100644
> --- a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
> +++ b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
> @@ -3,24 +3,20 @@
>  #include <io.h>
>  #include <common.h>
>  #include <debug_ll.h>
> -#include <firmware.h>
>  #include <asm/mmu.h>
>  #include <asm/cache.h>
> -#include <asm/sections.h>
>  #include <asm/barebox-arm.h>
>  #include <asm/barebox-arm-head.h>
>  #include <i2c/i2c-early.h>
>  #include <linux/sizes.h>
> -#include <mach/atf.h>
> -#include <mach/xload.h>
>  #include <mach/esdctl.h>
>  #include <mach/generic.h>
>  #include <mach/imx8mm-regs.h>
>  #include <mach/iomux-mx8mm.h>
>  #include <mach/imx8m-ccm-regs.h>
>  #include <mfd/bd71837.h>
> +#include <soc/imx8m.h>
>  #include <soc/imx8m/ddr.h>
> -#include <soc/fsl/fsl_udc.h>
>  #include <image-metadata.h>
>  
>  extern char __dtb_imx8mm_evk_start[];
> @@ -96,11 +92,6 @@ extern struct dram_timing_info imx8mm_evk_dram_timing;
>  
>  static void start_atf(void)
>  {
> -	size_t bl31_size;
> -	const u8 *bl31;
> -	enum bootsource src;
> -	int instance;
> -
>  	/*
>  	 * If we are in EL3 we are running for the first time and need to
>  	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
> @@ -112,35 +103,7 @@ static void start_atf(void)
>  	power_init_board();
>  	imx8mm_ddr_init(&imx8mm_evk_dram_timing);
>  
> -	imx8mm_get_boot_source(&src, &instance);
> -	switch (src) {
> -	case BOOTSOURCE_MMC:
> -		imx8m_esdhc_load_image(instance, false);
> -		break;
> -	case BOOTSOURCE_SERIAL:
> -		imx8mm_barebox_load_usb((void *)MX8M_ATF_BL33_BASE_ADDR);
> -	break;
> -	default:
> -		printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
> -		hang();
> -	}
> -
> -	/*
> -	 * On completion the TF-A will jump to MX8M_ATF_BL33_BASE_ADDR
> -	 * in EL2. Copy the image there, but replace the PBL part of
> -	 * that image with ourselves. On a high assurance boot only the
> -	 * currently running code is validated and contains the checksum
> -	 * for the piggy data, so we need to ensure that we are running
> -	 * the same code in DRAM.
> -	 */
> -	memcpy((void *)MX8M_ATF_BL33_BASE_ADDR,
> -	       __image_start, barebox_pbl_size);
> -
> -	get_builtin_firmware(imx8mm_bl31_bin, &bl31, &bl31_size);
> -
> -	imx8mm_atf_load_bl31(bl31, bl31_size);
> -
> -	/* not reached */
> +	imx8mm_load_and_start_image_via_tfa();
>  }
>  
>  /*
> diff --git a/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c b/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
> index 24d98fe6c993..95d062d0b575 100644
> --- a/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
> +++ b/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
> @@ -14,6 +14,7 @@
>  #include <mach/xload.h>
>  #include <soc/fsl/fsl_udc.h>
>  #include <soc/imx8m/ddr.h>
> +#include <soc/imx8m.h>
>  
>  extern char __dtb_imx8mm_prt8mm_start[];
>  
> @@ -37,11 +38,6 @@ extern struct dram_timing_info prt8mm_dram_timing;
>  
>  static void start_atf(void)
>  {
> -	size_t bl31_size;
> -	const u8 *bl31;
> -	enum bootsource src;
> -	int instance;
> -
>  	/*
>  	 * If we are in EL3 we are running for the first time and need to
>  	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
> @@ -54,34 +50,7 @@ static void start_atf(void)
>  
>  	imx8mm_ddr_init(&prt8mm_dram_timing);
>  
> -	imx8mm_get_boot_source(&src, &instance);
> -	switch (src) {
> -	case BOOTSOURCE_MMC:
> -		imx8m_esdhc_load_image(instance, false);
> -		break;
> -	case BOOTSOURCE_SERIAL:
> -		imx8mm_barebox_load_usb((void *)MX8M_ATF_BL33_BASE_ADDR);
> -		break;
> -	default:
> -		printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
> -		hang();
> -	}
> -
> -	/*
> -	 * On completion the TF-A will jump to MX8M_ATF_BL33_BASE_ADDR
> -	 * in EL2. Copy the image there, but replace the PBL part of
> -	 * that image with ourselves. On a high assurance boot only the
> -	 * currently running code is validated and contains the checksum
> -	 * for the piggy data, so we need to ensure that we are running
> -	 * the same code in DRAM.
> -	 */
> -	memcpy((void *)MX8MM_ATF_BL33_BASE_ADDR,
> -	       __image_start, barebox_pbl_size);
> -
> -	get_builtin_firmware(imx8mm_bl31_bin, &bl31, &bl31_size);
> -	imx8mm_atf_load_bl31(bl31, bl31_size);
> -
> -	/* not reached */
> +	imx8mm_load_and_start_image_via_tfa();
>  }
>  
>  /*
> diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
> index 9ab9ddd20385..709620e5df26 100644
> --- a/arch/arm/mach-imx/atf.c
> +++ b/arch/arm/mach-imx/atf.c
> @@ -1,7 +1,13 @@
>  // SPDX-License-Identifier: GPL-2.0-only
>  
> +#include <asm/sections.h>
>  #include <common.h>
> +#include <firmware.h>
>  #include <mach/atf.h>
> +#include <mach/generic.h>
> +#include <mach/xload.h>
> +#include <soc/imx8m.h>
> +#include <soc/fsl/fsl_udc.h>
>  
>  /**
>   * imx8m_atf_load_bl31 - Load ATF BL31 blob and transfer control to it
> @@ -63,3 +69,41 @@ void imx8mq_atf_load_bl31(const void *fw, size_t fw_size)
>  {
>  	imx8m_atf_load_bl31(fw, fw_size, (void *)MX8MQ_ATF_BL31_BASE_ADDR);
>  }
> +
> +void imx8mm_load_and_start_image_via_tfa(void)
> +{
> +	size_t bl31_size;
> +	const u8 *bl31;
> +	enum bootsource src;
> +	int instance;
> +
> +	imx8mm_get_boot_source(&src, &instance);
> +	switch (src) {
> +	case BOOTSOURCE_MMC:
> +		imx8m_esdhc_load_image(instance, false);
> +		break;
> +	case BOOTSOURCE_SERIAL:
> +		imx8mm_barebox_load_usb((void *)MX8M_ATF_BL33_BASE_ADDR);
> +		break;
> +	default:
> +		printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
> +		hang();
> +	}
> +
> +	/*
> +	 * On completion the TF-A will jump to MX8M_ATF_BL33_BASE_ADDR
> +	 * in EL2. Copy the image there, but replace the PBL part of
> +	 * that image with ourselves. On a high assurance boot only the
> +	 * currently running code is validated and contains the checksum
> +	 * for the piggy data, so we need to ensure that we are running
> +	 * the same code in DRAM.
> +	 */
> +	memcpy((void *)MX8M_ATF_BL33_BASE_ADDR,
> +	       __image_start, barebox_pbl_size);
> +
> +	get_builtin_firmware(imx8mm_bl31_bin, &bl31, &bl31_size);
> +
> +	imx8mm_atf_load_bl31(bl31, bl31_size);
> +
> +	/* not reached */
> +}
> diff --git a/include/soc/imx8m.h b/include/soc/imx8m.h
> new file mode 100644
> index 000000000000..03b9b59b0b44
> --- /dev/null
> +++ b/include/soc/imx8m.h
> @@ -0,0 +1,8 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef __MACH_IMX8M_H__
> +#define __MACH_IMX8M_H__
> +
> +void imx8mm_load_and_start_image_via_tfa(void);
> +
> +#endif
> -- 
> 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 |



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-11 10:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06  8:12 [PATCH] ARM: i.MX8MM: Consolidate common code to load image and jump to it via TF-A Uwe Kleine-König
2022-07-06 12:01 ` Marco Felsch
2022-07-06 14:48   ` Uwe Kleine-König
2022-07-11 10:51 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox