#endif
}
+static inline void send_ack(struct usbd_ops *usbd, int data)
+{
+ *((ulong *) usbd->tx_data) = data;
+ usbd->send_data(usbd->tx_data, usbd->tx_len);
+}
+
+static inline int check_mmc_device(struct usbd_ops *usbd)
+{
+ if (usbd->mmc_total)
+ return 0;
+
+ printf("\nError: Couldn't find the MMC device\n");
+ send_ack(usbd, STATUS_ERROR);
+ return 1;
+}
+
/* Parsing received data packet and Process data */
static int process_data(struct usbd_ops *usbd)
{
(uint)down_ram_addr, (int)len);
#endif
/* response */
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, STATUS_DONE);
/* Receive image by using dma */
recvlen = usbd->recv_data();
(int)recvlen, (int)len);
/* Retry this commad */
- *((ulong *) usbd->tx_data) = STATUS_RETRY;
+ send_ack(usbd, STATUS_RETRY);
} else
- *((ulong *) usbd->tx_data) = STATUS_DONE;
+ send_ack(usbd, STATUS_DONE);
- usbd->send_data(usbd->tx_data, usbd->tx_len);
return 1;
/* Report partition info */
printf("COMMAND_PARTITION_SYNC - Part%d, %d blocks\n",
part_id, blocks);
- *((ulong *) usbd->tx_data) = blocks;
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, blocks);
return 1;
case COMMAND_WRITE_PART_0:
ret = 1;
}
- *((ulong *) usbd->tx_data) = ret;
/* Write image success -> Report status */
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, ret);
return !ret;
/* Download complete -> reset */
usbd_phone_down();
- *((ulong *) usbd->tx_data) = STATUS_DONE;
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, STATUS_DONE);
return 1;
case COMMAND_CHANGE_USB:
s5p_get_cpu_rev() == 2 ? "-Fused" : "",
img_rev ? "EVT1" : "EVT0",
img_rev == 2 ? "-Fused" : "");
- *((ulong *) usbd->tx_data) = STATUS_ERROR;
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, STATUS_ERROR);
return 0;
}
}
printf("\n!!! ERROR !!!\n"
"Please download the u-boot.bin.\n"
"Other images are not allowed.\n\n");
- *((ulong *) usbd->tx_data) = STATUS_ERROR;
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, STATUS_ERROR);
return 0;
}
}
#ifdef CONFIG_CMD_MMC
case IMG_MMC:
+ if (check_mmc_device(usbd))
+ return 0;
if (mmc_part_write)
ret = write_file_mmc_part(usbd, len);
break;
#endif
case IMG_V2:
+ if (check_mmc_device(usbd))
+ return 0;
+
ret = write_mmc_image(usbd, len, part_id);
break;
case IMG_MBR:
+ if (check_mmc_device(usbd))
+ return 0;
+
#ifdef CONFIG_CMD_MBR
set_mbr_info(usbd, (char *)down_ram_addr, len);
#endif
break;
case IMG_BOOTLOADER:
+ if (check_mmc_device(usbd))
+ return 0;
+
#ifdef CONFIG_BOOTLOADER_SECTOR
erase_env_area(usbd);
break;
case IMG_KERNEL_V2:
+ if (check_mmc_device(usbd))
+ return 0;
+
ret = write_fat_file(usbd, "uImage", part_id, len);
break;
case IMG_MODEM_V2:
+ if (check_mmc_device(usbd))
+ return 0;
+
ret = write_fat_file(usbd, "modem.bin", part_id, len);
break;
if (ret) {
/* Retry this commad */
- *((ulong *) usbd->tx_data) = STATUS_RETRY;
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, STATUS_RETRY);
return 1;
} else
- *((ulong *) usbd->tx_data) = STATUS_DONE;
-
- /* Write image success -> Report status */
- usbd->send_data(usbd->tx_data, usbd->tx_len);
+ send_ack(usbd, STATUS_DONE);
write_part++;