mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] ARM: i.MX8M: define imx8mX_load_bl33 and imx8mX_load_and_start_tfa
Date: Mon, 15 Aug 2022 14:55:51 +0200	[thread overview]
Message-ID: <20220815125551.2329928-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220815125551.2329928-1-a.fatoum@pengutronix.de>

For most users imx8mX_load_and_start_tfa saves a good deal of
boilerplate. It's not always sufficient though:

  - board code may need a pointer to bl33 to install other firmware
    besides barebox proper from there before jumping to bl31 (TF-A).

  - board code may want to use a different ARM Trusted Firmware,
    e.g. when OP-TEE is to be installed.

Thus define two more helper: imx8mX_load_bl33 and
imx8mn_load_and_start_tfa, which allows board code to avoid duplicating
the chainload logic and focus on doing the board specific stuff only.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-imx/atf.c                | 43 ++++++++++++--------------
 arch/arm/mach-imx/include/mach/atf.h   | 12 +++++++
 arch/arm/mach-imx/include/mach/xload.h |  4 +++
 3 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
index 675e90792a32..5301c0fbe8e5 100644
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -70,13 +70,10 @@ __noreturn void imx8mq_atf_load_bl31(const void *fw, size_t fw_size)
 	imx8m_atf_start_bl31(fw, fw_size, (void *)MX8MQ_ATF_BL31_BASE_ADDR);
 }
 
-__noreturn void imx8mm_load_and_start_image_via_tfa(void)
+void imx8mm_load_bl33(void *bl33)
 {
-	size_t bl31_size;
-	const u8 *bl31;
 	enum bootsource src;
 	int instance;
-	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
 
 	imx8mm_get_boot_source(&src, &instance);
 	switch (src) {
@@ -122,16 +119,16 @@ __noreturn void imx8mm_load_and_start_image_via_tfa(void)
 	 * the same code in DRAM.
 	 */
 	memcpy(bl33, __image_start, barebox_pbl_size);
+}
 
-	get_builtin_firmware(imx8mm_bl31_bin, &bl31, &bl31_size);
-
-	imx8mm_atf_load_bl31(bl31, bl31_size);
+__noreturn void imx8mm_load_and_start_image_via_tfa(void)
+{
+	imx8mm_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
+	imx8mm_load_and_start_tfa(imx8mm_bl31_bin);
 }
 
-__noreturn void imx8mp_load_and_start_image_via_tfa(void)
+void imx8mp_load_bl33(void *bl33)
 {
-	size_t bl31_size;
-	const u8 *bl31;
 	enum bootsource src;
 	int instance;
 
@@ -157,18 +154,17 @@ __noreturn void imx8mp_load_and_start_image_via_tfa(void)
 	 * 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(imx8mp_bl31_bin, &bl31, &bl31_size);
+	memcpy(bl33, __image_start, barebox_pbl_size);
+}
 
-	imx8mp_atf_load_bl31(bl31, bl31_size);
+void imx8mp_load_and_start_image_via_tfa(void)
+{
+	imx8mp_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
+	imx8mp_load_and_start_tfa(imx8mp_bl31_bin);
 }
 
-__noreturn void imx8mn_load_and_start_image_via_tfa(void)
+void imx8mn_load_bl33(void *bl33)
 {
-	size_t bl31_size;
-	const u8 *bl31;
 	enum bootsource src;
 	int instance;
 
@@ -194,10 +190,11 @@ __noreturn void imx8mn_load_and_start_image_via_tfa(void)
 	 * 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(imx8mn_bl31_bin, &bl31, &bl31_size);
+	memcpy(bl33, __image_start, barebox_pbl_size);
+}
 
-	imx8mn_atf_load_bl31(bl31, bl31_size);
+void imx8mn_load_and_start_image_via_tfa(void)
+{
+	imx8mn_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
+	imx8mn_load_and_start_tfa(imx8mn_bl31_bin);
 }
diff --git a/arch/arm/mach-imx/include/mach/atf.h b/arch/arm/mach-imx/include/mach/atf.h
index ca54bb5fbf82..b3c4ecb92576 100644
--- a/arch/arm/mach-imx/include/mach/atf.h
+++ b/arch/arm/mach-imx/include/mach/atf.h
@@ -23,4 +23,16 @@ void __noreturn imx8mn_atf_load_bl31(const void *fw, size_t fw_size);
 void __noreturn imx8mp_atf_load_bl31(const void *fw, size_t fw_size);
 void __noreturn imx8mq_atf_load_bl31(const void *fw, size_t fw_size);
 
+#define imx8m_load_and_start_tfa(soc,fw_name) do { \
+	size_t __bl31_size; \
+	const u8 *__bl31; \
+	soc##_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR); \
+	get_builtin_firmware(fw_name, &__bl31, &__bl31_size); \
+	soc##_atf_load_bl31(__bl31, __bl31_size); \
+} while (0)
+
+#define imx8mm_load_and_start_tfa(fw_name) imx8m_load_and_start_tfa(imx8mm, fw_name)
+#define imx8mn_load_and_start_tfa(fw_name) imx8m_load_and_start_tfa(imx8mn, fw_name)
+#define imx8mp_load_and_start_tfa(fw_name) imx8m_load_and_start_tfa(imx8mp, fw_name)
+
 #endif
diff --git a/arch/arm/mach-imx/include/mach/xload.h b/arch/arm/mach-imx/include/mach/xload.h
index fe43d2502632..82bf663c4266 100644
--- a/arch/arm/mach-imx/include/mach/xload.h
+++ b/arch/arm/mach-imx/include/mach/xload.h
@@ -16,6 +16,10 @@ int imx8m_esdhc_load_image(int instance, bool start);
 int imx8mn_esdhc_load_image(int instance, bool start);
 int imx8mp_esdhc_load_image(int instance, bool start);
 
+void imx8mm_load_bl33(void *bl33);
+void imx8mn_load_bl33(void *bl33);
+void imx8mp_load_bl33(void *bl33);
+
 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);
-- 
2.30.2




  parent reply	other threads:[~2022-08-15 12:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 12:55 [PATCH 1/3] ARM: i.MX8M: atf: mark ATF start functions as __noreturn Ahmad Fatoum
2022-08-15 12:55 ` [PATCH 2/3] ARM: i.MX8M: rename imx8m_atf_load_bl31 for clarity Ahmad Fatoum
2022-08-15 12:55 ` Ahmad Fatoum [this message]
2022-08-16  6:14   ` [PATCH 3/3] ARM: i.MX8M: define imx8mX_load_bl33 and imx8mX_load_and_start_tfa Marco Felsch
2022-08-16  7:31     ` Ahmad Fatoum

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=20220815125551.2329928-3-a.fatoum@pengutronix.de \
    --to=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