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