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