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

add error_check function.

add usb_ingenic_configration
This commit is contained in:
xiangfu 2009-05-12 14:41:52 +00:00
parent 72dd61a7c7
commit d66be487ab
2 changed files with 86 additions and 41 deletions

View File

@ -106,9 +106,25 @@ out:
return res; return res;
} }
int boot(char *stage1_path, char *stage2_path){ int init_cfg()
{
ingenic_dev.file_buff = &hand;
ingenic_dev.file_len = sizeof(struct hand_t);
if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
return -1;
int res = 0; if (usb_ingenic_configration(&ingenic_dev, DS_hand) != 1)
return -1;
ingenic_dev.file_buff = ret;
ingenic_dev.file_len = 8;
if (usb_read_data_from_ingenic(&ingenic_dev) != 1)
return -1;
return 1;
}
int boot(char *stage1_path, char *stage2_path){
int status; int status;
status = usb_get_ingenic_cpu(&ingenic_dev); status = usb_get_ingenic_cpu(&ingenic_dev);
@ -130,12 +146,12 @@ int boot(char *stage1_path, char *stage2_path){
hand.fw_args.cpu_id = 0x4750; hand.fw_args.cpu_id = 0x4750;
break; break;
default: default:
goto out; return 1;
} }
if (status) { if (status) {
printf("Booted"); printf("Booted");
goto out; return 1;
} else { } else {
printf("Unboot"); printf("Unboot");
printf("\n Now booting device"); printf("\n Now booting device");
@ -143,37 +159,54 @@ int boot(char *stage1_path, char *stage2_path){
/* now we upload the usb boot stage1 */ /* now we upload the usb boot stage1 */
printf("\n Upload usb boot stage1"); printf("\n Upload usb boot stage1");
if (load_file(&ingenic_dev, stage1_path) < 1) if (load_file(&ingenic_dev, stage1_path) < 1)
goto out; return -1;
if (usb_ingenic_upload(&ingenic_dev, 1) < 1) if (usb_ingenic_upload(&ingenic_dev, 1) < 1) {
goto cleanup; if (ingenic_dev.file_buff)
free(ingenic_dev.file_buff);
return -1;
}
/* now we upload the usb boot stage2 */ /* now we upload the usb boot stage2 */
sleep(1); sleep(1);
printf("\n Upload usb boot stage2"); printf("\n Upload usb boot stage2");
if (load_file(&ingenic_dev, stage2_path) < 1) if (load_file(&ingenic_dev, stage2_path) < 1) {
goto cleanup;
if (usb_ingenic_upload(&ingenic_dev, 2) < 1)
goto cleanup;
}
res = 1;
cleanup:
if (ingenic_dev.file_buff) if (ingenic_dev.file_buff)
free(ingenic_dev.file_buff); free(ingenic_dev.file_buff);
out: return -1;
return res; }
if (usb_ingenic_upload(&ingenic_dev, 2) < 1) {
if (ingenic_dev.file_buff)
free(ingenic_dev.file_buff);
return -1;
}
}
sleep(1);
printf("\n Now configure Ingenic device");
(init_cfg() == 1) ?
printf("\n Configure success!"):
printf("\n Configure fail!");
return 1;
} }
/* nand function */ /* nand function */
int error_check(unsigned char *org,unsigned char * obj,unsigned int size)
{
unsigned int i;
for (i = 0; i < size; i++) {
if (org[i] != obj[i]) {
printf("\n Check Error! %d=%x:%x ", i, org[i], obj[i]);
return 0;
}
}
/* printf("\n Check pass"); */
return 1;
}
int nand_markbad(struct nand_in_t *nand_in) int nand_markbad(struct nand_in_t *nand_in)
{ {
/* if (Handle_Open(nand_in->dev)==-1) { */
/* printf("\n Can not connect device!"); */
/* return -1; */
/* } */
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) { if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf("\n Device unboot! Boot it first!"); printf("\n Device unboot! Boot it first!");
return -1; return -1;
@ -206,9 +239,7 @@ int nand_program_check(struct nand_in_t *nand_in,
} }
#if 0 #if 0
/* 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++)
(nand_out->status)[i] = 0; /* set all status to fail */ (nand_out->status)[i] = 0; /* set all status to fail */
#endif #endif
@ -222,10 +253,6 @@ int nand_program_check(struct nand_in_t *nand_in,
usb_send_data_to_ingenic(&ingenic_dev); usb_send_data_to_ingenic(&ingenic_dev);
/* WriteFile(hDevice, nand_in->buf, nand_in->length , &nWritten, NULL); */ /* WriteFile(hDevice, nand_in->buf, nand_in->length , &nWritten, NULL); */
/* dump_data(nand_in->buf, 100); */ /* dump_data(nand_in->buf, 100); */
/* WriteFile(hDevice, nand_in->buf, nand_in->length * hand.nand_ps, &nWritten, NULL); */
/* Send data to be program */
/* Only send once! */
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;
/* page_num = nand_in->length / hand.nand_ps +1; */ /* page_num = nand_in->length / hand.nand_ps +1; */
@ -367,11 +394,6 @@ 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);
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
printf("\n---debug----------------");
return -1;
}
ingenic_dev.file_buff = ret; ingenic_dev.file_buff = ret;
ingenic_dev.file_len = 8; ingenic_dev.file_len = 8;
usb_read_data_from_ingenic(&ingenic_dev); usb_read_data_from_ingenic(&ingenic_dev);
@ -518,7 +540,7 @@ int nprog(void)
"\n \t-o:\twith oob no ecc" "\n \t-o:\twith oob no ecc"
"\n \t-e:\twith oob and ecc"; "\n \t-e:\twith oob and ecc";
nand_in.buf = code_buf; nand_in.buf = code_buf;
nand_in.check = NULL; nand_in.check = error_check;
nand_in.dev = 0; nand_in.dev = 0;
nand_in.cs_map = cs; nand_in.cs_map = cs;
nand_in.max_chip =16; nand_in.max_chip =16;

View File

@ -205,10 +205,12 @@ int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, int len)
/* wLength */ 0, /* wLength */ 0,
USB_TIMEOUT); USB_TIMEOUT);
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);
return -1;
}
return status; return 1;
} }
int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, unsigned int stage_addr) int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, unsigned int stage_addr)
@ -229,7 +231,7 @@ int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, unsigned i
return -1; return -1;
} }
return status; return 1;
} }
int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev) int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
@ -259,6 +261,7 @@ int usb_read_data_from_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;
} }
@ -328,5 +331,25 @@ int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops)
return -1; return -1;
} }
return status; return 1;
}
int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops)
{
int status;
status = usb_control_msg(ingenic_dev->usb_handle,
/* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
/* bRequest */ VR_CONFIGRATION,
/* wValue */ ops,
/* wIndex */ 0,
/* Data */ 0,
/* wLength */ 0,
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr, "Error - can't init Ingenic configration: %i\n", status);
return -1;
}
return 1;
} }