blob: cddf1a46d491726ac48de4dbce04b10d50b36497 [file] [log] [blame]
Marek Vasutbf527662023-05-31 03:03:58 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Tests for bdinfo command
4 *
5 * Copyright 2023 Marek Vasut <marek.vasut+renesas@mailbox.org>
6 */
7
8#include <common.h>
9#include <console.h>
10#include <mapmem.h>
11#include <asm/global_data.h>
12#include <dm/uclass.h>
13#include <test/suites.h>
14#include <test/ut.h>
15#include <dm.h>
16#include <env.h>
17#include <lmb.h>
18#include <net.h>
19#include <video.h>
20#include <vsprintf.h>
21#include <asm/cache.h>
22#include <asm/global_data.h>
23#include <display_options.h>
24
25DECLARE_GLOBAL_DATA_PTR;
26
27/* Declare a new bdinfo test */
28#define BDINFO_TEST(_name, _flags) UNIT_TEST(_name, _flags, bdinfo_test)
29
Simon Glass2c522af2023-07-11 20:46:30 -060030static int test_num_l(struct unit_test_state *uts, const char *name,
31 ulong value)
Marek Vasutbf527662023-05-31 03:03:58 +020032{
Simon Glass2c522af2023-07-11 20:46:30 -060033 ut_assert_nextline("%-12s= 0x%0*lx", name, 2 * (int)sizeof(value),
34 value);
35
36 return 0;
Marek Vasutbf527662023-05-31 03:03:58 +020037}
38
Simon Glass2c522af2023-07-11 20:46:30 -060039static int test_num_ll(struct unit_test_state *uts, const char *name,
40 unsigned long long value)
Marek Vasutbf527662023-05-31 03:03:58 +020041{
Simon Glass2c522af2023-07-11 20:46:30 -060042 ut_assert_nextline("%-12s= 0x%.*llx", name, 2 * (int)sizeof(ulong),
43 value);
44
45 return 0;
Marek Vasutbf527662023-05-31 03:03:58 +020046}
47
Simon Glass2c522af2023-07-11 20:46:30 -060048static int test_eth(struct unit_test_state *uts)
Marek Vasutbf527662023-05-31 03:03:58 +020049{
50 const int idx = eth_get_dev_index();
51 uchar enetaddr[6];
52 char name[10];
53 int ret;
54
55 if (idx)
56 sprintf(name, "eth%iaddr", idx);
57 else
58 strcpy(name, "ethaddr");
59
60 ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr);
61
62 ut_assert_nextline("current eth = %s", eth_get_name());
63 if (!ret)
64 ut_assert_nextline("%-12s= (not set)", name);
65 else
66 ut_assert_nextline("%-12s= %pM", name, enetaddr);
67 ut_assert_nextline("IP addr = %s", env_get("ipaddr"));
Simon Glass2c522af2023-07-11 20:46:30 -060068
69 return 0;
Marek Vasutbf527662023-05-31 03:03:58 +020070}
71
Simon Glass2c522af2023-07-11 20:46:30 -060072static int test_video_info(struct unit_test_state *uts)
Marek Vasutbf527662023-05-31 03:03:58 +020073{
74 const struct udevice *dev;
75 struct uclass *uc;
76
77 uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) {
78 ut_assert_nextline("%-12s= %s %sactive", "Video", dev->name,
79 device_active(dev) ? "" : "in");
80 if (device_active(dev)) {
81 struct video_priv *upriv = dev_get_uclass_priv(dev);
82 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
83
Simon Glass2c522af2023-07-11 20:46:30 -060084 ut_assertok(test_num_ll(uts, "FB base",
85 (ulong)upriv->fb));
Marek Vasutbf527662023-05-31 03:03:58 +020086 if (upriv->copy_fb) {
Simon Glass2c522af2023-07-11 20:46:30 -060087 ut_assertok(test_num_ll(uts, "FB copy",
88 (ulong)upriv->copy_fb));
89 ut_assertok(test_num_l(uts, " copy size",
90 plat->copy_size));
Marek Vasutbf527662023-05-31 03:03:58 +020091 }
92 ut_assert_nextline("%-12s= %dx%dx%d", "FB size",
93 upriv->xsize, upriv->ysize,
94 1 << upriv->bpix);
95 }
96 }
Simon Glass2c522af2023-07-11 20:46:30 -060097
98 return 0;
Marek Vasutbf527662023-05-31 03:03:58 +020099}
100
Simon Glass2c522af2023-07-11 20:46:30 -0600101static int lmb_test_dump_region(struct unit_test_state *uts,
102 struct lmb_region *rgn, char *name)
Marek Vasutbf527662023-05-31 03:03:58 +0200103{
104 unsigned long long base, size, end;
105 enum lmb_flags flags;
106 int i;
107
108 ut_assert_nextline(" %s.cnt = 0x%lx / max = 0x%lx", name, rgn->cnt, rgn->max);
109
110 for (i = 0; i < rgn->cnt; i++) {
111 base = rgn->region[i].base;
112 size = rgn->region[i].size;
113 end = base + size - 1;
114 flags = rgn->region[i].flags;
115
116 ut_assert_nextline(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x",
117 name, i, base, end, size, flags);
118 }
Simon Glass2c522af2023-07-11 20:46:30 -0600119
120 return 0;
Marek Vasutbf527662023-05-31 03:03:58 +0200121}
122
Simon Glass2c522af2023-07-11 20:46:30 -0600123static int lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb)
Marek Vasutbf527662023-05-31 03:03:58 +0200124{
125 ut_assert_nextline("lmb_dump_all:");
126 lmb_test_dump_region(uts, &lmb->memory, "memory");
127 lmb_test_dump_region(uts, &lmb->reserved, "reserved");
Simon Glass2c522af2023-07-11 20:46:30 -0600128
129 return 0;
Marek Vasutbf527662023-05-31 03:03:58 +0200130}
131
132static int bdinfo_test_move(struct unit_test_state *uts)
133{
134 struct bd_info *bd = gd->bd;
135 int i;
136
137 /* Test moving the working BDINFO to a new location */
138 ut_assertok(console_record_reset_enable());
139 ut_assertok(run_commandf("bdinfo"));
140
Simon Glass2c522af2023-07-11 20:46:30 -0600141 ut_assertok(test_num_l(uts, "boot_params", 0));
Marek Vasutbf527662023-05-31 03:03:58 +0200142
143 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
144 if (bd->bi_dram[i].size) {
Simon Glass2c522af2023-07-11 20:46:30 -0600145 ut_assertok(test_num_l(uts, "DRAM bank", i));
146 ut_assertok(test_num_ll(uts, "-> start",
147 bd->bi_dram[i].start));
148 ut_assertok(test_num_ll(uts, "-> size",
149 bd->bi_dram[i].size));
Marek Vasutbf527662023-05-31 03:03:58 +0200150 }
151 }
152
153 /* CONFIG_SYS_HAS_SRAM testing not supported */
Simon Glass2c522af2023-07-11 20:46:30 -0600154 ut_assertok(test_num_l(uts, "flashstart", 0));
155 ut_assertok(test_num_l(uts, "flashsize", 0));
156 ut_assertok(test_num_l(uts, "flashoffset", 0));
Marek Vasutbf527662023-05-31 03:03:58 +0200157 ut_assert_nextline("baudrate = %lu bps",
158 env_get_ulong("baudrate", 10, 1234));
Simon Glass2c522af2023-07-11 20:46:30 -0600159 ut_assertok(test_num_l(uts, "relocaddr", gd->relocaddr));
160 ut_assertok(test_num_l(uts, "reloc off", gd->reloc_off));
Marek Vasutbf527662023-05-31 03:03:58 +0200161 ut_assert_nextline("%-12s= %u-bit", "Build", (uint)sizeof(void *) * 8);
162
163 if (IS_ENABLED(CONFIG_CMD_NET))
Simon Glass2c522af2023-07-11 20:46:30 -0600164 ut_assertok(test_eth(uts));
Marek Vasutbf527662023-05-31 03:03:58 +0200165
166 /*
167 * Make sure environment variable "fdtcontroladdr" address
168 * matches mapped control DT address.
169 */
170 ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234));
Simon Glass2c522af2023-07-11 20:46:30 -0600171 ut_assertok(test_num_l(uts, "fdt_blob",
172 (ulong)map_to_sysmem(gd->fdt_blob)));
173 ut_assertok(test_num_l(uts, "new_fdt",
174 (ulong)map_to_sysmem(gd->new_fdt)));
175 ut_assertok(test_num_l(uts, "fdt_size", (ulong)gd->fdt_size));
Marek Vasutbf527662023-05-31 03:03:58 +0200176
177 if (IS_ENABLED(CONFIG_VIDEO))
178 test_video_info(uts);
179
180 /* The gd->multi_dtb_fit may not be available, hence, #if below. */
181#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
Simon Glass2c522af2023-07-11 20:46:30 -0600182 ut_assertok(test_num_l(uts, "multi_dtb_fit", (ulong)gd->multi_dtb_fit));
Marek Vasutbf527662023-05-31 03:03:58 +0200183#endif
184
185 if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) {
186 struct lmb lmb;
187
188 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
189 lmb_test_dump_all(uts, &lmb);
190 if (IS_ENABLED(CONFIG_OF_REAL))
191 ut_assert_nextline("devicetree = %s", fdtdec_get_srcname());
192 }
193
194 ut_assertok(ut_check_console_end(uts));
195
196 return 0;
197}
198
199BDINFO_TEST(bdinfo_test_move, UT_TESTF_CONSOLE_REC);
200
201int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
202{
203 struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test);
204 const int n_ents = UNIT_TEST_SUITE_COUNT(bdinfo_test);
205
206 return cmd_ut_category("bdinfo", "bdinfo_test_", tests, n_ents, argc, argv);
207}