[U-Boot] [PATCH v2 2/3] dm: add a command to list devices in a tree-like format
Simon Glass
sjg at chromium.org
Thu Nov 20 16:00:41 CET 2014
Hi Masahiro,
On 20 November 2014 12:20, Masahiro Yamada <yamada.m at jp.panasonic.com> wrote:
> 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.
This looks very similar to the 'dm tree' command. Can we unify these?
Perhaps move the commands into common/cmd_dm.c? Then we can use the
CONFIG_CMD_DM option instead of a new one.
Also I think 'dm xxx' is better than things 'showdev'. The 'dm' prefix
can be used for all DM commands.
>
> => 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 at 0
> i2c_eeprom [ + ] | |-- eeprom at 2c
> i2c_emul [ + ] | | \-- emul
> i2c_generic [ + ] | \-- generic_59
> spi [ ] |-- spi at 0
> spi_emul [ ] | \-- flash at 0
> cros_ec [ + ] \-- cros-ec at 0
>
> Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
> ---
>
> Changes in v2:
> - Fix the tree format
>
> common/Makefile | 1 +
> common/cmd_showdev.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 71 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..f73bfba
> --- /dev/null
> +++ b/common/cmd_showdev.c
> @@ -0,0 +1,70 @@
> +/*
> + * Copyright (C) 2014 Panasonic Corporation
> + * Author: Masahiro Yamada <yamada.m at 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 "|-- "
Is there really any value in these?
> +
> +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 ? '+' : ' ');
This line could be combined with the above.
> +
> + 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) {
> + is_last = list_is_last(&child->sibling_node, &dev->child_head);
> + show_devices(child, depth + 1, (last_flag << 1) | is_last);
> + }
> +}
> +
> +static int do_showdev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> +{
> + printf(" Class Probed Name\n");
Remove the first space?
> + 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
>
Regards,
Simon
More information about the U-Boot
mailing list