2 * USB Downloader for SAMSUNG Platform
4 * Copyright (C) 2007-2010 Samsung Electronics
5 * Minkyu Kang <mk7.kang@samsung.com>
13 static struct usbd_ops usbd_ops;
14 static unsigned long down_ram_addr;
16 int update_boot_image(void)
18 struct onenand_op *onenand_ops = onenand_get_interface();
22 /* case: IPL, Recovery, u-boot are one file */
24 len = CONFIG_RECOVERY_SIZE + CONFIG_RECOVERY_ADDR;
26 /* case: IPL, Recover are one file and u-boot is another */
27 offset = CONFIG_RECOVERY_ADDR;
28 len = CONFIG_RECOVERY_SIZE;
31 onenand_ops->erase(offset, len, 0);
33 onenand_ops->write(offset, len, NULL, (u_char *)down_ram_addr);
38 /* Parsing received data packet and Process data */
39 static int process_data(struct usbd_ops *usbd)
41 ulong cmd = 0, arg = 0, len = 0, flag = 0;
47 cmd = *((ulong *) usbd->rx_data + 0);
48 arg = *((ulong *) usbd->rx_data + 1);
49 len = *((ulong *) usbd->rx_data + 2);
50 flag = *((ulong *) usbd->rx_data + 3);
53 *((ulong *) usbd->tx_data) = 0;
56 case COMMAND_DOWNLOAD_IMAGE:
57 usbd->recv_setup((char *)down_ram_addr, (int)len);
60 usbd->send_data(usbd->tx_data, usbd->tx_len);
63 recvlen = usbd->recv_data();
65 /* Retry this commad */
67 *((ulong *) usbd->tx_data) = STATUS_RETRY;
69 *((ulong *) usbd->tx_data) = STATUS_DONE;
71 usbd->send_data(usbd->tx_data, usbd->tx_len);
74 case COMMAND_PARTITION_SYNC:
75 *((ulong *) usbd->tx_data) = CONFIG_RECOVERY_BOOT_BLOCKS - 1;
76 usbd->send_data(usbd->tx_data, usbd->tx_len);
79 case COMMAND_WRITE_PART_1:
83 /* Download complete -> reset */
84 case COMMAND_RESET_PDA:
94 case COMMAND_RESET_USB:
103 /* Erase and Write to NAND */
115 /* Retry this commad */
116 *((ulong *) usbd->tx_data) = STATUS_RETRY;
117 usbd->send_data(usbd->tx_data, usbd->tx_len);
120 *((ulong *) usbd->tx_data) = STATUS_DONE;
122 /* Write image success -> Report status */
123 usbd->send_data(usbd->tx_data, usbd->tx_len);
128 int do_usbd_down(void)
130 struct usbd_ops *usbd;
132 /* interface setting */
133 usbd = usbd_set_interface(&usbd_ops);
134 down_ram_addr = usbd->ram_addr;
136 /* init the usb controller */
139 /* receive setting */
140 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
142 /* detect the download request from Host PC */
143 if (usbd->recv_data())
144 usbd->send_data(usbd->tx_data, usbd->tx_len);
148 /* receive the data from Host PC */
150 usbd->recv_setup(usbd->rx_data, usbd->rx_len);
152 if (usbd->recv_data()) {
153 if (process_data(usbd) == 0)