[PATCH v4 8/8] meminfo: Show the lmb records

Simon Glass sjg at chromium.org
Mon Oct 21 10:19:32 CEST 2024


Add the lmb records onto the end of the memory map.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v4:
- Add new patch to show the lmb records

 cmd/meminfo.c      | 26 +++++++++++++++++++++++++-
 test/cmd/meminfo.c |  6 +++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/cmd/meminfo.c b/cmd/meminfo.c
index 0e6d2f9cc2c..5e83d61c2dd 100644
--- a/cmd/meminfo.c
+++ b/cmd/meminfo.c
@@ -8,6 +8,7 @@
 #include <bootstage.h>
 #include <command.h>
 #include <display_options.h>
+#include <lmb.h>
 #include <malloc.h>
 #include <mapmem.h>
 #include <asm/global_data.h>
@@ -25,6 +26,27 @@ static void print_region(const char *name, ulong base, ulong size, ulong *uptop)
 	*uptop = base;
 }
 
+static void show_lmb(const struct lmb *lmb, ulong *uptop)
+{
+	int i;
+
+	for (i = lmb->used_mem.count - 1; i >= 0; i--) {
+		const struct lmb_region *rgn = alist_get(&lmb->used_mem, i,
+							 struct lmb_region);
+
+		/*
+		 * Assume that the top lmb region is the U-Boot region, so just
+		 * take account of the memory not already reported
+		 */
+		if (lmb->used_mem.count - 1)
+			print_region("lmb", rgn->base, *uptop - rgn->base,
+				     uptop);
+		else
+			print_region("lmb", rgn->base, rgn->size, uptop);
+		*uptop = rgn->base;
+	}
+}
+
 static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
@@ -63,7 +85,9 @@ static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc,
 			     bloblist_get_total_size(), &upto);
 	stk_bot = gd->start_addr_sp - CONFIG_STACK_SIZE;
 	print_region("stack", stk_bot, CONFIG_STACK_SIZE, &upto);
-	print_region("free", gd->ram_base, stk_bot, &upto);
+	if (IS_ENABLED(CONFIG_LMB))
+		show_lmb(lmb_get(), &upto);
+	print_region("free", gd->ram_base, upto, &upto);
 
 	return 0;
 }
diff --git a/test/cmd/meminfo.c b/test/cmd/meminfo.c
index 84981305bf0..53b41e3b49e 100644
--- a/test/cmd/meminfo.c
+++ b/test/cmd/meminfo.c
@@ -30,7 +30,11 @@ static int cmd_test_meminfo(struct unit_test_state *uts)
 	ut_assert_nextlinen("bootstage");
 	ut_assert_nextlinen("bloblist");
 	ut_assert_nextlinen("stack");
-	ut_assert_nextlinen("free");
+
+	/* we expect at least one lmb line, but don't know how many */
+	ut_assert_nextlinen("lmb");
+	ut_assert_skip_to_linen("free");
+
 	ut_assert_console_end();
 
 	return 0;
-- 
2.43.0



More information about the U-Boot mailing list