Commit a56642c7baa02ec4f054d630ec4e5e56d8e087da

Authored by Masahiro Yamada
Committed by Simon Glass
1 parent 80d9ef8d40

dm_test: improve the appearance shown by "dm tree" command

The command "dm tree" lists devices in a tree-like format.
This commit makes it look more like what the Unix command "tree"
shows.

=> dm tree
 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
 spi         [   ]    |-- spi@0
 spi_emul    [   ]    |   `-- flash@0
 cros_ec     [ + ]    `-- cros-ec@0

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>

Showing 1 changed file with 52 additions and 51 deletions Side-by-side Diff

... ... @@ -16,71 +16,72 @@
16 16 #include <dm/test.h>
17 17 #include <dm/uclass-internal.h>
18 18  
19   -/**
20   - * dm_display_line() - Display information about a single device
21   - *
22   - * Displays a single line of information with an option prefix
23   - *
24   - * @dev: Device to display
25   - * @buf: Prefix to display at the start of the line
26   - */
27   -static void dm_display_line(struct udevice *dev, char *buf)
  19 +static void show_devices(struct udevice *dev, int depth, int last_flag)
28 20 {
29   - printf("%s- %c %s @ %08lx", buf,
30   - dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
31   - dev->name, (ulong)map_to_sysmem(dev));
32   - if (dev->req_seq != -1)
33   - printf(", %d", dev->req_seq);
34   - puts("\n");
35   -}
  21 + int i, is_last;
  22 + struct udevice *child;
  23 + char class_name[12];
36 24  
37   -static int display_succ(struct udevice *in, char *buf)
38   -{
39   - int len;
40   - int ip = 0;
41   - char local[16];
42   - struct udevice *pos, *n, *prev = NULL;
  25 + /* print the first 11 characters to not break the tree-format. */
  26 + strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
  27 + printf(" %-11s [ %c ] ", class_name,
  28 + dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
43 29  
44   - dm_display_line(in, buf);
45   -
46   - if (list_empty(&in->child_head))
47   - return 0;
48   -
49   - len = strlen(buf);
50   - strncpy(local, buf, sizeof(local));
51   - snprintf(local + len, 2, "|");
52   - if (len && local[len - 1] == '`')
53   - local[len - 1] = ' ';
54   -
55   - list_for_each_entry_safe(pos, n, &in->child_head, sibling_node) {
56   - if (ip++)
57   - display_succ(prev, local);
58   - prev = pos;
  30 + for (i = depth; i >= 0; i--) {
  31 + is_last = (last_flag >> i) & 1;
  32 + if (i) {
  33 + if (is_last)
  34 + printf(" ");
  35 + else
  36 + printf("| ");
  37 + } else {
  38 + if (is_last)
  39 + printf("`-- ");
  40 + else
  41 + printf("|-- ");
  42 + }
59 43 }
60 44  
61   - snprintf(local + len, 2, "`");
62   - display_succ(prev, local);
  45 + printf("%s\n", dev->name);
63 46  
64   - return 0;
  47 + list_for_each_entry(child, &dev->child_head, sibling_node) {
  48 + is_last = list_is_last(&child->sibling_node, &dev->child_head);
  49 + show_devices(child, depth + 1, (last_flag << 1) | is_last);
  50 + }
65 51 }
66 52  
67   -static int dm_dump(struct udevice *dev)
68   -{
69   - if (!dev)
70   - return -EINVAL;
71   - return display_succ(dev, "");
72   -}
73   -
74 53 static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
75 54 char * const argv[])
76 55 {
77 56 struct udevice *root;
78 57  
79 58 root = dm_root();
80   - printf("ROOT %08lx\n", (ulong)map_to_sysmem(root));
81   - return dm_dump(root);
  59 + if (root) {
  60 + printf(" Class Probed Name\n");
  61 + printf("----------------------------------------\n");
  62 + show_devices(root, -1, 0);
  63 + }
  64 +
  65 + return 0;
82 66 }
83 67  
  68 +/**
  69 + * dm_display_line() - Display information about a single device
  70 + *
  71 + * Displays a single line of information with an option prefix
  72 + *
  73 + * @dev: Device to display
  74 + */
  75 +static void dm_display_line(struct udevice *dev)
  76 +{
  77 + printf("- %c %s @ %08lx",
  78 + dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
  79 + dev->name, (ulong)map_to_sysmem(dev));
  80 + if (dev->req_seq != -1)
  81 + printf(", %d", dev->req_seq);
  82 + puts("\n");
  83 +}
  84 +
84 85 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
85 86 char * const argv[])
86 87 {
... ... @@ -99,7 +100,7 @@
99 100 if (list_empty(&uc->dev_head))
100 101 continue;
101 102 list_for_each_entry(dev, &uc->dev_head, uclass_node) {
102   - dm_display_line(dev, "");
  103 + dm_display_line(dev);
103 104 }
104 105 puts("\n");
105 106 }