cmd: bootefi: allocate device-tree copy from high memory
[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 <dm.h>
12 #include <env.h>
13 #include <lmb.h>
14 #include <net.h>
15 #include <video.h>
16 #include <vsprintf.h>
17 #include <asm/cache.h>
18 #include <asm/global_data.h>
19 #include <display_options.h>
20
21 DECLARE_GLOBAL_DATA_PTR;
22
23 void bdinfo_print_size(const char *name, uint64_t size)
24 {
25         printf("%-12s= ", name);
26         print_size(size, "\n");
27 }
28
29 void bdinfo_print_str(const char *name, const char *str)
30 {
31         printf("%-12s= %s\n", name, str);
32 }
33
34 void bdinfo_print_num_l(const char *name, ulong value)
35 {
36         printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
37 }
38
39 void bdinfo_print_num_ll(const char *name, unsigned long long value)
40 {
41         printf("%-12s= 0x%.*llx\n", name, 2 * (int)sizeof(ulong), value);
42 }
43
44 static void print_eth(int idx)
45 {
46         char name[10], *val;
47         if (idx)
48                 sprintf(name, "eth%iaddr", idx);
49         else
50                 strcpy(name, "ethaddr");
51         val = env_get(name);
52         if (!val)
53                 val = "(not set)";
54         printf("%-12s= %s\n", name, val);
55 }
56
57 void bdinfo_print_mhz(const char *name, unsigned long hz)
58 {
59         char buf[32];
60
61         printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
62 }
63
64 static void print_bi_dram(const struct bd_info *bd)
65 {
66         int i;
67
68         for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
69                 if (bd->bi_dram[i].size) {
70                         bdinfo_print_num_l("DRAM bank", i);
71                         bdinfo_print_num_ll("-> start", bd->bi_dram[i].start);
72                         bdinfo_print_num_ll("-> size",  bd->bi_dram[i].size);
73                 }
74         }
75 }
76
77 __weak void arch_print_bdinfo(void)
78 {
79 }
80
81 static void show_video_info(void)
82 {
83         const struct udevice *dev;
84         struct uclass *uc;
85
86         uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) {
87                 printf("%-12s= %s %sactive\n", "Video", dev->name,
88                        device_active(dev) ? "" : "in");
89                 if (device_active(dev)) {
90                         struct video_priv *upriv = dev_get_uclass_priv(dev);
91                         struct video_uc_plat *plat = dev_get_uclass_plat(dev);
92
93                         bdinfo_print_num_ll("FB base", (ulong)upriv->fb);
94                         if (upriv->copy_fb) {
95                                 bdinfo_print_num_ll("FB copy",
96                                                     (ulong)upriv->copy_fb);
97                                 bdinfo_print_num_l(" copy size",
98                                                    plat->copy_size);
99                         }
100                         printf("%-12s= %dx%dx%d\n", "FB size", upriv->xsize,
101                                upriv->ysize, 1 << upriv->bpix);
102                 }
103         }
104 }
105
106 int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
107 {
108         struct bd_info *bd = gd->bd;
109
110 #ifdef DEBUG
111         bdinfo_print_num_l("bd address", (ulong)bd);
112 #endif
113         bdinfo_print_num_l("boot_params", (ulong)bd->bi_boot_params);
114         print_bi_dram(bd);
115         if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
116                 bdinfo_print_num_l("sramstart", (ulong)bd->bi_sramstart);
117                 bdinfo_print_num_l("sramsize", (ulong)bd->bi_sramsize);
118         }
119         bdinfo_print_num_l("flashstart", (ulong)bd->bi_flashstart);
120         bdinfo_print_num_l("flashsize", (ulong)bd->bi_flashsize);
121         bdinfo_print_num_l("flashoffset", (ulong)bd->bi_flashoffset);
122         printf("baudrate    = %u bps\n", gd->baudrate);
123         bdinfo_print_num_l("relocaddr", gd->relocaddr);
124         bdinfo_print_num_l("reloc off", gd->reloc_off);
125         printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
126         if (IS_ENABLED(CONFIG_CMD_NET)) {
127                 printf("current eth = %s\n", eth_get_name());
128                 print_eth(0);
129                 printf("IP addr     = %s\n", env_get("ipaddr"));
130         }
131         bdinfo_print_num_l("fdt_blob", (ulong)gd->fdt_blob);
132         bdinfo_print_num_l("new_fdt", (ulong)gd->new_fdt);
133         bdinfo_print_num_l("fdt_size", (ulong)gd->fdt_size);
134         if (IS_ENABLED(CONFIG_VIDEO))
135                 show_video_info();
136 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
137         bdinfo_print_num_l("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
138 #endif
139         if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) {
140                 struct lmb lmb;
141
142                 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
143                 lmb_dump_all_force(&lmb);
144                 if (IS_ENABLED(CONFIG_OF_REAL))
145                         printf("devicetree  = %s\n", fdtdec_get_srcname());
146         }
147
148         arch_print_bdinfo();
149
150         return 0;
151 }
152
153 U_BOOT_CMD(
154         bdinfo, 1,      1,      do_bdinfo,
155         "print Board Info structure",
156         ""
157 );