efi_driver: EFI block driver
[platform/kernel/u-boot.git] / cmd / bdinfo.c
1 /*
2  * (C) Copyright 2003
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 /*
9  * Boot support
10  */
11 #include <common.h>
12 #include <command.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%08lX\n", name, 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_8xx) || 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 !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_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)
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                 printf("fdt_blob = %p\n", 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 #if defined(CONFIG_CMD_NET)
381         print_eth_ip_addr();
382         print_mhz("ethspeed",       bd->bi_ethspeed);
383 #endif
384         print_baudrate();
385
386         return 0;
387 }
388
389 #elif defined(CONFIG_SANDBOX)
390
391 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
392 {
393         bd_t *bd = gd->bd;
394
395         print_bi_boot_params(bd);
396         print_bi_dram(bd);
397         print_eth_ip_addr();
398
399 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
400         print_num("FB base  ", gd->fb_base);
401 #endif
402         return 0;
403 }
404
405 #elif defined(CONFIG_NDS32)
406
407 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
408 {
409         bd_t *bd = gd->bd;
410
411         print_num("arch_number",        bd->bi_arch_number);
412         print_bi_boot_params(bd);
413         print_bi_dram(bd);
414         print_eth_ip_addr();
415         print_baudrate();
416
417         return 0;
418 }
419
420 #elif defined(CONFIG_RISCV)
421
422 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
423 {
424         bd_t *bd = gd->bd;
425
426         print_num("arch_number", bd->bi_arch_number);
427         print_bi_boot_params(bd);
428         print_bi_dram(bd);
429         print_eth_ip_addr();
430         print_baudrate();
431
432         return 0;
433 }
434
435 #elif defined(CONFIG_ARC)
436
437 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
438 {
439         bd_t *bd = gd->bd;
440
441         print_bi_mem(bd);
442         print_eth_ip_addr();
443         print_baudrate();
444
445         return 0;
446 }
447
448 #elif defined(CONFIG_XTENSA)
449
450 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
451 {
452         print_std_bdinfo(gd->bd);
453         return 0;
454 }
455
456 #else
457  #error "a case for this architecture does not exist!"
458 #endif
459
460 /* -------------------------------------------------------------------- */
461
462 U_BOOT_CMD(
463         bdinfo, 1,      1,      do_bdinfo,
464         "print Board Info structure",
465         ""
466 );