9
0
Fork 0

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>
This commit is contained in:
Sascha Hauer 2012-03-18 13:31:05 +01:00
parent 38a1971e5b
commit 7e614c143d
1 changed files with 22 additions and 4 deletions

View File

@ -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,