mirror of
git://projects.qi-hardware.com/xburst-tools.git
synced 2024-11-01 18:22:28 +02:00
now the reflash function is work :-)
This commit is contained in:
parent
fe484a65ee
commit
b5a4d70021
194
flash-tool/cmd.c
194
flash-tool/cmd.c
@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
* (C) Copyright 2009
|
* (C) Copyright 2009
|
||||||
* Author: Marek Lindner <lindner_marek@yahoo.de>
|
* Author: Marek Lindner <lindner_marek@yahoo.de>
|
||||||
|
* Author: Xiangfu Liu <xiangfu.z@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@ -75,7 +76,8 @@ static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path)
|
|||||||
ingenic_dev->file_buff = malloc(ingenic_dev->file_len);
|
ingenic_dev->file_buff = malloc(ingenic_dev->file_len);
|
||||||
|
|
||||||
if (!ingenic_dev->file_buff) {
|
if (!ingenic_dev->file_buff) {
|
||||||
fprintf(stderr, "Error - can't allocate memory to read file '%s': %s\n",
|
fprintf(stderr, "Error - "
|
||||||
|
"can't allocate memory to read file '%s': %s\n",
|
||||||
file_path, strerror(errno));
|
file_path, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -96,7 +98,9 @@ static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path)
|
|||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(ingenic_dev->file_buff + 8, &hand.fw_args, sizeof(struct fw_args_t));
|
/* write args to code */
|
||||||
|
memcpy(ingenic_dev->file_buff + 8, &hand.fw_args,
|
||||||
|
sizeof(struct fw_args_t));
|
||||||
|
|
||||||
res = 1;
|
res = 1;
|
||||||
|
|
||||||
@ -108,8 +112,13 @@ out:
|
|||||||
|
|
||||||
int init_cfg()
|
int init_cfg()
|
||||||
{
|
{
|
||||||
|
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
|
||||||
|
printf("\n Device unboot! Boot it first!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
ingenic_dev.file_buff = &hand;
|
ingenic_dev.file_buff = &hand;
|
||||||
ingenic_dev.file_len = sizeof(struct hand_t);
|
ingenic_dev.file_len = sizeof(hand);
|
||||||
if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
|
if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -179,12 +188,13 @@ int boot(char *stage1_path, char *stage2_path){
|
|||||||
free(ingenic_dev.file_buff);
|
free(ingenic_dev.file_buff);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
printf("\n Boot success!");
|
||||||
}
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
printf("\n Now configure Ingenic device");
|
printf("\n Now configure Ingenic device");
|
||||||
(init_cfg() == 1) ?
|
(init_cfg() == 1)
|
||||||
printf("\n Configure success!"):
|
? printf("\n Configure success!")
|
||||||
printf("\n Configure fail!");
|
: printf("\n Configure fail!");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -195,7 +205,8 @@ int error_check(unsigned char *org,unsigned char * obj,unsigned int size)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
if (org[i] != obj[i]) {
|
if (org[i] != obj[i]) {
|
||||||
printf("\n Check Error! %d = %x : %x ", i, org[i], obj[i]);
|
printf("\n Check Error! %d = %x : %x ",
|
||||||
|
i, org[i], obj[i]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,7 +243,7 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#ifdef CONFIG_NAND_OUT
|
||||||
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 */
|
||||||
@ -247,23 +258,24 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
usb_send_data_to_ingenic(&ingenic_dev);
|
usb_send_data_to_ingenic(&ingenic_dev);
|
||||||
/* 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)
|
||||||
/* page_num = nand_in->length / hand.nand_ps +1; */
|
continue;
|
||||||
if (nand_in->option == NO_OOB) {
|
if (nand_in->option == NO_OOB) {
|
||||||
page_num = nand_in->length / hand.nand_ps;
|
page_num = nand_in->length / hand.nand_ps;
|
||||||
if ((nand_in->length % hand.nand_ps) !=0)
|
if ((nand_in->length % hand.nand_ps) !=0)
|
||||||
page_num++;
|
page_num++;
|
||||||
/*temp = ((i<<4) & 0xff0) + NAND_PROGRAM; */
|
|
||||||
} else {
|
} else {
|
||||||
page_num = nand_in->length / (hand.nand_ps + hand.nand_os);
|
page_num = nand_in->length /
|
||||||
|
(hand.nand_ps + hand.nand_os);
|
||||||
if ((nand_in->length% (hand.nand_ps + hand.nand_os)) !=0)
|
if ((nand_in->length% (hand.nand_ps + hand.nand_os)) !=0)
|
||||||
page_num++;
|
page_num++;
|
||||||
/* temp = ((i<<4) & 0xff0) + NAND_PROGRAM_OOB; */
|
|
||||||
}
|
}
|
||||||
temp = ((nand_in->option << 12) & 0xf000) + ((i<<4) & 0xff0) + NAND_PROGRAM;
|
temp = ((nand_in->option << 12) & 0xf000) +
|
||||||
|
((i<<4) & 0xff0) + NAND_PROGRAM;
|
||||||
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);
|
||||||
|
|
||||||
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
||||||
printf(" Finish! ");
|
printf(" Finish! ");
|
||||||
|
|
||||||
@ -273,27 +285,45 @@ int nand_program_check(struct nand_in_t *nand_in,
|
|||||||
|
|
||||||
switch (nand_in->option) {
|
switch (nand_in->option) {
|
||||||
case OOB_ECC:
|
case OOB_ECC:
|
||||||
temp = ((OOB_ECC << 12) & 0xf000) +((i << 4) & 0xff0) + NAND_READ;
|
temp = ((OOB_ECC << 12) & 0xf000) +
|
||||||
break;
|
((i << 4) & 0xff0) + NAND_READ;
|
||||||
case OOB_NO_ECC: /* do not support data verify */
|
|
||||||
temp = ((OOB_NO_ECC << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ;
|
|
||||||
break;
|
|
||||||
case NO_OOB:
|
|
||||||
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...");
|
||||||
usb_read_data_from_ingenic(&ingenic_dev, check_buf,
|
usb_read_data_from_ingenic(&ingenic_dev, check_buf,
|
||||||
page_num * (hand.nand_ps + hand.nand_os));
|
page_num * (hand.nand_ps + hand.nand_os));
|
||||||
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
||||||
|
break;
|
||||||
|
case OOB_NO_ECC: /* do not support data verify */
|
||||||
|
temp = ((OOB_NO_ECC << 12) & 0xf000) +
|
||||||
|
((i << 4) & 0xff0) + NAND_READ;
|
||||||
|
usb_ingenic_nand_ops(&ingenic_dev, temp);
|
||||||
|
printf("Checking...");
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev, check_buf,
|
||||||
|
page_num * (hand.nand_ps + hand.nand_os));
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
||||||
|
break;
|
||||||
|
case NO_OOB:
|
||||||
|
temp = ((NO_OOB << 12) & 0xf000) +
|
||||||
|
((i << 4) & 0xff0) + NAND_READ;
|
||||||
|
usb_ingenic_nand_ops(&ingenic_dev, temp);
|
||||||
|
printf("Checking...");
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev, check_buf,
|
||||||
|
page_num * hand.nand_ps);
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
printf(" End at %d ",cur_page);
|
printf(" End at %d ",cur_page);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -361,15 +391,17 @@ int nand_erase(struct nand_in_t *nand_in)
|
|||||||
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
||||||
printf(" Finish!");
|
printf(" Finish!");
|
||||||
}
|
}
|
||||||
/* handle_Close(); need to change */
|
|
||||||
end_block = ((ret[3] << 24) |
|
end_block = ((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;
|
||||||
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) {
|
||||||
printf("\n There are marked bad blocks :%d ",end_block - start_blk - blk_num );
|
/* not force erase, show bad block infomation */
|
||||||
} else { /* force erase, no bad block infomation can show */
|
printf("\n There are marked bad blocks :%d ",
|
||||||
|
end_block - start_blk - blk_num );
|
||||||
|
} 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 !" );
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -410,9 +442,12 @@ int nand_program_file(struct nand_in_t *nand_in,
|
|||||||
n_in.length = flen / (hand.nand_ps * hand.nand_ppb) + 1;
|
n_in.length = flen / (hand.nand_ps * hand.nand_ppb) + 1;
|
||||||
} else {
|
} else {
|
||||||
if (flen % (hand.nand_ppb * (hand.nand_ps + hand.nand_os)) == 0)
|
if (flen % (hand.nand_ppb * (hand.nand_ps + hand.nand_os)) == 0)
|
||||||
n_in.length = flen / ((hand.nand_ps + hand.nand_os) * hand.nand_ppb);
|
n_in.length = flen /
|
||||||
|
((hand.nand_ps + hand.nand_os) * hand.nand_ppb);
|
||||||
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("\n length %d flen %d ", 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;
|
||||||
@ -443,7 +478,8 @@ int nand_program_file(struct nand_in_t *nand_in,
|
|||||||
page_num = transfer_size / (hand.nand_ps + hand.nand_os);
|
page_num = transfer_size / (hand.nand_ps + hand.nand_os);
|
||||||
|
|
||||||
code_len = transfer_size;
|
code_len = transfer_size;
|
||||||
fread(code_buf, 1, code_len, fp); /* read code from file to buffer */
|
fread(code_buf, 1, code_len, fp);
|
||||||
|
/* read code from file to buffer */
|
||||||
printf("\n No.%d Programming...",k+1);
|
printf("\n No.%d Programming...",k+1);
|
||||||
nand_in->length = code_len; /* code length,not page number! */
|
nand_in->length = code_len; /* code length,not page number! */
|
||||||
nand_in->buf = code_buf;
|
nand_in->buf = code_buf;
|
||||||
@ -456,20 +492,18 @@ int nand_program_file(struct nand_in_t *nand_in,
|
|||||||
|
|
||||||
#ifdef CONFIG_NAND_OUT
|
#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];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* offset += code_len - 1; */
|
|
||||||
offset += code_len ;
|
offset += code_len ;
|
||||||
/* start_page += page_num; */
|
|
||||||
/* nand_in->start += page_num; */
|
|
||||||
fseek(fp,offset,SEEK_SET);
|
fseek(fp,offset,SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j) {
|
if (j) {
|
||||||
j += hand.nand_ps - (j % hand.nand_ps);
|
j += hand.nand_ps - (j % hand.nand_ps);
|
||||||
memset(code_buf, 0, j); /* set all to null */
|
memset(code_buf, 0, j); /* set all to null */
|
||||||
fread(code_buf, 1, j, fp); /* read code from file to buffer */
|
fread(code_buf, 1, j, fp);/* read code from file to buffer */
|
||||||
nand_in->length = j;
|
nand_in->length = j;
|
||||||
nand_in->buf = code_buf;
|
nand_in->buf = code_buf;
|
||||||
printf("\n No.%d Programming...",k+1);
|
printf("\n No.%d Programming...",k+1);
|
||||||
@ -482,7 +516,8 @@ int nand_program_file(struct nand_in_t *nand_in,
|
|||||||
|
|
||||||
#ifdef CONFIG_NAND_OUT
|
#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];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -491,7 +526,17 @@ int nand_program_file(struct nand_in_t *nand_in,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nprog(void)
|
int init_nand_in(void)
|
||||||
|
{
|
||||||
|
nand_in.buf = code_buf;
|
||||||
|
nand_in.check = error_check;
|
||||||
|
nand_in.dev = 0;
|
||||||
|
nand_in.cs_map = cs;
|
||||||
|
nand_in.max_chip = 16;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nand_prog(void)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char *image_file;
|
char *image_file;
|
||||||
@ -504,11 +549,7 @@ int nprog(void)
|
|||||||
"\n \t-n:\tno oob"
|
"\n \t-n:\tno oob"
|
||||||
"\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;
|
init_nand_in();
|
||||||
nand_in.check = error_check;
|
|
||||||
nand_in.dev = 0;
|
|
||||||
nand_in.cs_map = cs;
|
|
||||||
nand_in.max_chip =16;
|
|
||||||
|
|
||||||
if (com_argc != 6) {
|
if (com_argc != 6) {
|
||||||
printf("\n not enough argument.");
|
printf("\n not enough argument.");
|
||||||
@ -523,11 +564,11 @@ int nprog(void)
|
|||||||
image_file = com_argv[2];
|
image_file = com_argv[2];
|
||||||
nand_in.dev = atoi(com_argv[3]);
|
nand_in.dev = atoi(com_argv[3]);
|
||||||
(nand_in.cs_map)[atoi(com_argv[4])] = 1;
|
(nand_in.cs_map)[atoi(com_argv[4])] = 1;
|
||||||
if (!strcmp(com_argv[5],"-e"))
|
if (!strcmp(com_argv[5], "-e"))
|
||||||
nand_in.option = OOB_ECC;
|
nand_in.option = OOB_ECC;
|
||||||
else if (!strcmp(com_argv[5],"-o"))
|
else if (!strcmp(com_argv[5], "-o"))
|
||||||
nand_in.option = OOB_NO_ECC;
|
nand_in.option = OOB_NO_ECC;
|
||||||
else if (!strcmp(com_argv[5],"-n"))
|
else if (!strcmp(com_argv[5], "-n"))
|
||||||
nand_in.option = NO_OOB;
|
nand_in.option = NO_OOB;
|
||||||
else
|
else
|
||||||
printf("%s", help);
|
printf("%s", help);
|
||||||
@ -537,17 +578,70 @@ int nprog(void)
|
|||||||
else
|
else
|
||||||
nand_program_file(&nand_in,&nand_out, image_file);
|
nand_program_file(&nand_in,&nand_out, image_file);
|
||||||
|
|
||||||
#if 0
|
#ifdef CONFIG_NAND_OUT
|
||||||
printf("\n Flash check result:");
|
printf("\n Flash check result:");
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
printf(" %d", (nand_out.status)[i]);
|
printf(" %d", (nand_out.status)[i]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("\n nprog %d %s %d %d %d", nand_in.start,
|
printf("\n nprog %d %s %d %d %d", nand_in.start,
|
||||||
image_file,
|
image_file,
|
||||||
nand_in.dev,
|
nand_in.dev,
|
||||||
(nand_in.cs_map)[atoi(com_argv[4])],
|
(nand_in.cs_map)[atoi(com_argv[4])],
|
||||||
nand_in.option);
|
nand_in.option);
|
||||||
|
|
||||||
printf("\n not implement yet!! just test");
|
printf("\n not implement yet!! just test");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nand_query(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned char csn;
|
||||||
|
|
||||||
|
if (com_argc < 3) {
|
||||||
|
printf("\n Usage:");
|
||||||
|
printf(" nquery (1) (2) ");
|
||||||
|
printf("\n (1):device index number"
|
||||||
|
"\n (2):flash index number");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
init_nand_in();
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_DEV_NUM; i++)
|
||||||
|
(nand_in.cs_map)[i] = 0;
|
||||||
|
|
||||||
|
nand_in.dev = atoi(com_argv[1]);
|
||||||
|
(nand_in.cs_map)[atoi(com_argv[2])] = 1;
|
||||||
|
|
||||||
|
for (i = 0; i < nand_in.max_chip; i++) {
|
||||||
|
if ((nand_in.cs_map)[i] != 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i >= nand_in.max_chip)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (usb_get_ingenic_cpu(&ingenic_dev) < 3) {
|
||||||
|
printf("\n Device unboot! Boot it first!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
csn = i;
|
||||||
|
printf("\n ID of No.%d device No.%d flash: ", nand_in.dev, csn);
|
||||||
|
|
||||||
|
unsigned short ops = ((csn << 4) & 0xff0) + NAND_QUERY;
|
||||||
|
usb_ingenic_nand_ops(&ingenic_dev, ops);
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
||||||
|
printf("\n Vendor ID :0x%x ",(unsigned char)ret[0]);
|
||||||
|
printf("\n Product ID :0x%x ",(unsigned char)ret[1]);
|
||||||
|
printf("\n Chip ID :0x%x ",(unsigned char)ret[2]);
|
||||||
|
printf("\n Page ID :0x%x ",(unsigned char)ret[3]);
|
||||||
|
printf("\n Plane ID :0x%x ",(unsigned char)ret[4]);
|
||||||
|
|
||||||
|
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
|
||||||
|
printf("\n Operation status: Success!");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#define MAX_COMMAND_LENGTH 100
|
#define MAX_COMMAND_LENGTH 100
|
||||||
|
|
||||||
int boot(char *stage1_path, char *stage2_path);
|
int boot(char *stage1_path, char *stage2_path);
|
||||||
int nprog(void);
|
int nand_prog(void);
|
||||||
|
int nand_query(void);
|
||||||
|
|
||||||
#endif /* __CMD_H__ */
|
#endif /* __CMD_H__ */
|
||||||
|
@ -155,8 +155,11 @@ int command_handle(char *buf)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
case 6:
|
||||||
|
nand_query();
|
||||||
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
nprog();
|
nand_prog();
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
handle_help();
|
handle_help();
|
||||||
|
@ -37,7 +37,8 @@ static int get_ingenic_device(struct ingenic_dev *ingenic_dev)
|
|||||||
usb_busses = usb_get_busses();
|
usb_busses = usb_get_busses();
|
||||||
|
|
||||||
for (usb_bus = usb_busses; usb_bus != NULL; usb_bus = usb_bus->next) {
|
for (usb_bus = usb_busses; usb_bus != NULL; usb_bus = usb_bus->next) {
|
||||||
for (usb_dev = usb_bus->devices; usb_dev != NULL; usb_dev = usb_dev->next) {
|
for (usb_dev = usb_bus->devices; usb_dev != NULL;
|
||||||
|
usb_dev = usb_dev->next) {
|
||||||
|
|
||||||
if ((usb_dev->descriptor.idVendor == VENDOR_ID) &&
|
if ((usb_dev->descriptor.idVendor == VENDOR_ID) &&
|
||||||
(usb_dev->descriptor.idProduct == PRODUCT_ID)) {
|
(usb_dev->descriptor.idProduct == PRODUCT_ID)) {
|
||||||
@ -66,13 +67,15 @@ static int get_ingenic_interface(struct ingenic_dev *ingenic_dev)
|
|||||||
if (!usb_config_desc)
|
if (!usb_config_desc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (if_index = 0; if_index < usb_config_desc->bNumInterfaces; if_index++) {
|
for (if_index = 0; if_index < usb_config_desc->bNumInterfaces;
|
||||||
|
if_index++) {
|
||||||
usb_if = &usb_config_desc->interface[if_index];
|
usb_if = &usb_config_desc->interface[if_index];
|
||||||
|
|
||||||
if (!usb_if)
|
if (!usb_if)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (alt_index = 0; alt_index < usb_if->num_altsetting; alt_index++) {
|
for (alt_index = 0; alt_index < usb_if->num_altsetting;
|
||||||
|
alt_index++) {
|
||||||
usb_if_desc = &usb_if->altsetting[alt_index];
|
usb_if_desc = &usb_if->altsetting[alt_index];
|
||||||
|
|
||||||
if (!usb_if_desc)
|
if (!usb_if_desc)
|
||||||
@ -80,7 +83,8 @@ static int get_ingenic_interface(struct ingenic_dev *ingenic_dev)
|
|||||||
|
|
||||||
if ((usb_if_desc->bInterfaceClass == 0xff) &&
|
if ((usb_if_desc->bInterfaceClass == 0xff) &&
|
||||||
(usb_if_desc->bInterfaceSubClass == 0)) {
|
(usb_if_desc->bInterfaceSubClass == 0)) {
|
||||||
ingenic_dev->interface = usb_if_desc->bInterfaceNumber;
|
ingenic_dev->interface =
|
||||||
|
usb_if_desc->bInterfaceNumber;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,13 +113,15 @@ int usb_ingenic_init(struct ingenic_dev *ingenic_dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (num_ingenic > 1) {
|
if (num_ingenic > 1) {
|
||||||
fprintf(stderr, "Error - too many Ingenic devices found: %i\n", num_ingenic);
|
fprintf(stderr, "Error - too many Ingenic devices found: %i\n",
|
||||||
|
num_ingenic);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev);
|
ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev);
|
||||||
if (!ingenic_dev->usb_handle) {
|
if (!ingenic_dev->usb_handle) {
|
||||||
fprintf(stderr, "Error - can't open Ingenic device: %s\n", usb_strerror());
|
fprintf(stderr, "Error - can't open Ingenic device: %s\n",
|
||||||
|
usb_strerror());
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +130,10 @@ int usb_ingenic_init(struct ingenic_dev *ingenic_dev)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface) < 0) {
|
if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface)
|
||||||
fprintf(stderr, "Error - can't claim Ingenic interface: %s\n", usb_strerror());
|
< 0) {
|
||||||
|
fprintf(stderr, "Error - can't claim Ingenic interface: %s\n",
|
||||||
|
usb_strerror());
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +152,7 @@ int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev)
|
|||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
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,
|
||||||
/* wValue */ 0,
|
/* wValue */ 0,
|
||||||
/* wIndex */ 0,
|
/* wIndex */ 0,
|
||||||
@ -153,12 +161,14 @@ int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev)
|
|||||||
USB_TIMEOUT);
|
USB_TIMEOUT);
|
||||||
|
|
||||||
if (status != sizeof(ingenic_dev->cpu_info_buff) - 1 ) {
|
if (status != sizeof(ingenic_dev->cpu_info_buff) - 1 ) {
|
||||||
fprintf(stderr, "Error - can't retrieve Ingenic CPU information: %i\n", status);
|
fprintf(stderr, "Error - "
|
||||||
|
"can't retrieve Ingenic CPU information: %i\n", status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
ingenic_dev->cpu_info_buff[8] = '\0';
|
ingenic_dev->cpu_info_buff[8] = '\0';
|
||||||
printf("\n CPU data: %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x : %s\n",
|
printf("\n CPU data: "
|
||||||
|
"%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x : %s\n",
|
||||||
ingenic_dev->cpu_info_buff[0], ingenic_dev->cpu_info_buff[1],
|
ingenic_dev->cpu_info_buff[0], ingenic_dev->cpu_info_buff[1],
|
||||||
ingenic_dev->cpu_info_buff[2], ingenic_dev->cpu_info_buff[3],
|
ingenic_dev->cpu_info_buff[2], ingenic_dev->cpu_info_buff[3],
|
||||||
ingenic_dev->cpu_info_buff[4], ingenic_dev->cpu_info_buff[5],
|
ingenic_dev->cpu_info_buff[4], ingenic_dev->cpu_info_buff[5],
|
||||||
@ -208,14 +218,16 @@ int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, int len)
|
|||||||
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 -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
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)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
/* tell the device the RAM address to store the file */
|
/* tell the device the RAM address to store the file */
|
||||||
@ -229,7 +241,8 @@ int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, unsigned i
|
|||||||
USB_TIMEOUT);
|
USB_TIMEOUT);
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
fprintf(stderr, "Error - can't set the address on Ingenic device: %i\n", status);
|
fprintf(stderr, "Error - "
|
||||||
|
"can't set the address on Ingenic device: %i\n", status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,23 +258,26 @@ int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
|
|||||||
/* 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\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, char *buff, int len)
|
int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev,
|
||||||
|
unsigned char *buff, unsigned 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,
|
||||||
/* bulk data */ buff,
|
/* bulk data */ buff,
|
||||||
/* bulk data length */ len,
|
/* bulk data length */ len,
|
||||||
USB_TIMEOUT);
|
USB_TIMEOUT);
|
||||||
if (status < len) {
|
if (status < len) {
|
||||||
fprintf(stderr, "Error - can't read bulk data from Ingenic CPU: %i\n", status);
|
fprintf(stderr, "Error - "
|
||||||
|
"can't read bulk data from Ingenic device:%i\n", status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +295,8 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
|
|||||||
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);
|
||||||
printf("\n Download stage %d program and execute at 0x%08x ", stage, (stage_addr));
|
printf("\n Download stage %d program and execute at 0x%08x ",
|
||||||
|
stage, (stage_addr));
|
||||||
usb_send_data_to_ingenic(ingenic_dev);
|
usb_send_data_to_ingenic(ingenic_dev);
|
||||||
|
|
||||||
if (stage == 2) {
|
if (stage == 2) {
|
||||||
@ -298,9 +315,8 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
|
|||||||
USB_TIMEOUT);
|
USB_TIMEOUT);
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, "Error - can't start the uploaded binary "
|
||||||
"Error - can't start the uploaded binary on the Ingenic device: %i\n",
|
"on the Ingenic device: %i\n", status);
|
||||||
status);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +328,8 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
|
|||||||
void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev)
|
void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev)
|
||||||
{
|
{
|
||||||
if ((ingenic_dev->usb_handle) && (ingenic_dev->interface))
|
if ((ingenic_dev->usb_handle) && (ingenic_dev->interface))
|
||||||
usb_release_interface(ingenic_dev->usb_handle, ingenic_dev->interface);
|
usb_release_interface(ingenic_dev->usb_handle,
|
||||||
|
ingenic_dev->interface);
|
||||||
|
|
||||||
if (ingenic_dev->usb_handle)
|
if (ingenic_dev->usb_handle)
|
||||||
usb_close(ingenic_dev->usb_handle);
|
usb_close(ingenic_dev->usb_handle);
|
||||||
@ -331,7 +348,8 @@ int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops)
|
|||||||
USB_TIMEOUT);
|
USB_TIMEOUT);
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
fprintf(stderr, "Error - can't set Ingenic device nand ops: %i\n", status);
|
fprintf(stderr, "Error - "
|
||||||
|
"can't set Ingenic device nand ops: %i\n", status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +369,8 @@ int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops)
|
|||||||
USB_TIMEOUT);
|
USB_TIMEOUT);
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
fprintf(stderr, "Error - can't init Ingenic configration: %i\n", status);
|
fprintf(stderr, "Error - "
|
||||||
|
"can't init Ingenic configration: %i\n", status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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, char *buff, int len);
|
int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev,unsigned char *buff, unsigned int len);
|
||||||
|
|
||||||
#endif /* __INGENIC_USB_H__ */
|
#endif /* __INGENIC_USB_H__ */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user