mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command
@ 2022-11-01 18:06 Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 1/5] ARM: asm: set aside new arm_mem_scratch space Ahmad Fatoum
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2022-11-01 18:06 UTC (permalink / raw)
  To: barebox

The ROM event log of the i.MX8M* can help with debugging boot
failures as it lists various information about boot mode, image,
fallback and recovery as well as timestamps when some actions along
the boot process occurred.

This adds a new bootrom -l command that supports reading this out.

Ahmad Fatoum (5):
  ARM: asm: set aside new arm_mem_scratch space
  ARM: i.MX8M: esdctl: export imx8m_barebox_earlymem_size
  ARM: i.MX8M: define imx8mX_scratch_space() helper
  ARM: i.MX8M: support saving BootROM event log before clobbering OCRAM
  ARM: i.MX8M: implement bootrom log viewing command

 arch/arm/include/asm/barebox-arm.h          |   7 +
 arch/arm/mach-imx/Kconfig                   |   4 +
 arch/arm/mach-imx/Makefile                  |   1 +
 arch/arm/mach-imx/atf.c                     |   3 +
 arch/arm/mach-imx/bootrom-cmd.c             | 220 ++++++++++++++++++++
 arch/arm/mach-imx/esdctl.c                  |  11 +-
 arch/arm/mach-imx/include/mach/esdctl.h     |   3 +
 arch/arm/mach-imx/include/mach/imx8m-regs.h |   8 +
 arch/arm/mach-imx/include/mach/romapi.h     |  11 +
 arch/arm/mach-imx/include/mach/xload.h      |  11 +
 arch/arm/mach-imx/romapi.c                  |  26 +++
 arch/arm/mach-imx/xload-common.c            |  10 +
 commands/Kconfig                            |   8 +
 13 files changed, 320 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-imx/bootrom-cmd.c

-- 
2.30.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] ARM: asm: set aside new arm_mem_scratch space
  2022-11-01 18:06 [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
@ 2022-11-01 18:06 ` Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 2/5] ARM: i.MX8M: esdctl: export imx8m_barebox_earlymem_size Ahmad Fatoum
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2022-11-01 18:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

While ARMv7 and later allow mapping the interrupt vector table at
arbitrary address, older ARMs only accept 0x0000_0000 and 0xFFFF_0000
(i.e. SZ_4G - SZ_64K).

For this reason, barebox grows its stack down from the last SZ_64K
of the early memory bank and leaves the last 64K for MMU IVT setup.
That way if the early memory bank extends till the end of the 4G
address space, installing the IVT at 0xFFFF_0000 won't break anything.

SZ_64K is way more than any IVT would need, so let us repurpose the
last SZ_32K to be some generic scratch space for prebootloader to report
data to barebox proper. No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/include/asm/barebox-arm.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index dd12f642d993..2dcd4153200f 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -73,6 +73,13 @@ static inline void arm_fixup_vectors(void)
 
 void *barebox_arm_boot_dtb(void);
 
+#define __arm_mem_scratch(endmem) ((endmem) - SZ_32K)
+
+static inline const void *arm_mem_scratch_get(void)
+{
+	return (const void *)__arm_mem_scratch(arm_mem_endmem_get());
+}
+
 #define __arm_mem_stack_top(membase, endmem) ((endmem) - SZ_64K)
 
 #if defined(CONFIG_BOOTM_OPTEE) || defined(CONFIG_PBL_OPTEE)
-- 
2.30.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] ARM: i.MX8M: esdctl: export imx8m_barebox_earlymem_size
  2022-11-01 18:06 [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 1/5] ARM: asm: set aside new arm_mem_scratch space Ahmad Fatoum
@ 2022-11-01 18:06 ` Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 3/5] ARM: i.MX8M: define imx8mX_scratch_space() helper Ahmad Fatoum
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2022-11-01 18:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Board code will need to find out early endmem to use newly defined
scratch space, so factor out a new helper function to get earlymem size.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-imx/esdctl.c              | 11 ++++++++---
 arch/arm/mach-imx/include/mach/esdctl.h |  3 +++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c
index a55ee06b8346..8de20ed42338 100644
--- a/arch/arm/mach-imx/esdctl.c
+++ b/arch/arm/mach-imx/esdctl.c
@@ -923,7 +923,7 @@ void __noreturn vf610_barebox_entry(void *boarddata)
 			  boarddata);
 }
 
-static void __noreturn imx8m_barebox_entry(void *boarddata, unsigned buswidth)
+resource_size_t imx8m_barebox_earlymem_size(unsigned buswidth)
 {
 	resource_size_t size;
 
@@ -937,8 +937,13 @@ static void __noreturn imx8m_barebox_entry(void *boarddata, unsigned buswidth)
 	 * pool placement. The rest of the system should be able to
 	 * detect and utilize full amount of memory.
 	 */
-	size = min_t(resource_size_t, SZ_4G - MX8M_DDR_CSD1_BASE_ADDR, size);
-	barebox_arm_entry(MX8M_DDR_CSD1_BASE_ADDR, size, boarddata);
+	return min_t(resource_size_t, SZ_4G - MX8M_DDR_CSD1_BASE_ADDR, size);
+}
+
+static void __noreturn imx8m_barebox_entry(void *boarddata, unsigned buswidth)
+{
+	barebox_arm_entry(MX8M_DDR_CSD1_BASE_ADDR,
+			  imx8m_barebox_earlymem_size(buswidth), boarddata);
 }
 
 void __noreturn imx8mm_barebox_entry(void *boarddata)
diff --git a/arch/arm/mach-imx/include/mach/esdctl.h b/arch/arm/mach-imx/include/mach/esdctl.h
index b0b531aed4a2..01533478cce8 100644
--- a/arch/arm/mach-imx/include/mach/esdctl.h
+++ b/arch/arm/mach-imx/include/mach/esdctl.h
@@ -131,6 +131,8 @@
 #define ESDCFGx_tRC_16			0x0000000f
 
 #ifndef __ASSEMBLY__
+#include <linux/types.h>
+
 void __noreturn imx1_barebox_entry(void *boarddata);
 void __noreturn imx25_barebox_entry(void *boarddata);
 void __noreturn imx27_barebox_entry(void *boarddata);
@@ -148,6 +150,7 @@ void __noreturn imx8mq_barebox_entry(void *boarddata);
 void __noreturn imx7d_barebox_entry(void *boarddata);
 #define imx6sx_barebox_entry(boarddata) imx6ul_barebox_entry(boarddata)
 void imx_esdctl_disable(void);
+resource_size_t imx8m_barebox_earlymem_size(unsigned buswidth);
 #endif
 
 #endif /* __MACH_ESDCTL_V2_H */
-- 
2.30.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] ARM: i.MX8M: define imx8mX_scratch_space() helper
  2022-11-01 18:06 [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 1/5] ARM: asm: set aside new arm_mem_scratch space Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 2/5] ARM: i.MX8M: esdctl: export imx8m_barebox_earlymem_size Ahmad Fatoum
@ 2022-11-01 18:06 ` Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 4/5] ARM: i.MX8M: support saving BootROM event log before clobbering OCRAM Ahmad Fatoum
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2022-11-01 18:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Now that we have a generic ARM scratch area and a way to find out where
it is, add new helper functions that return a pointer to this area.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-imx/include/mach/xload.h | 11 +++++++++++
 arch/arm/mach-imx/xload-common.c       | 10 ++++++++++
 2 files changed, 21 insertions(+)

diff --git a/arch/arm/mach-imx/include/mach/xload.h b/arch/arm/mach-imx/include/mach/xload.h
index 82bf663c4266..d19bedb9e84a 100644
--- a/arch/arm/mach-imx/include/mach/xload.h
+++ b/arch/arm/mach-imx/include/mach/xload.h
@@ -30,4 +30,15 @@ int piggydata_size(void);
 extern unsigned char input_data[];
 extern unsigned char input_data_end[];
 
+struct imx_scratch_space {
+	u32 bootrom_log[128];
+};
+
+struct imx_scratch_space *__imx8m_scratch_space(int ddr_buswidth);
+
+#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)
+
 #endif /* __MACH_XLOAD_H */
diff --git a/arch/arm/mach-imx/xload-common.c b/arch/arm/mach-imx/xload-common.c
index f4bcca1d1483..710dcc1ed909 100644
--- a/arch/arm/mach-imx/xload-common.c
+++ b/arch/arm/mach-imx/xload-common.c
@@ -4,6 +4,9 @@
 #include <asm/sections.h>
 #include <linux/sizes.h>
 #include <mach/xload.h>
+#include <mach/esdctl.h>
+#include <mach/imx8m-regs.h>
+#include <asm/barebox-arm.h>
 
 int imx_image_size(void)
 {
@@ -16,3 +19,10 @@ int piggydata_size(void)
 	return input_data_end - input_data;
 }
 
+struct imx_scratch_space *__imx8m_scratch_space(int ddr_buswidth)
+{
+	ulong endmem = MX8M_DDR_CSD1_BASE_ADDR +
+		imx8m_barebox_earlymem_size(ddr_buswidth);
+
+	return (void *)__arm_mem_scratch(endmem);
+}
-- 
2.30.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] ARM: i.MX8M: support saving BootROM event log before clobbering OCRAM
  2022-11-01 18:06 [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2022-11-01 18:06 ` [PATCH 3/5] ARM: i.MX8M: define imx8mX_scratch_space() helper Ahmad Fatoum
@ 2022-11-01 18:06 ` Ahmad Fatoum
  2022-11-01 18:06 ` [PATCH 5/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
  2022-12-02  8:46 ` [PATCH 0/5] " Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2022-11-01 18:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The ROM event log[1] is a data structure populated by the i.MX BootROM
on i.MX6 and later. It's found by dereferencing a 32-bit address at a
fixed location within the BootROM. If valid, this address will point
into the On-Chip SRAM. On the i.MX8M, we load the ARM trusted firmware
into the On-Chip SRAM and may end up overwriting the BootROM event log,
before the user has a chance to parse it. Thus save the BootROM log into
the newly defined i.MX scratch space for later usage.

[1]: NXP AN12853 "i.MX ROMs Log Events" Rev. 0 -  May 2020

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-imx/Kconfig                   |  3 +++
 arch/arm/mach-imx/atf.c                     |  3 +++
 arch/arm/mach-imx/include/mach/imx8m-regs.h |  8 +++++++
 arch/arm/mach-imx/include/mach/romapi.h     | 11 +++++++++
 arch/arm/mach-imx/romapi.c                  | 26 +++++++++++++++++++++
 5 files changed, 51 insertions(+)

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index da71480887ad..e99cadb1f53a 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -932,6 +932,9 @@ config IMX_IIM_FUSE_BLOW
 	  enable it:
 	    imx_iim0.permanent_write_enable=1
 
+config IMX_SAVE_BOOTROM_LOG
+	bool
+
 config HAB
 	bool
 
diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
index 67462bc36189..9907e5f2ba97 100644
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -125,6 +125,7 @@ void imx8mm_load_bl33(void *bl33)
 
 __noreturn void imx8mm_load_and_start_image_via_tfa(void)
 {
+	imx8mm_save_bootrom_log();
 	imx8mm_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
 	imx8mm_load_and_start_tfa(imx8mm_bl31_bin);
 }
@@ -161,6 +162,7 @@ void imx8mp_load_bl33(void *bl33)
 
 void imx8mp_load_and_start_image_via_tfa(void)
 {
+	imx8mp_save_bootrom_log();
 	imx8mp_load_bl33((void *)MX8M_ATF_BL33_BASE_ADDR);
 	imx8mp_load_and_start_tfa(imx8mp_bl31_bin);
 }
@@ -197,6 +199,7 @@ void imx8mn_load_bl33(void *bl33)
 
 void imx8mn_load_and_start_image_via_tfa(void)
 {
+	imx8mn_save_bootrom_log();
 	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/imx8m-regs.h b/arch/arm/mach-imx/include/mach/imx8m-regs.h
index a5017faf830e..794e1bdd88a4 100644
--- a/arch/arm/mach-imx/include/mach/imx8m-regs.h
+++ b/arch/arm/mach-imx/include/mach/imx8m-regs.h
@@ -3,6 +3,14 @@
 #ifndef __MACH_IMX8M_REGS_H
 #define __MACH_IMX8M_REGS_H
 
+/*
+ * Actual addressable OCRAM size may differ from SoC to SoC, but all of
+ * i.MX8MQ/M/N/P have this region of MMIO address space set aside for
+ * OCRAM only.
+ */
+#define	MX8M_OCRAM_BASE_ADDR		0x00900000
+#define	MX8M_OCRAM_MAX_SIZE		0x00200000
+
 #define MX8M_GPIO1_BASE_ADDR		0X30200000
 #define MX8M_GPIO2_BASE_ADDR		0x30210000
 #define MX8M_GPIO3_BASE_ADDR		0x30220000
diff --git a/arch/arm/mach-imx/include/mach/romapi.h b/arch/arm/mach-imx/include/mach/romapi.h
index 8022fc411e9d..d22ba7259dd0 100644
--- a/arch/arm/mach-imx/include/mach/romapi.h
+++ b/arch/arm/mach-imx/include/mach/romapi.h
@@ -1,6 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef __MACH_IMX_ROMAPI_H
 #define __MACH_IMX_ROMAPI_H
 
+#include <mach/xload.h>
+
 struct rom_api {
 	u16 ver;
 	u16 tag;
@@ -34,4 +37,12 @@ enum boot_dev_type_e {
 int imx8mp_bootrom_load_image(void);
 int imx8mn_bootrom_load_image(void);
 
+/* only call after DRAM has been configured */
+void imx8m_save_bootrom_log(void *dst);
+
+#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/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
index 5d00d71154d7..48512a8d045e 100644
--- a/arch/arm/mach-imx/romapi.c
+++ b/arch/arm/mach-imx/romapi.c
@@ -1,7 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) "romapi: " fmt
+
 #include <common.h>
 #include <asm/sections.h>
 #include <mach/romapi.h>
 #include <mach/atf.h>
+#include <mach/imx8m-regs.h>
 
 static int imx8m_bootrom_load(struct rom_api *rom_api, void *adr, size_t size)
 {
@@ -42,3 +47,24 @@ int imx8mn_bootrom_load_image(void)
 {
 	return imx8mp_bootrom_load_image();
 }
+
+void imx8m_save_bootrom_log(void *dest)
+{
+	ulong rom_log_addr;
+
+	if (!IS_ENABLED(CONFIG_IMX_SAVE_BOOTROM_LOG)) {
+		pr_debug("skipping bootrom log saving\n");
+		return;
+	}
+
+	rom_log_addr = *(u32 *)0x9e0;
+
+	if (rom_log_addr < MX8M_OCRAM_BASE_ADDR ||
+	    rom_log_addr >= MX8M_OCRAM_BASE_ADDR + MX8M_OCRAM_MAX_SIZE ||
+	    rom_log_addr & 0x3) {
+		pr_warn("No BootROM log found at address 0x%08lx\n", rom_log_addr);
+		return;
+	}
+
+	memcpy(dest, (u32 *)rom_log_addr, 128 * sizeof(u32));
+}
-- 
2.30.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] ARM: i.MX8M: implement bootrom log viewing command
  2022-11-01 18:06 [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2022-11-01 18:06 ` [PATCH 4/5] ARM: i.MX8M: support saving BootROM event log before clobbering OCRAM Ahmad Fatoum
@ 2022-11-01 18:06 ` Ahmad Fatoum
  2022-12-02  8:46 ` [PATCH 0/5] " Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2022-11-01 18:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The ROM event log[1] of the i.MX8M* can help with debugging boot
failures as it lists various information about boot mode, image,
fallback and recovery as well as timestamps when some actions along
the boot process occurred.

Add a new bootrom -l command that supports reading this out. A generic
name is intentionally chosen, as other SoCs also provide similar
functionality and it would be nice if they can just reuse the name and
command line arguments in future.

[1]: NXP AN12853 "i.MX ROMs Log Events" Rev. 0 -  May 2020

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-imx/Kconfig       |   1 +
 arch/arm/mach-imx/Makefile      |   1 +
 arch/arm/mach-imx/bootrom-cmd.c | 220 ++++++++++++++++++++++++++++++++
 commands/Kconfig                |   8 ++
 4 files changed, 230 insertions(+)
 create mode 100644 arch/arm/mach-imx/bootrom-cmd.c

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index e99cadb1f53a..4895238dd280 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -934,6 +934,7 @@ config IMX_IIM_FUSE_BLOW
 
 config IMX_SAVE_BOOTROM_LOG
 	bool
+	default CMD_BOOTROM
 
 config HAB
 	bool
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 390cdaf50218..cc834fed7be7 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_IMX_IIM)	+= iim.o
 obj-$(CONFIG_NAND_IMX) += nand.o
 lwl-$(CONFIG_ARCH_IMX_EXTERNAL_BOOT_NAND) += external-nand-boot.o
 obj-y += devices.o imx.o
+obj-$(CONFIG_CMD_BOOTROM) += bootrom-cmd.o
 obj-pbl-y += esdctl.o boot.o
 obj-$(CONFIG_BAREBOX_UPDATE) += imx-bbu-internal.o
 obj-$(CONFIG_BAREBOX_UPDATE_IMX_EXTERNAL_NAND) += imx-bbu-external-nand.o
diff --git a/arch/arm/mach-imx/bootrom-cmd.c b/arch/arm/mach-imx/bootrom-cmd.c
new file mode 100644
index 000000000000..6269f86cbc0d
--- /dev/null
+++ b/arch/arm/mach-imx/bootrom-cmd.c
@@ -0,0 +1,220 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <command.h>
+#include <errno.h>
+#include <getopt.h>
+#include <printk.h>
+#include <linux/bitops.h>
+#include <linux/bitfield.h>
+#include <mach/imx8m-regs.h>
+#include <mach/xload.h>
+#include <asm/barebox-arm.h>
+
+/* i.MX7 and later ID field is swapped compared to i.MX6 */
+#define ROM_EVENT_FORMAT_V0_RES	GENMASK(31, 24)
+#define ROM_EVENT_FORMAT_V0_ID	GENMASK(23, 0)
+#define ROM_EVENT_FORMAT_V1_ID	GENMASK(31, 24)
+#define		ROM_EVENT_FORMAT_V1_ID_TYPE	GENMASK(31, 28)
+#define		ROM_EVENT_FORMAT_V1_ID_IDX	GENMASK(27, 24)
+#define ROM_EVENT_FORMAT_V1_RES	GENMASK(23, 0)
+
+static const char *lookup(const char *table[], size_t table_size, size_t idx)
+{
+	const char *str = NULL;
+
+	if (idx < table_size)
+		str = table[idx];
+
+	return str ?: "unknown";
+}
+
+#define LOOKUP(table, idx) lookup(table, ARRAY_SIZE(table), idx)
+
+static const char *boot_mode_0x1y[] = {
+	"Fuse", "Serial Download", "Internal Download", "Test Mode"
+};
+
+static const char *secure_config_0x2y[] = {
+	"FAB", "Field Return", "Open", "Closed"
+};
+
+static const char *boot_image_0x5y[] = {
+	"primary", "secondary"
+};
+
+static const char *boot_device_0x6y[] = {
+	"RAW NAND", "SD or EMMC", NULL, NULL, "ECSPI NOR", NULL, NULL, "QSPI NOR"
+};
+
+/* Parse the ROM event ID defintion version 1 log, see AN12853 */
+static int imx8m_bootrom_decode_log(const u32 *rom_log)
+{
+	int i;
+
+	for (i = 0; i < 128; i++) {
+		u8 event_id = FIELD_GET(ROM_EVENT_FORMAT_V1_ID, rom_log[i]);
+		u8 event_id_idx = FIELD_GET(ROM_EVENT_FORMAT_V1_ID_IDX, rom_log[i]);
+		const char *arg = NULL;
+
+		printf("[%02x] ", event_id);
+		switch (event_id) {
+		case 0x0:
+			printf("End of list\n");
+			return 0;
+		case 0x01:
+			printf("ROM event version 0x%02x\n", rom_log[i] & 0xFF);
+			continue;
+
+		case 0x10 ... 0x13:
+			printf("Boot mode is Boot from %s\n",
+			       LOOKUP(boot_mode_0x1y, event_id_idx));
+			continue;
+
+		case 0x20 ... 0x23:
+			printf("Secure config is %s\n",
+			       LOOKUP(secure_config_0x2y, event_id_idx));
+			continue;
+
+		case 0x30 ... 0x31:
+		case 0xe0:
+			printf("Internal use\n");
+			continue;
+
+		case 0x40 ... 0x41:
+			printf("FUSE_SEL_VALUE Fuse is %sblown\n",
+			       event_id_idx ? "" : "not ");
+			continue;
+
+		case 0x50 ... 0x51:
+			printf("Boot from the %s boot image\n",
+			       LOOKUP(boot_image_0x5y, event_id_idx));
+			continue;
+
+		case 0x74:
+			arg = "SPI NAND";
+			fallthrough;
+		case 0x60 ... 0x67:
+			printf("Primary boot from %s device\n",
+			       arg ?: LOOKUP(boot_device_0x6y, event_id_idx));
+			continue;
+
+		case 0x71:
+			printf("Recovery boot from ECSPI NOR device\n");
+			continue;
+		case 0x72:
+			printf("No Recovery boot device\n");
+			continue;
+		case 0x73:
+			printf("Manufacture boot from SD or EMMC\n");
+			continue;
+
+		case 0x80:
+			printf("Start to perform the device initialization: @%u ticks\n",
+			       rom_log[++i]);
+			continue;
+		case 0x81:
+			printf("The boot device initialization completes: @%u ticks\n",
+			       rom_log[++i]);
+			continue;
+		case 0x82:
+			printf("Start to execute boot device driver pre-config\n");
+			continue;
+		case 0x83:
+			printf("Boot device driver pre-config completes\n");
+			continue;
+		case 0x8E:
+			printf("Boot device driver pre-config fails\n");
+			continue;
+		case 0x8f:
+			printf("boot device initialization fails: @%u ticks\n",
+			       rom_log[++i]);
+			continue;
+
+		case 0x90:
+			printf("Start to read data from boot device: @ offset %08x\n",
+			       rom_log[++i]);
+			continue;
+		case 0x91:
+			printf("Reading data from boot device completes: @%u ticks\n",
+			       rom_log[++i]);
+			continue;
+		case 0x9f:
+			printf("Reading data from boot device fails: @%u ticks\n",
+			       rom_log[++i]);
+			continue;
+
+		case 0xa0:
+			printf("Image authentication result: %s (0x%08x) @%u ticks\n",
+			       (rom_log[i+1] & 0xFF) == 0xF0 ? "PASS" : "FAIL",
+			       rom_log[i+1], rom_log[i+2]);
+			i += 2;
+			continue;
+		case 0xa1:
+			printf("IVT header is not valid\n");
+			continue;
+
+		case 0xc0:
+			printf("Jump to the boot image soon: @ offset 0x%08x @ %u ticks\n",
+			       rom_log[i+1], rom_log[i+2]);
+			i += 2;
+			continue;
+
+		case 0xd0:
+			printf("Enters serial download processing\n");
+			continue;
+
+		case 0xf0:
+			printf("Enters ROM exception handler\n");
+			continue;
+		default:
+			printf("Unknown\n");
+			continue;
+		}
+	}
+
+	return -EILSEQ;
+}
+
+static int do_bootrom(int argc, char *argv[])
+{
+	const struct imx_scratch_space *scratch = arm_mem_scratch_get();
+	const u32 *rom_log_addr = scratch->bootrom_log;
+	bool log = false;
+	int ret, opt;
+
+	while((opt = getopt(argc, argv, "la:")) > 0) {
+		switch(opt) {
+		case 'a':
+			ret = kstrtoul(optarg, 0, (ulong *)&rom_log_addr);
+			if (ret)
+				return ret;
+			rom_log_addr = (const u32 *)rom_log_addr;
+		case 'l':
+			log = true;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (log)
+		return imx8m_bootrom_decode_log(rom_log_addr);
+
+	return COMMAND_ERROR_USAGE;
+}
+
+BAREBOX_CMD_HELP_START(bootrom)
+BAREBOX_CMD_HELP_TEXT("List information about the specified files or directories.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-l",  "list event log")
+BAREBOX_CMD_HELP_OPT ("-a ADDR",  "event log address (default PBL scratch space)")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(bootrom)
+	.cmd            = do_bootrom,
+	BAREBOX_CMD_DESC("Interact with BootROM on i.MX8M")
+	BAREBOX_CMD_OPTS("[-la]")
+	BAREBOX_CMD_HELP(cmd_bootrom_help)
+	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+BAREBOX_CMD_END
diff --git a/commands/Kconfig b/commands/Kconfig
index a59616ad1474..555ae401a02d 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -60,6 +60,14 @@ config CMD_RISCV_CPUINFO
 	help
 	  Show info about RISC-V CPU
 
+config CMD_BOOTROM
+	bool "bootrom command"
+	depends on ARCH_IMX8M
+	help
+	  Interact with bootrom on i.MX8M
+
+	  bootrom [-la]
+
 config CMD_DEVINFO
 	tristate
 	default y
-- 
2.30.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command
  2022-11-01 18:06 [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2022-11-01 18:06 ` [PATCH 5/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
@ 2022-12-02  8:46 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2022-12-02  8:46 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Tue, Nov 01, 2022 at 07:06:38PM +0100, Ahmad Fatoum wrote:
> The ROM event log of the i.MX8M* can help with debugging boot
> failures as it lists various information about boot mode, image,
> fallback and recovery as well as timestamps when some actions along
> the boot process occurred.
> 
> This adds a new bootrom -l command that supports reading this out.
> 
> Ahmad Fatoum (5):
>   ARM: asm: set aside new arm_mem_scratch space
>   ARM: i.MX8M: esdctl: export imx8m_barebox_earlymem_size
>   ARM: i.MX8M: define imx8mX_scratch_space() helper
>   ARM: i.MX8M: support saving BootROM event log before clobbering OCRAM
>   ARM: i.MX8M: implement bootrom log viewing command

Applied, thanks

Sascha

> 
>  arch/arm/include/asm/barebox-arm.h          |   7 +
>  arch/arm/mach-imx/Kconfig                   |   4 +
>  arch/arm/mach-imx/Makefile                  |   1 +
>  arch/arm/mach-imx/atf.c                     |   3 +
>  arch/arm/mach-imx/bootrom-cmd.c             | 220 ++++++++++++++++++++
>  arch/arm/mach-imx/esdctl.c                  |  11 +-
>  arch/arm/mach-imx/include/mach/esdctl.h     |   3 +
>  arch/arm/mach-imx/include/mach/imx8m-regs.h |   8 +
>  arch/arm/mach-imx/include/mach/romapi.h     |  11 +
>  arch/arm/mach-imx/include/mach/xload.h      |  11 +
>  arch/arm/mach-imx/romapi.c                  |  26 +++
>  arch/arm/mach-imx/xload-common.c            |  10 +
>  commands/Kconfig                            |   8 +
>  13 files changed, 320 insertions(+), 3 deletions(-)
>  create mode 100644 arch/arm/mach-imx/bootrom-cmd.c
> 
> -- 
> 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 |



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-02  8:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 18:06 [PATCH 0/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
2022-11-01 18:06 ` [PATCH 1/5] ARM: asm: set aside new arm_mem_scratch space Ahmad Fatoum
2022-11-01 18:06 ` [PATCH 2/5] ARM: i.MX8M: esdctl: export imx8m_barebox_earlymem_size Ahmad Fatoum
2022-11-01 18:06 ` [PATCH 3/5] ARM: i.MX8M: define imx8mX_scratch_space() helper Ahmad Fatoum
2022-11-01 18:06 ` [PATCH 4/5] ARM: i.MX8M: support saving BootROM event log before clobbering OCRAM Ahmad Fatoum
2022-11-01 18:06 ` [PATCH 5/5] ARM: i.MX8M: implement bootrom log viewing command Ahmad Fatoum
2022-12-02  8:46 ` [PATCH 0/5] " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox