Merge https://gitlab.denx.de/u-boot/custodians/u-boot-sh
[platform/kernel/u-boot.git] / cmd / bdinfo.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Implements the 'bd' command to show board information
4  *
5  * (C) Copyright 2003
6  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7  */
8
9 #include <common.h>
10 #include <command.h>
11 #include <env.h>
12 #include <net.h>
13 #include <vsprintf.h>
14 #include <asm/cache.h>
15
16 DECLARE_GLOBAL_DATA_PTR;
17
18 void bdinfo_print_num(const char *name, ulong value)
19 {
20         printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
21 }
22
23 static void print_eth(int idx)
24 {
25         char name[10], *val;
26         if (idx)
27                 sprintf(name, "eth%iaddr", idx);
28         else
29                 strcpy(name, "ethaddr");
30         val = env_get(name);
31         if (!val)
32                 val = "(not set)";
33         printf("%-12s= %s\n", name, val);
34 }
35
36 static void print_lnum(const char *name, unsigned long long value)
37 {
38         printf("%-12s= 0x%.8llX\n", name, value);
39 }
40
41 void bdinfo_print_mhz(const char *name, unsigned long hz)
42 {
43         char buf[32];
44
45         printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
46 }
47
48 static void print_bi_dram(const struct bd_info *bd)
49 {
50 #ifdef CONFIG_NR_DRAM_BANKS
51         int i;
52
53         for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
54                 if (bd->bi_dram[i].size) {
55                         bdinfo_print_num("DRAM bank",   i);
56                         bdinfo_print_num("-> start",    bd->bi_dram[i].start);
57                         bdinfo_print_num("-> size",     bd->bi_dram[i].size);
58                 }
59         }
60 #endif
61 }
62
63 __weak void arch_print_bdinfo(void)
64 {
65 }
66
67 int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
68 {
69         struct bd_info *bd = gd->bd;
70
71 #ifdef DEBUG
72         bdinfo_print_num("bd address", (ulong)bd);
73 #endif
74         bdinfo_print_num("boot_params", (ulong)bd->bi_boot_params);
75         print_bi_dram(bd);
76         bdinfo_print_num("memstart", (ulong)bd->bi_memstart);
77         print_lnum("memsize", (u64)bd->bi_memsize);
78         bdinfo_print_num("flashstart", (ulong)bd->bi_flashstart);
79         bdinfo_print_num("flashsize", (ulong)bd->bi_flashsize);
80         bdinfo_print_num("flashoffset", (ulong)bd->bi_flashoffset);
81         printf("baudrate    = %u bps\n", gd->baudrate);
82         bdinfo_print_num("relocaddr", gd->relocaddr);
83         bdinfo_print_num("reloc off", gd->reloc_off);
84         printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
85         if (IS_ENABLED(CONFIG_CMD_NET)) {
86                 printf("current eth = %s\n", eth_get_name());
87                 print_eth(0);
88                 printf("IP addr     = %s\n", env_get("ipaddr"));
89         }
90         bdinfo_print_num("fdt_blob", (ulong)gd->fdt_blob);
91         bdinfo_print_num("new_fdt", (ulong)gd->new_fdt);
92         bdinfo_print_num("fdt_size", (ulong)gd->fdt_size);
93 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) || defined(CONFIG_DM_VIDEO)
94         bdinfo_print_num("FB base  ", gd->fb_base);
95 #endif
96 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
97         bdinfo_print_num("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
98 #endif
99
100         arch_print_bdinfo();
101
102         return 0;
103 }
104
105 U_BOOT_CMD(
106         bdinfo, 1,      1,      do_bdinfo,
107         "print Board Info structure",
108         ""
109 );