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: mfe@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/9] ARM: i.MX8M: imx8mn-evk: use generic imx8mn_load_and_start_image_via_tfa
Date: Fri,  5 Aug 2022 14:54:06 +0200	[thread overview]
Message-ID: <20220805125413.1046239-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220805125413.1046239-1-a.fatoum@pengutronix.de>

Like already done for i.MX8MM and i.MX8MP, we can considerably reduce
i.MX8MN board code duplication by moving the TF-A loading and jumping
code into common helpers.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/boards/nxp-imx8mn-evk/lowlevel.c | 31 +------------------
 arch/arm/mach-imx/atf.c                   | 36 +++++++++++++++++++++++
 arch/arm/mach-imx/include/mach/xload.h    |  1 +
 3 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/arch/arm/boards/nxp-imx8mn-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mn-evk/lowlevel.c
index 9e44d343b7ed..ddc6e4fd2b29 100644
--- a/arch/arm/boards/nxp-imx8mn-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mn-evk/lowlevel.c
@@ -132,11 +132,7 @@ extern struct dram_timing_info imx8mn_evk_ddr4_timing, imx8mn_evk_lpddr4_timing;
 static void start_atf(void)
 {
 	struct dram_timing_info *dram_timing = &imx8mn_evk_lpddr4_timing;
-	size_t bl31_size;
-	const u8 *bl31;
-	enum bootsource src;
 	void *i2c;
-	int instance;
 	int ret;
 
 	/*
@@ -163,32 +159,7 @@ static void start_atf(void)
 
 	imx8mn_ddr_init(dram_timing, dram_timing->dram_type);
 
-	imx8mn_get_boot_source(&src, &instance);
-	switch (src) {
-	case BOOTSOURCE_MMC:
-		imx8mn_esdhc_load_image(instance, false);
-		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(imx8mn_bl31_bin, &bl31, &bl31_size);
-
-	imx8mn_atf_load_bl31(bl31, bl31_size);
-
-	/* not reached */
+	imx8mn_load_and_start_image_via_tfa();
 }
 
 /*
diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
index 8fc523d3de61..bb9e04c9746b 100644
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -168,3 +168,39 @@ void imx8mp_load_and_start_image_via_tfa(void)
 
 	/* not reached */
 }
+
+void imx8mn_load_and_start_image_via_tfa(void)
+{
+	size_t bl31_size;
+	const u8 *bl31;
+	enum bootsource src;
+	int instance;
+
+	imx8mn_get_boot_source(&src, &instance);
+	switch (src) {
+	case BOOTSOURCE_MMC:
+		imx8mn_esdhc_load_image(instance, false);
+		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(imx8mn_bl31_bin, &bl31, &bl31_size);
+
+	imx8mn_atf_load_bl31(bl31, bl31_size);
+
+	/* not reached */
+}
diff --git a/arch/arm/mach-imx/include/mach/xload.h b/arch/arm/mach-imx/include/mach/xload.h
index cfc52a94879d..3090c9c83bd7 100644
--- a/arch/arm/mach-imx/include/mach/xload.h
+++ b/arch/arm/mach-imx/include/mach/xload.h
@@ -14,6 +14,7 @@ int imx8mn_esdhc_load_image(int instance, bool start);
 int imx8mp_esdhc_load_image(int instance, bool start);
 
 void imx8mm_load_and_start_image_via_tfa(void);
+void imx8mn_load_and_start_image_via_tfa(void);
 void imx8mp_load_and_start_image_via_tfa(void);
 
 int imx_image_size(void);
-- 
2.30.2




  parent reply	other threads:[~2022-08-05 12:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 12:54 [PATCH 0/9] ARM: i.MX8MN: clean up and enable imx-usb-loader Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 1/9] ARM: i.MX8M: move TF-A chainload functions in <mach/xload.h> Ahmad Fatoum
2022-08-05 12:54 ` Ahmad Fatoum [this message]
2022-08-05 12:54 ` [PATCH 3/9] ARM: i.MX8MN: add SDPS barebox-side support Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 4/9] ARM: i.MX8MN: evk: simplify DDR4/LPDDR4 selection code Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 5/9] ddr: imx8m: rename type to more fitting ddrc|dram_type Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 6/9] ARM: i.MX8M: remove struct dram_timing_info::dram_type again Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 7/9] pbl: generalize fsl i2c_early API into pbl_i2c Ahmad Fatoum
2022-08-08  8:44   ` Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 8/9] i2c: add <pbl/pmic.h> for PBL use Ahmad Fatoum
2022-08-05 12:54 ` [PATCH 9/9] ARM: i.MX8M: use new pbl/pmic.h API Ahmad Fatoum
2022-08-08  8:30 ` [PATCH 0/9] ARM: i.MX8MN: clean up and enable imx-usb-loader Marco Felsch
2022-08-08 12:32 ` Sascha Hauer

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=20220805125413.1046239-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mfe@pengutronix.de \
    /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