recovery: update is modified to support various image
[kernel/u-boot.git] / recovery / usbd.c
index c26ffc2..811b788 100644 (file)
@@ -7,36 +7,17 @@
  */
 
 #include <common.h>
+#include "recovery.h"
 #include "usbd.h"
-#include "onenand.h"
 
-#define OPS_READ       0
-#define OPS_WRITE      1
-
-static struct usbd_ops usbd_ops;
-static unsigned long down_ram_addr;
-
-int update_boot_image(void)
-{
-       struct onenand_op *onenand_ops = onenand_get_interface();
-       ulong len, offset;
-
-#if 1
-       /* case: IPL, Recovery, u-boot are one file */
-       offset = 0;
-       len = CONFIG_RECOVERY_SIZE + CONFIG_RECOVERY_ADDR;
+#ifdef RECOVERY_DEBUG
+#define        PUTS(s) serial_puts(DEBUG_MARK"usb: "s)
 #else
-       /* case: IPL, Recover are one file and u-boot is another */
-       offset = CONFIG_RECOVERY_ADDR;
-       len = CONFIG_RECOVERY_SIZE;
+#define PUTS(s)
 #endif
-       /* Erase */
-       onenand_ops->erase(offset, len, 0);
-       /* Write */
-       onenand_ops->write(offset, len, NULL, (u_char *)down_ram_addr);
 
-       return 0;
-}
+static struct usbd_ops usbd_ops;
+static unsigned long down_ram_addr;
 
 /* Parsing received data packet and Process data */
 static int process_data(struct usbd_ops *usbd)
@@ -57,6 +38,7 @@ static int process_data(struct usbd_ops *usbd)
 
        switch (cmd) {
        case COMMAND_DOWNLOAD_IMAGE:
+               PUTS("COMMAND_DOWNLOAD_IMAGE\n");
                usbd->recv_setup((char *)down_ram_addr, (int)len);
 
                /* response */
@@ -66,9 +48,10 @@ static int process_data(struct usbd_ops *usbd)
                recvlen = usbd->recv_data();
 
                /* Retry this commad */
-               if (recvlen < len)
+               if (recvlen < len) {
+                       PUTS("Error: wrong image size\n");
                        *((ulong *) usbd->tx_data) = STATUS_RETRY;
-               else
+               else
                        *((ulong *) usbd->tx_data) = STATUS_DONE;
 
                usbd->send_data(usbd->tx_data, usbd->tx_len);
@@ -80,11 +63,14 @@ static int process_data(struct usbd_ops *usbd)
                return 1;
 
        case COMMAND_WRITE_PART_1:
+               PUTS("COMMAND_WRITE_PART_BOOT\n");
                img_type = IMG_BOOT;
                break;
 
        /* Download complete -> reset */
        case COMMAND_RESET_PDA:
+               PUTS("Download finished and Auto reset!\n");
+               PUTS("Wait........\n");
                /* Stop USB */
                usbd->usb_stop();
 
@@ -95,6 +81,8 @@ static int process_data(struct usbd_ops *usbd)
 
        /* Error */
        case COMMAND_RESET_USB:
+               PUTS("Error is occured!(maybe previous step)->\
+                               Turn off and restart!\n");
                /* Stop USB */
                usbd->usb_stop();
                return 0;
@@ -106,7 +94,7 @@ static int process_data(struct usbd_ops *usbd)
        /* Erase and Write to NAND */
        switch (img_type) {
        case IMG_BOOT:
-               update_boot_image();
+               ret = board_update_image((u32 *)down_ram_addr, len);
                break;
 
        default:
@@ -132,6 +120,7 @@ int do_usbd_down(void)
 {
        struct usbd_ops *usbd;
 
+       PUTS("USB Downloader\n");
        /* interface setting */
        usbd = usbd_set_interface(&usbd_ops);
        down_ram_addr = usbd->ram_addr;
@@ -148,6 +137,8 @@ int do_usbd_down(void)
        else
                return 0;
 
+       PUTS("Receive the packet\n");
+
        /* receive the data from Host PC */
        while (1) {
                usbd->recv_setup(usbd->rx_data, usbd->rx_len);