Commit 2e48836895d1246b40f7e166695651882e7bb68c
Committed by
Tom Rini
1 parent
2280fa56a0
Exists in
emb_lf_v2022.04
cmd: dm: Fixed/Added DM driver listing subcommands
Renamed dm "drivers" subcommand to "compat" (as it listed compatibility strings) and prevent it from segfaulting when drivers have no of_match populated. Added a new "drivers" subcommand to dump a list of all known DM drivers and for each, their uclass id, uclass driver and names of attached devices. Added a new "static" subcommand to dump a list of DM drivers with statically defined platform data. Signed-off-by: Niel Fourie <lusus@denx.de> Cc: Simon Glass <sjg@chromium.org> Cc: Sean Anderson <seanga2@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Showing 4 changed files with 101 additions and 4 deletions Side-by-side Diff
cmd/dm.c
... | ... | @@ -48,11 +48,29 @@ |
48 | 48 | return 0; |
49 | 49 | } |
50 | 50 | |
51 | +static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc, | |
52 | + char * const argv[]) | |
53 | +{ | |
54 | + dm_dump_driver_compat(); | |
55 | + | |
56 | + return 0; | |
57 | +} | |
58 | + | |
59 | +static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag, int argc, | |
60 | + char * const argv[]) | |
61 | +{ | |
62 | + dm_dump_static_driver_info(); | |
63 | + | |
64 | + return 0; | |
65 | +} | |
66 | + | |
51 | 67 | static struct cmd_tbl test_commands[] = { |
52 | 68 | U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""), |
53 | 69 | U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""), |
54 | 70 | U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""), |
55 | 71 | U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""), |
72 | + U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""), | |
73 | + U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""), | |
56 | 74 | }; |
57 | 75 | |
58 | 76 | static __maybe_unused void dm_reloc(void) |
... | ... | @@ -94,6 +112,8 @@ |
94 | 112 | "tree Dump driver model tree ('*' = activated)\n" |
95 | 113 | "dm uclass Dump list of instances for each uclass\n" |
96 | 114 | "dm devres Dump list of device resources for each device\n" |
97 | - "dm drivers Dump list of drivers and their compatible strings" | |
115 | + "dm drivers Dump list of drivers with uclass and instances\n" | |
116 | + "dm compat Dump list of drivers with compatibility strings\n" | |
117 | + "dm static Dump list of drivers with static platform data" | |
98 | 118 | ); |
drivers/core/dump.c
... | ... | @@ -97,7 +97,7 @@ |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | -void dm_dump_drivers(void) | |
100 | +void dm_dump_driver_compat(void) | |
101 | 101 | { |
102 | 102 | struct driver *d = ll_entry_start(struct driver, driver); |
103 | 103 | const int n_ents = ll_entry_count(struct driver, driver); |
... | ... | @@ -118,6 +118,59 @@ |
118 | 118 | |
119 | 119 | for (; match && match->compatible; match++) |
120 | 120 | printf("%-20.20s %s\n", "", match->compatible); |
121 | + } | |
122 | +} | |
123 | + | |
124 | +void dm_dump_drivers(void) | |
125 | +{ | |
126 | + struct driver *d = ll_entry_start(struct driver, driver); | |
127 | + const int n_ents = ll_entry_count(struct driver, driver); | |
128 | + struct driver *entry; | |
129 | + struct udevice *udev; | |
130 | + struct uclass *uc; | |
131 | + int i; | |
132 | + | |
133 | + puts("Driver uid uclass Devices\n"); | |
134 | + puts("----------------------------------------------------------\n"); | |
135 | + | |
136 | + for (entry = d; entry < d + n_ents; entry++) { | |
137 | + uclass_get(entry->id, &uc); | |
138 | + | |
139 | + printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id, | |
140 | + uc ? uc->uc_drv->name : "<no uclass>"); | |
141 | + | |
142 | + if (!uc) { | |
143 | + puts("\n"); | |
144 | + continue; | |
145 | + } | |
146 | + | |
147 | + i = 0; | |
148 | + uclass_foreach_dev(udev, uc) { | |
149 | + if (udev->driver != entry) | |
150 | + continue; | |
151 | + if (i) | |
152 | + printf("%-51.51s", ""); | |
153 | + | |
154 | + printf("%-25.25s\n", udev->name); | |
155 | + i++; | |
156 | + } | |
157 | + if (!i) | |
158 | + puts("<none>\n"); | |
159 | + } | |
160 | +} | |
161 | + | |
162 | +void dm_dump_static_driver_info(void) | |
163 | +{ | |
164 | + struct driver_info *drv = ll_entry_start(struct driver_info, | |
165 | + driver_info); | |
166 | + const int n_ents = ll_entry_count(struct driver_info, driver_info); | |
167 | + struct driver_info *entry; | |
168 | + | |
169 | + puts("Driver Address\n"); | |
170 | + puts("---------------------------------\n"); | |
171 | + for (entry = drv; entry != drv + n_ents; entry++) { | |
172 | + printf("%-25.25s @%08lx\n", entry->name, | |
173 | + (ulong)map_to_sysmem(entry->platdata)); | |
121 | 174 | } |
122 | 175 | } |
include/dm/util.h
... | ... | @@ -42,5 +42,11 @@ |
42 | 42 | /* Dump out a list of drivers */ |
43 | 43 | void dm_dump_drivers(void); |
44 | 44 | |
45 | +/* Dump out a list with each driver's compatibility strings */ | |
46 | +void dm_dump_driver_compat(void); | |
47 | + | |
48 | +/* Dump out a list of drivers with static platform data */ | |
49 | +void dm_dump_static_driver_info(void); | |
50 | + | |
45 | 51 | #endif |
test/py/tests/test_dm.py
... | ... | @@ -4,14 +4,32 @@ |
4 | 4 | import pytest |
5 | 5 | |
6 | 6 | @pytest.mark.buildconfigspec('cmd_dm') |
7 | -def test_dm_drivers(u_boot_console): | |
8 | - """Test that each driver in `dm tree` is also listed in `dm drivers`.""" | |
7 | +def test_dm_compat(u_boot_console): | |
8 | + """Test that each driver in `dm tree` is also listed in `dm compat`.""" | |
9 | 9 | response = u_boot_console.run_command('dm tree') |
10 | 10 | driver_index = response.find('Driver') |
11 | 11 | assert driver_index != -1 |
12 | 12 | drivers = (line[driver_index:].split()[0] |
13 | 13 | for line in response[:-1].split('\n')[2:]) |
14 | 14 | |
15 | + response = u_boot_console.run_command('dm compat') | |
16 | + for driver in drivers: | |
17 | + assert driver in response | |
18 | + | |
19 | +@pytest.mark.buildconfigspec('cmd_dm') | |
20 | +def test_dm_drivers(u_boot_console): | |
21 | + """Test that each driver in `dm compat` is also listed in `dm drivers`.""" | |
22 | + response = u_boot_console.run_command('dm compat') | |
23 | + drivers = (line[:20].rstrip() for line in response[:-1].split('\n')[2:]) | |
24 | + response = u_boot_console.run_command('dm drivers') | |
25 | + for driver in drivers: | |
26 | + assert driver in response | |
27 | + | |
28 | +@pytest.mark.buildconfigspec('cmd_dm') | |
29 | +def test_dm_static(u_boot_console): | |
30 | + """Test that each driver in `dm static` is also listed in `dm drivers`.""" | |
31 | + response = u_boot_console.run_command('dm static') | |
32 | + drivers = (line[:25].rstrip() for line in response[:-1].split('\n')[2:]) | |
15 | 33 | response = u_boot_console.run_command('dm drivers') |
16 | 34 | for driver in drivers: |
17 | 35 | assert driver in response |