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 <command.h>
10 #include <dm.h>
11 #include <env.h>
12 #include <getopt.h>
13 #include <lmb.h>
14 #include <mapmem.h>
15 #include <net.h>
16 #include <serial.h>
17 #include <video.h>
18 #include <vsprintf.h>
19 #include <asm/cache.h>
20 #include <asm/global_data.h>
21 #include <display_options.h>
22
23 DECLARE_GLOBAL_DATA_PTR;
24
bdinfo_print_size(const char * name,uint64_t size)25 void bdinfo_print_size(const char *name, uint64_t size)
26 {
27 printf("%-12s= ", name);
28 print_size(size, "\n");
29 }
30
bdinfo_print_str(const char * name,const char * str)31 void bdinfo_print_str(const char *name, const char *str)
32 {
33 printf("%-12s= %s\n", name, str);
34 }
35
bdinfo_print_num_l(const char * name,ulong value)36 void bdinfo_print_num_l(const char *name, ulong value)
37 {
38 printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
39 }
40
bdinfo_print_num_ll(const char * name,unsigned long long value)41 void bdinfo_print_num_ll(const char *name, unsigned long long value)
42 {
43 printf("%-12s= 0x%.*llx\n", name, 2 * (int)sizeof(ulong), value);
44 }
45
print_eth(void)46 static void print_eth(void)
47 {
48 const int idx = eth_get_dev_index();
49 char ipstr[] = "ipaddr\0\0";
50 uchar enetaddr[6];
51 char name[10];
52 int ret;
53
54 if (idx)
55 sprintf(name, "eth%iaddr", idx);
56 else
57 strcpy(name, "ethaddr");
58
59 ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr);
60
61 printf("current eth = %s\n", eth_get_name());
62 if (!ret)
63 printf("%-12s= (not set)\n", name);
64 else
65 printf("%-12s= %pM\n", name, enetaddr);
66
67 if (idx > 0)
68 sprintf(ipstr, "ipaddr%d", idx);
69
70 printf("IP addr = %s\n", env_get(ipstr));
71 }
72
bdinfo_print_mhz(const char * name,unsigned long hz)73 void bdinfo_print_mhz(const char *name, unsigned long hz)
74 {
75 char buf[32];
76
77 printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
78 }
79
print_bi_dram(const struct bd_info * bd)80 static void print_bi_dram(const struct bd_info *bd)
81 {
82 int i;
83
84 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
85 if (bd->bi_dram[i].size) {
86 bdinfo_print_num_l("DRAM bank", i);
87 bdinfo_print_num_ll("-> start", bd->bi_dram[i].start);
88 bdinfo_print_num_ll("-> size", bd->bi_dram[i].size);
89 }
90 }
91 }
92
arch_print_bdinfo(void)93 __weak void arch_print_bdinfo(void)
94 {
95 }
96
show_video_info(void)97 static void show_video_info(void)
98 {
99 const struct udevice *dev;
100 struct uclass *uc;
101
102 uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) {
103 printf("%-12s= %s %sactive\n", "Video", dev->name,
104 device_active(dev) ? "" : "in");
105 if (device_active(dev)) {
106 struct video_priv *upriv = dev_get_uclass_priv(dev);
107 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
108
109 bdinfo_print_num_ll("FB base", (ulong)upriv->fb);
110 if (upriv->copy_fb) {
111 bdinfo_print_num_ll("FB copy",
112 (ulong)upriv->copy_fb);
113 bdinfo_print_num_l(" copy size",
114 plat->copy_size);
115 }
116 printf("%-12s= %dx%dx%d\n", "FB size", upriv->xsize,
117 upriv->ysize, 1 << upriv->bpix);
118 }
119 }
120 }
121
print_serial(struct udevice * dev)122 static void print_serial(struct udevice *dev)
123 {
124 struct serial_device_info info;
125 int ret;
126
127 if (!dev || !IS_ENABLED(CONFIG_DM_SERIAL))
128 return;
129
130 ret = serial_getinfo(dev, &info);
131 if (ret)
132 return;
133
134 bdinfo_print_num_l("serial addr", info.addr);
135 bdinfo_print_num_l(" width", info.reg_width);
136 bdinfo_print_num_l(" shift", info.reg_shift);
137 bdinfo_print_num_l(" offset", info.reg_offset);
138 bdinfo_print_num_l(" clock", info.clock);
139 }
140
bdinfo_print_all(struct bd_info * bd)141 static int bdinfo_print_all(struct bd_info *bd)
142 {
143 #ifdef DEBUG
144 bdinfo_print_num_l("bd address", (ulong)bd);
145 #endif
146 bdinfo_print_num_l("boot_params", (ulong)bd->bi_boot_params);
147 print_bi_dram(bd);
148 bdinfo_print_num_l("flashstart", (ulong)bd->bi_flashstart);
149 bdinfo_print_num_l("flashsize", (ulong)bd->bi_flashsize);
150 bdinfo_print_num_l("flashoffset", (ulong)bd->bi_flashoffset);
151 printf("baudrate = %u bps\n", gd->baudrate);
152 bdinfo_print_num_l("relocaddr", gd->relocaddr);
153 bdinfo_print_num_l("reloc off", gd->reloc_off);
154 printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
155 if (IS_ENABLED(CONFIG_CMD_NET) || IS_ENABLED(CONFIG_CMD_NET_LWIP))
156 print_eth();
157 bdinfo_print_num_l("fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob));
158 if (IS_ENABLED(CONFIG_VIDEO))
159 show_video_info();
160 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
161 bdinfo_print_num_l("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
162 #endif
163 if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) {
164 lmb_dump_all_force();
165 if (IS_ENABLED(CONFIG_OF_REAL))
166 printf("devicetree = %s\n", fdtdec_get_srcname());
167 }
168 print_serial(gd->cur_serial_dev);
169
170 if (IS_ENABLED(CONFIG_CMD_BDINFO_EXTRA)) {
171 bdinfo_print_num_ll("stack ptr", (ulong)&bd);
172 bdinfo_print_num_ll("ram_top ptr", (ulong)gd->ram_top);
173 bdinfo_print_num_l("malloc base", gd_malloc_start());
174 }
175
176 arch_print_bdinfo();
177
178 return 0;
179 }
180
do_bdinfo(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])181 int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
182 {
183 struct bd_info *bd = gd->bd;
184 struct getopt_state gs;
185 int opt;
186
187 if (!CONFIG_IS_ENABLED(GETOPT) || argc == 1)
188 return bdinfo_print_all(bd);
189
190 getopt_init_state(&gs);
191 while ((opt = getopt(&gs, argc, argv, "aem")) > 0) {
192 switch (opt) {
193 case 'a':
194 return bdinfo_print_all(bd);
195 case 'e':
196 if (!IS_ENABLED(CONFIG_CMD_NET) &&
197 !IS_ENABLED(CONFIG_CMD_NET_LWIP))
198 return CMD_RET_USAGE;
199 print_eth();
200 return CMD_RET_SUCCESS;
201 case 'm':
202 print_bi_dram(bd);
203 return CMD_RET_SUCCESS;
204 default:
205 return CMD_RET_USAGE;
206 }
207 }
208
209 return CMD_RET_USAGE;
210 }
211
212 U_BOOT_CMD(
213 bdinfo, 2, 1, do_bdinfo,
214 "print Board Info structure",
215 ""
216 );
217