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:
parent
38a1971e5b
commit
7e614c143d
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue