recovery: update is modified to support various image
[kernel/u-boot.git] / recovery / usbd.c
index a850718..811b788 100644 (file)
@@ -7,10 +7,14 @@
  */
 
 #include <common.h>
-#include <usbd.h>
+#include "recovery.h"
+#include "usbd.h"
 
-#define OPS_READ       0
-#define OPS_WRITE      1
+#ifdef RECOVERY_DEBUG
+#define        PUTS(s) serial_puts(DEBUG_MARK"usb: "s)
+#else
+#define PUTS(s)
+#endif
 
 static struct usbd_ops usbd_ops;
 static unsigned long down_ram_addr;
@@ -34,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 */
@@ -43,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);
@@ -57,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();
 
@@ -72,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;
@@ -83,11 +94,7 @@ static int process_data(struct usbd_ops *usbd)
        /* Erase and Write to NAND */
        switch (img_type) {
        case IMG_BOOT:
-               /* TO DO */
-               /* Erase */
-               /* Write */
-               /* offset: CONFIG_RECOVERY_ADDR */
-               /* size: CONFIG_RECOVERY_SIZE */
+               ret = board_update_image((u32 *)down_ram_addr, len);
                break;
 
        default:
@@ -113,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;
@@ -129,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);