Make use of device state flags and print only devices with errors.
The result will look like this:
barebox@RIoTboard i.MX6S:/ devinfo -e
`-- [email protected] <-- (error!)
   `-- miibus0
      `-- mdio0-phy04
         `-- 0x00000000-0x0000003f (  64 Bytes): /dev/mdio0-phy04
   `-- eth0

Signed-off-by: Oleksij Rempel <[email protected]>
---
 commands/devinfo.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/commands/devinfo.c b/commands/devinfo.c
index 2e2e48e42c..af57cac522 100644
--- a/commands/devinfo.c
+++ b/commands/devinfo.c
@@ -5,6 +5,7 @@
 #include <common.h>
 #include <complete.h>
 #include <driver.h>
+#include <getopt.h>
 
 static int do_devinfo_subtree(struct device_d *dev, int depth)
 {
@@ -16,6 +17,9 @@ static int do_devinfo_subtree(struct device_d *dev, int depth)
                printf("   ");
 
        printf("`-- %s", dev_name(dev));
+       if (dev_have_err(dev))
+               printf(" <-- (error!)");
+
        if (!list_empty(&dev->cdevs)) {
                printf("\n");
                list_for_each_entry(cdev, &dev->cdevs, devices_list) {
@@ -43,6 +47,15 @@ static int do_devinfo_subtree(struct device_d *dev, int 
depth)
        return 0;
 }
 
+static int do_devinfo_err(void)
+{
+       struct device_d *dev;
+
+       for_each_device(dev)
+               if (dev_have_err(dev))
+                       do_devinfo_subtree(dev, 0);
+       return 0;
+}
 
 static int do_devinfo(int argc, char *argv[])
 {
@@ -58,6 +71,23 @@ static int do_devinfo(int argc, char *argv[])
                                do_devinfo_subtree(dev, 0);
                }
        } else {
+               bool dev_err = false;
+               int opt;
+
+               while ((opt = getopt(argc, argv, "e")) > 0) {
+                       switch (opt) {
+                       case 'e':
+                               dev_err = true;
+                               break;
+                       default:
+                               return COMMAND_ERROR_USAGE;
+                       }
+               }
+
+               if (dev_err) {
+                       return do_devinfo_err();
+               }
+
                dev = get_device_by_name(argv[1]);
                if (!dev)
                        return -ENODEV;
-- 
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to