Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 1 | // 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 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 8 | #include <alist.h> |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 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> |
Simon Glass | 3ddee31 | 2023-07-12 09:04:37 -0600 | [diff] [blame] | 19 | #include <serial.h> |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 20 | #include <video.h> |
| 21 | #include <vsprintf.h> |
| 22 | #include <asm/cache.h> |
| 23 | #include <asm/global_data.h> |
| 24 | #include <display_options.h> |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | /* Declare a new bdinfo test */ |
| 29 | #define BDINFO_TEST(_name, _flags) UNIT_TEST(_name, _flags, bdinfo_test) |
| 30 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 31 | static int test_num_l(struct unit_test_state *uts, const char *name, |
| 32 | ulong value) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 33 | { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 34 | ut_assert_nextline("%-12s= 0x%0*lx", name, 2 * (int)sizeof(value), |
| 35 | value); |
| 36 | |
| 37 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 40 | static int test_num_ll(struct unit_test_state *uts, const char *name, |
| 41 | unsigned long long value) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 42 | { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 43 | ut_assert_nextline("%-12s= 0x%.*llx", name, 2 * (int)sizeof(ulong), |
| 44 | value); |
| 45 | |
| 46 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 49 | static int test_eth(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 50 | { |
| 51 | const int idx = eth_get_dev_index(); |
| 52 | uchar enetaddr[6]; |
| 53 | char name[10]; |
| 54 | int ret; |
| 55 | |
| 56 | if (idx) |
| 57 | sprintf(name, "eth%iaddr", idx); |
| 58 | else |
| 59 | strcpy(name, "ethaddr"); |
| 60 | |
| 61 | ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr); |
| 62 | |
| 63 | ut_assert_nextline("current eth = %s", eth_get_name()); |
| 64 | if (!ret) |
| 65 | ut_assert_nextline("%-12s= (not set)", name); |
| 66 | else |
| 67 | ut_assert_nextline("%-12s= %pM", name, enetaddr); |
| 68 | ut_assert_nextline("IP addr = %s", env_get("ipaddr")); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 69 | |
| 70 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 73 | static int test_video_info(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 74 | { |
| 75 | const struct udevice *dev; |
| 76 | struct uclass *uc; |
| 77 | |
| 78 | uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) { |
| 79 | ut_assert_nextline("%-12s= %s %sactive", "Video", dev->name, |
| 80 | device_active(dev) ? "" : "in"); |
| 81 | if (device_active(dev)) { |
| 82 | struct video_priv *upriv = dev_get_uclass_priv(dev); |
| 83 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
| 84 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 85 | ut_assertok(test_num_ll(uts, "FB base", |
| 86 | (ulong)upriv->fb)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 87 | if (upriv->copy_fb) { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 88 | ut_assertok(test_num_ll(uts, "FB copy", |
| 89 | (ulong)upriv->copy_fb)); |
| 90 | ut_assertok(test_num_l(uts, " copy size", |
| 91 | plat->copy_size)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 92 | } |
| 93 | ut_assert_nextline("%-12s= %dx%dx%d", "FB size", |
| 94 | upriv->xsize, upriv->ysize, |
| 95 | 1 << upriv->bpix); |
| 96 | } |
| 97 | } |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 98 | |
| 99 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 102 | static int lmb_test_dump_region(struct unit_test_state *uts, |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 103 | struct alist *lmb_rgn_lst, char *name) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 104 | { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 105 | struct lmb_region *rgn = lmb_rgn_lst->data; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 106 | unsigned long long base, size, end; |
| 107 | enum lmb_flags flags; |
| 108 | int i; |
| 109 | |
Heinrich Schuchardt | 2abe305 | 2024-11-07 11:14:42 +0100 | [diff] [blame] | 110 | ut_assert_nextline(" %s.count = %#x", name, lmb_rgn_lst->count); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 111 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 112 | for (i = 0; i < lmb_rgn_lst->count; i++) { |
| 113 | base = rgn[i].base; |
| 114 | size = rgn[i].size; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 115 | end = base + size - 1; |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 116 | flags = rgn[i].flags; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 117 | |
Simon Glass | a44bd85 | 2023-10-01 19:15:16 -0600 | [diff] [blame] | 118 | if (!IS_ENABLED(CONFIG_SANDBOX) && i == 3) { |
| 119 | ut_assert_nextlinen(" %s[%d]\t[", name, i); |
| 120 | continue; |
| 121 | } |
Heinrich Schuchardt | 2abe305 | 2024-11-07 11:14:42 +0100 | [diff] [blame] | 122 | ut_assert_nextlinen(" %s[%d]\t[%#llx-%#llx], %#llx bytes, flags: ", |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 123 | name, i, base, end, size); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 124 | } |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 125 | |
| 126 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 129 | static int lmb_test_dump_all(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 130 | { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 131 | struct lmb *lmb = lmb_get(); |
| 132 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 133 | ut_assert_nextline("lmb_dump_all:"); |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 134 | ut_assertok(lmb_test_dump_region(uts, &lmb->free_mem, "memory")); |
| 135 | ut_assertok(lmb_test_dump_region(uts, &lmb->used_mem, "reserved")); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 136 | |
| 137 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 140 | static int bdinfo_check_mem(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 141 | { |
| 142 | struct bd_info *bd = gd->bd; |
| 143 | int i; |
| 144 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 145 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 146 | if (bd->bi_dram[i].size) { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 147 | ut_assertok(test_num_l(uts, "DRAM bank", i)); |
| 148 | ut_assertok(test_num_ll(uts, "-> start", |
| 149 | bd->bi_dram[i].start)); |
| 150 | ut_assertok(test_num_ll(uts, "-> size", |
| 151 | bd->bi_dram[i].size)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static int bdinfo_test_all(struct unit_test_state *uts) |
| 159 | { |
| 160 | ut_assertok(test_num_l(uts, "boot_params", 0)); |
| 161 | |
| 162 | ut_assertok(bdinfo_check_mem(uts)); |
| 163 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 164 | /* CONFIG_SYS_HAS_SRAM testing not supported */ |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 165 | ut_assertok(test_num_l(uts, "flashstart", 0)); |
| 166 | ut_assertok(test_num_l(uts, "flashsize", 0)); |
| 167 | ut_assertok(test_num_l(uts, "flashoffset", 0)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 168 | ut_assert_nextline("baudrate = %lu bps", |
| 169 | env_get_ulong("baudrate", 10, 1234)); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 170 | ut_assertok(test_num_l(uts, "relocaddr", gd->relocaddr)); |
| 171 | ut_assertok(test_num_l(uts, "reloc off", gd->reloc_off)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 172 | ut_assert_nextline("%-12s= %u-bit", "Build", (uint)sizeof(void *) * 8); |
| 173 | |
| 174 | if (IS_ENABLED(CONFIG_CMD_NET)) |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 175 | ut_assertok(test_eth(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Make sure environment variable "fdtcontroladdr" address |
| 179 | * matches mapped control DT address. |
| 180 | */ |
| 181 | ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234)); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 182 | ut_assertok(test_num_l(uts, "fdt_blob", |
| 183 | (ulong)map_to_sysmem(gd->fdt_blob))); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 184 | |
| 185 | if (IS_ENABLED(CONFIG_VIDEO)) |
Simon Glass | 43b9a32 | 2023-10-01 19:15:17 -0600 | [diff] [blame] | 186 | ut_assertok(test_video_info(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 187 | |
| 188 | /* The gd->multi_dtb_fit may not be available, hence, #if below. */ |
| 189 | #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 190 | ut_assertok(test_num_l(uts, "multi_dtb_fit", (ulong)gd->multi_dtb_fit)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 191 | #endif |
| 192 | |
| 193 | if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 194 | ut_assertok(lmb_test_dump_all(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 195 | if (IS_ENABLED(CONFIG_OF_REAL)) |
| 196 | ut_assert_nextline("devicetree = %s", fdtdec_get_srcname()); |
| 197 | } |
| 198 | |
Simon Glass | 3ddee31 | 2023-07-12 09:04:37 -0600 | [diff] [blame] | 199 | if (IS_ENABLED(CONFIG_DM_SERIAL)) { |
| 200 | struct serial_device_info info; |
| 201 | |
| 202 | ut_assertnonnull(gd->cur_serial_dev); |
| 203 | ut_assertok(serial_getinfo(gd->cur_serial_dev, &info)); |
| 204 | |
| 205 | ut_assertok(test_num_l(uts, "serial addr", info.addr)); |
| 206 | ut_assertok(test_num_l(uts, " width", info.reg_width)); |
| 207 | ut_assertok(test_num_l(uts, " shift", info.reg_shift)); |
| 208 | ut_assertok(test_num_l(uts, " offset", info.reg_offset)); |
| 209 | ut_assertok(test_num_l(uts, " clock", info.clock)); |
| 210 | } |
| 211 | |
Simon Glass | 5087c77 | 2023-07-15 21:38:46 -0600 | [diff] [blame] | 212 | if (IS_ENABLED(CONFIG_CMD_BDINFO_EXTRA)) { |
| 213 | ut_assert_nextlinen("stack ptr"); |
| 214 | ut_assertok(test_num_ll(uts, "ram_top ptr", |
| 215 | (unsigned long long)gd->ram_top)); |
| 216 | ut_assertok(test_num_l(uts, "malloc base", gd_malloc_start())); |
| 217 | } |
| 218 | |
Simon Glass | 43b9a32 | 2023-10-01 19:15:17 -0600 | [diff] [blame] | 219 | if (IS_ENABLED(CONFIG_X86)) |
| 220 | ut_check_skip_to_linen(uts, " high end ="); |
| 221 | |
Marek Vasut | eb0b1db | 2023-10-07 23:41:03 +0200 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int bdinfo_test_full(struct unit_test_state *uts) |
| 226 | { |
| 227 | /* Test BDINFO full print */ |
Marek Vasut | eb0b1db | 2023-10-07 23:41:03 +0200 | [diff] [blame] | 228 | ut_assertok(run_commandf("bdinfo")); |
| 229 | ut_assertok(bdinfo_test_all(uts)); |
| 230 | ut_assertok(run_commandf("bdinfo -a")); |
| 231 | ut_assertok(bdinfo_test_all(uts)); |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 232 | ut_assert_console_end(); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 233 | |
| 234 | return 0; |
| 235 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 236 | BDINFO_TEST(bdinfo_test_full, UTF_CONSOLE); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 237 | |
Marek Vasut | 2409924 | 2023-10-07 23:41:04 +0200 | [diff] [blame] | 238 | static int bdinfo_test_help(struct unit_test_state *uts) |
| 239 | { |
| 240 | /* Test BDINFO unknown option help text print */ |
Marek Vasut | 949f0fe | 2023-12-10 16:01:56 +0100 | [diff] [blame] | 241 | if (!CONFIG_IS_ENABLED(GETOPT)) { |
| 242 | ut_asserteq(0, run_commandf("bdinfo -h")); |
| 243 | ut_assertok(bdinfo_test_all(uts)); |
| 244 | } else { |
| 245 | ut_asserteq(1, run_commandf("bdinfo -h")); |
| 246 | ut_assert_nextlinen("bdinfo: invalid option -- h"); |
| 247 | ut_assert_nextlinen("bdinfo - print Board Info structure"); |
| 248 | ut_assert_nextline_empty(); |
| 249 | ut_assert_nextlinen("Usage:"); |
| 250 | ut_assert_nextlinen("bdinfo"); |
| 251 | } |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 252 | ut_assert_console_end(); |
Marek Vasut | 2409924 | 2023-10-07 23:41:04 +0200 | [diff] [blame] | 253 | |
| 254 | return 0; |
| 255 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 256 | BDINFO_TEST(bdinfo_test_help, UTF_CONSOLE); |
Marek Vasut | 2409924 | 2023-10-07 23:41:04 +0200 | [diff] [blame] | 257 | |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 258 | static int bdinfo_test_memory(struct unit_test_state *uts) |
| 259 | { |
| 260 | /* Test BDINFO memory layout only print */ |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 261 | ut_assertok(run_commandf("bdinfo -m")); |
Marek Vasut | 949f0fe | 2023-12-10 16:01:56 +0100 | [diff] [blame] | 262 | if (!CONFIG_IS_ENABLED(GETOPT)) |
| 263 | ut_assertok(bdinfo_test_all(uts)); |
| 264 | else |
| 265 | ut_assertok(bdinfo_check_mem(uts)); |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 266 | ut_assert_console_end(); |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 267 | |
| 268 | return 0; |
| 269 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 270 | BDINFO_TEST(bdinfo_test_memory, UTF_CONSOLE); |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 271 | |
Marek Vasut | f14a03b | 2023-10-07 23:41:06 +0200 | [diff] [blame] | 272 | static int bdinfo_test_eth(struct unit_test_state *uts) |
| 273 | { |
| 274 | /* Test BDINFO ethernet settings only print */ |
Marek Vasut | f14a03b | 2023-10-07 23:41:06 +0200 | [diff] [blame] | 275 | ut_assertok(run_commandf("bdinfo -e")); |
Marek Vasut | 949f0fe | 2023-12-10 16:01:56 +0100 | [diff] [blame] | 276 | if (!CONFIG_IS_ENABLED(GETOPT)) |
| 277 | ut_assertok(bdinfo_test_all(uts)); |
| 278 | else if (IS_ENABLED(CONFIG_CMD_NET)) |
Marek Vasut | f14a03b | 2023-10-07 23:41:06 +0200 | [diff] [blame] | 279 | ut_assertok(test_eth(uts)); |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 280 | ut_assert_console_end(); |
Marek Vasut | f14a03b | 2023-10-07 23:41:06 +0200 | [diff] [blame] | 281 | |
| 282 | return 0; |
| 283 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 284 | BDINFO_TEST(bdinfo_test_eth, UTF_CONSOLE); |
Marek Vasut | f14a03b | 2023-10-07 23:41:06 +0200 | [diff] [blame] | 285 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 286 | int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 287 | { |
| 288 | struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test); |
| 289 | const int n_ents = UNIT_TEST_SUITE_COUNT(bdinfo_test); |
| 290 | |
| 291 | return cmd_ut_category("bdinfo", "bdinfo_test_", tests, n_ents, argc, argv); |
| 292 | } |