1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2024 Google LLC
10 #include <display_options.h>
14 #include <asm/global_data.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 static void print_region(const char *name, ulong base, ulong size, ulong *uptop)
20 ulong end = base + size;
22 printf("%-12s %8lx %8lx %8lx", name, base, size, end);
24 printf(" %8lx", *uptop - end);
29 static void show_lmb(const struct lmb *lmb, ulong *uptop)
33 for (i = lmb->used_mem.count - 1; i >= 0; i--) {
34 const struct lmb_region *rgn = alist_get(&lmb->used_mem, i,
38 * Assume that the top lmb region is the U-Boot region, so just
39 * take account of the memory not already reported
41 if (lmb->used_mem.count - 1)
42 print_region("lmb", rgn->base, *uptop - rgn->base,
45 print_region("lmb", rgn->base, rgn->size, uptop);
50 static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc,
56 print_size(gd->ram_size, "\n");
58 if (!IS_ENABLED(CONFIG_CMD_MEMINFO_MAP))
61 printf("\n%-12s %8s %8s %8s %8s\n", "Region", "Base", "Size", "End",
63 printf("------------------------------------------------\n");
65 if (IS_ENABLED(CONFIG_VIDEO))
66 print_region("video", gd_video_bottom(),
67 gd_video_size(), &upto);
68 if (IS_ENABLED(CONFIG_TRACE))
69 print_region("trace", map_to_sysmem(gd_trace_buff()),
70 gd_trace_size(), &upto);
71 print_region("code", gd->relocaddr, gd->mon_len, &upto);
72 print_region("malloc", map_to_sysmem((void *)mem_malloc_start),
73 mem_malloc_end - mem_malloc_start, &upto);
74 print_region("board_info", map_to_sysmem(gd->bd),
75 sizeof(struct bd_info), &upto);
76 print_region("global_data", map_to_sysmem((void *)gd),
77 sizeof(struct global_data), &upto);
78 print_region("devicetree", map_to_sysmem(gd->fdt_blob),
79 fdt_totalsize(gd->fdt_blob), &upto);
80 if (IS_ENABLED(CONFIG_BOOTSTAGE))
81 print_region("bootstage", map_to_sysmem(gd_bootstage()),
82 bootstage_get_size(false), &upto);
83 if (IS_ENABLED(CONFIG_BLOBLIST))
84 print_region("bloblist", map_to_sysmem(gd_bloblist()),
85 bloblist_get_total_size(), &upto);
86 stk_bot = gd->start_addr_sp - CONFIG_STACK_SIZE;
87 print_region("stack", stk_bot, CONFIG_STACK_SIZE, &upto);
88 if (IS_ENABLED(CONFIG_LMB))
89 show_lmb(lmb_get(), &upto);
90 print_region("free", gd->ram_base, upto, &upto);
96 meminfo, 1, 1, do_meminfo,
97 "display memory information",