On Wed, Jul 06, 2022 at 10:12:36AM +0200, Uwe Kleine-König wrote:
> Signed-off-by: Uwe Kleine-König <u.kleine-koe...@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 |

Reply via email to