[PATCH 7/8] usb command: by default scan only once for USB devices

Sascha Hauer s.hauer at pengutronix.de
Sun Mar 18 10:26:43 EDT 2012


We normally do not expect USB devices to be hotplugged. Instead of
rescanning each time the usb command is called, scan only once.
This makes the usb command safe for being called multiple times
without making already registered USB devices reinitialized. To
really scan multiple times a '-f' option is introduced.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/usb.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/commands/usb.c b/commands/usb.c
index 6605e03..e28afd0 100644
--- a/commands/usb.c
+++ b/commands/usb.c
@@ -22,17 +22,35 @@
 #include <common.h>
 #include <command.h>
 #include <usb/usb.h>
+#include <getopt.h>
+
+static int scanned;
 
 static int do_usb(int argc, char *argv[])
 {
-	usb_rescan();
+	int opt;
+
+	while ((opt = getopt(argc, argv, "f")) > 0) {
+		switch (opt) {
+		case 'f':
+			scanned = 0;
+			break;
+		}
+	}
+
+	if (!scanned) {
+		usb_rescan();
+		scanned = 1;
+	}
 
 	return 0;
 }
 
-static const __maybe_unused char cmd_usb_help[] =
-"Usage: usb\n"
-"(re-)detect USB devices\n";
+BAREBOX_CMD_HELP_START(usb)
+BAREBOX_CMD_HELP_USAGE("usb [-f]\n")
+BAREBOX_CMD_HELP_SHORT("Scan for USB devices.\n")
+BAREBOX_CMD_HELP_OPT("-f", "force. Rescan if if if have scanned once\n")
+BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(usb)
 	.cmd		= do_usb,
-- 
1.7.9.1




More information about the barebox mailing list