Marek Vasut | bf52766 | 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 | |
| 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> |
Simon Glass | 347a845 | 2023-07-12 09:04:37 -0600 | [diff] [blame] | 19 | #include <serial.h> |
Marek Vasut | bf52766 | 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 | 2c522af | 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 | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 33 | { |
Simon Glass | 2c522af | 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 | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Simon Glass | 2c522af | 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 | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 42 | { |
Simon Glass | 2c522af | 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 | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 49 | static int test_eth(struct unit_test_state *uts) |
Marek Vasut | bf52766 | 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 | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 69 | |
| 70 | return 0; |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 73 | static int test_video_info(struct unit_test_state *uts) |
Marek Vasut | bf52766 | 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 | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 85 | ut_assertok(test_num_ll(uts, "FB base", |
| 86 | (ulong)upriv->fb)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 87 | if (upriv->copy_fb) { |
Simon Glass | 2c522af | 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 | bf52766 | 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 | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 98 | |
| 99 | return 0; |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 102 | static int lmb_test_dump_region(struct unit_test_state *uts, |
| 103 | struct lmb_region *rgn, char *name) |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 104 | { |
| 105 | unsigned long long base, size, end; |
| 106 | enum lmb_flags flags; |
| 107 | int i; |
| 108 | |
| 109 | ut_assert_nextline(" %s.cnt = 0x%lx / max = 0x%lx", name, rgn->cnt, rgn->max); |
| 110 | |
| 111 | for (i = 0; i < rgn->cnt; i++) { |
| 112 | base = rgn->region[i].base; |
| 113 | size = rgn->region[i].size; |
| 114 | end = base + size - 1; |
| 115 | flags = rgn->region[i].flags; |
| 116 | |
| 117 | ut_assert_nextline(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x", |
| 118 | name, i, base, end, size, flags); |
| 119 | } |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 120 | |
| 121 | return 0; |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 122 | } |
| 123 | |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 124 | static int lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb) |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 125 | { |
| 126 | ut_assert_nextline("lmb_dump_all:"); |
| 127 | lmb_test_dump_region(uts, &lmb->memory, "memory"); |
| 128 | lmb_test_dump_region(uts, &lmb->reserved, "reserved"); |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 129 | |
| 130 | return 0; |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static int bdinfo_test_move(struct unit_test_state *uts) |
| 134 | { |
| 135 | struct bd_info *bd = gd->bd; |
| 136 | int i; |
| 137 | |
| 138 | /* Test moving the working BDINFO to a new location */ |
| 139 | ut_assertok(console_record_reset_enable()); |
| 140 | ut_assertok(run_commandf("bdinfo")); |
| 141 | |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 142 | ut_assertok(test_num_l(uts, "boot_params", 0)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 143 | |
| 144 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 145 | if (bd->bi_dram[i].size) { |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 146 | ut_assertok(test_num_l(uts, "DRAM bank", i)); |
| 147 | ut_assertok(test_num_ll(uts, "-> start", |
| 148 | bd->bi_dram[i].start)); |
| 149 | ut_assertok(test_num_ll(uts, "-> size", |
| 150 | bd->bi_dram[i].size)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | /* CONFIG_SYS_HAS_SRAM testing not supported */ |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 155 | ut_assertok(test_num_l(uts, "flashstart", 0)); |
| 156 | ut_assertok(test_num_l(uts, "flashsize", 0)); |
| 157 | ut_assertok(test_num_l(uts, "flashoffset", 0)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 158 | ut_assert_nextline("baudrate = %lu bps", |
| 159 | env_get_ulong("baudrate", 10, 1234)); |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 160 | ut_assertok(test_num_l(uts, "relocaddr", gd->relocaddr)); |
| 161 | ut_assertok(test_num_l(uts, "reloc off", gd->reloc_off)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 162 | ut_assert_nextline("%-12s= %u-bit", "Build", (uint)sizeof(void *) * 8); |
| 163 | |
| 164 | if (IS_ENABLED(CONFIG_CMD_NET)) |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 165 | ut_assertok(test_eth(uts)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * Make sure environment variable "fdtcontroladdr" address |
| 169 | * matches mapped control DT address. |
| 170 | */ |
| 171 | ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234)); |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 172 | ut_assertok(test_num_l(uts, "fdt_blob", |
| 173 | (ulong)map_to_sysmem(gd->fdt_blob))); |
| 174 | ut_assertok(test_num_l(uts, "new_fdt", |
| 175 | (ulong)map_to_sysmem(gd->new_fdt))); |
| 176 | ut_assertok(test_num_l(uts, "fdt_size", (ulong)gd->fdt_size)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 177 | |
| 178 | if (IS_ENABLED(CONFIG_VIDEO)) |
| 179 | test_video_info(uts); |
| 180 | |
| 181 | /* The gd->multi_dtb_fit may not be available, hence, #if below. */ |
| 182 | #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) |
Simon Glass | 2c522af | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 183 | ut_assertok(test_num_l(uts, "multi_dtb_fit", (ulong)gd->multi_dtb_fit)); |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 184 | #endif |
| 185 | |
| 186 | if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) { |
| 187 | struct lmb lmb; |
| 188 | |
| 189 | lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); |
| 190 | lmb_test_dump_all(uts, &lmb); |
| 191 | if (IS_ENABLED(CONFIG_OF_REAL)) |
| 192 | ut_assert_nextline("devicetree = %s", fdtdec_get_srcname()); |
| 193 | } |
| 194 | |
Simon Glass | 347a845 | 2023-07-12 09:04:37 -0600 | [diff] [blame] | 195 | if (IS_ENABLED(CONFIG_DM_SERIAL)) { |
| 196 | struct serial_device_info info; |
| 197 | |
| 198 | ut_assertnonnull(gd->cur_serial_dev); |
| 199 | ut_assertok(serial_getinfo(gd->cur_serial_dev, &info)); |
| 200 | |
| 201 | ut_assertok(test_num_l(uts, "serial addr", info.addr)); |
| 202 | ut_assertok(test_num_l(uts, " width", info.reg_width)); |
| 203 | ut_assertok(test_num_l(uts, " shift", info.reg_shift)); |
| 204 | ut_assertok(test_num_l(uts, " offset", info.reg_offset)); |
| 205 | ut_assertok(test_num_l(uts, " clock", info.clock)); |
| 206 | } |
| 207 | |
Simon Glass | b279f51 | 2023-07-15 21:38:46 -0600 | [diff] [blame] | 208 | if (IS_ENABLED(CONFIG_CMD_BDINFO_EXTRA)) { |
| 209 | ut_assert_nextlinen("stack ptr"); |
| 210 | ut_assertok(test_num_ll(uts, "ram_top ptr", |
| 211 | (unsigned long long)gd->ram_top)); |
| 212 | ut_assertok(test_num_l(uts, "malloc base", gd_malloc_start())); |
| 213 | } |
| 214 | |
Marek Vasut | bf52766 | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 215 | ut_assertok(ut_check_console_end(uts)); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | BDINFO_TEST(bdinfo_test_move, UT_TESTF_CONSOLE_REC); |
| 221 | |
| 222 | int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 223 | { |
| 224 | struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test); |
| 225 | const int n_ents = UNIT_TEST_SUITE_COUNT(bdinfo_test); |
| 226 | |
| 227 | return cmd_ut_category("bdinfo", "bdinfo_test_", tests, n_ents, argc, argv); |
| 228 | } |