USB storage count
authorKim B. Heino <Kim.Heino@bluegiga.com>
Fri, 12 Mar 2010 13:46:56 +0000 (15:46 +0200)
committerRemy Bohmer <linux@bohmer.net>
Thu, 8 Apr 2010 19:40:00 +0000 (21:40 +0200)
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>
common/cmd_usb.c
common/usb_storage.c

index 6b5c582550b6dd26a3e8e32a5733f503027f9071..ee3755c121cda7336c75e1e75679afd1694886b2 100644 (file)
@@ -387,7 +387,7 @@ int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
        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 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        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 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                } 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++;
                                debug("print_part of %x\n", devno);
                                print_part(stor_dev);
@@ -668,12 +671,12 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                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;
index a8642c9cc519b7d2787bd76d03e2ad7f58153e51..239bddc5118d5238f9e8205123742ab2a127ee84 100644 (file)
@@ -175,7 +175,7 @@ void uhci_show_temp_int_td(void);
 
 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;
 }