[PATCH] cmd: dm: allow for selecting uclass and device
AKASHI Takahiro
takahiro.akashi at linaro.org
Tue Aug 22 04:46:11 CEST 2023
The output from "dm tree" or "dm uclass" is a bit annoying
if the number of devices available on the system is huge.
(This is especially true on sandbox when I debug some DM code.)
With this patch, we can specify the uclass or the device
that we are interested in in order to limit the output.
For instance,
=> dm uclass usb
uclass 121: usb
0 usb at 1 @ 0bd008b0, seq 1
=> dm tree usb:usb at 1
Class Index Probed Driver Name
-----------------------------------------------------------
usb 0 [ ] usb_sandbox usb at 1
usb_hub 0 [ ] usb_hub `-- hub
usb_emul 0 [ ] usb_sandbox_hub `-- hub-emul
usb_emul 1 [ ] usb_sandbox_flash |-- flash-stick at 0
usb_emul 2 [ ] usb_sandbox_flash |-- flash-stick at 1
usb_emul 3 [ ] usb_sandbox_flash |-- flash-stick at 2
usb_emul 4 [ ] usb_sandbox_keyb `-- keyb at 3
Please note that, at "dm tree", the uclass name (usb) as well as
the device name (usb at 1) is required.
Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
cmd/dm.c | 30 ++++++++++++++++++++--------
drivers/core/dump.c | 48 +++++++++++++++++++++++++++++++++++++++------
include/dm/util.h | 13 ++++++++----
3 files changed, 73 insertions(+), 18 deletions(-)
diff --git a/cmd/dm.c b/cmd/dm.c
index 3263547cbec6..99268df2f87a 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -59,11 +59,20 @@ static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag,
static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
- bool sort;
+ bool sort = false;
+ char *device = NULL;
- sort = argc > 1 && !strcmp(argv[1], "-s");
+ if (argc > 1) {
+ if (!strcmp(argv[1], "-s")) {
+ sort = true;
+ argc--;
+ argv++;
+ }
+ if (argc > 1)
+ device = argv[1];
+ }
- dm_dump_tree(sort);
+ dm_dump_tree(device, sort);
return 0;
}
@@ -71,7 +80,12 @@ static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
- dm_dump_uclass();
+ char *uclass = NULL;
+
+ if (argc > 1)
+ uclass = argv[1];
+
+ dm_dump_uclass(uclass);
return 0;
}
@@ -91,8 +105,8 @@ static char dm_help_text[] =
"dm drivers Dump list of drivers with uclass and instances\n"
DM_MEM_HELP
"dm static Dump list of drivers with static platform data\n"
- "dm tree [-s] Dump tree of driver model devices (-s=sort)\n"
- "dm uclass Dump list of instances for each uclass"
+ "dm tree [-s][name] Dump tree of driver model devices (-s=sort)\n"
+ "dm uclass [name] Dump list of instances for each uclass"
;
#endif
@@ -102,5 +116,5 @@ U_BOOT_CMD_WITH_SUBCMDS(dm, "Driver model low level access", dm_help_text,
U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_dm_dump_drivers),
DM_MEM
U_BOOT_SUBCMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info),
- U_BOOT_SUBCMD_MKENT(tree, 2, 1, do_dm_dump_tree),
- U_BOOT_SUBCMD_MKENT(uclass, 1, 1, do_dm_dump_uclass));
+ U_BOOT_SUBCMD_MKENT(tree, 3, 1, do_dm_dump_tree),
+ U_BOOT_SUBCMD_MKENT(uclass, 2, 1, do_dm_dump_uclass));
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index 3e77832a3a00..855d6ca002b7 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -85,11 +85,35 @@ static void show_devices(struct udevice *dev, int depth, int last_flag,
}
}
-void dm_dump_tree(bool sort)
+void dm_dump_tree(char *uclass, bool sort)
{
struct udevice *root;
- root = dm_root();
+ if (uclass) {
+ char *device;
+ enum uclass_id id;
+
+ device = strchr(uclass, ':');
+ if (!device) {
+ printf("name %s: invalid format\n", uclass);
+ return;
+ }
+ *device = '\0';
+ device++;
+
+ id = uclass_get_by_name(uclass);
+ if (id == UCLASS_INVALID) {
+ printf("uclass %s: not found\n", uclass);
+ return;
+ }
+ if (uclass_find_device_by_name(id, device, &root)) {
+ printf("device %s:%s: not found\n", uclass, device);
+ return;
+ }
+ } else {
+ root = dm_root();
+ }
+
if (root) {
int dev_count, uclasses;
struct udevice **devs = NULL;
@@ -127,13 +151,25 @@ static void dm_display_line(struct udevice *dev, int index)
puts("\n");
}
-void dm_dump_uclass(void)
+void dm_dump_uclass(char *uclass)
{
struct uclass *uc;
- int ret;
- int id;
+ enum uclass_id id;
+ int count, ret;
+
+ if (uclass) {
+ id = uclass_get_by_name(uclass);
+ if (id == UCLASS_INVALID) {
+ printf("uclass %s: not found\n", uclass);
+ return;
+ }
+ count = 1;
+ } else {
+ id = 0;
+ count = UCLASS_COUNT;
+ }
- for (id = 0; id < UCLASS_COUNT; id++) {
+ for ( ; count; id++, count--) {
struct udevice *dev;
int i = 0;
diff --git a/include/dm/util.h b/include/dm/util.h
index 4bb49e9e8c01..ee1b34c103e3 100644
--- a/include/dm/util.h
+++ b/include/dm/util.h
@@ -27,14 +27,19 @@ struct list_head;
int list_count_items(struct list_head *head);
/**
- * Dump out a tree of all devices
+ * Dump out a tree of all devices starting @uclass
*
+ * @uclass: uclass+device name
* @sort: Sort by uclass name
*/
-void dm_dump_tree(bool sort);
+void dm_dump_tree(char *uclass, bool sort);
-/* Dump out a list of uclasses and their devices */
-void dm_dump_uclass(void);
+/*
+ * Dump out a list of uclasses and their devices
+ *
+ * @uclass: uclass name
+ */
+void dm_dump_uclass(char *uclass);
#ifdef CONFIG_DEBUG_DEVRES
/* Dump out a list of device resources */
--
2.34.1
More information about the U-Boot
mailing list