2 * USB Downloader for SAMSUNG Platform
4 * Copyright (C) 2007-2010 Samsung Electronics
5 * Minkyu Kang <mk7.kang@samsung.com>
15 #define PUTS(s) serial_puts (DEBUG_MARK"usb: "s)
20 static struct usbd_ops usbd_ops;
21 static unsigned long down_ram_addr;
23 int update_boot_image(void)
25 struct onenand_op *onenand_ops = onenand_get_interface();
29 /* case: IPL, Recovery, u-boot are one file */
31 len = CONFIG_RECOVERY_SIZE + CONFIG_RECOVERY_ADDR;
33 /* case: IPL, Recover are one file and u-boot is another */
34 offset = CONFIG_RECOVERY_ADDR;
35 len = CONFIG_RECOVERY_SIZE;
38 onenand_ops->erase(offset, len, 0);
40 onenand_ops->write(offset, len, NULL, (u_char *)down_ram_addr);
45 /* Parsing received data packet and Process data */
46 static int process_data(struct usbd_ops *usbd)
48 ulong cmd = 0, arg = 0, len = 0, flag = 0;
54 cmd = *((ulong *) usbd->rx_data + 0);
55 arg = *((ulong *) usbd->rx_data + 1);
56 len = *((ulong *) usbd->rx_data + 2);
57 flag = *((ulong *) usbd->rx_data + 3);
60 *((ulong *) usbd->tx_data) = 0;
63 case COMMAND_DOWNLOAD_IMAGE:
64 PUTS("COMMAND_DOWNLOAD_IMAGE\n");
65 usbd->recv_setup((char *)down_ram_addr, (int)len);
68 usbd->send_data(usbd->tx_data, usbd->tx_len);
71 recvlen = usbd->recv_data();
73 /* Retry this commad */
75 PUTS("Error: wrong image size\n");
76 *((ulong *) usbd->tx_data) = STATUS_RETRY;
79 *((ulong *) usbd->tx_data) = STATUS_DONE;
81 usbd->send_data(usbd->tx_data, usbd->tx_len);
84 case COMMAND_PARTITION_SYNC:
85 *((ulong *) usbd->tx_data) = CONFIG_RECOVERY_BOOT_BLOCKS - 1;
86 usbd->send_data(usbd->tx_data, usbd->tx_len);
89 case COMMAND_WRITE_PART_1:
90 PUTS("COMMAND_WRITE_PART_BOOT\n");
94 /* Download complete -> reset */
95 case COMMAND_RESET_PDA:
96 PUTS("Download finished and Auto reset!\n");
97 PUTS("Wait........\n");
107 case COMMAND_RESET_USB:
108 PUTS("Error is occured!(maybe previous step)->\
109 Turn off and restart!\n");
118 /* Erase and Write to NAND */
130 /* Retry this commad */
131 *((ulong *) usbd->tx_data) = STATUS_RETRY;
132 usbd->send_data(usbd->tx_data, usbd->tx_len);
135 *((ulong *) usbd->tx_data) = STATUS_DONE;
137 /* Write image success -> Report status */
138 usbd->send_data(usbd->tx_data, usbd->tx_len);
143 int do_usbd_down(void)
145 struct usbd_ops *usbd;
147 PUTS("USB Downloader\n");
148 /* interface setting */
149 usbd = usbd_set_interface(&usbd_ops);
150 down_ram_addr = usbd->ram_addr;
152 /* init the usb controller */
155 /* receive setting */
156 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
158 /* detect the download request from Host PC */
159 if (usbd->recv_data())
160 usbd->send_data(usbd->tx_data, usbd->tx_len);
164 PUTS("Receive the packet\n");
166 /* receive the data from Host PC */
168 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
170 if (usbd->recv_data()) {
171 if (process_data(usbd) == 0)