Merge branch '2020-08-06-Kconfig-sram-options'
[platform/kernel/u-boot.git] / cmd / bdinfo.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Implements the 'bd' command to show board information
4  *
5  * (C) Copyright 2003
6  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7  */
8
9 #include <common.h>
10 #include <command.h>
11 #include <env.h>
12 #include <lmb.h>
13 #include <net.h>
14 #include <vsprintf.h>
15 #include <asm/cache.h>
16
17 DECLARE_GLOBAL_DATA_PTR;
18
19 void bdinfo_print_num(const char *name, ulong value)
20 {
21         printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
22 }
23
24 static void print_eth(int idx)
25 {
26         char name[10], *val;
27         if (idx)
28                 sprintf(name, "eth%iaddr", idx);
29         else
30                 strcpy(name, "ethaddr");
31         val = env_get(name);
32         if (!val)
33                 val = "(not set)";
34         printf("%-12s= %s\n", name, val);
35 }
36
37 static void print_phys_addr(const char *name, phys_addr_t value)
38 {
39         printf("%-12s= 0x%.*llx\n", name, 2 * (int)sizeof(ulong),
40                (unsigned long long)value);
41 }
42
43 void bdinfo_print_mhz(const char *name, unsigned long hz)
44 {
45         char buf[32];
46
47         printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
48 }
49
50 static void print_bi_dram(const struct bd_info *bd)
51 {
52 #ifdef CONFIG_NR_DRAM_BANKS
53         int i;
54
55         for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
56                 if (bd->bi_dram[i].size) {
57                         bdinfo_print_num("DRAM bank",   i);
58                         bdinfo_print_num("-> start",    bd->bi_dram[i].start);
59                         bdinfo_print_num("-> size",     bd->bi_dram[i].size);
60                 }
61         }
62 #endif
63 }
64
65 __weak void arch_print_bdinfo(void)
66 {
67 }
68
69 int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
70 {
71         struct bd_info *bd = gd->bd;
72
73 #ifdef DEBUG
74         bdinfo_print_num("bd address", (ulong)bd);
75 #endif
76         bdinfo_print_num("boot_params", (ulong)bd->bi_boot_params);
77         print_bi_dram(bd);
78         bdinfo_print_num("memstart", (ulong)bd->bi_memstart);
79         print_phys_addr("memsize", bd->bi_memsize);
80         if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
81                 bdinfo_print_num("sramstart", (ulong)bd->bi_sramstart);
82                 bdinfo_print_num("sramsize", (ulong)bd->bi_sramsize);
83         }
84         bdinfo_print_num("flashstart", (ulong)bd->bi_flashstart);
85         bdinfo_print_num("flashsize", (ulong)bd->bi_flashsize);
86         bdinfo_print_num("flashoffset", (ulong)bd->bi_flashoffset);
87         printf("baudrate    = %u bps\n", gd->baudrate);
88         bdinfo_print_num("relocaddr", gd->relocaddr);
89         bdinfo_print_num("reloc off", gd->reloc_off);
90         printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
91         if (IS_ENABLED(CONFIG_CMD_NET)) {
92                 printf("current eth = %s\n", eth_get_name());
93                 print_eth(0);
94                 printf("IP addr     = %s\n", env_get("ipaddr"));
95         }
96         bdinfo_print_num("fdt_blob", (ulong)gd->fdt_blob);
97         bdinfo_print_num("new_fdt", (ulong)gd->new_fdt);
98         bdinfo_print_num("fdt_size", (ulong)gd->fdt_size);
99 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) || defined(CONFIG_DM_VIDEO)
100         bdinfo_print_num("FB base  ", gd->fb_base);
101 #endif
102 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
103         bdinfo_print_num("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
104 #endif
105         if (gd->fdt_blob) {
106                 struct lmb lmb;
107
108                 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
109                 lmb_dump_all_force(&lmb);
110         }
111
112         arch_print_bdinfo();
113
114         return 0;
115 }
116
117 U_BOOT_CMD(
118         bdinfo, 1,      1,      do_bdinfo,
119         "print Board Info structure",
120         ""
121 );