mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 04/18] ARM: i.MX8M: romapi: refactor saving the bootrom log
Date: Tue, 16 Jan 2024 18:07:24 +0100	[thread overview]
Message-ID: <20240116170738.209954-5-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20240116170738.209954-1-m.felsch@pengutronix.de>

Saving the bootrom log to the scratch area was the last open coded part.
Move the code to the scratch module to make the scratch handling
completely opaque.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/arm/mach-imx/atf.c     | 12 ++++++++----
 arch/arm/mach-imx/romapi.c  |  6 ++----
 arch/arm/mach-imx/scratch.c | 33 ++++++++++++++++++++++++++++++---
 include/mach/imx/romapi.h   |  7 +------
 include/mach/imx/scratch.h  | 11 ++++++-----
 5 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
index 5dfa7eeb50b9..3f796249061d 100644
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -123,7 +123,8 @@ __noreturn void imx8mm_load_and_start_image_via_tfa(void)
 	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
 	unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(32);
 
-	imx8mm_save_bootrom_log();
+	imx8mm_init_scratch_space();
+	imx8m_save_bootrom_log();
 	imx8mm_load_bl33(bl33);
 
 	if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MM_OPTEE)) {
@@ -186,7 +187,8 @@ __noreturn void imx8mp_load_and_start_image_via_tfa(void)
 	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
 	unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(32);
 
-	imx8mp_save_bootrom_log();
+	imx8mp_init_scratch_space();
+	imx8m_save_bootrom_log();
 	imx8mp_load_bl33(bl33);
 
 	if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MP_OPTEE)) {
@@ -250,7 +252,8 @@ __noreturn void imx8mn_load_and_start_image_via_tfa(void)
 	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
 	unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(16);
 
-	imx8mn_save_bootrom_log();
+	imx8mn_init_scratch_space();
+	imx8m_save_bootrom_log();
 	imx8mn_load_bl33(bl33);
 
 	if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MN_OPTEE)) {
@@ -307,7 +310,8 @@ __noreturn void imx8mq_load_and_start_image_via_tfa(void)
 	void *bl33 = (void *)MX8M_ATF_BL33_BASE_ADDR;
 	unsigned long endmem = MX8M_DDR_CSD1_BASE_ADDR + imx8m_barebox_earlymem_size(32);
 
-	imx8mq_save_bootrom_log();
+	imx8mq_init_scratch_space();
+	imx8m_save_bootrom_log();
 	imx8mq_load_bl33(bl33);
 
 	if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MQ_OPTEE)) {
diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
index 51e35c9d2aa2..a245357fdf5d 100644
--- a/arch/arm/mach-imx/romapi.c
+++ b/arch/arm/mach-imx/romapi.c
@@ -226,7 +226,7 @@ const u32 *imx8m_get_bootrom_log(void)
 	return NULL;
 }
 
-void imx8m_save_bootrom_log(void *dest)
+void imx8m_save_bootrom_log(void)
 {
 	const u32 *rom_log;
 
@@ -241,7 +241,5 @@ void imx8m_save_bootrom_log(void *dest)
 		return;
 	}
 
-	pr_debug("Saving bootrom log to 0x%p\n", dest);
-
-	memcpy(dest, rom_log, 128 * sizeof(u32));
+	imx8m_scratch_save_bootrom_log(rom_log);
 }
diff --git a/arch/arm/mach-imx/scratch.c b/arch/arm/mach-imx/scratch.c
index fba00955c095..f4faff835c8c 100644
--- a/arch/arm/mach-imx/scratch.c
+++ b/arch/arm/mach-imx/scratch.c
@@ -3,26 +3,53 @@
 #include <asm/barebox-arm.h>
 #include <init.h>
 #include <linux/err.h>
+#include <linux/printk.h>
 #include <mach/imx/imx8m-regs.h>
 #include <mach/imx/esdctl.h>
 #include <mach/imx/scratch.h>
 #include <memory.h>
+#include <pbl.h>
 
 struct imx_scratch_space {
 	u32 bootrom_log[128];
 };
 
-void *__imx8m_scratch_space(int ddr_buswidth)
+static struct imx_scratch_space *scratch;
+
+void imx8m_init_scratch_space(int ddr_buswidth, bool zero_init)
 {
 	ulong endmem = MX8M_DDR_CSD1_BASE_ADDR +
 		imx8m_barebox_earlymem_size(ddr_buswidth);
 
-	return (void *)arm_mem_scratch(endmem);
+	scratch = (void *)arm_mem_scratch(endmem);
+
+	if (zero_init)
+		memset(scratch, 0, sizeof(*scratch));
+}
+
+void imx8m_scratch_save_bootrom_log(const u32 *rom_log)
+{
+	size_t sz = sizeof(scratch->bootrom_log);
+
+	if (!scratch) {
+		pr_err("No scratch area initialized, skip saving bootrom log");
+		return;
+	}
+
+	pr_debug("Saving bootrom log to scratch area 0x%p\n", &scratch->bootrom_log);
+
+	memcpy(scratch->bootrom_log, rom_log, sz);
 }
 
 const u32 *imx8m_scratch_get_bootrom_log(void)
 {
-	const struct imx_scratch_space *scratch = arm_mem_scratch_get();
+	if (!scratch) {
+		if (IN_PBL)
+			return ERR_PTR(-EINVAL);
+		else
+			scratch = (void *)arm_mem_scratch_get();
+	}
+
 	return scratch->bootrom_log;
 }
 
diff --git a/include/mach/imx/romapi.h b/include/mach/imx/romapi.h
index 710068a8d41d..ae4e49cd7d25 100644
--- a/include/mach/imx/romapi.h
+++ b/include/mach/imx/romapi.h
@@ -41,12 +41,7 @@ int imx8mn_romapi_load_image(void);
 int imx93_romapi_load_image(void);
 
 /* only call after DRAM has been configured */
-void imx8m_save_bootrom_log(void *dst);
+void imx8m_save_bootrom_log(void);
 const u32 *imx8m_get_bootrom_log(void);
 
-#define imx8mq_save_bootrom_log() imx8m_save_bootrom_log(imx8mq_scratch_space())
-#define imx8mm_save_bootrom_log() imx8m_save_bootrom_log(imx8mm_scratch_space())
-#define imx8mn_save_bootrom_log() imx8m_save_bootrom_log(imx8mn_scratch_space())
-#define imx8mp_save_bootrom_log() imx8m_save_bootrom_log(imx8mp_scratch_space())
-
 #endif /* __MACH_IMX_ROMAPI_H */
diff --git a/include/mach/imx/scratch.h b/include/mach/imx/scratch.h
index 9b01cf315622..487171fbee97 100644
--- a/include/mach/imx/scratch.h
+++ b/include/mach/imx/scratch.h
@@ -3,13 +3,14 @@
 #ifndef __MACH_IMX_SCRATCH_H
 #define __MACH_IMX_SCRATCH_H
 
-void *__imx8m_scratch_space(int ddr_buswidth);
+void imx8m_init_scratch_space(int ddr_buswidth, bool zero_init);
 
 const u32 *imx8m_scratch_get_bootrom_log(void);
+void imx8m_scratch_save_bootrom_log(const u32 *rom_log);
 
-#define imx8mq_scratch_space() __imx8m_scratch_space(32)
-#define imx8mm_scratch_space() __imx8m_scratch_space(32)
-#define imx8mn_scratch_space() __imx8m_scratch_space(16)
-#define imx8mp_scratch_space() __imx8m_scratch_space(32)
+#define imx8mq_init_scratch_space() imx8m_init_scratch_space(32, true)
+#define imx8mm_init_scratch_space() imx8m_init_scratch_space(32, true)
+#define imx8mn_init_scratch_space() imx8m_init_scratch_space(16, true)
+#define imx8mp_init_scratch_space() imx8m_init_scratch_space(32, true)
 
 #endif /* __MACH_IMX_SCRATCH_H */
-- 
2.39.2




  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 ` Marco Felsch [this message]
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 ` [PATCH v2 16/18] ARM: i.MX8M: allow board code to configure the bl33 loadaddr Marco Felsch
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-5-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