We are adding more and more drivers to driver model these days. Compared with the ad-hoc driver system, it seems pretty difficult to understand how drivers are working on driver model. For ex. - Which devices have been bound? - Which devices have been probed? - Which is the parent of this device? etc.
I hope this tool will help us test/review driver model patches. Just hit "showdev" on the command line and it will list all the bound devices in a tree-like format with Class and Probed flag. => showdev Class Probed Name ---------------------------------------- root [ + ] root_driver demo [ ] |-- demo_shape_drv demo [ ] |-- demo_simple_drv demo [ ] |-- demo_shape_drv demo [ ] |-- demo_simple_drv demo [ ] |-- demo_shape_drv test [ ] |-- test_drv test [ ] |-- test_drv test [ ] |-- test_drv gpio [ ] |-- gpio_sandbox serial [ ] |-- serial_sandbox serial [ + ] |-- serial demo [ ] |-- triangle demo [ ] |-- square demo [ ] |-- hexagon gpio [ ] |-- gpios i2c [ + ] |-- i2c@0 i2c_eeprom [ + ] | |-- eeprom@2c i2c_emul [ + ] | | \-- emul i2c_generic [ + ] | \-- generic_59 spi [ ] |-- spi@0 spi_emul [ ] | \-- flash@0 cros_ec [ + ] \-- cros-ec@0 Signed-off-by: Masahiro Yamada <yamad...@jp.panasonic.com> --- common/Makefile | 1 + common/cmd_showdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 common/cmd_showdev.c diff --git a/common/Makefile b/common/Makefile index 6cc4de8..c26c764 100644 --- a/common/Makefile +++ b/common/Makefile @@ -84,6 +84,7 @@ obj-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o obj-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o obj-$(CONFIG_CMD_DATE) += cmd_date.o obj-$(CONFIG_CMD_DEMO) += cmd_demo.o +obj-$(CONFIG_CMD_SHOWDEV) += cmd_showdev.o obj-$(CONFIG_CMD_SOUND) += cmd_sound.o ifdef CONFIG_4xx obj-$(CONFIG_CMD_SETGETDCR) += cmd_dcr.o diff --git a/common/cmd_showdev.c b/common/cmd_showdev.c new file mode 100644 index 0000000..6761865 --- /dev/null +++ b/common/cmd_showdev.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2014 Panasonic Corporation + * Author: Masahiro Yamada <yamad...@jp.panasonic.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <linux/string.h> +#include <linux/list.h> +#include <dm/device.h> +#include <dm/uclass.h> + +DECLARE_GLOBAL_DATA_PTR; + +#define INDENT1 " " +#define INDENT2 "| " +#define INDENT3 "\\-- " +#define INDENT4 "|-- " + +static void show_devices(struct udevice *dev, int depth, int last_flag) +{ + int i, is_last; + struct udevice *child; + char class_name[12]; + + /* print the first 11 characters to not break the tree-format. */ + strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name)); + printf(" %-11s ", class_name); + + printf("[ %c ] ", dev->flags & DM_FLAG_ACTIVATED ? '+' : ' '); + + for (i = depth; i >= 0; i--) { + is_last = (last_flag >> i) & 1; + if (i) { + if (is_last) + printf(INDENT1); + else + printf(INDENT2); + } else { + if (is_last) + printf(INDENT3); + else + printf(INDENT4); + } + } + + printf("%s\n", dev->name); + + list_for_each_entry(child, &dev->child_head, sibling_node) { + last_flag <<= 1; + last_flag |= list_is_last(&child->sibling_node, + &dev->child_head); + show_devices(child, depth + 1, last_flag); + } +} + +static int do_showdev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + printf(" Class Probed Name\n"); + printf("----------------------------------------\n"); + + show_devices(gd->dm_root, -1, 0); + + return 0; +} + +U_BOOT_CMD( + showdev, 1, 1, do_showdev, + "show devices in a tree-like format.", + "" +); -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot