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 | |
| 30 | static void bdinfo_test_num_l(struct unit_test_state *uts, |
| 31 | const char *name, ulong value) |
| 32 | { |
| 33 | ut_assert_nextline("%-12s= 0x%0*lx", name, 2 * (int)sizeof(value), value); |
| 34 | } |
| 35 | |
| 36 | static void bdinfo_test_num_ll(struct unit_test_state *uts, |
| 37 | const char *name, unsigned long long value) |
| 38 | { |
| 39 | ut_assert_nextline("%-12s= 0x%.*llx", name, 2 * (int)sizeof(ulong), value); |
| 40 | } |
| 41 | |
| 42 | static void test_eth(struct unit_test_state *uts) |
| 43 | { |
| 44 | const int idx = eth_get_dev_index(); |
| 45 | uchar enetaddr[6]; |
| 46 | char name[10]; |
| 47 | int ret; |
| 48 | |
| 49 | if (idx) |
| 50 | sprintf(name, "eth%iaddr", idx); |
| 51 | else |
| 52 | strcpy(name, "ethaddr"); |
| 53 | |
| 54 | ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr); |
| 55 | |
| 56 | ut_assert_nextline("current eth = %s", eth_get_name()); |
| 57 | if (!ret) |
| 58 | ut_assert_nextline("%-12s= (not set)", name); |
| 59 | else |
| 60 | ut_assert_nextline("%-12s= %pM", name, enetaddr); |
| 61 | ut_assert_nextline("IP addr = %s", env_get("ipaddr")); |
| 62 | } |
| 63 | |
| 64 | static void test_video_info(struct unit_test_state *uts) |
| 65 | { |
| 66 | const struct udevice *dev; |
| 67 | struct uclass *uc; |
| 68 | |
| 69 | uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) { |
| 70 | ut_assert_nextline("%-12s= %s %sactive", "Video", dev->name, |
| 71 | device_active(dev) ? "" : "in"); |
| 72 | if (device_active(dev)) { |
| 73 | struct video_priv *upriv = dev_get_uclass_priv(dev); |
| 74 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
| 75 | |
| 76 | bdinfo_test_num_ll(uts, "FB base", (ulong)upriv->fb); |
| 77 | if (upriv->copy_fb) { |
| 78 | bdinfo_test_num_ll(uts, "FB copy", |
| 79 | (ulong)upriv->copy_fb); |
| 80 | bdinfo_test_num_l(uts, " copy size", |
| 81 | plat->copy_size); |
| 82 | } |
| 83 | ut_assert_nextline("%-12s= %dx%dx%d", "FB size", |
| 84 | upriv->xsize, upriv->ysize, |
| 85 | 1 << upriv->bpix); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | static void lmb_test_dump_region(struct unit_test_state *uts, |
| 91 | struct lmb_region *rgn, char *name) |
| 92 | { |
| 93 | unsigned long long base, size, end; |
| 94 | enum lmb_flags flags; |
| 95 | int i; |
| 96 | |
| 97 | ut_assert_nextline(" %s.cnt = 0x%lx / max = 0x%lx", name, rgn->cnt, rgn->max); |
| 98 | |
| 99 | for (i = 0; i < rgn->cnt; i++) { |
| 100 | base = rgn->region[i].base; |
| 101 | size = rgn->region[i].size; |
| 102 | end = base + size - 1; |
| 103 | flags = rgn->region[i].flags; |
| 104 | |
| 105 | ut_assert_nextline(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x", |
| 106 | name, i, base, end, size, flags); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | static void lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb) |
| 111 | { |
| 112 | ut_assert_nextline("lmb_dump_all:"); |
| 113 | lmb_test_dump_region(uts, &lmb->memory, "memory"); |
| 114 | lmb_test_dump_region(uts, &lmb->reserved, "reserved"); |
| 115 | } |
| 116 | |
| 117 | static int bdinfo_test_move(struct unit_test_state *uts) |
| 118 | { |
| 119 | struct bd_info *bd = gd->bd; |
| 120 | int i; |
| 121 | |
| 122 | /* Test moving the working BDINFO to a new location */ |
| 123 | ut_assertok(console_record_reset_enable()); |
| 124 | ut_assertok(run_commandf("bdinfo")); |
| 125 | |
| 126 | bdinfo_test_num_l(uts, "boot_params", 0); |
| 127 | |
| 128 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 129 | if (bd->bi_dram[i].size) { |
| 130 | bdinfo_test_num_l(uts, "DRAM bank", i); |
| 131 | bdinfo_test_num_ll(uts, "-> start", bd->bi_dram[i].start); |
| 132 | bdinfo_test_num_ll(uts, "-> size", bd->bi_dram[i].size); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /* CONFIG_SYS_HAS_SRAM testing not supported */ |
| 137 | bdinfo_test_num_l(uts, "flashstart", 0); |
| 138 | bdinfo_test_num_l(uts, "flashsize", 0); |
| 139 | bdinfo_test_num_l(uts, "flashoffset", 0); |
| 140 | ut_assert_nextline("baudrate = %lu bps", |
| 141 | env_get_ulong("baudrate", 10, 1234)); |
| 142 | bdinfo_test_num_l(uts, "relocaddr", gd->relocaddr); |
| 143 | bdinfo_test_num_l(uts, "reloc off", gd->reloc_off); |
| 144 | ut_assert_nextline("%-12s= %u-bit", "Build", (uint)sizeof(void *) * 8); |
| 145 | |
| 146 | if (IS_ENABLED(CONFIG_CMD_NET)) |
| 147 | test_eth(uts); |
| 148 | |
| 149 | /* |
| 150 | * Make sure environment variable "fdtcontroladdr" address |
| 151 | * matches mapped control DT address. |
| 152 | */ |
| 153 | ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234)); |
| 154 | bdinfo_test_num_l(uts, "fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob)); |
| 155 | bdinfo_test_num_l(uts, "new_fdt", (ulong)map_to_sysmem(gd->new_fdt)); |
| 156 | bdinfo_test_num_l(uts, "fdt_size", (ulong)gd->fdt_size); |
| 157 | |
| 158 | if (IS_ENABLED(CONFIG_VIDEO)) |
| 159 | test_video_info(uts); |
| 160 | |
| 161 | /* The gd->multi_dtb_fit may not be available, hence, #if below. */ |
| 162 | #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) |
| 163 | bdinfo_test_num_l(uts, "multi_dtb_fit", (ulong)gd->multi_dtb_fit); |
| 164 | #endif |
| 165 | |
| 166 | if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) { |
| 167 | struct lmb lmb; |
| 168 | |
| 169 | lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); |
| 170 | lmb_test_dump_all(uts, &lmb); |
| 171 | if (IS_ENABLED(CONFIG_OF_REAL)) |
| 172 | ut_assert_nextline("devicetree = %s", fdtdec_get_srcname()); |
| 173 | } |
| 174 | |
| 175 | ut_assertok(ut_check_console_end(uts)); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | BDINFO_TEST(bdinfo_test_move, UT_TESTF_CONSOLE_REC); |
| 181 | |
| 182 | int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 183 | { |
| 184 | struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test); |
| 185 | const int n_ents = UNIT_TEST_SUITE_COUNT(bdinfo_test); |
| 186 | |
| 187 | return cmd_ut_category("bdinfo", "bdinfo_test_", tests, n_ents, argc, argv); |
| 188 | } |