2 * USB Downloader for SAMSUNG Platform
4 * Copyright (C) 2007-2010 Samsung Electronics
5 * Minkyu Kang <mk7.kang@samsung.com>
14 #define PUTS(s) serial_puts(DEBUG_MARK"usb: "s)
19 static struct usbd_ops usbd_ops;
20 static unsigned long down_ram_addr;
22 /* Parsing received data packet and Process data */
23 static int process_data(struct usbd_ops *usbd)
25 ulong cmd = 0, arg = 0, len = 0, flag = 0;
31 cmd = *((ulong *) usbd->rx_data + 0);
32 arg = *((ulong *) usbd->rx_data + 1);
33 len = *((ulong *) usbd->rx_data + 2);
34 flag = *((ulong *) usbd->rx_data + 3);
37 *((ulong *) usbd->tx_data) = 0;
40 case COMMAND_DOWNLOAD_IMAGE:
41 PUTS("COMMAND_DOWNLOAD_IMAGE\n");
42 usbd->recv_setup((char *)down_ram_addr, (int)len);
45 usbd->send_data(usbd->tx_data, usbd->tx_len);
48 recvlen = usbd->recv_data();
50 /* Retry this commad */
52 PUTS("Error: wrong image size\n");
53 *((ulong *) usbd->tx_data) = STATUS_RETRY;
55 *((ulong *) usbd->tx_data) = STATUS_DONE;
57 usbd->send_data(usbd->tx_data, usbd->tx_len);
60 case COMMAND_PARTITION_SYNC:
61 *((ulong *) usbd->tx_data) = CONFIG_RECOVERY_BOOT_BLOCKS - 1;
62 usbd->send_data(usbd->tx_data, usbd->tx_len);
65 case COMMAND_WRITE_PART_1:
66 PUTS("COMMAND_WRITE_PART_BOOT\n");
70 /* Download complete -> reset */
71 case COMMAND_RESET_PDA:
72 PUTS("Download finished and Auto reset!\n");
73 PUTS("Wait........\n");
83 case COMMAND_RESET_USB:
84 PUTS("Error is occured!(maybe previous step)->\
85 Turn off and restart!\n");
94 /* Erase and Write to NAND */
97 ret = board_update_image((u32 *)down_ram_addr, len);
106 /* Retry this commad */
107 *((ulong *) usbd->tx_data) = STATUS_RETRY;
108 usbd->send_data(usbd->tx_data, usbd->tx_len);
111 *((ulong *) usbd->tx_data) = STATUS_DONE;
113 /* Write image success -> Report status */
114 usbd->send_data(usbd->tx_data, usbd->tx_len);
119 int do_usbd_down(void)
121 struct usbd_ops *usbd;
123 PUTS("USB Downloader\n");
124 /* interface setting */
125 usbd = usbd_set_interface(&usbd_ops);
126 down_ram_addr = usbd->ram_addr;
128 /* init the usb controller */
131 /* receive setting */
132 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
134 /* detect the download request from Host PC */
135 if (usbd->recv_data())
136 usbd->send_data(usbd->tx_data, usbd->tx_len);
140 PUTS("Receive the packet\n");
142 /* receive the data from Host PC */
144 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
146 if (usbd->recv_data()) {
147 if (process_data(usbd) == 0)