usbd: error handling for mmc device
authorMinkyu Kang <mk7.kang@samsung.com>
Wed, 8 Dec 2010 07:39:04 +0000 (16:39 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Wed, 8 Dec 2010 07:39:04 +0000 (16:39 +0900)
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
arch/arm/cpu/armv7/s5p-common/usb_downloader.c
build.sh
common/cmd_usbd.c

index 453e4f0..428e9a1 100644 (file)
@@ -68,12 +68,19 @@ static void usbd_set_mmc_dev(struct usbd_ops *usbd)
                return;
 
        usbd->mmc_dev = 0;
-       /* FIXME */
-       usbd->mmc_max = 0x8000;
 
        mmc = find_mmc_device(usbd->mmc_dev);
        mmc_init(mmc);
 
+       if (!mmc->read_bl_len) {
+               mmc_type = -1;
+               usbd->mmc_max = 0;
+               usbd->mmc_total = 0;
+               return;
+       }
+
+       /* FIXME */
+       usbd->mmc_max = 0x8000;
        usbd->mmc_blk = mmc->read_bl_len;
        usbd->mmc_total = mmc->capacity / mmc->read_bl_len;
 
@@ -82,6 +89,8 @@ static void usbd_set_mmc_dev(struct usbd_ops *usbd)
 
        if (!strncmp(mmc_name, "SEM", 3))
                mmc_type = 1;
+       else
+               mmc_type = 0;
 }
 #endif
 
@@ -124,9 +133,9 @@ static int usb_init(void)
                fb_printf(rev_info);
 
 #ifdef CONFIG_GENERIC_MMC
-               if (mmc_type)
+               if (mmc_type == 1)
                        fb_printf("MMC: iNAND\n");
-               else
+               else if (mmc_type == 0)
                        fb_printf("MMC: MoviNAND\n");
 
                fb_printf("\n");
index 17cce31..3c24324 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -150,8 +150,8 @@ elif [ "$USER" = "dofmind" ]; then
        tar cvf system_uboot.tar u-boot.bin
        mv -f system_uboot*.tar /home/release
 elif [ "$USER" = "prom" ]; then
-       tar cvf system_uboot.tar u-boot.bin
-       mv -f system_uboot* /home/share/Work/bin
+       tar cvf boot_system_uboot.tar u-boot.bin
+       mv -f boot_system_uboot* /home/share/Work/bin
 elif [ "$USER" = "jaehoon" ]; then
        tar cvf system_uboot.tar u-boot.bin
        mv -f system_uboot* /home/jaehoon/shared/new/
index 9887c58..8ed02c2 100644 (file)
@@ -860,6 +860,22 @@ static void erase_env_area(struct usbd_ops *usbd)
 #endif
 }
 
+static inline void send_ack(struct usbd_ops *usbd, int data)
+{
+       *((ulong *) usbd->tx_data) = data;
+       usbd->send_data(usbd->tx_data, usbd->tx_len);
+}
+
+static inline int check_mmc_device(struct usbd_ops *usbd)
+{
+       if (usbd->mmc_total)
+               return 0;
+
+       printf("\nError: Couldn't find the MMC device\n");
+       send_ack(usbd, STATUS_ERROR);
+       return 1;
+}
+
 /* Parsing received data packet and Process data */
 static int process_data(struct usbd_ops *usbd)
 {
@@ -904,7 +920,7 @@ static int process_data(struct usbd_ops *usbd)
                                (uint)down_ram_addr, (int)len);
 #endif
                /* response */
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
+               send_ack(usbd, STATUS_DONE);
 
                /* Receive image by using dma */
                recvlen = usbd->recv_data();
@@ -913,11 +929,10 @@ static int process_data(struct usbd_ops *usbd)
                                        (int)recvlen, (int)len);
 
                        /* Retry this commad */
-                       *((ulong *) usbd->tx_data) = STATUS_RETRY;
+                       send_ack(usbd, STATUS_RETRY);
                } else
-                       *((ulong *) usbd->tx_data) = STATUS_DONE;
+                       send_ack(usbd, STATUS_DONE);
 
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
                return 1;
 
        /* Report partition info */
@@ -958,8 +973,7 @@ static int process_data(struct usbd_ops *usbd)
                printf("COMMAND_PARTITION_SYNC - Part%d, %d blocks\n",
                                part_id, blocks);
 
-               *((ulong *) usbd->tx_data) = blocks;
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
+               send_ack(usbd, blocks);
                return 1;
 
        case COMMAND_WRITE_PART_0:
@@ -1082,9 +1096,8 @@ static int process_data(struct usbd_ops *usbd)
                        ret = 1;
                }
 
-               *((ulong *) usbd->tx_data) = ret;
                /* Write image success -> Report status */
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
+               send_ack(usbd, ret);
 
                return !ret;
        /* Download complete -> reset */
@@ -1133,8 +1146,7 @@ static int process_data(struct usbd_ops *usbd)
 
                usbd_phone_down();
 
-               *((ulong *) usbd->tx_data) = STATUS_DONE;
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
+               send_ack(usbd, STATUS_DONE);
                return 1;
 
        case COMMAND_CHANGE_USB:
@@ -1187,8 +1199,7 @@ static int process_data(struct usbd_ops *usbd)
                                        s5p_get_cpu_rev() == 2 ? "-Fused" : "",
                                        img_rev ? "EVT1" : "EVT0",
                                        img_rev == 2 ? "-Fused" : "");
-                               *((ulong *) usbd->tx_data) = STATUS_ERROR;
-                               usbd->send_data(usbd->tx_data, usbd->tx_len);
+                               send_ack(usbd, STATUS_ERROR);
                                return 0;
                        }
                }
@@ -1202,8 +1213,7 @@ static int process_data(struct usbd_ops *usbd)
                                printf("\n!!! ERROR !!!\n"
                                        "Please download the u-boot.bin.\n"
                                        "Other images are not allowed.\n\n");
-                               *((ulong *) usbd->tx_data) = STATUS_ERROR;
-                               usbd->send_data(usbd->tx_data, usbd->tx_len);
+                               send_ack(usbd, STATUS_ERROR);
                                return 0;
                        }
                }
@@ -1325,6 +1335,8 @@ out:
 
 #ifdef CONFIG_CMD_MMC
        case IMG_MMC:
+               if (check_mmc_device(usbd))
+                       return 0;
 
                if (mmc_part_write)
                        ret = write_file_mmc_part(usbd, len);
@@ -1335,16 +1347,25 @@ out:
                break;
 #endif
        case IMG_V2:
+               if (check_mmc_device(usbd))
+                       return 0;
+
                ret = write_mmc_image(usbd, len, part_id);
                break;
 
        case IMG_MBR:
+               if (check_mmc_device(usbd))
+                       return 0;
+
 #ifdef CONFIG_CMD_MBR
                set_mbr_info(usbd, (char *)down_ram_addr, len);
 #endif
                break;
 
        case IMG_BOOTLOADER:
+               if (check_mmc_device(usbd))
+                       return 0;
+
 #ifdef CONFIG_BOOTLOADER_SECTOR
                erase_env_area(usbd);
 
@@ -1356,10 +1377,16 @@ out:
                break;
 
        case IMG_KERNEL_V2:
+               if (check_mmc_device(usbd))
+                       return 0;
+
                ret = write_fat_file(usbd, "uImage", part_id, len);
                break;
 
        case IMG_MODEM_V2:
+               if (check_mmc_device(usbd))
+                       return 0;
+
                ret = write_fat_file(usbd, "modem.bin", part_id, len);
                break;
 
@@ -1370,14 +1397,10 @@ out:
 
        if (ret) {
                /* Retry this commad */
-               *((ulong *) usbd->tx_data) = STATUS_RETRY;
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
+               send_ack(usbd, STATUS_RETRY);
                return 1;
        } else
-               *((ulong *) usbd->tx_data) = STATUS_DONE;
-
-       /* Write image success -> Report status */
-       usbd->send_data(usbd->tx_data, usbd->tx_len);
+               send_ack(usbd, STATUS_DONE);
 
        write_part++;