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