xref: /openbmc/u-boot/cmd/bdinfo.c (revision ae485b54)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2003
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6 
7 /*
8  * Boot support
9  */
10 #include <common.h>
11 #include <command.h>
12 #include <linux/compiler.h>
13 
14 DECLARE_GLOBAL_DATA_PTR;
15 
16 __maybe_unused
17 static void print_num(const char *name, ulong value)
18 {
19 	printf("%-12s= 0x%08lX\n", name, value);
20 }
21 
22 __maybe_unused
23 static void print_eth(int idx)
24 {
25 	char name[10], *val;
26 	if (idx)
27 		sprintf(name, "eth%iaddr", idx);
28 	else
29 		strcpy(name, "ethaddr");
30 	val = env_get(name);
31 	if (!val)
32 		val = "(not set)";
33 	printf("%-12s= %s\n", name, val);
34 }
35 
36 #ifndef CONFIG_DM_ETH
37 __maybe_unused
38 static void print_eths(void)
39 {
40 	struct eth_device *dev;
41 	int i = 0;
42 
43 	do {
44 		dev = eth_get_dev_by_index(i);
45 		if (dev) {
46 			printf("eth%dname    = %s\n", i, dev->name);
47 			print_eth(i);
48 			i++;
49 		}
50 	} while (dev);
51 
52 	printf("current eth = %s\n", eth_get_name());
53 	printf("ip_addr     = %s\n", env_get("ipaddr"));
54 }
55 #endif
56 
57 __maybe_unused
58 static void print_lnum(const char *name, unsigned long long value)
59 {
60 	printf("%-12s= 0x%.8llX\n", name, value);
61 }
62 
63 __maybe_unused
64 static void print_mhz(const char *name, unsigned long hz)
65 {
66 	char buf[32];
67 
68 	printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
69 }
70 
71 
72 static inline void print_bi_boot_params(const bd_t *bd)
73 {
74 	print_num("boot_params",	(ulong)bd->bi_boot_params);
75 }
76 
77 static inline void print_bi_mem(const bd_t *bd)
78 {
79 #if defined(CONFIG_SH)
80 	print_num("mem start      ",	(ulong)bd->bi_memstart);
81 	print_lnum("mem size       ",	(u64)bd->bi_memsize);
82 #elif defined(CONFIG_ARC)
83 	print_num("mem start",		(ulong)bd->bi_memstart);
84 	print_lnum("mem size",		(u64)bd->bi_memsize);
85 #else
86 	print_num("memstart",		(ulong)bd->bi_memstart);
87 	print_lnum("memsize",		(u64)bd->bi_memsize);
88 #endif
89 }
90 
91 static inline void print_bi_dram(const bd_t *bd)
92 {
93 #ifdef CONFIG_NR_DRAM_BANKS
94 	int i;
95 
96 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
97 		if (bd->bi_dram[i].size) {
98 			print_num("DRAM bank",	i);
99 			print_num("-> start",	bd->bi_dram[i].start);
100 			print_num("-> size",	bd->bi_dram[i].size);
101 		}
102 	}
103 #endif
104 }
105 
106 static inline void print_bi_flash(const bd_t *bd)
107 {
108 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_SH)
109 	print_num("flash start    ",	(ulong)bd->bi_flashstart);
110 	print_num("flash size     ",	(ulong)bd->bi_flashsize);
111 	print_num("flash offset   ",	(ulong)bd->bi_flashoffset);
112 
113 #elif defined(CONFIG_NIOS2)
114 	print_num("flash start",	(ulong)bd->bi_flashstart);
115 	print_num("flash size",		(ulong)bd->bi_flashsize);
116 	print_num("flash offset",	(ulong)bd->bi_flashoffset);
117 #else
118 	print_num("flashstart",		(ulong)bd->bi_flashstart);
119 	print_num("flashsize",		(ulong)bd->bi_flashsize);
120 	print_num("flashoffset",	(ulong)bd->bi_flashoffset);
121 #endif
122 }
123 
124 static inline void print_eth_ip_addr(void)
125 {
126 #if defined(CONFIG_CMD_NET)
127 	print_eth(0);
128 #if defined(CONFIG_HAS_ETH1)
129 	print_eth(1);
130 #endif
131 #if defined(CONFIG_HAS_ETH2)
132 	print_eth(2);
133 #endif
134 #if defined(CONFIG_HAS_ETH3)
135 	print_eth(3);
136 #endif
137 #if defined(CONFIG_HAS_ETH4)
138 	print_eth(4);
139 #endif
140 #if defined(CONFIG_HAS_ETH5)
141 	print_eth(5);
142 #endif
143 	printf("IP addr     = %s\n", env_get("ipaddr"));
144 #endif
145 }
146 
147 static inline void print_baudrate(void)
148 {
149 #if defined(CONFIG_PPC)
150 	printf("baudrate    = %6u bps\n", gd->baudrate);
151 #else
152 	printf("baudrate    = %u bps\n", gd->baudrate);
153 #endif
154 }
155 
156 static inline void __maybe_unused print_std_bdinfo(const bd_t *bd)
157 {
158 	print_bi_boot_params(bd);
159 	print_bi_mem(bd);
160 	print_bi_flash(bd);
161 	print_eth_ip_addr();
162 	print_baudrate();
163 }
164 
165 #if defined(CONFIG_PPC)
166 void __weak board_detail(void)
167 {
168 	/* Please define board_detail() for your platform */
169 }
170 
171 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
172 {
173 	bd_t *bd = gd->bd;
174 
175 #ifdef DEBUG
176 	print_num("bd address",		(ulong)bd);
177 #endif
178 	print_bi_mem(bd);
179 	print_bi_flash(bd);
180 	print_num("sramstart",		bd->bi_sramstart);
181 	print_num("sramsize",		bd->bi_sramsize);
182 #if	defined(CONFIG_MPC8xx) || defined(CONFIG_E500)
183 	print_num("immr_base",		bd->bi_immr_base);
184 #endif
185 	print_num("bootflags",		bd->bi_bootflags);
186 #if defined(CONFIG_CPM2)
187 	print_mhz("vco",		bd->bi_vco);
188 	print_mhz("sccfreq",		bd->bi_sccfreq);
189 	print_mhz("brgfreq",		bd->bi_brgfreq);
190 #endif
191 	print_mhz("intfreq",		bd->bi_intfreq);
192 #if defined(CONFIG_CPM2)
193 	print_mhz("cpmfreq",		bd->bi_cpmfreq);
194 #endif
195 	print_mhz("busfreq",		bd->bi_busfreq);
196 
197 #ifdef CONFIG_ENABLE_36BIT_PHYS
198 #ifdef CONFIG_PHYS_64BIT
199 	puts("addressing  = 36-bit\n");
200 #else
201 	puts("addressing  = 32-bit\n");
202 #endif
203 #endif
204 
205 	print_eth_ip_addr();
206 	print_baudrate();
207 	print_num("relocaddr", gd->relocaddr);
208 	board_detail();
209 	return 0;
210 }
211 
212 #elif defined(CONFIG_NIOS2)
213 
214 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
215 {
216 	bd_t *bd = gd->bd;
217 
218 	print_bi_dram(bd);
219 	print_bi_flash(bd);
220 
221 #if defined(CONFIG_SYS_SRAM_BASE)
222 	print_num ("sram start",	(ulong)bd->bi_sramstart);
223 	print_num ("sram size",		(ulong)bd->bi_sramsize);
224 #endif
225 
226 	print_eth_ip_addr();
227 	print_baudrate();
228 
229 	return 0;
230 }
231 
232 #elif defined(CONFIG_MICROBLAZE)
233 
234 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
235 {
236 	bd_t *bd = gd->bd;
237 
238 	print_bi_dram(bd);
239 	print_bi_flash(bd);
240 #if defined(CONFIG_SYS_SRAM_BASE)
241 	print_num("sram start     ",	(ulong)bd->bi_sramstart);
242 	print_num("sram size      ",	(ulong)bd->bi_sramsize);
243 #endif
244 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
245 	print_eths();
246 #endif
247 	print_baudrate();
248 	print_num("relocaddr", gd->relocaddr);
249 	print_num("reloc off", gd->reloc_off);
250 	print_num("fdt_blob", (ulong)gd->fdt_blob);
251 	print_num("new_fdt", (ulong)gd->new_fdt);
252 	print_num("fdt_size", (ulong)gd->fdt_size);
253 
254 	return 0;
255 }
256 
257 #elif defined(CONFIG_M68K)
258 
259 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
260 {
261 	bd_t *bd = gd->bd;
262 
263 	print_bi_mem(bd);
264 	print_bi_flash(bd);
265 #if defined(CONFIG_SYS_INIT_RAM_ADDR)
266 	print_num("sramstart",		(ulong)bd->bi_sramstart);
267 	print_num("sramsize",		(ulong)bd->bi_sramsize);
268 #endif
269 #if defined(CONFIG_SYS_MBAR)
270 	print_num("mbar",		bd->bi_mbar_base);
271 #endif
272 	print_mhz("cpufreq",		bd->bi_intfreq);
273 	print_mhz("busfreq",		bd->bi_busfreq);
274 #ifdef CONFIG_PCI
275 	print_mhz("pcifreq",		bd->bi_pcifreq);
276 #endif
277 #ifdef CONFIG_EXTRA_CLOCK
278 	print_mhz("flbfreq",		bd->bi_flbfreq);
279 	print_mhz("inpfreq",		bd->bi_inpfreq);
280 	print_mhz("vcofreq",		bd->bi_vcofreq);
281 #endif
282 	print_eth_ip_addr();
283 	print_baudrate();
284 
285 	return 0;
286 }
287 
288 #elif defined(CONFIG_MIPS)
289 
290 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
291 {
292 	print_std_bdinfo(gd->bd);
293 	print_num("relocaddr", gd->relocaddr);
294 	print_num("reloc off", gd->reloc_off);
295 
296 	return 0;
297 }
298 
299 #elif defined(CONFIG_ARM)
300 
301 static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc,
302 			char * const argv[])
303 {
304 	bd_t *bd = gd->bd;
305 
306 	print_num("arch_number",	bd->bi_arch_number);
307 	print_bi_boot_params(bd);
308 	print_bi_dram(bd);
309 
310 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
311 	if (gd->arch.secure_ram & MEM_RESERVE_SECURE_SECURED) {
312 		print_num("Secure ram",
313 			  gd->arch.secure_ram & MEM_RESERVE_SECURE_ADDR_MASK);
314 	}
315 #endif
316 #ifdef CONFIG_RESV_RAM
317 	if (gd->arch.resv_ram)
318 		print_num("Reserved ram", gd->arch.resv_ram);
319 #endif
320 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
321 	print_eths();
322 #endif
323 	print_baudrate();
324 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
325 	print_num("TLB addr", gd->arch.tlb_addr);
326 #endif
327 	print_num("relocaddr", gd->relocaddr);
328 	print_num("reloc off", gd->reloc_off);
329 	print_num("irq_sp", gd->irq_sp);	/* irq stack pointer */
330 	print_num("sp start ", gd->start_addr_sp);
331 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
332 	print_num("FB base  ", gd->fb_base);
333 #endif
334 	/*
335 	 * TODO: Currently only support for davinci SOC's is added.
336 	 * Remove this check once all the board implement this.
337 	 */
338 #ifdef CONFIG_CLOCKS
339 	printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq);
340 	printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq);
341 	printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq);
342 #endif
343 #ifdef CONFIG_BOARD_TYPES
344 	printf("Board Type  = %ld\n", gd->board_type);
345 #endif
346 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
347 	printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr,
348 	       CONFIG_VAL(SYS_MALLOC_F_LEN));
349 #endif
350 	if (gd->fdt_blob)
351 		printf("fdt_blob = %p\n", gd->fdt_blob);
352 
353 	return 0;
354 }
355 
356 #elif defined(CONFIG_SH)
357 
358 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
359 {
360 	bd_t *bd = gd->bd;
361 
362 	print_bi_mem(bd);
363 	print_bi_flash(bd);
364 	print_eth_ip_addr();
365 	print_baudrate();
366 	return 0;
367 }
368 
369 #elif defined(CONFIG_X86)
370 
371 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
372 {
373 	bd_t *bd = gd->bd;
374 
375 	print_bi_boot_params(bd);
376 
377 	print_bi_dram(bd);
378 
379 	print_num("relocaddr", gd->relocaddr);
380 	print_num("reloc off", gd->reloc_off);
381 #if defined(CONFIG_CMD_NET)
382 	print_eth_ip_addr();
383 	print_mhz("ethspeed",	    bd->bi_ethspeed);
384 #endif
385 	print_baudrate();
386 
387 	return 0;
388 }
389 
390 #elif defined(CONFIG_SANDBOX)
391 
392 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
393 {
394 	bd_t *bd = gd->bd;
395 
396 	print_bi_boot_params(bd);
397 	print_bi_dram(bd);
398 	print_eth_ip_addr();
399 
400 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
401 	print_num("FB base  ", gd->fb_base);
402 #endif
403 	return 0;
404 }
405 
406 #elif defined(CONFIG_NDS32)
407 
408 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
409 {
410 	bd_t *bd = gd->bd;
411 
412 	print_num("arch_number",	bd->bi_arch_number);
413 	print_bi_boot_params(bd);
414 	print_bi_dram(bd);
415 	print_eth_ip_addr();
416 	print_baudrate();
417 
418 	return 0;
419 }
420 
421 #elif defined(CONFIG_RISCV)
422 
423 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
424 {
425 	bd_t *bd = gd->bd;
426 
427 	print_num("arch_number", bd->bi_arch_number);
428 	print_bi_boot_params(bd);
429 	print_bi_dram(bd);
430 	print_eth_ip_addr();
431 	print_baudrate();
432 
433 	return 0;
434 }
435 
436 #elif defined(CONFIG_ARC)
437 
438 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
439 {
440 	bd_t *bd = gd->bd;
441 
442 	print_bi_mem(bd);
443 	print_eth_ip_addr();
444 	print_baudrate();
445 
446 	return 0;
447 }
448 
449 #elif defined(CONFIG_XTENSA)
450 
451 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
452 {
453 	print_std_bdinfo(gd->bd);
454 	return 0;
455 }
456 
457 #else
458  #error "a case for this architecture does not exist!"
459 #endif
460 
461 /* -------------------------------------------------------------------- */
462 
463 U_BOOT_CMD(
464 	bdinfo,	1,	1,	do_bdinfo,
465 	"print Board Info structure",
466 	""
467 );
468