cmd/bdinfo: extract print_bi_flash
[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 = getenv(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", getenv("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 #elif defined(CONFIG_AVR32)
87         print_num("memstart",           (ulong)bd->bi_dram[0].start);
88         print_lnum("memsize",           (u64)bd->bi_dram[0].size);
89 #else
90         print_num("memstart",           (ulong)bd->bi_memstart);
91         print_lnum("memsize",           (u64)bd->bi_memsize);
92 #endif
93 }
94
95 static inline void print_bi_dram(const bd_t *bd)
96 {
97 #ifdef CONFIG_NR_DRAM_BANKS
98         int i;
99
100         for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
101                 print_num("DRAM bank",  i);
102                 print_num("-> start",   bd->bi_dram[i].start);
103                 print_num("-> size",    bd->bi_dram[i].size);
104         }
105 #endif
106 }
107
108 static inline void print_bi_flash(const bd_t *bd)
109 {
110 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_SH)
111         print_num("flash start    ",    (ulong)bd->bi_flashstart);
112         print_num("flash size     ",    (ulong)bd->bi_flashsize);
113         print_num("flash offset   ",    (ulong)bd->bi_flashoffset);
114
115 #elif defined(CONFIG_NIOS2) || defined(CONFIG_OPENRISC)
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 #else
120         print_num("flashstart",         (ulong)bd->bi_flashstart);
121         print_num("flashsize",          (ulong)bd->bi_flashsize);
122         print_num("flashoffset",        (ulong)bd->bi_flashoffset);
123 #endif
124 }
125
126 #if defined(CONFIG_PPC)
127 void __weak board_detail(void)
128 {
129         /* Please define boot_detail() for your platform */
130 }
131
132 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
133 {
134         bd_t *bd = gd->bd;
135
136 #ifdef DEBUG
137         print_num("bd address",         (ulong)bd);
138 #endif
139         print_bi_mem(bd);
140         print_bi_flash(bd);
141         print_num("sramstart",          bd->bi_sramstart);
142         print_num("sramsize",           bd->bi_sramsize);
143 #if     defined(CONFIG_5xx)  || defined(CONFIG_8xx) || \
144         defined(CONFIG_MPC8260) || defined(CONFIG_E500)
145         print_num("immr_base",          bd->bi_immr_base);
146 #endif
147         print_num("bootflags",          bd->bi_bootflags);
148 #if     defined(CONFIG_405EP) || \
149         defined(CONFIG_405GP) || \
150         defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
151         defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \
152         defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
153         defined(CONFIG_XILINX_405)
154         print_mhz("procfreq",           bd->bi_procfreq);
155         print_mhz("plb_busfreq",        bd->bi_plb_busfreq);
156 #if     defined(CONFIG_405EP) || defined(CONFIG_405GP) || \
157         defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
158         defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \
159         defined(CONFIG_440SPE) || defined(CONFIG_XILINX_405)
160         print_mhz("pci_busfreq",        bd->bi_pci_busfreq);
161 #endif
162 #else   /* ! CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
163 #if defined(CONFIG_CPM2)
164         print_mhz("vco",                bd->bi_vco);
165         print_mhz("sccfreq",            bd->bi_sccfreq);
166         print_mhz("brgfreq",            bd->bi_brgfreq);
167 #endif
168         print_mhz("intfreq",            bd->bi_intfreq);
169 #if defined(CONFIG_CPM2)
170         print_mhz("cpmfreq",            bd->bi_cpmfreq);
171 #endif
172         print_mhz("busfreq",            bd->bi_busfreq);
173 #endif /* CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
174
175 #ifdef CONFIG_ENABLE_36BIT_PHYS
176 #ifdef CONFIG_PHYS_64BIT
177         puts("addressing  = 36-bit\n");
178 #else
179         puts("addressing  = 32-bit\n");
180 #endif
181 #endif
182
183         print_eth(0);
184 #if defined(CONFIG_HAS_ETH1)
185         print_eth(1);
186 #endif
187 #if defined(CONFIG_HAS_ETH2)
188         print_eth(2);
189 #endif
190 #if defined(CONFIG_HAS_ETH3)
191         print_eth(3);
192 #endif
193 #if defined(CONFIG_HAS_ETH4)
194         print_eth(4);
195 #endif
196 #if defined(CONFIG_HAS_ETH5)
197         print_eth(5);
198 #endif
199
200         printf("IP addr     = %s\n", getenv("ipaddr"));
201         printf("baudrate    = %6u bps\n", gd->baudrate);
202         print_num("relocaddr", gd->relocaddr);
203         board_detail();
204         return 0;
205 }
206
207 #elif defined(CONFIG_NIOS2)
208
209 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
210 {
211         bd_t *bd = gd->bd;
212
213         print_bi_dram(bd);
214         print_bi_flash(bd);
215
216 #if defined(CONFIG_SYS_SRAM_BASE)
217         print_num ("sram start",        (ulong)bd->bi_sramstart);
218         print_num ("sram size",         (ulong)bd->bi_sramsize);
219 #endif
220
221 #if defined(CONFIG_CMD_NET)
222         print_eth(0);
223         printf("ip_addr     = %s\n", getenv("ipaddr"));
224 #endif
225
226         printf("baudrate    = %u bps\n", gd->baudrate);
227
228         return 0;
229 }
230
231 #elif defined(CONFIG_MICROBLAZE)
232
233 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
234 {
235         bd_t *bd = gd->bd;
236
237         print_bi_dram(bd);
238         print_bi_flash(bd);
239 #if defined(CONFIG_SYS_SRAM_BASE)
240         print_num("sram start     ",    (ulong)bd->bi_sramstart);
241         print_num("sram size      ",    (ulong)bd->bi_sramsize);
242 #endif
243 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
244         print_eths();
245 #endif
246         printf("baudrate    = %u bps\n", gd->baudrate);
247         print_num("relocaddr", gd->relocaddr);
248         print_num("reloc off", gd->reloc_off);
249         print_num("fdt_blob", (ulong)gd->fdt_blob);
250         print_num("new_fdt", (ulong)gd->new_fdt);
251         print_num("fdt_size", (ulong)gd->fdt_size);
252
253         return 0;
254 }
255
256 #elif defined(CONFIG_SPARC)
257
258 int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
259 {
260         bd_t *bd = gd->bd;
261
262 #ifdef DEBUG
263         print_num("bd address             ", (ulong) bd);
264 #endif
265         print_num("memstart               ", bd->bi_memstart);
266         print_lnum("memsize                ", bd->bi_memsize);
267         print_num("flashstart             ", bd->bi_flashstart);
268         print_num("CONFIG_SYS_MONITOR_BASE       ", CONFIG_SYS_MONITOR_BASE);
269         print_num("CONFIG_ENV_ADDR           ", CONFIG_ENV_ADDR);
270         printf("CONFIG_SYS_RELOC_MONITOR_BASE = 0x%x (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
271                CONFIG_SYS_MONITOR_LEN);
272         printf("CONFIG_SYS_MALLOC_BASE        = 0x%x (%d)\n", CONFIG_SYS_MALLOC_BASE,
273                CONFIG_SYS_MALLOC_LEN);
274         printf("CONFIG_SYS_INIT_SP_OFFSET     = 0x%x (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
275                CONFIG_SYS_STACK_SIZE);
276         printf("CONFIG_SYS_PROM_OFFSET        = 0x%x (%d)\n", CONFIG_SYS_PROM_OFFSET,
277                CONFIG_SYS_PROM_SIZE);
278         printf("CONFIG_SYS_GBL_DATA_OFFSET    = 0x%x (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
279                GENERATED_GBL_DATA_SIZE);
280
281 #if defined(CONFIG_CMD_NET)
282         print_eth(0);
283         printf("ip_addr     = %s\n", getenv("ipaddr"));
284 #endif
285         printf("baudrate               = %6u bps\n", gd->baudrate);
286         return 0;
287 }
288
289 #elif defined(CONFIG_M68K)
290
291 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
292 {
293         bd_t *bd = gd->bd;
294
295         print_bi_mem(bd);
296         print_bi_flash(bd);
297 #if defined(CONFIG_SYS_INIT_RAM_ADDR)
298         print_num("sramstart",          (ulong)bd->bi_sramstart);
299         print_num("sramsize",           (ulong)bd->bi_sramsize);
300 #endif
301 #if defined(CONFIG_SYS_MBAR)
302         print_num("mbar",               bd->bi_mbar_base);
303 #endif
304         print_mhz("cpufreq",            bd->bi_intfreq);
305         print_mhz("busfreq",            bd->bi_busfreq);
306 #ifdef CONFIG_PCI
307         print_mhz("pcifreq",            bd->bi_pcifreq);
308 #endif
309 #ifdef CONFIG_EXTRA_CLOCK
310         print_mhz("flbfreq",            bd->bi_flbfreq);
311         print_mhz("inpfreq",            bd->bi_inpfreq);
312         print_mhz("vcofreq",            bd->bi_vcofreq);
313 #endif
314 #if defined(CONFIG_CMD_NET)
315         print_eth(0);
316 #if defined(CONFIG_HAS_ETH1)
317         print_eth(1);
318 #endif
319 #if defined(CONFIG_HAS_ETH2)
320         print_eth(2);
321 #endif
322 #if defined(CONFIG_HAS_ETH3)
323         print_eth(3);
324 #endif
325
326         printf("ip_addr     = %s\n", getenv("ipaddr"));
327 #endif
328         printf("baudrate    = %u bps\n", gd->baudrate);
329
330         return 0;
331 }
332
333 #elif defined(CONFIG_BLACKFIN)
334
335 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
336 {
337         bd_t *bd = gd->bd;
338
339         printf("U-Boot      = %s\n", bd->bi_r_version);
340         printf("CPU         = %s\n", bd->bi_cpu);
341         printf("Board       = %s\n", bd->bi_board_name);
342         print_mhz("VCO",        bd->bi_vco);
343         print_mhz("CCLK",       bd->bi_cclk);
344         print_mhz("SCLK",       bd->bi_sclk);
345
346         print_bi_boot_params(bd);
347         print_bi_mem(bd);
348         print_bi_flash(bd);
349
350         print_eth(0);
351         printf("ip_addr     = %s\n", getenv("ipaddr"));
352         printf("baudrate    = %u bps\n", gd->baudrate);
353
354         return 0;
355 }
356
357 #elif defined(CONFIG_MIPS)
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_boot_params(bd);
364         print_bi_mem(bd);
365         print_bi_flash(bd);
366
367         print_eth(0);
368         printf("ip_addr     = %s\n", getenv("ipaddr"));
369         printf("baudrate    = %u bps\n", gd->baudrate);
370         print_num("relocaddr", gd->relocaddr);
371         print_num("reloc off", gd->reloc_off);
372
373         return 0;
374 }
375
376 #elif defined(CONFIG_AVR32)
377
378 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
379 {
380         bd_t *bd = gd->bd;
381
382         print_bi_boot_params(bd);
383         print_bi_mem(bd);
384         print_bi_flash(bd);
385
386         print_eth(0);
387         printf("ip_addr     = %s\n", getenv("ipaddr"));
388         printf("baudrate    = %u bps\n", gd->baudrate);
389
390         return 0;
391 }
392
393 #elif defined(CONFIG_ARM)
394
395 static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc,
396                         char * const argv[])
397 {
398         bd_t *bd = gd->bd;
399
400         print_num("arch_number",        bd->bi_arch_number);
401         print_bi_boot_params(bd);
402         print_bi_dram(bd);
403
404 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
405         if (gd->arch.secure_ram & MEM_RESERVE_SECURE_SECURED) {
406                 print_num("Secure ram",
407                           gd->arch.secure_ram & MEM_RESERVE_SECURE_ADDR_MASK);
408         }
409 #endif
410 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
411         print_eths();
412 #endif
413         printf("baudrate    = %u bps\n", gd->baudrate);
414 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
415         print_num("TLB addr", gd->arch.tlb_addr);
416 #endif
417         print_num("relocaddr", gd->relocaddr);
418         print_num("reloc off", gd->reloc_off);
419         print_num("irq_sp", gd->irq_sp);        /* irq stack pointer */
420         print_num("sp start ", gd->start_addr_sp);
421 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
422         print_num("FB base  ", gd->fb_base);
423 #endif
424         /*
425          * TODO: Currently only support for davinci SOC's is added.
426          * Remove this check once all the board implement this.
427          */
428 #ifdef CONFIG_CLOCKS
429         printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq);
430         printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq);
431         printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq);
432 #endif
433 #ifdef CONFIG_BOARD_TYPES
434         printf("Board Type  = %ld\n", gd->board_type);
435 #endif
436 #ifdef CONFIG_SYS_MALLOC_F
437         printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr,
438                CONFIG_SYS_MALLOC_F_LEN);
439 #endif
440
441         return 0;
442 }
443
444 #elif defined(CONFIG_SH)
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_mem(bd);
451         print_bi_flash(bd);
452
453 #if defined(CONFIG_CMD_NET)
454         print_eth(0);
455         printf("ip_addr     = %s\n", getenv("ipaddr"));
456 #endif
457         printf("baudrate    = %u bps\n", gd->baudrate);
458         return 0;
459 }
460
461 #elif defined(CONFIG_X86)
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_boot_params(bd);
468         print_num("bi_memstart",        bd->bi_memstart);
469         print_num("bi_memsize",         bd->bi_memsize);
470         print_num("bi_flashstart",      bd->bi_flashstart);
471         print_num("bi_flashsize",       bd->bi_flashsize);
472         print_num("bi_flashoffset",     bd->bi_flashoffset);
473         print_num("bi_sramstart",       bd->bi_sramstart);
474         print_num("bi_sramsize",        bd->bi_sramsize);
475         print_num("bi_bootflags",       bd->bi_bootflags);
476         print_mhz("cpufreq",            bd->bi_intfreq);
477         print_mhz("busfreq",            bd->bi_busfreq);
478
479         print_bi_dram(bd);
480
481 #if defined(CONFIG_CMD_NET)
482         print_eth(0);
483         printf("ip_addr     = %s\n", getenv("ipaddr"));
484         print_mhz("ethspeed",       bd->bi_ethspeed);
485 #endif
486         printf("baudrate    = %u bps\n", gd->baudrate);
487
488         return 0;
489 }
490
491 #elif defined(CONFIG_SANDBOX)
492
493 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
494 {
495         bd_t *bd = gd->bd;
496
497         print_bi_boot_params(bd);
498         print_bi_dram(bd);
499
500 #if defined(CONFIG_CMD_NET)
501         print_eth(0);
502         printf("ip_addr     = %s\n", getenv("ipaddr"));
503 #endif
504 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
505         print_num("FB base  ", gd->fb_base);
506 #endif
507         return 0;
508 }
509
510 #elif defined(CONFIG_NDS32)
511
512 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
513 {
514         bd_t *bd = gd->bd;
515
516         print_num("arch_number",        bd->bi_arch_number);
517         print_bi_boot_params(bd);
518         print_bi_dram(bd);
519
520 #if defined(CONFIG_CMD_NET)
521         print_eth(0);
522         printf("ip_addr     = %s\n", getenv("ipaddr"));
523 #endif
524         printf("baudrate    = %u bps\n", gd->baudrate);
525
526         return 0;
527 }
528
529 #elif defined(CONFIG_OPENRISC)
530
531 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
532 {
533         bd_t *bd = gd->bd;
534
535         print_bi_mem(bd);
536         print_bi_flash(bd);
537
538 #if defined(CONFIG_CMD_NET)
539         print_eth(0);
540         printf("ip_addr     = %s\n", getenv("ipaddr"));
541 #endif
542
543         printf("baudrate    = %u bps\n", gd->baudrate);
544
545         return 0;
546 }
547
548 #elif defined(CONFIG_ARC)
549
550 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
551 {
552         bd_t *bd = gd->bd;
553
554         print_bi_mem(bd);
555
556 #if defined(CONFIG_CMD_NET)
557         print_eth(0);
558         printf("ip_addr     = %s\n", getenv("ipaddr"));
559 #endif
560         printf("baudrate    = %d bps\n", gd->baudrate);
561
562         return 0;
563 }
564
565 #else
566  #error "a case for this architecture does not exist!"
567 #endif
568
569 /* -------------------------------------------------------------------- */
570
571 U_BOOT_CMD(
572         bdinfo, 1,      1,      do_bdinfo,
573         "print Board Info structure",
574         ""
575 );