From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 16/18] ARM: i.MX8M: allow board code to configure the bl33 loadaddr
Date: Tue, 16 Jan 2024 18:07:36 +0100 [thread overview]
Message-ID: <20240116170738.209954-17-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20240116170738.209954-1-m.felsch@pengutronix.de>
At an helper to load_and_start the image on arbitrary load addresses.
This should be taken with caution since it requires to configure the
TF-A correctly as well, therefore the functions are prefixt with '__'.
One use case of the new helper is to place OP-TEE at the very beginning
of the DRAM and barebox afterwards e.g. if multiple DRAM setups are
required for the platform/som-family.
A nice side effect of this change is to bundle the usage of
MX8M*_ATF_BL33_BASE_ADDR at a single place.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
arch/arm/mach-imx/atf.c | 42 +++++++++++++++++++++++-----------
arch/arm/mach-imx/romapi.c | 15 ++++++------
arch/arm/mach-imx/xload-qspi.c | 14 ++++++------
drivers/mci/imx-esdhc-pbl.c | 12 ++++++----
include/mach/imx/romapi.h | 4 ++--
include/mach/imx/xload.h | 17 +++++++++-----
6 files changed, 63 insertions(+), 41 deletions(-)
diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
index d7698b397f47..f5b62d24ebeb 100644
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -66,7 +66,7 @@ void imx8mm_load_bl33(void *bl33)
imx8mm_get_boot_source(&src, &instance);
switch (src) {
case BOOTSOURCE_MMC:
- imx8m_esdhc_load_image(instance);
+ imx8m_esdhc_load_image(instance, bl33);
break;
case BOOTSOURCE_SERIAL:
if (!IS_ENABLED(CONFIG_USB_GADGET_DRIVER_ARC_PBL)) {
@@ -99,7 +99,7 @@ void imx8mm_load_bl33(void *bl33)
break;
case BOOTSOURCE_SPI:
- imx8mm_qspi_load_image(instance);
+ imx8mm_qspi_load_image(instance, bl33);
break;
default:
printf("Unsupported bootsource BOOTSOURCE_%d\n", src);
@@ -136,10 +136,14 @@ static void imx_adjust_optee_memory(void **bl32, void **bl32_image, size_t *bl32
}
__noreturn void imx8mm_load_and_start_image_via_tfa(void)
+{
+ __imx8mm_load_and_start_image_via_tfa((void *)MX8M_ATF_BL33_BASE_ADDR);
+}
+
+__noreturn void __imx8mm_load_and_start_image_via_tfa(void *bl33)
{
const void *bl31;
size_t bl31_size;
- void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(32);
imx8mm_init_scratch_space();
@@ -176,13 +180,13 @@ void imx8mp_load_bl33(void *bl33)
imx8mp_get_boot_source(&src, &instance);
switch (src) {
case BOOTSOURCE_MMC:
- imx8mp_esdhc_load_image(instance);
+ imx8mp_esdhc_load_image(instance, bl33);
break;
case BOOTSOURCE_SERIAL:
- imx8mp_romapi_load_image();
+ imx8mp_romapi_load_image(bl33);
break;
case BOOTSOURCE_SPI:
- imx8mp_qspi_load_image(instance);
+ imx8mp_qspi_load_image(instance, bl33);
break;
default:
printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
@@ -202,10 +206,14 @@ void imx8mp_load_bl33(void *bl33)
}
__noreturn void imx8mp_load_and_start_image_via_tfa(void)
+{
+ __imx8mp_load_and_start_image_via_tfa((void *)MX8M_ATF_BL33_BASE_ADDR);
+}
+
+__noreturn void __imx8mp_load_and_start_image_via_tfa(void *bl33)
{
const void *bl31;
size_t bl31_size;
- void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(32);
imx8mp_init_scratch_space();
@@ -243,13 +251,13 @@ void imx8mn_load_bl33(void *bl33)
imx8mn_get_boot_source(&src, &instance);
switch (src) {
case BOOTSOURCE_MMC:
- imx8mn_esdhc_load_image(instance);
+ imx8mn_esdhc_load_image(instance, bl33);
break;
case BOOTSOURCE_SERIAL:
- imx8mn_romapi_load_image();
+ imx8mn_romapi_load_image(bl33);
break;
case BOOTSOURCE_SPI:
- imx8mn_qspi_load_image(instance);
+ imx8mn_qspi_load_image(instance, bl33);
break;
default:
printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
@@ -269,10 +277,14 @@ void imx8mn_load_bl33(void *bl33)
}
__noreturn void imx8mn_load_and_start_image_via_tfa(void)
+{
+ __imx8mn_load_and_start_image_via_tfa((void *)MX8M_ATF_BL33_BASE_ADDR);
+}
+
+__noreturn void __imx8mn_load_and_start_image_via_tfa(void *bl33)
{
const void *bl31;
size_t bl31_size;
- void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(16);
imx8mn_init_scratch_space();
@@ -309,7 +321,7 @@ void imx8mq_load_bl33(void *bl33)
imx8mn_get_boot_source(&src, &instance);
switch (src) {
case BOOTSOURCE_MMC:
- imx8m_esdhc_load_image(instance);
+ imx8m_esdhc_load_image(instance, bl33);
break;
default:
printf("Unhandled bootsource BOOTSOURCE_%d\n", src);
@@ -329,10 +341,14 @@ void imx8mq_load_bl33(void *bl33)
}
__noreturn void imx8mq_load_and_start_image_via_tfa(void)
+{
+ __imx8mq_load_and_start_image_via_tfa((void *)MX8M_ATF_BL33_BASE_ADDR);
+}
+
+__noreturn void __imx8mq_load_and_start_image_via_tfa(void *bl33)
{
const void *bl31;
size_t bl31_size;
- void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(32);
imx8mq_init_scratch_space();
diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
index a245357fdf5d..797b479c3e91 100644
--- a/arch/arm/mach-imx/romapi.c
+++ b/arch/arm/mach-imx/romapi.c
@@ -79,25 +79,24 @@ static int imx_romapi_load_seekable(struct rom_api *rom_api, void *adr, uint32_t
}
/* read piggydata via a bootrom callback and place it behind our copy in SDRAM */
-static int imx_romapi_load_image(struct rom_api *rom_api)
+static int imx_romapi_load_image(struct rom_api *rom_api, void *bl33)
{
- return imx_romapi_load_stream(rom_api,
- (void *)MX8M_ATF_BL33_BASE_ADDR + barebox_pbl_size,
- __image_end - __piggydata_start);
+ return imx_romapi_load_stream(rom_api, bl33 + barebox_pbl_size,
+ __image_end - __piggydata_start);
}
-int imx8mp_romapi_load_image(void)
+int imx8mp_romapi_load_image(void *bl33)
{
struct rom_api *rom_api = (void *)0x980;
OPTIMIZER_HIDE_VAR(rom_api);
- return imx_romapi_load_image(rom_api);
+ return imx_romapi_load_image(rom_api, bl33);
}
-int imx8mn_romapi_load_image(void)
+int imx8mn_romapi_load_image(void *bl33)
{
- return imx8mp_romapi_load_image();
+ return imx8mp_romapi_load_image(bl33);
}
static int imx_romapi_boot_device_seekable(struct rom_api *rom_api)
diff --git a/arch/arm/mach-imx/xload-qspi.c b/arch/arm/mach-imx/xload-qspi.c
index 5089f20d627c..327a560f8b70 100644
--- a/arch/arm/mach-imx/xload-qspi.c
+++ b/arch/arm/mach-imx/xload-qspi.c
@@ -32,24 +32,24 @@ int imx8m_qspi_read(void *dest, size_t len, void *priv)
* A negative error code is returned when this function fails.
*/
static
-int imx8m_qspi_load_image(int instance, off_t offset, off_t ivt_offset)
+int imx8m_qspi_load_image(int instance, off_t offset, off_t ivt_offset, void *bl33)
{
void __iomem *qspi_ahb = IOMEM(IMX8M_QSPI_MMAP);
- return imx_load_image(MX8M_DDR_CSD1_BASE_ADDR, MX8M_ATF_BL33_BASE_ADDR,
+ return imx_load_image(MX8M_DDR_CSD1_BASE_ADDR, (ptrdiff_t)bl33,
offset, ivt_offset, false, 0,
imx8m_qspi_read, qspi_ahb);
}
-int imx8mm_qspi_load_image(int instance)
+int imx8mm_qspi_load_image(int instance, void *bl33)
{
- return imx8m_qspi_load_image(instance, 0, SZ_4K);
+ return imx8m_qspi_load_image(instance, 0, SZ_4K, bl33);
}
-int imx8mn_qspi_load_image(int instance)
+int imx8mn_qspi_load_image(int instance, void *bl33)
{
- return imx8m_qspi_load_image(instance, SZ_4K, 0);
+ return imx8m_qspi_load_image(instance, SZ_4K, 0, bl33);
}
-int imx8mp_qspi_load_image(int instance)
+int imx8mp_qspi_load_image(int instance, void *bl33)
__alias(imx8mn_qspi_load_image);
diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c
index 2cb703a0c552..5b1d9a3cf41e 100644
--- a/drivers/mci/imx-esdhc-pbl.c
+++ b/drivers/mci/imx-esdhc-pbl.c
@@ -242,6 +242,7 @@ int imx7_esdhc_start_image(int instance)
/**
* imx8m_esdhc_load_image - Load and optionally start an image from USDHC controller
* @instance: The USDHC controller instance (0..2)
+ * @bl33: Where to load the bl33 barebox image
*
* This uses esdhc_start_image() to load an image from SD/MMC. It is
* assumed that the image is the currently running barebox image (This
@@ -251,7 +252,7 @@ int imx7_esdhc_start_image(int instance)
* Return: If image successfully loaded, returns 0.
* A negative error code is returned when this function fails.
*/
-int imx8m_esdhc_load_image(int instance)
+int imx8m_esdhc_load_image(int instance, void *bl33)
{
struct esdhc_soc_data data;
struct fsl_esdhc_host host = { 0 };
@@ -262,13 +263,14 @@ int imx8m_esdhc_load_image(int instance)
return ret;
return esdhc_load_image(&host, MX8M_DDR_CSD1_BASE_ADDR,
- MX8MQ_ATF_BL33_BASE_ADDR, SZ_32K, SZ_1K,
+ (ptrdiff_t)bl33, SZ_32K, SZ_1K,
false);
}
/**
* imx8mp_esdhc_load_image - Load and optionally start an image from USDHC controller
* @instance: The USDHC controller instance (0..2)
+ * @bl33: Where to load the bl33 barebox image
*
* This uses esdhc_start_image() to load an image from SD/MMC. It is
* assumed that the image is the currently running barebox image (This
@@ -278,7 +280,7 @@ int imx8m_esdhc_load_image(int instance)
* Return: If image successfully loaded, returns 0.
* A negative error code is returned when this function fails.
*/
-int imx8mp_esdhc_load_image(int instance)
+int imx8mp_esdhc_load_image(int instance, void *bl33)
{
struct esdhc_soc_data data;
struct fsl_esdhc_host host = { 0 };
@@ -292,10 +294,10 @@ int imx8mp_esdhc_load_image(int instance)
offset = esdhc_bootpart_active(&host)? 0 : SZ_32K;
return esdhc_load_image(&host, MX8M_DDR_CSD1_BASE_ADDR,
- MX8MQ_ATF_BL33_BASE_ADDR, offset, 0, false);
+ (ptrdiff_t)bl33, offset, 0, false);
}
-int imx8mn_esdhc_load_image(int instance)
+int imx8mn_esdhc_load_image(int instance, void *bl33)
__alias(imx8mp_esdhc_load_image);
#endif
diff --git a/include/mach/imx/romapi.h b/include/mach/imx/romapi.h
index ae4e49cd7d25..e26b98097d37 100644
--- a/include/mach/imx/romapi.h
+++ b/include/mach/imx/romapi.h
@@ -36,8 +36,8 @@ enum boot_dev_type_e {
#define ROM_API_OKAY 0xF0
/* Below functions only load and don't start the image */
-int imx8mp_romapi_load_image(void);
-int imx8mn_romapi_load_image(void);
+int imx8mp_romapi_load_image(void *bl33);
+int imx8mn_romapi_load_image(void *bl33);
int imx93_romapi_load_image(void);
/* only call after DRAM has been configured */
diff --git a/include/mach/imx/xload.h b/include/mach/imx/xload.h
index 99f526d38be9..3a396ac4535c 100644
--- a/include/mach/imx/xload.h
+++ b/include/mach/imx/xload.h
@@ -16,12 +16,12 @@ int imx7_esdhc_start_image(int instance);
int imx7_nand_start_image(void);
/* Below functions only load and don't start the image */
-int imx8m_esdhc_load_image(int instance);
-int imx8mn_esdhc_load_image(int instance);
-int imx8mp_esdhc_load_image(int instance);
-int imx8mm_qspi_load_image(int instance);
-int imx8mn_qspi_load_image(int instance);
-int imx8mp_qspi_load_image(int instance);
+int imx8m_esdhc_load_image(int instance, void *bl33);
+int imx8mn_esdhc_load_image(int instance, void *bl33);
+int imx8mp_esdhc_load_image(int instance, void *bl33);
+int imx8mm_qspi_load_image(int instance, void *bl33);
+int imx8mn_qspi_load_image(int instance, void *bl33);
+int imx8mp_qspi_load_image(int instance, void *bl33);
void imx8mm_load_bl33(void *bl33);
void imx8mn_load_bl33(void *bl33);
@@ -32,6 +32,11 @@ void __noreturn imx8mm_load_and_start_image_via_tfa(void);
void __noreturn imx8mn_load_and_start_image_via_tfa(void);
void __noreturn imx8mp_load_and_start_image_via_tfa(void);
void __noreturn imx8mq_load_and_start_image_via_tfa(void);
+void __noreturn __imx8mm_load_and_start_image_via_tfa(void *bl33);
+void __noreturn __imx8mn_load_and_start_image_via_tfa(void *bl33);
+void __noreturn __imx8mp_load_and_start_image_via_tfa(void *bl33);
+void __noreturn __imx8mq_load_and_start_image_via_tfa(void *bl33);
+
void __noreturn imx93_load_and_start_image_via_tfa(void);
int imx_load_image(ptrdiff_t address, ptrdiff_t entry, u32 offset,
--
2.39.2
next prev parent reply other threads:[~2024-01-16 17:09 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 17:07 [PATCH v2 00/18] Dynamic OP-TEE Loading Marco Felsch
2024-01-16 17:07 ` [PATCH v2 01/18] ARM: i.MX8M: atf: make use of imx8m*_save_bootrom_log macros Marco Felsch
2024-01-16 17:07 ` [PATCH v2 02/18] ARM: i.MX8M: bundle imx-scratch code Marco Felsch
2024-01-17 14:36 ` Sascha Hauer
2024-01-18 9:11 ` Marco Felsch
2024-01-18 10:16 ` Sascha Hauer
2024-01-16 17:07 ` [PATCH v2 03/18] ARM: i.MX8M: scratch: make imx_scratch_space private Marco Felsch
2024-01-16 17:07 ` [PATCH v2 04/18] ARM: i.MX8M: romapi: refactor saving the bootrom log Marco Felsch
2024-01-16 17:07 ` [PATCH v2 05/18] ARM: i.MX8M: scratch: add optee_hdr area Marco Felsch
2024-01-17 15:00 ` Sascha Hauer
2024-01-18 9:07 ` Marco Felsch
2024-01-16 17:07 ` [PATCH v2 06/18] common: limit BOOTM_OPTEE to 32bit systems Marco Felsch
2024-01-16 17:07 ` [PATCH v2 07/18] common: add OPTEE_SHM_SIZE to configure optee shared memory Marco Felsch
2024-01-16 17:07 ` [PATCH v2 08/18] optee: add support to verify 64-bit headers as well Marco Felsch
2024-01-16 17:07 ` [PATCH v2 09/18] optee: add header version check Marco Felsch
2024-01-16 17:07 ` [PATCH v2 10/18] optee: add helper functions to set/get the optee memory base Marco Felsch
2024-01-16 17:07 ` [PATCH v2 11/18] optee: optee_verify_header: constify optee_header Marco Felsch
2024-01-16 17:07 ` [PATCH v2 12/18] ARM64: mmu: add dynamic optee memory mapping support Marco Felsch
2024-01-17 14:33 ` Sascha Hauer
2024-01-18 9:13 ` Marco Felsch
2024-01-18 10:17 ` Sascha Hauer
2024-01-16 17:07 ` [PATCH v2 13/18] ARM: i.MX8M: add dynamic optee memory of-fixup support Marco Felsch
2024-01-16 17:07 ` [PATCH v2 14/18] drivers: tee: optee: add support for dynamic optee memory base address Marco Felsch
2024-01-16 17:07 ` [PATCH v2 15/18] ARM: i.MX8M: atf: add support for optee hdr parsing Marco Felsch
2024-01-16 17:07 ` Marco Felsch [this message]
2024-01-16 17:07 ` [PATCH v2 17/18] ARM: i.MX8M: cleanup MX8M*_ATF_BL33_BASE_ADDR defines Marco Felsch
2024-01-16 17:07 ` [PATCH v2 18/18] ARM: i.MX8M: fix optee of-fixup logic Marco Felsch
2024-01-18 15:30 ` Sascha Hauer
2024-01-18 16:52 ` Marco Felsch
2024-01-19 8:02 ` [PATCH v2 00/18] Dynamic OP-TEE Loading Sascha Hauer
2024-01-19 8:09 ` Sascha Hauer
2024-01-19 8:20 ` Marco Felsch
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=20240116170738.209954-17-m.felsch@pengutronix.de \
--to=m.felsch@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