From: Kim B. Heino <Kim.Heino@bluegiga.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] USB storage count
Date: Fri, 12 Mar 2010 15:46:56 +0200 [thread overview]
Message-ID: <20100312154656.6f0dfd64@bluegiga.com> (raw)
Here's another USB storage patch. Currently U-Boot handles storage
devices #0 - #4 as valid devices, even if there is none connected. This
patch fixes usb_stor_get_dev() to check detected device count instead
of MAX-define.
This is very important for ill behaving devices. usb_dev_desc[] can be
partially initialized if device probe fails.
After fixing get_dev() it was easy to fix "usb part" etc commands.
Previously it outputed "Unknown partition table" five times, now it's
"no USB devices available".
Signed-off-by: Kim B. Heino <Kim.Heino@bluegiga.com>
diff -ur u-boot.orig/common/cmd_usb.c u-boot/common/cmd_usb.c
--- u-boot.orig/common/cmd_usb.c 2010-03-12 10:49:23.000000000 +0200
+++ u-boot/common/cmd_usb.c 2010-03-12 15:21:57.587689570 +0200
@@ -387,7 +387,7 @@
dev = simple_strtoul(boot_device, &ep, 16);
stor_dev = usb_stor_get_dev(dev);
- if (stor_dev->type == DEV_TYPE_UNKNOWN) {
+ if (stor_dev == NULL || stor_dev->type == DEV_TYPE_UNKNOWN) {
printf("\n** Device %d not available\n", dev);
return 1;
}
@@ -595,8 +595,10 @@
if (strncmp(argv[1], "part", 4) == 0) {
int devno, ok = 0;
if (argc == 2) {
- for (devno = 0; devno < USB_MAX_STOR_DEV; ++devno) {
+ for (devno = 0; ; ++devno) {
stor_dev = usb_stor_get_dev(devno);
+ if (stor_dev == NULL)
+ break;
if (stor_dev->type != DEV_TYPE_UNKNOWN) {
ok++;
if (devno)
@@ -608,7 +610,8 @@
} else {
devno = simple_strtoul(argv[2], NULL, 16);
stor_dev = usb_stor_get_dev(devno);
- if (stor_dev->type != DEV_TYPE_UNKNOWN) {
+ if (stor_dev != NULL &&
+ stor_dev->type != DEV_TYPE_UNKNOWN) {
ok++;
printf("print_part of %x\n", devno);
print_part(stor_dev);
@@ -668,12 +671,12 @@
if (argc == 3) {
int dev = (int)simple_strtoul(argv[2], NULL, 10);
printf("\nUSB device %d: ", dev);
- if (dev >= USB_MAX_STOR_DEV) {
+ stor_dev = usb_stor_get_dev(dev);
+ if (stor_dev == NULL) {
printf("unknown device\n");
return 1;
}
printf("\n Device %d: ", dev);
- stor_dev = usb_stor_get_dev(dev);
dev_print(stor_dev);
if (stor_dev->type == DEV_TYPE_UNKNOWN)
return 1;
diff -ur u-boot.orig/common/usb_storage.c u-boot/common/usb_storage.c
--- u-boot.orig/common/usb_storage.c 2010-03-12 10:49:23.000000000 +0200
+++ u-boot/common/usb_storage.c 2010-03-12 15:18:34.000564615 +0200
@@ -175,7 +175,7 @@
block_dev_desc_t *usb_stor_get_dev(int index)
{
- return (index < USB_MAX_STOR_DEV) ? &usb_dev_desc[index] : NULL;
+ return (index < usb_max_devs) ? &usb_dev_desc[index] : NULL;
}
next reply other threads:[~2010-03-12 13:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-12 13:46 Kim B. Heino [this message]
2010-03-24 19:48 ` [U-Boot] [PATCH] USB storage count Remy Bohmer
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=20100312154656.6f0dfd64@bluegiga.com \
--to=kim.heino@bluegiga.com \
--cc=u-boot@lists.denx.de \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.