mirror of
git://projects.qi-hardware.com/xburst-tools.git
synced 2024-11-01 16:25:20 +02:00
add nand_read function
This commit is contained in:
parent
7513e53951
commit
f7998e35b8
@ -168,6 +168,30 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* nand function */
|
/* nand function */
|
||||||
|
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) {
|
||||||
|
printf("\n Device unboot! Boot it first!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* printf("mark bad block : %d \n",nand_in->start); */
|
||||||
|
usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start);
|
||||||
|
usb_ingenic_nand_ops(&ingenic_dev, NAND_MARK_BAD);
|
||||||
|
ingenic_dev.file_buff = ret;
|
||||||
|
ingenic_dev.file_len = 8;
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev);
|
||||||
|
printf("\n Mark bad block at %d ",((ret[3] << 24) |
|
||||||
|
(ret[2] << 16) |
|
||||||
|
(ret[1] << 8) |
|
||||||
|
(ret[0] << 0)) / hand.nand_ppb);
|
||||||
|
/* Handle_Close(); */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int nand_program_check(struct nand_in_t *nand_in,
|
int nand_program_check(struct nand_in_t *nand_in,
|
||||||
struct nand_out_t *nand_out)
|
struct nand_out_t *nand_out)
|
||||||
{
|
{
|
||||||
@ -197,8 +221,12 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
printf("\n Device unboot! Boot it first!");
|
printf("\n Device unboot! Boot it first!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
ingenic_dev.file_buff = nand_in->buf;
|
||||||
|
ingenic_dev.file_len = nand_in->length;
|
||||||
|
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); */
|
/* WriteFile(hDevice, nand_in->buf, nand_in->length * hand.nand_ps, &nWritten, NULL); */
|
||||||
/* Send data to be program */
|
/* Send data to be program */
|
||||||
/* Only send once! */
|
/* Only send once! */
|
||||||
@ -220,6 +248,9 @@ 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;
|
||||||
|
ingenic_dev.file_len = 8;
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev);
|
||||||
/* ReadFile(hDevice, ret, 8, &nRead, NULL); needs change */
|
/* ReadFile(hDevice, ret, 8, &nRead, NULL); needs change */
|
||||||
printf(" Finish! ");
|
printf(" Finish! ");
|
||||||
switch (nand_in->option)
|
switch (nand_in->option)
|
||||||
@ -231,6 +262,12 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
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);
|
usb_ingenic_nand_ops(&ingenic_dev, temp);
|
||||||
printf("Checking...");
|
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, */
|
/* ReadFile(hDevice, check_buf, */
|
||||||
/* page_num * (hand.nand_ps + hand.nand_os), &nRead, NULL); */
|
/* page_num * (hand.nand_ps + hand.nand_os), &nRead, NULL); */
|
||||||
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need change */
|
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need change */
|
||||||
@ -238,26 +275,37 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
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_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);
|
||||||
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);
|
usb_ingenic_nand_ops(&ingenic_dev, temp);
|
||||||
printf("Checking...");
|
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, check_buf, page_num * (hand.nand_ps + hand.nand_os), &nRead, NULL); */
|
||||||
/* ReadFile(hDevice, ret, 8, &nRead, NULL); needs change*/
|
/* 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_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);
|
||||||
temp = ((NO_OOB<<12) & 0xf000) +((i<<4) & 0xff0) + NAND_READ;
|
temp = ((NO_OOB << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ;
|
||||||
usb_ingenic_nand_ops(&ingenic_dev, temp);
|
usb_ingenic_nand_ops(&ingenic_dev, temp);
|
||||||
printf("Checking...");
|
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 , &nRead, NULL); */
|
/* ReadFile(hDevice, check_buf, page_num * hand.nand_ps , &nRead, NULL); */
|
||||||
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need change*/
|
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need change*/
|
||||||
break;
|
break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
#if 1
|
#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!");
|
||||||
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);
|
||||||
@ -265,15 +313,12 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#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; */
|
||||||
printf(" fail!");
|
printf(" fail!");
|
||||||
struct nand_in_t bad;
|
struct nand_in_t bad;
|
||||||
@ -284,7 +329,7 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
printf(" End at %d ",cur_page);
|
printf(" End at %d ",cur_page);
|
||||||
bad.start = (cur_page - 1) / hand.nand_ppb;
|
bad.start = (cur_page - 1) / hand.nand_ppb;
|
||||||
if (cur_page % hand.nand_ppb==0)
|
if (cur_page % hand.nand_ppb==0)
|
||||||
;/* API_Nand_Markbad(&bad);need change */
|
nand_markbad(&bad);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -324,6 +369,9 @@ int nand_erase(struct nand_in_t *nand_in)
|
|||||||
usb_send_data_to_ingenic(&ingenic_dev);
|
usb_send_data_to_ingenic(&ingenic_dev);
|
||||||
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;
|
||||||
|
ingenic_dev.file_len = 8;
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev);
|
||||||
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need to change*/
|
/* ReadFile(hDevice, ret, 8, &nRead, NULL); need to change*/
|
||||||
printf(" Finish!");
|
printf(" Finish!");
|
||||||
}
|
}
|
||||||
@ -394,9 +442,9 @@ int nand_program_file(struct nand_in_t *nand_in,
|
|||||||
j = flen % transfer_size;
|
j = flen % transfer_size;
|
||||||
fseek(fp,0,SEEK_SET); /* file point return to begin */
|
fseek(fp,0,SEEK_SET); /* file point return to begin */
|
||||||
offset = 0;
|
offset = 0;
|
||||||
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
|
#if 0
|
||||||
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! */
|
||||||
@ -473,6 +521,7 @@ int nprog(void)
|
|||||||
printf("%s", help);
|
printf("%s", help);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < MAX_DEV_NUM; i++)
|
for (i = 0; i < MAX_DEV_NUM; i++)
|
||||||
(nand_in.cs_map)[i] = 0;
|
(nand_in.cs_map)[i] = 0;
|
||||||
|
|
||||||
|
@ -116,10 +116,10 @@ int usb_ingenic_init(struct ingenic_dev *ingenic_dev)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usb_set_configuration(ingenic_dev->usb_handle, 1) < 0) {
|
/* if (usb_set_configuration(ingenic_dev->usb_handle, 1) < 0) { */
|
||||||
fprintf(stderr, "Error - can't set Ingenic configuration: %s\n", usb_strerror());
|
/* fprintf(stderr, "Error - can't set Ingenic configuration: %s\n", usb_strerror()); */
|
||||||
goto out;
|
/* goto out; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if (get_ingenic_interface(ingenic_dev) < 1) {
|
if (get_ingenic_interface(ingenic_dev) < 1) {
|
||||||
fprintf(stderr, "Error - can't find Ingenic interface\n");
|
fprintf(stderr, "Error - can't find Ingenic interface\n");
|
||||||
@ -250,6 +250,21 @@ int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
status = usb_bulk_read(ingenic_dev->usb_handle,
|
||||||
|
/* endpoint */ INGENIC_IN_ENDPOINT,
|
||||||
|
/* bulk data */ ingenic_dev->file_buff,
|
||||||
|
/* bulk data length */ ingenic_dev->file_len,
|
||||||
|
USB_TIMEOUT);
|
||||||
|
if (status < ingenic_dev->file_len) {
|
||||||
|
fprintf(stderr, "Error - can't send bulk data to Ingenic CPU: %i\n", status);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
|
int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define INGENIC_OUT_ENDPOINT 0x01
|
#define INGENIC_OUT_ENDPOINT 0x01
|
||||||
|
#define INGENIC_IN_ENDPOINT 0x81
|
||||||
|
|
||||||
#define VR_GET_CPU_INFO 0x00
|
#define VR_GET_CPU_INFO 0x00
|
||||||
#define VR_SET_DATA_ADDRESS 0x01
|
#define VR_SET_DATA_ADDRESS 0x01
|
||||||
@ -57,7 +58,7 @@ struct ingenic_dev {
|
|||||||
uint8_t interface;
|
uint8_t interface;
|
||||||
char cpu_info_buff[9];
|
char cpu_info_buff[9];
|
||||||
char *file_buff;
|
char *file_buff;
|
||||||
int file_len;
|
unsigned int file_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
int usb_ingenic_init(struct ingenic_dev *ingenic_dev);
|
int usb_ingenic_init(struct ingenic_dev *ingenic_dev);
|
||||||
@ -70,6 +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);
|
||||||
|
|
||||||
#endif /* __INGENIC_USB_H__ */
|
#endif /* __INGENIC_USB_H__ */
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (usb_ingenic_init(&ingenic_dev) < 1)
|
if (usb_ingenic_init(&ingenic_dev) < 1)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (parse_configure(&hand, CONFIG_FILE_PATH) < 1)
|
if (parse_configure(&hand, CONFIG_FILE_PATH) < 1)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
Loading…
Reference in New Issue
Block a user