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 | |
| 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 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | /* Declare a new bdinfo test */ |
| 28 | #define BDINFO_TEST(_name, _flags) UNIT_TEST(_name, _flags, bdinfo_test) |
| 29 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 30 | static int test_num_l(struct unit_test_state *uts, const char *name, |
| 31 | ulong value) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 32 | { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 33 | ut_assert_nextline("%-12s= 0x%0*lx", name, 2 * (int)sizeof(value), |
| 34 | value); |
| 35 | |
| 36 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 39 | static int test_num_ll(struct unit_test_state *uts, const char *name, |
| 40 | unsigned long long value) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 41 | { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 42 | ut_assert_nextline("%-12s= 0x%.*llx", name, 2 * (int)sizeof(ulong), |
| 43 | value); |
| 44 | |
| 45 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 46 | } |
| 47 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 48 | static int test_eth(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 49 | { |
| 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 Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 68 | |
| 69 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 72 | static int test_video_info(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 73 | { |
| 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 Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 84 | ut_assertok(test_num_ll(uts, "FB base", |
| 85 | (ulong)upriv->fb)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 86 | if (upriv->copy_fb) { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 87 | 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 Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 91 | } |
| 92 | ut_assert_nextline("%-12s= %dx%dx%d", "FB size", |
| 93 | upriv->xsize, upriv->ysize, |
| 94 | 1 << upriv->bpix); |
| 95 | } |
| 96 | } |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 97 | |
| 98 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 101 | static int lmb_test_dump_region(struct unit_test_state *uts, |
| 102 | struct lmb_region *rgn, char *name) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 103 | { |
| 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 Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 119 | |
| 120 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 123 | static int lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 124 | { |
| 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 Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 128 | |
| 129 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static 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 Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 141 | ut_assertok(test_num_l(uts, "boot_params", 0)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 142 | |
| 143 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 144 | if (bd->bi_dram[i].size) { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 145 | 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 Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | /* CONFIG_SYS_HAS_SRAM testing not supported */ |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 154 | 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 Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 157 | ut_assert_nextline("baudrate = %lu bps", |
| 158 | env_get_ulong("baudrate", 10, 1234)); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 159 | ut_assertok(test_num_l(uts, "relocaddr", gd->relocaddr)); |
| 160 | ut_assertok(test_num_l(uts, "reloc off", gd->reloc_off)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 161 | ut_assert_nextline("%-12s= %u-bit", "Build", (uint)sizeof(void *) * 8); |
| 162 | |
| 163 | if (IS_ENABLED(CONFIG_CMD_NET)) |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 164 | ut_assertok(test_eth(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 165 | |
| 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 Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 171 | 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 Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 176 | |
| 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 Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 182 | 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] | 183 | #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 | |
| 199 | BDINFO_TEST(bdinfo_test_move, UT_TESTF_CONSOLE_REC); |
| 200 | |
| 201 | int 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 | } |