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

change usb_read_data_from_ingenic functio to take three argument

This commit is contained in:
xiangfu 2009-05-14 09:15:11 +00:00
parent d66be487ab
commit fe484a65ee
3 changed files with 86 additions and 117 deletions

View File

@ -116,9 +116,7 @@ int init_cfg()
if (usb_ingenic_configration(&ingenic_dev, DS_hand) != 1) if (usb_ingenic_configration(&ingenic_dev, DS_hand) != 1)
return -1; return -1;
ingenic_dev.file_buff = ret; if (usb_read_data_from_ingenic(&ingenic_dev, ret, 8) != 1)
ingenic_dev.file_len = 8;
if (usb_read_data_from_ingenic(&ingenic_dev) != 1)
return -1; return -1;
return 1; return 1;
@ -201,7 +199,6 @@ int error_check(unsigned char *org,unsigned char * obj,unsigned int size)
return 0; return 0;
} }
} }
/* printf("\n Check pass"); */
return 1; return 1;
} }
@ -211,17 +208,14 @@ int nand_markbad(struct nand_in_t *nand_in)
printf("\n Device unboot! Boot it first!"); printf("\n Device unboot! Boot it first!");
return -1; return -1;
} }
/* printf("mark bad block : %d \n",nand_in->start); */ printf("\n mark bad block : %d ",nand_in->start);
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start); usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
usb_ingenic_nand_ops(&ingenic_dev, NAND_MARK_BAD); usb_ingenic_nand_ops(&ingenic_dev, NAND_MARK_BAD);
ingenic_dev.file_buff = ret; usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
ingenic_dev.file_len = 8;
usb_read_data_from_ingenic(&ingenic_dev);
printf("\n Mark bad block at %d ",((ret[3] << 24) | printf("\n Mark bad block at %d ",((ret[3] << 24) |
(ret[2] << 16) | (ret[2] << 16) |
(ret[1] << 8) | (ret[1] << 8) |
(ret[0] << 0)) / hand.nand_ppb); (ret[0] << 0)) / hand.nand_ppb);
/* Handle_Close(); */
return 0; return 0;
} }
@ -251,7 +245,6 @@ int nand_program_check(struct nand_in_t *nand_in,
ingenic_dev.file_buff = nand_in->buf; ingenic_dev.file_buff = nand_in->buf;
ingenic_dev.file_len = nand_in->length; ingenic_dev.file_len = nand_in->length;
usb_send_data_to_ingenic(&ingenic_dev); usb_send_data_to_ingenic(&ingenic_dev);
/* WriteFile(hDevice, nand_in->buf, nand_in->length , &nWritten, NULL); */
/* dump_data(nand_in->buf, 100); */ /* dump_data(nand_in->buf, 100); */
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) continue; if ((nand_in->cs_map)[i]==0) continue;
@ -271,63 +264,32 @@ int nand_program_check(struct nand_in_t *nand_in,
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start); usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
usb_send_data_length_to_ingenic(&ingenic_dev, page_num); usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
usb_ingenic_nand_ops(&ingenic_dev, temp); usb_ingenic_nand_ops(&ingenic_dev, temp);
ingenic_dev.file_buff = ret; usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
ingenic_dev.file_len = 8;
usb_read_data_from_ingenic(&ingenic_dev);
/* ReadFile(hDevice, ret, 8, &nRead, NULL); needs change */
printf(" Finish! "); printf(" Finish! ");
switch (nand_in->option)
{
case OOB_ECC:
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start); usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
/* Read back to check! */ /* Read back to check! */
usb_send_data_length_to_ingenic(&ingenic_dev, page_num); usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
switch (nand_in->option) {
case OOB_ECC:
temp = ((OOB_ECC << 12) & 0xf000) +((i << 4) & 0xff0) + NAND_READ; temp = ((OOB_ECC << 12) & 0xf000) +((i << 4) & 0xff0) + NAND_READ;
usb_ingenic_nand_ops(&ingenic_dev, temp);
printf("Checking...");
ingenic_dev.file_buff = check_buf;
ingenic_dev.file_len = page_num * (hand.nand_ps + hand.nand_os);
usb_read_data_from_ingenic(&ingenic_dev);
ingenic_dev.file_buff = ret;
ingenic_dev.file_len = 8;
usb_read_data_from_ingenic(&ingenic_dev);
/* ReadFile(hDevice, check_buf, */
/* page_num * (hand.nand_ps + hand.nand_os), &nRead, NULL); */
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need change */
break; break;
case OOB_NO_ECC: /* do not support data verify */ case OOB_NO_ECC: /* do not support data verify */
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
temp = ((OOB_NO_ECC << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ; temp = ((OOB_NO_ECC << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ;
usb_ingenic_nand_ops(&ingenic_dev, temp);
printf("Checking...");
ingenic_dev.file_buff = check_buf;
ingenic_dev.file_len = page_num * (hand.nand_ps + hand.nand_os);
usb_read_data_from_ingenic(&ingenic_dev);
ingenic_dev.file_buff = ret;
ingenic_dev.file_len = 8;
usb_read_data_from_ingenic(&ingenic_dev);
/* ReadFile(hDevice, check_buf, page_num * (hand.nand_ps + hand.nand_os), &nRead, NULL); */
/* ReadFile(hDevice, ret, 8, &nRead, NULL); needs change*/
break; break;
case NO_OOB: case NO_OOB:
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
usb_send_data_length_to_ingenic(&ingenic_dev, page_num);
temp = ((NO_OOB << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ; temp = ((NO_OOB << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ;
break;
default:
;
}
usb_ingenic_nand_ops(&ingenic_dev, temp); usb_ingenic_nand_ops(&ingenic_dev, temp);
printf("Checking..."); printf("Checking...");
ingenic_dev.file_buff = check_buf; usb_read_data_from_ingenic(&ingenic_dev, check_buf,
ingenic_dev.file_len = page_num * (hand.nand_ps + hand.nand_os); page_num * (hand.nand_ps + hand.nand_os));
usb_read_data_from_ingenic(&ingenic_dev); usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
ingenic_dev.file_buff = ret;
ingenic_dev.file_len = 8;
usb_read_data_from_ingenic(&ingenic_dev);
/* ReadFile(hDevice, check_buf, page_num * hand.nand_ps , &nRead, NULL); */
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need change*/
break;
default:;
}
#if 1
if (nand_in->start < 1 && hand.nand_ps == 4096 && hand.fw_args.cpu_id == 0x4740) { if (nand_in->start < 1 && hand.nand_ps == 4096 && hand.fw_args.cpu_id == 0x4740) {
/* (nand_out->status)[i] = 1; */ /* (nand_out->status)[i] = 1; */
printf(" no check!"); printf(" no check!");
@ -335,11 +297,14 @@ int nand_program_check(struct nand_in_t *nand_in,
printf(" End at %d ",cur_page); printf(" End at %d ",cur_page);
continue; continue;
} }
#endif
if (nand_in->check(nand_in->buf, check_buf, nand_in->length)) { if (nand_in->check(nand_in->buf, check_buf, nand_in->length)) {
/* (nand_out->status)[i] = 1; */ /* (nand_out->status)[i] = 1; */
printf(" pass!"); printf(" pass!");
cur_page = (ret[3]<<24)|(ret[2]<<16)|(ret[1]<<8)|(ret[0]<<0); cur_page = (ret[3] << 24) |
(ret[2] << 16) |
(ret[1] << 8) |
(ret[0] << 0);
printf(" End at %d ",cur_page); printf(" End at %d ",cur_page);
} else { } else {
/* (nand_out->status)[i] = 0; */ /* (nand_out->status)[i] = 0; */
@ -356,7 +321,6 @@ int nand_program_check(struct nand_in_t *nand_in,
} }
} }
/* handle_Close(); */
*start_page = cur_page; *start_page = cur_page;
return 0; return 0;
} }
@ -394,9 +358,7 @@ int nand_erase(struct nand_in_t *nand_in)
unsigned short temp = ((i << 4) & 0xff0) + NAND_ERASE; unsigned short temp = ((i << 4) & 0xff0) + NAND_ERASE;
usb_ingenic_nand_ops(&ingenic_dev, temp); usb_ingenic_nand_ops(&ingenic_dev, temp);
ingenic_dev.file_buff = ret; usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
ingenic_dev.file_len = 8;
usb_read_data_from_ingenic(&ingenic_dev);
printf(" Finish!"); printf(" Finish!");
} }
/* handle_Close(); need to change */ /* handle_Close(); need to change */
@ -425,7 +387,7 @@ int nand_program_file(struct nand_in_t *nand_in,
struct nand_in_t n_in; struct nand_in_t n_in;
struct nand_out_t n_out; struct nand_out_t n_out;
#if 0 #ifdef CONFIG_NAND_OUT
/* nand_out->status = (unsigned char *)malloc(nand_in->max_chip * sizeof(unsigned char)); */ /* nand_out->status = (unsigned char *)malloc(nand_in->max_chip * sizeof(unsigned char)); */
nand_out->status = status_buf; nand_out->status = status_buf;
for (i=0; i<nand_in->max_chip; i++) for (i=0; i<nand_in->max_chip; i++)
@ -452,7 +414,7 @@ int nand_program_file(struct nand_in_t *nand_in,
else else
n_in.length = flen / ((hand.nand_ps + hand.nand_os) * hand.nand_ppb) + 1; n_in.length = flen / ((hand.nand_ps + hand.nand_os) * hand.nand_ppb) + 1;
} }
/* printf(" length %d flen %d \n",n_in.length,flen); */ /* printf("\n length %d flen %d ", n_in.length, flen); */
n_in.cs_map = nand_in->cs_map; n_in.cs_map = nand_in->cs_map;
n_in.dev = nand_in->dev; n_in.dev = nand_in->dev;
n_in.max_chip = nand_in->max_chip; n_in.max_chip = nand_in->max_chip;
@ -469,7 +431,8 @@ int nand_program_file(struct nand_in_t *nand_in,
printf("\n Total size to send in byte is :%d", flen); printf("\n Total size to send in byte is :%d", flen);
printf("\n Image type : %s", IMAGE_TYPE[nand_in->option]); printf("\n Image type : %s", IMAGE_TYPE[nand_in->option]);
printf("\n It will cause %d times buffer transfer.", m + 1); printf("\n It will cause %d times buffer transfer.", m + 1);
#if 0
#ifdef CONFIG_NAND_OUT
for (i = 0; i < nand_in->max_chip; i++) for (i = 0; i < nand_in->max_chip; i++)
(nand_out->status)[i] = 1; /* set all status to success! */ (nand_out->status)[i] = 1; /* set all status to success! */
#endif #endif
@ -490,7 +453,8 @@ int nand_program_file(struct nand_in_t *nand_in,
if (start_page - nand_in->start > hand.nand_ppb) if (start_page - nand_in->start > hand.nand_ppb)
printf("\n Skip a old bad block !"); printf("\n Skip a old bad block !");
nand_in->start = start_page; nand_in->start = start_page;
#if 0
#ifdef CONFIG_NAND_OUT
for (i = 0; i < nand_in->max_chip; i++) { for (i = 0; i < nand_in->max_chip; i++) {
(nand_out->status)[i] = (nand_out->status)[i] * (n_out.status)[i]; (nand_out->status)[i] = (nand_out->status)[i] * (n_out.status)[i];
} }
@ -515,7 +479,8 @@ int nand_program_file(struct nand_in_t *nand_in,
if (start_page - nand_in->start > hand.nand_ppb) if (start_page - nand_in->start > hand.nand_ppb)
printf(" Skip a old bad block !"); printf(" Skip a old bad block !");
#if 0
#ifdef CONFIG_NAND_OUT
for (i=0; i < nand_in->max_chip; i++) { for (i=0; i < nand_in->max_chip; i++) {
(nand_out->status)[i] = (nand_out->status)[i] * (n_out.status)[i]; (nand_out->status)[i] = (nand_out->status)[i] * (n_out.status)[i];
} }

View File

@ -58,7 +58,9 @@ static int get_ingenic_interface(struct ingenic_dev *ingenic_dev)
struct usb_interface *usb_if; struct usb_interface *usb_if;
int config_index, if_index, alt_index; int config_index, if_index, alt_index;
for (config_index = 0; config_index < ingenic_dev->usb_dev->descriptor.bNumConfigurations; config_index++) { for (config_index = 0;
config_index < ingenic_dev->usb_dev->descriptor.bNumConfigurations;
config_index++) {
usb_config_desc = &ingenic_dev->usb_dev->config[config_index]; usb_config_desc = &ingenic_dev->usb_dev->config[config_index];
if (!usb_config_desc) if (!usb_config_desc)
@ -246,19 +248,20 @@ int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
fprintf(stderr, "Error - can't send bulk data to Ingenic CPU: %i\n", status); fprintf(stderr, "Error - can't send bulk data to Ingenic CPU: %i\n", status);
return -1; return -1;
} }
return 1; return 1;
} }
int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev) int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev, char *buff, int len)
{ {
int status; int status;
status = usb_bulk_read(ingenic_dev->usb_handle, status = usb_bulk_read(ingenic_dev->usb_handle,
/* endpoint */ INGENIC_IN_ENDPOINT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, /* endpoint */ INGENIC_IN_ENDPOINT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bulk data */ ingenic_dev->file_buff, /* bulk data */ buff,
/* bulk data length */ ingenic_dev->file_len, /* bulk data length */ len,
USB_TIMEOUT); USB_TIMEOUT);
if (status < ingenic_dev->file_len) { if (status < len) {
fprintf(stderr, "Error - can't send bulk data to Ingenic CPU: %i\n", status); fprintf(stderr, "Error - can't read bulk data from Ingenic CPU: %i\n", status);
return -1; return -1;
} }
@ -272,6 +275,7 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
unsigned int stage2_addr; unsigned int stage2_addr;
stage2_addr = total_size + 0x80000000; stage2_addr = total_size + 0x80000000;
stage2_addr -= CODE_SIZE; stage2_addr -= CODE_SIZE;
int stage_addr = (stage == 1 ? 0x80002000 : stage2_addr); int stage_addr = (stage == 1 ? 0x80002000 : stage2_addr);
usb_send_data_address_to_ingenic(ingenic_dev, stage_addr); usb_send_data_address_to_ingenic(ingenic_dev, stage_addr);
@ -294,15 +298,15 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
USB_TIMEOUT); USB_TIMEOUT);
if (status != 0) { if (status != 0) {
fprintf(stderr, "Error - can't start the uploaded binary on the Ingenic device: %i\n", status); fprintf(stderr,
goto out; "Error - can't start the uploaded binary on the Ingenic device: %i\n",
status);
return status;
} }
usb_get_ingenic_cpu(ingenic_dev); usb_get_ingenic_cpu(ingenic_dev);
status = 1;
out: return 1;
return status;
} }
void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev) void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev)

View File

@ -71,7 +71,7 @@ int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev);
int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev,
int len); int len);
int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops); int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops);
int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev); int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev, char *buff, int len);
#endif /* __INGENIC_USB_H__ */ #endif /* __INGENIC_USB_H__ */