[PATCH 6/8] cmd: meminfo: widen memory map addresses to phys_addr_t

Raymond Mao raymondmaoca at gmail.com
Fri Jun 12 22:18:59 CEST 2026


From: Guodong Xu <guodong at riscstar.com>

On 32-bit builds 'ulong' is only 32 bits wide, so the memory map
truncates any address or size at or above 4 GiB even though the
columns already allow 13 hex digits. Boards with large DRAM therefore
print wrong bases, sizes and gaps.

Use phys_addr_t for every region address and print it as a 64-bit
value so the map is correct regardless of the build's long width.

Signed-off-by: Guodong Xu <guodong at riscstar.com>
Signed-off-by: Raymond Mao <raymond.mao at riscstar.com>
---
 cmd/meminfo.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/cmd/meminfo.c b/cmd/meminfo.c
index 69a5b1b51a2..537ef2a0e13 100644
--- a/cmd/meminfo.c
+++ b/cmd/meminfo.c
@@ -21,18 +21,23 @@ void __weak arch_dump_mem_attrs(void)
 {
 }
 
-static void print_region(const char *name, ulong base, ulong size, ulong *uptop)
+static void print_region(const char *name, phys_addr_t base, phys_addr_t size,
+			 phys_addr_t *uptop)
 {
-	ulong end = base + size;
+	phys_addr_t end = base + size;
 
-	printf("%-12s %13lx %13lx %13lx", name, base, size, end);
+	printf("%-12s %13llx %13llx %13llx",
+	       name,
+	       (unsigned long long)base,
+	       (unsigned long long)size,
+	       (unsigned long long)end);
 	if (*uptop)
-		printf(" %13lx", *uptop - end);
+		printf(" %13llx", (unsigned long long)(*uptop - end));
 	putc('\n');
 	*uptop = base;
 }
 
-static void show_lmb(const struct lmb *lmb, ulong *uptop)
+static void show_lmb(const struct lmb *lmb, phys_addr_t *uptop)
 {
 	int i;
 
@@ -56,7 +61,7 @@ static void show_lmb(const struct lmb *lmb, ulong *uptop)
 static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
-	ulong upto, stk_bot;
+	phys_addr_t upto, stk_bot;
 
 	puts("DRAM:  ");
 	print_size(gd->ram_size, "\n");
-- 
2.25.1



More information about the U-Boot mailing list