]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - test/dm/cmd_dm.c
dm: test: Allow 'dm test' to select a particular test to run
[karo-tx-uboot.git] / test / dm / cmd_dm.c
index aa8122c00541f41b4e46845977628775bc172ca0..2f527e959b57e3e819e25efc240663922f267d4d 100644 (file)
 #include <common.h>
 #include <dm.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <errno.h>
 #include <asm/io.h>
 #include <dm/root.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
 
-static int display_succ(struct udevice *in, char *buf)
+static void show_devices(struct udevice *dev, int depth, int last_flag)
 {
-       int len;
-       int ip = 0;
-       char local[16];
-       struct udevice *pos, *n, *prev = NULL;
-
-       printf("%s- %s @ %08lx", buf, in->name, (ulong)map_to_sysmem(in));
-       if (in->flags & DM_FLAG_ACTIVATED)
-               puts(" - activated");
-       puts("\n");
-
-       if (list_empty(&in->child_head))
-               return 0;
-
-       len = strlen(buf);
-       strncpy(local, buf, sizeof(local));
-       snprintf(local + len, 2, "|");
-       if (len && local[len - 1] == '`')
-               local[len - 1] = ' ';
-
-       list_for_each_entry_safe(pos, n, &in->child_head, sibling_node) {
-               if (ip++)
-                       display_succ(prev, local);
-               prev = pos;
+       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 [ %c ]    ", class_name,
+              dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
+
+       for (i = depth; i >= 0; i--) {
+               is_last = (last_flag >> i) & 1;
+               if (i) {
+                       if (is_last)
+                               printf("    ");
+                       else
+                               printf("|   ");
+               } else {
+                       if (is_last)
+                               printf("`-- ");
+                       else
+                               printf("|-- ");
+               }
        }
 
-       snprintf(local + len, 2, "`");
-       display_succ(prev, local);
-
-       return 0;
-}
+       printf("%s\n", dev->name);
 
-static int dm_dump(struct udevice *dev)
-{
-       if (!dev)
-               return -EINVAL;
-       return display_succ(dev, "");
+       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_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -62,8 +57,30 @@ static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
        struct udevice *root;
 
        root = dm_root();
-       printf("ROOT %08lx\n", (ulong)map_to_sysmem(root));
-       return dm_dump(root);
+       if (root) {
+               printf(" Class       Probed   Name\n");
+               printf("----------------------------------------\n");
+               show_devices(root, -1, 0);
+       }
+
+       return 0;
+}
+
+/**
+ * dm_display_line() - Display information about a single device
+ *
+ * Displays a single line of information with an option prefix
+ *
+ * @dev:       Device to display
+ */
+static void dm_display_line(struct udevice *dev)
+{
+       printf("- %c %s @ %08lx",
+              dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
+              dev->name, (ulong)map_to_sysmem(dev));
+       if (dev->seq != -1 || dev->req_seq != -1)
+               printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
+       puts("\n");
 }
 
 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -81,11 +98,10 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
                        continue;
 
                printf("uclass %d: %s\n", id, uc->uc_drv->name);
-               for (ret = uclass_first_device(id, &dev);
-                    dev;
-                    ret = uclass_next_device(&dev)) {
-                       printf("  %s @ %08lx:\n", dev->name,
-                              (ulong)map_to_sysmem(dev));
+               if (list_empty(&uc->dev_head))
+                       continue;
+               list_for_each_entry(dev, &uc->dev_head, uclass_node) {
+                       dm_display_line(dev);
                }
                puts("\n");
        }
@@ -97,7 +113,12 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
 static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
                          char * const argv[])
 {
-       return dm_test_main();
+       const char *test_name = NULL;
+
+       if (argc > 0)
+               test_name = argv[0];
+
+       return dm_test_main(test_name);
 }
 #define TEST_HELP "\ndm test         Run tests"
 #else
@@ -117,7 +138,7 @@ static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        cmd_tbl_t *test_cmd;
        int ret;
 
-       if (argc != 2)
+       if (argc < 2)
                return CMD_RET_USAGE;
        test_cmd = find_cmd_tbl(argv[1], test_commands,
                                ARRAY_SIZE(test_commands));
@@ -132,9 +153,9 @@ static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-       dm,     2,      1,      do_dm,
+       dm,     3,      1,      do_dm,
        "Driver model low level access",
-       "tree         Dump driver model tree\n"
+       "tree         Dump driver model tree ('*' = activated)\n"
        "dm uclass        Dump list of instances for each uclass"
        TEST_HELP
 );