diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-03-18 13:31:05 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-03-18 15:03:31 +0100 |
commit | 7e614c143dc894fec1773bdd0b8f825b503204d3 (patch) | |
tree | 4f51e7235183d1a3f840d674339bf02efb399699 /commands | |
parent | 38a1971e5b8ad7f30722d84e74152c980338fbdb (diff) | |
download | barebox-7e614c143dc894fec1773bdd0b8f825b503204d3.tar.gz barebox-7e614c143dc894fec1773bdd0b8f825b503204d3.tar.xz |
usb command: by default scan only once for USB devices
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@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/usb.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/commands/usb.c b/commands/usb.c index 6605e031a7..e28afd051b 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, |