]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd: dm: Fixed/Added DM driver listing subcommands
authorNiel Fourie <lusus@denx.de>
Tue, 24 Mar 2020 15:17:05 +0000 (16:17 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 7 Jul 2020 19:37:13 +0000 (15:37 -0400)
Renamed dm "drivers" subcommand to "compat" (as it listed
compatibility strings) and prevent it from segfaulting when
drivers have no of_match populated.

Added a new "drivers" subcommand to dump a list of all known DM
drivers and for each, their uclass id, uclass driver and names of
attached devices.

Added a new "static" subcommand to dump a list of DM drivers with
statically defined platform data.

Signed-off-by: Niel Fourie <lusus@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/dm.c
drivers/core/dump.c
include/dm/util.h
test/py/tests/test_dm.py

index 4e307ac5245bfe0d8e9122c94abe4d71a5dde5f8..1dd19fe45b5490c9ef58dec2c11d72609a5c3ebe 100644 (file)
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -48,11 +48,29 @@ static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int flag, int argc,
        return 0;
 }
 
+static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
+                                   char * const argv[])
+{
+       dm_dump_driver_compat();
+
+       return 0;
+}
+
+static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag, int argc,
+                                        char * const argv[])
+{
+       dm_dump_static_driver_info();
+
+       return 0;
+}
+
 static struct cmd_tbl test_commands[] = {
        U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
        U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
        U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
        U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
+       U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
+       U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""),
 };
 
 static __maybe_unused void dm_reloc(void)
@@ -94,5 +112,7 @@ U_BOOT_CMD(
        "tree          Dump driver model tree ('*' = activated)\n"
        "dm uclass        Dump list of instances for each uclass\n"
        "dm devres        Dump list of device resources for each device\n"
-       "dm drivers       Dump list of drivers and their compatible strings"
+       "dm drivers       Dump list of drivers with uclass and instances\n"
+       "dm compat        Dump list of drivers with compatibility strings\n"
+       "dm static        Dump list of drivers with static platform data"
 );
index cb8a25b9ad63be91dc63b9f3c117b05235563737..6debaf97a1df05ba50e00a10cc875a52abab4e4b 100644 (file)
@@ -97,7 +97,7 @@ void dm_dump_uclass(void)
        }
 }
 
-void dm_dump_drivers(void)
+void dm_dump_driver_compat(void)
 {
        struct driver *d = ll_entry_start(struct driver, driver);
        const int n_ents = ll_entry_count(struct driver, driver);
@@ -120,3 +120,56 @@ void dm_dump_drivers(void)
                        printf("%-20.20s  %s\n", "", match->compatible);
        }
 }
+
+void dm_dump_drivers(void)
+{
+       struct driver *d = ll_entry_start(struct driver, driver);
+       const int n_ents = ll_entry_count(struct driver, driver);
+       struct driver *entry;
+       struct udevice *udev;
+       struct uclass *uc;
+       int i;
+
+       puts("Driver                    uid uclass               Devices\n");
+       puts("----------------------------------------------------------\n");
+
+       for (entry = d; entry < d + n_ents; entry++) {
+               uclass_get(entry->id, &uc);
+
+               printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
+                      uc ? uc->uc_drv->name : "<no uclass>");
+
+               if (!uc) {
+                       puts("\n");
+                       continue;
+               }
+
+               i = 0;
+               uclass_foreach_dev(udev, uc) {
+                       if (udev->driver != entry)
+                               continue;
+                       if (i)
+                               printf("%-51.51s", "");
+
+                       printf("%-25.25s\n", udev->name);
+                       i++;
+               }
+               if (!i)
+                       puts("<none>\n");
+       }
+}
+
+void dm_dump_static_driver_info(void)
+{
+       struct driver_info *drv = ll_entry_start(struct driver_info,
+                                                driver_info);
+       const int n_ents = ll_entry_count(struct driver_info, driver_info);
+       struct driver_info *entry;
+
+       puts("Driver                    Address\n");
+       puts("---------------------------------\n");
+       for (entry = drv; entry != drv + n_ents; entry++) {
+               printf("%-25.25s @%08lx\n", entry->name,
+                      (ulong)map_to_sysmem(entry->platdata));
+       }
+}
index 23f8deb14e6e13b95195762ba21c14102cb1e701..9773db6de179d11b2fe87ccda1798f8a7f24fa35 100644 (file)
@@ -42,4 +42,10 @@ static inline void dm_dump_devres(void)
 /* Dump out a list of drivers */
 void dm_dump_drivers(void);
 
+/* Dump out a list with each driver's compatibility strings */
+void dm_dump_driver_compat(void);
+
+/* Dump out a list of drivers with static platform data */
+void dm_dump_static_driver_info(void);
+
 #endif
index f6fbf8ba4c5b0b9c85d40b555c0cd4af51fc74d7..97203b536e172326aa8aa2819ff305c157af0f28 100644 (file)
@@ -4,14 +4,32 @@
 import pytest
 
 @pytest.mark.buildconfigspec('cmd_dm')
-def test_dm_drivers(u_boot_console):
-    """Test that each driver in `dm tree` is also listed in `dm drivers`."""
+def test_dm_compat(u_boot_console):
+    """Test that each driver in `dm tree` is also listed in `dm compat`."""
     response = u_boot_console.run_command('dm tree')
     driver_index = response.find('Driver')
     assert driver_index != -1
     drivers = (line[driver_index:].split()[0]
                for line in response[:-1].split('\n')[2:])
 
+    response = u_boot_console.run_command('dm compat')
+    for driver in drivers:
+        assert driver in response
+
+@pytest.mark.buildconfigspec('cmd_dm')
+def test_dm_drivers(u_boot_console):
+    """Test that each driver in `dm compat` is also listed in `dm drivers`."""
+    response = u_boot_console.run_command('dm compat')
+    drivers = (line[:20].rstrip() for line in response[:-1].split('\n')[2:])
+    response = u_boot_console.run_command('dm drivers')
+    for driver in drivers:
+        assert driver in response
+
+@pytest.mark.buildconfigspec('cmd_dm')
+def test_dm_static(u_boot_console):
+    """Test that each driver in `dm static` is also listed in `dm drivers`."""
+    response = u_boot_console.run_command('dm static')
+    drivers = (line[:25].rstrip() for line in response[:-1].split('\n')[2:])
     response = u_boot_console.run_command('dm drivers')
     for driver in drivers:
         assert driver in response