1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-01 20:31:52 +02:00

add usb_send_data_address_to_ingenic,

usb_send_data_to_ingenic function.
This commit is contained in:
xiangfu 2009-05-01 16:14:55 +00:00
parent b22c1f680e
commit acc365174f
3 changed files with 57 additions and 38 deletions

View File

@ -163,7 +163,6 @@ cleanup:
if (ingenic_dev.file_buff) if (ingenic_dev.file_buff)
free(ingenic_dev.file_buff); free(ingenic_dev.file_buff);
out: out:
usb_ingenic_cleanup(&ingenic_dev);
return res; return res;
} }
@ -177,7 +176,6 @@ int nand_program_check(struct nand_in_t *nand_in,
int nand_erase(struct nand_in_t *nand_in) int nand_erase(struct nand_in_t *nand_in)
{ {
#if 0
unsigned int start_blk, blk_num, end_block; unsigned int start_blk, blk_num, end_block;
int i; int i;
@ -197,28 +195,29 @@ int nand_erase(struct nand_in_t *nand_in)
return -1; return -1;
} }
#if 0
for (i = 0; i < nand_in->max_chip; i++) { for (i = 0; i < nand_in->max_chip; i++) {
if ((nand_in->cs_map)[i]==0) if ((nand_in->cs_map)[i]==0)
continue; continue;
printf("\n Erasing No.%d device No.%d flash......", printf("\n Erasing No.%d device No.%d flash......",
nand_in->dev, i); nand_in->dev, i);
JZ4740_USB_SET_DATA_ADDRESS(start_blk,hDevice); JZ4740_USB_SET_DATA_ADDRESS(start_blk, hDevice);
JZ4740_USB_SET_DATA_LENGTH(blk_num,hDevice); JZ4740_USB_SET_DATA_LENGTH(blk_num, hDevice);
unsigned short temp = ((i<<4) & 0xff0) + NAND_ERASE; unsigned short temp = ((i<<4) & 0xff0) + NAND_ERASE;
JZ4740_USB_NAND_OPS(temp,hDevice); JZ4740_USB_NAND_OPS(temp,hDevice);
ReadFile(hDevice, ret, 8, &nRead, NULL); ReadFile(hDevice, ret, 8, &nRead, NULL);
printf(" Finish!"); printf(" Finish!");
} }
Handle_Close(); Handle_Close();
end_block = ((ret[3]<<24)|(ret[2]<<16)|(ret[1]<<8)|(ret[0]<<0)) / Hand.nand_ppb; end_block = ((ret[3] << 24) |
(ret[2] << 16) |
(ret[1] << 8) |
(ret[0] << 0)) / Hand.nand_ppb;
printf("\n Operation end position : %d ",end_block); printf("\n Operation end position : %d ",end_block);
if ( !Hand.nand_force_erase ) //not force erase ,show bad block infomation if (!hand.nand_force_erase) { /* not force erase, show bad block infomation */
{
printf("\n There are marked bad blocks :%d ",end_block - start_blk - blk_num ); printf("\n There are marked bad blocks :%d ",end_block - start_blk - blk_num );
} } else { /* force erase, no bad block infomation can show */
else //force erase ,no bad block infomation can show
{
printf("\n Force erase ,no bad block infomation !" ); printf("\n Force erase ,no bad block infomation !" );
} }
#endif #endif

View File

@ -141,6 +141,9 @@ int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev)
{ {
int status; int status;
memset(&ingenic_dev->cpu_info_buff, 0,
ARRAY_SIZE(ingenic_dev->cpu_info_buff));
status = usb_control_msg(ingenic_dev->usb_handle, status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, /* bmRequestType */ USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_GET_CPU_INFO, /* bRequest */ VR_GET_CPU_INFO,
@ -192,31 +195,9 @@ int usb_ingenic_flush_cache(struct ingenic_dev *ingenic_dev)
return 1; return 1;
} }
int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage) int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev)
{ {
int status; int status;
unsigned int stage2_addr;
stage2_addr = total_size + 0x80000000;
stage2_addr -= CODE_SIZE;
int stage_addr = (stage == 1 ? 0x80002000 : stage2_addr);
/* tell the device the RAM address to store the file */
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_SET_DATA_ADDRESS,
/* wValue */ STAGE_ADDR_MSB(stage_addr),
/* wIndex */ STAGE_ADDR_LSB(stage_addr),
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - can't set the address on Ingenic device: %i\n", status);
goto out;
}
#if 0
/* tell the device the length of the file to be uploaded */ /* tell the device the length of the file to be uploaded */
status = usb_control_msg(ingenic_dev->usb_handle, status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
@ -229,20 +210,58 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
if (status != 0) if (status != 0)
fprintf(stderr, "Error - can't set data length on Ingenic device: %i\n", status); fprintf(stderr, "Error - can't set data length on Ingenic device: %i\n", status);
#endif
printf("\n Download stage %d program and execute at 0x%08x ", stage, (stage_addr)); return status;
/* upload the file */ }
int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, unsigned int stage_addr)
{
int status;
/* tell the device the RAM address to store the file */
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_SET_DATA_ADDRESS,
/* wValue */ STAGE_ADDR_MSB(stage_addr),
/* wIndex */ STAGE_ADDR_LSB(stage_addr),
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - can't set the address on Ingenic device: %i\n", status);
return -1;
}
return status;
}
int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
{
int status;
status = usb_bulk_write(ingenic_dev->usb_handle, status = usb_bulk_write(ingenic_dev->usb_handle,
/* endpoint */ INGENIC_OUT_ENDPOINT, /* endpoint */ INGENIC_OUT_ENDPOINT,
/* bulk data */ ingenic_dev->file_buff, /* bulk data */ ingenic_dev->file_buff,
/* bulk data length */ ingenic_dev->file_len, /* bulk data length */ ingenic_dev->file_len,
USB_TIMEOUT); USB_TIMEOUT);
if (status < ingenic_dev->file_len) { if (status < ingenic_dev->file_len) {
fprintf(stderr, "Error - can't send bulk data to Ingenic CPU: %i\nfile length: %d\n", status, ingenic_dev->file_len); fprintf(stderr, "Error - can't send bulk data to Ingenic CPU: %i\n", status);
return -1; return -1;
} }
return 1;
}
int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
{
int status;
unsigned int stage2_addr;
stage2_addr = total_size + 0x80000000;
stage2_addr -= CODE_SIZE;
int stage_addr = (stage == 1 ? 0x80002000 : stage2_addr);
usb_send_data_address_to_ingenic(ingenic_dev, stage_addr);
printf("\n Download stage %d program and execute at 0x%08x ", stage, (stage_addr));
usb_send_data_to_ingenic(ingenic_dev);
if (stage == 2) { if (stage == 2) {
sleep(1); sleep(1);

View File

@ -102,6 +102,7 @@ int main(int argc, char **argv)
command_handle(com_buf); command_handle(com_buf);
} }
usb_ingenic_cleanup(&ingenic_dev);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }