2 * USB Downloader for SAMSUNG Platform
4 * Copyright (C) 2007-2010 Samsung Electronics
5 * Minkyu Kang <mk7.kang@samsung.com>
16 static struct usbd_ops usbd_ops;
17 static unsigned long down_ram_addr;
19 int update_boot_image(void)
21 struct onenand_op *onenand_ops = onenand_get_interface();
25 /* case: IPL, Recovery, u-boot are one file */
27 len = CONFIG_RECOVERY_SIZE + CONFIG_RECOVERY_ADDR;
29 /* case: IPL, Recover are one file and u-boot is another */
30 offset = CONFIG_RECOVERY_ADDR;
31 len = CONFIG_RECOVERY_SIZE;
34 onenand_ops->erase(offset, len, 0);
36 onenand_ops->write(offset, len, NULL, (u_char *)down_ram_addr);
41 /* Parsing received data packet and Process data */
42 static int process_data(struct usbd_ops *usbd)
44 ulong cmd = 0, arg = 0, len = 0, flag = 0;
50 cmd = *((ulong *) usbd->rx_data + 0);
51 arg = *((ulong *) usbd->rx_data + 1);
52 len = *((ulong *) usbd->rx_data + 2);
53 flag = *((ulong *) usbd->rx_data + 3);
56 *((ulong *) usbd->tx_data) = 0;
59 case COMMAND_DOWNLOAD_IMAGE:
60 usbd->recv_setup((char *)down_ram_addr, (int)len);
63 usbd->send_data(usbd->tx_data, usbd->tx_len);
66 recvlen = usbd->recv_data();
68 /* Retry this commad */
70 *((ulong *) usbd->tx_data) = STATUS_RETRY;
72 *((ulong *) usbd->tx_data) = STATUS_DONE;
74 usbd->send_data(usbd->tx_data, usbd->tx_len);
77 case COMMAND_PARTITION_SYNC:
78 *((ulong *) usbd->tx_data) = CONFIG_RECOVERY_BOOT_BLOCKS - 1;
79 usbd->send_data(usbd->tx_data, usbd->tx_len);
82 case COMMAND_WRITE_PART_1:
86 /* Download complete -> reset */
87 case COMMAND_RESET_PDA:
97 case COMMAND_RESET_USB:
106 /* Erase and Write to NAND */
118 /* Retry this commad */
119 *((ulong *) usbd->tx_data) = STATUS_RETRY;
120 usbd->send_data(usbd->tx_data, usbd->tx_len);
123 *((ulong *) usbd->tx_data) = STATUS_DONE;
125 /* Write image success -> Report status */
126 usbd->send_data(usbd->tx_data, usbd->tx_len);
131 int do_usbd_down(void)
133 struct usbd_ops *usbd;
135 /* interface setting */
136 usbd = usbd_set_interface(&usbd_ops);
137 down_ram_addr = usbd->ram_addr;
139 /* init the usb controller */
142 /* receive setting */
143 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
145 /* detect the download request from Host PC */
146 if (usbd->recv_data())
147 usbd->send_data(usbd->tx_data, usbd->tx_len);
151 /* receive the data from Host PC */
153 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
155 if (usbd->recv_data()) {
156 if (process_data(usbd) == 0)