mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1 2/2] devinfo: print only devices with errors
Date: Sun,  6 Jun 2021 14:24:00 +0200	[thread overview]
Message-ID: <20210606122400.22418-2-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20210606122400.22418-1-o.rempel@pengutronix.de>

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

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-06-06 12:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-06 12:23 [PATCH v1 1/2] add device state flags and add error state Oleksij Rempel
2021-06-06 12:24 ` Oleksij Rempel [this message]
2021-06-16  7:59   ` [PATCH v1 2/2] devinfo: print only devices with errors Sascha Hauer
2021-06-16  8:19     ` Oleksij Rempel
2021-06-21  8:07 ` [PATCH v1 1/2] add device state flags and add error state Ahmad Fatoum
2021-06-21  8:24   ` Bartosz Bilas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210606122400.22418-2-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH v1 2/2] devinfo: print only devices with errors' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox