mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: cpuinfo: add option to print early memory map
@ 2024-07-22 17:06 Ahmad Fatoum
  2024-07-24  8:38 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-22 17:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

While the iomem command is useful for visualizing the memory map, it has
some drawbacks:

  - It is only usable once barebox init has reached the shell
  - Not all its entries reflect the early barebox memory map

Address by teaching the cpuinfo command a new -m option that prints the
early memory map and print it by default if CONFIG_DEBUG_PBL is enabled.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/cpu/common.c              | 29 +++++++++++++++++++++++++++++
 arch/arm/cpu/cpuinfo.c             | 12 ++++++++++--
 arch/arm/cpu/uncompress.c          |  4 ++++
 arch/arm/include/asm/barebox-arm.h |  1 +
 4 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
index e9118b450d3f..339ef2db2534 100644
--- a/arch/arm/cpu/common.c
+++ b/arch/arm/cpu/common.c
@@ -156,3 +156,32 @@ int boot_cpu_mode(void)
 {
 	return __boot_cpu_mode;
 }
+
+void print_pbl_mem_layout(ulong membase, ulong endmem, ulong barebox_base)
+{
+	printf("endmem                = 0x%08lx\n", endmem);
+	if (OPTEE_SIZE)
+		printf("arm_mem_optee         = 0x%08lx+0x%08x\n", arm_mem_optee(endmem),
+		       OPTEE_SIZE);
+	printf("arm_mem_scratch       = 0x%08lx+0x%08lx\n",
+	       arm_mem_scratch(endmem),
+	       arm_mem_barebox_image_end(endmem) - arm_mem_scratch(endmem));
+	printf("arm_mem_stack         = 0x%08lx+0x%08x\n",
+	       arm_mem_stack(endmem), STACK_SIZE);
+	if (IS_ENABLED(CONFIG_STACK_GUARD_PAGE))
+		printf("arm_mem_guard_page    = 0x%08lx+0x%08x\n",
+		       arm_mem_guard_page(endmem), PAGE_SIZE);
+	printf("arm_mem_ttb           = 0x%08lx+0x%08x\n",
+	       arm_mem_ttb(endmem), ARM_EARLY_PAGETABLE_SIZE);
+#ifdef CONFIG_FS_PSTORE_RAMOOPS
+	printf("arm_mem_ramoops       = 0x%08lx+0x%08x\n",
+	       arm_mem_ramoops(endmem), CONFIG_FS_PSTORE_RAMOOPS_SIZE);
+#endif
+	printf("arm_mem_barebox_image = 0x%08lx+0x%08lx\n",
+	       barebox_base, arm_mem_barebox_image_end(endmem) - barebox_base);
+	printf("arm_mem_early_malloc  = 0x%08lx+0x%08x\n",
+	       barebox_base - ARM_MEM_EARLY_MALLOC_SIZE, ARM_MEM_EARLY_MALLOC_SIZE);
+	printf("membase               = 0x%08lx+0x%08lx\n",
+	       membase, endmem - membase);
+}
+
diff --git a/arch/arm/cpu/cpuinfo.c b/arch/arm/cpu/cpuinfo.c
index ce5f0109755a..7dca57248b69 100644
--- a/arch/arm/cpu/cpuinfo.c
+++ b/arch/arm/cpu/cpuinfo.c
@@ -7,7 +7,9 @@
 #include <getopt.h>
 #include <command.h>
 #include <complete.h>
+#include <memory.h>
 #include <asm/system.h>
+#include <asm/barebox-arm.h>
 
 #define CPU_ARCH_UNKNOWN	0
 #define CPU_ARCH_ARMv3		1
@@ -54,8 +56,13 @@ static int do_cpuinfo(int argc, char *argv[])
 	int opt, i;
 	int cpu_arch;
 
-	while ((opt = getopt(argc, argv, "s")) > 0) {
+	while ((opt = getopt(argc, argv, "sm")) > 0) {
 		switch (opt) {
+		case 'm':
+			print_pbl_mem_layout(arm_mem_membase_get(),
+					     arm_mem_endmem_get(),
+					     mem_malloc_end() + 1);
+			return 0;
 		case 's':
 			if (!IS_ENABLED(CONFIG_ARCH_HAS_STACK_DUMP))
 				return -ENOSYS;
@@ -277,12 +284,13 @@ static int do_cpuinfo(int argc, char *argv[])
 BAREBOX_CMD_HELP_START(cpuinfo)
 BAREBOX_CMD_HELP_TEXT("Shows misc info about CPU")
 BAREBOX_CMD_HELP_OPT ("-s", "print call stack info (if supported)")
+BAREBOX_CMD_HELP_OPT ("-m", "print PBL memory layout")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(cpuinfo)
 	.cmd            = do_cpuinfo,
 	BAREBOX_CMD_DESC("show info about CPU")
-	BAREBOX_CMD_OPTS("[-s]")
+	BAREBOX_CMD_OPTS("[-sm]")
 	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
 	BAREBOX_CMD_COMPLETE(empty_complete)
 	BAREBOX_CMD_HELP(cmd_cpuinfo_help)
diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index daacd2286698..0d9fa2c879c9 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -92,6 +92,10 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 	free_mem_ptr = barebox_base - ARM_MEM_EARLY_MALLOC_SIZE;
 	free_mem_end_ptr = barebox_base;
 
+#ifdef DEBUG
+	print_pbl_mem_layout(membase, memsize, barebox_base);
+#endif
+
 	pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx (uncompressed size: 0x%08x)\n",
 			pg_start, pg_len, barebox_base, uncompressed_len);
 
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 6071c6435535..7d35e88c8123 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -91,6 +91,7 @@ void *barebox_arm_boot_dtb(void);
  *                                   ↓
  *  ------------------------ arm_mem_early_malloc ----------------------
  */
+void print_pbl_mem_layout(ulong membase, ulong endmem, ulong barebox_base);
 
 static inline unsigned long arm_mem_optee(unsigned long endmem)
 {
-- 
2.39.2




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

end of thread, other threads:[~2024-07-24  8:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-22 17:06 [PATCH] ARM: cpuinfo: add option to print early memory map Ahmad Fatoum
2024-07-24  8:38 ` Sascha Hauer

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