2 * USB Downloader for SAMSUNG Platform
4 * Copyright (C) 2007-2010 Samsung Electronics
5 * Minkyu Kang <mk7.kang@samsung.com>
15 static struct usbd_ops usbd_ops;
16 static unsigned long down_ram_addr;
18 /* Parsing received data packet and Process data */
19 static int process_data(struct usbd_ops *usbd)
21 ulong cmd = 0, arg = 0, len = 0, flag = 0;
27 cmd = *((ulong *) usbd->rx_data + 0);
28 arg = *((ulong *) usbd->rx_data + 1);
29 len = *((ulong *) usbd->rx_data + 2);
30 flag = *((ulong *) usbd->rx_data + 3);
33 *((ulong *) usbd->tx_data) = 0;
36 case COMMAND_DOWNLOAD_IMAGE:
37 usbd->recv_setup((char *)down_ram_addr, (int)len);
40 usbd->send_data(usbd->tx_data, usbd->tx_len);
43 recvlen = usbd->recv_data();
45 /* Retry this commad */
47 *((ulong *) usbd->tx_data) = STATUS_RETRY;
49 *((ulong *) usbd->tx_data) = STATUS_DONE;
51 usbd->send_data(usbd->tx_data, usbd->tx_len);
54 case COMMAND_PARTITION_SYNC:
55 *((ulong *) usbd->tx_data) = CONFIG_RECOVERY_BOOT_BLOCKS - 1;
56 usbd->send_data(usbd->tx_data, usbd->tx_len);
59 case COMMAND_WRITE_PART_1:
63 /* Download complete -> reset */
64 case COMMAND_RESET_PDA:
74 case COMMAND_RESET_USB:
83 /* Erase and Write to NAND */
89 /* offset: CONFIG_RECOVERY_ADDR */
90 /* size: CONFIG_RECOVERY_SIZE */
99 /* Retry this commad */
100 *((ulong *) usbd->tx_data) = STATUS_RETRY;
101 usbd->send_data(usbd->tx_data, usbd->tx_len);
104 *((ulong *) usbd->tx_data) = STATUS_DONE;
106 /* Write image success -> Report status */
107 usbd->send_data(usbd->tx_data, usbd->tx_len);
112 int do_usbd_down(void)
114 struct usbd_ops *usbd;
116 /* interface setting */
117 usbd = usbd_set_interface(&usbd_ops);
118 down_ram_addr = usbd->ram_addr;
120 /* init the usb controller */
123 /* receive setting */
124 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
126 /* detect the download request from Host PC */
127 if (usbd->recv_data())
128 usbd->send_data(usbd->tx_data, usbd->tx_len);
132 /* receive the data from Host PC */
134 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
136 if (usbd->recv_data()) {
137 if (process_data(usbd) == 0)