From 8306c3b035bebce2d4060620d85192a401128bd7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Oct 2024 10:19:29 +0200 Subject: cmd: Move meminfo command into its own file In preparation for expanding this command, move it into a separate file. Rename the function to remove the extra underscore. Update the number of arguments to 1, since 3 is incorrect. Signed-off-by: Simon Glass Reviewed-by: Ilias Apalodimas --- cmd/Kconfig | 1 + cmd/Makefile | 1 + cmd/mem.c | 19 ------------------- cmd/meminfo.c | 26 ++++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 cmd/meminfo.c (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 3ee70f31b14..ec2fe7ad35c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -885,6 +885,7 @@ config MD5SUM_VERIFY config CMD_MEMINFO bool "meminfo" + default y if SANDBOX help Display memory information. diff --git a/cmd/Makefile b/cmd/Makefile index 3c5bd56e912..16e275eba63 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -110,6 +110,7 @@ obj-$(CONFIG_CMD_LOG) += log.o obj-$(CONFIG_CMD_LSBLK) += lsblk.o obj-$(CONFIG_CMD_MD5SUM) += md5sum.o obj-$(CONFIG_CMD_MEMORY) += mem.o +obj-$(CONFIG_CMD_MEMINFO) += meminfo.o obj-$(CONFIG_CMD_IO) += io.o obj-$(CONFIG_CMD_MII) += mii.o obj-$(CONFIG_CMD_MISC) += misc.o diff --git a/cmd/mem.c b/cmd/mem.c index 4d6fde28531..9e716776393 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -1379,17 +1379,6 @@ U_BOOT_CMD( #endif -#ifdef CONFIG_CMD_MEMINFO -static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) -{ - puts("DRAM: "); - print_size(gd->ram_size, "\n"); - - return 0; -} -#endif - U_BOOT_CMD( base, 2, 1, do_mem_base, "print or set address offset", @@ -1433,14 +1422,6 @@ U_BOOT_CMD( ); #endif /* CONFIG_CMD_MX_CYCLIC */ -#ifdef CONFIG_CMD_MEMINFO -U_BOOT_CMD( - meminfo, 3, 1, do_mem_info, - "display memory information", - "" -); -#endif - #ifdef CONFIG_CMD_RANDOM U_BOOT_CMD( random, 4, 0, do_random, diff --git a/cmd/meminfo.c b/cmd/meminfo.c new file mode 100644 index 00000000000..bb9bcec2e3f --- /dev/null +++ b/cmd/meminfo.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + puts("DRAM: "); + print_size(gd->ram_size, "\n"); + + return 0; +} + +U_BOOT_CMD( + meminfo, 1, 1, do_meminfo, + "display memory information", + "" +); -- cgit v1.2.3 From f18c048e6e6194b4f64d440f514dc158e4eb12a7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Oct 2024 10:19:30 +0200 Subject: cmd: Update the meminfo command to show the memory map U-Boot has a fairly rigid memory map which is normally not visible unless debugging is enabled in board_f.c Update the 'meminfo' command to show it. This command does not cover arch-specific pieces but gives a good overview of where things are. Signed-off-by: Simon Glass --- cmd/Kconfig | 11 +++++++++++ cmd/meminfo.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index ec2fe7ad35c..f79fda64a94 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -889,6 +889,17 @@ config CMD_MEMINFO help Display memory information. +config CMD_MEMINFO_MAP + bool "- with memory map" + depends on CMD_MEMINFO + default y if SANDBOX + help + Shows a memory map, in addition to just the DRAM size. This allows + seeing where U-Boot's memory area is, at the top of DRAM, as well as + detail about each piece of it. + + See doc/usage/cmd/meminfo.rst for more information. + config CMD_MEMORY bool "md, mm, nm, mw, cp, cmp, base, loop" default y diff --git a/cmd/meminfo.c b/cmd/meminfo.c index bb9bcec2e3f..0e6d2f9cc2c 100644 --- a/cmd/meminfo.c +++ b/cmd/meminfo.c @@ -4,18 +4,67 @@ * Written by Simon Glass */ +#include +#include #include #include +#include +#include #include DECLARE_GLOBAL_DATA_PTR; +static void print_region(const char *name, ulong base, ulong size, ulong *uptop) +{ + ulong end = base + size; + + printf("%-12s %8lx %8lx %8lx", name, base, size, end); + if (*uptop) + printf(" %8lx", *uptop - end); + putc('\n'); + *uptop = base; +} + static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) + char *const argv[]) { + ulong upto, stk_bot; + puts("DRAM: "); print_size(gd->ram_size, "\n"); + if (!IS_ENABLED(CONFIG_CMD_MEMINFO_MAP)) + return 0; + + printf("\n%-12s %8s %8s %8s %8s\n", "Region", "Base", "Size", "End", + "Gap"); + printf("------------------------------------------------\n"); + upto = 0; + if (IS_ENABLED(CONFIG_VIDEO)) + print_region("video", gd_video_bottom(), + gd_video_size(), &upto); + if (IS_ENABLED(CONFIG_TRACE)) + print_region("trace", map_to_sysmem(gd_trace_buff()), + gd_trace_size(), &upto); + print_region("code", gd->relocaddr, gd->mon_len, &upto); + print_region("malloc", map_to_sysmem((void *)mem_malloc_start), + mem_malloc_end - mem_malloc_start, &upto); + print_region("board_info", map_to_sysmem(gd->bd), + sizeof(struct bd_info), &upto); + print_region("global_data", map_to_sysmem((void *)gd), + sizeof(struct global_data), &upto); + print_region("devicetree", map_to_sysmem(gd->fdt_blob), + fdt_totalsize(gd->fdt_blob), &upto); + if (IS_ENABLED(CONFIG_BOOTSTAGE)) + print_region("bootstage", map_to_sysmem(gd_bootstage()), + bootstage_get_size(false), &upto); + if (IS_ENABLED(CONFIG_BLOBLIST)) + print_region("bloblist", map_to_sysmem(gd_bloblist()), + 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); + return 0; } -- cgit v1.2.3 From 9252b7f867f7638ba3f6af85058fee7b3993222d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Oct 2024 10:19:32 +0200 Subject: meminfo: Show the lmb records Add the lmb records onto the end of the memory map. Signed-off-by: Simon Glass --- cmd/meminfo.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'cmd') 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 #include #include +#include #include #include #include @@ -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; } -- cgit v1.2.3