1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-26 08:51:33 +02:00

now the reflash function is work :-)

This commit is contained in:
xiangfu 2009-05-14 17:11:03 +00:00
parent fe484a65ee
commit b5a4d70021
5 changed files with 194 additions and 77 deletions

View File

@ -3,6 +3,7 @@
*
* (C) Copyright 2009
* 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
* 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);
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));
return -1;
}
@ -96,7 +98,9 @@ static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path)
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;
@ -108,8 +112,13 @@ out:
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_len = sizeof(struct hand_t);
ingenic_dev.file_len = sizeof(hand);
if (usb_send_data_to_ingenic(&ingenic_dev) != 1)
return -1;
@ -179,12 +188,13 @@ int boot(char *stage1_path, char *stage2_path){
free(ingenic_dev.file_buff);
return -1;
}
printf("\n Boot success!");
}
sleep(1);
printf("\n Now configure Ingenic device");
(init_cfg() == 1) ?
printf("\n Configure success!"):
printf("\n Configure fail!");
(init_cfg() == 1)
? printf("\n Configure success!")
: printf("\n Configure fail!");
return 1;
}
@ -195,7 +205,8 @@ 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]);
printf("\n Check Error! %d = %x : %x ",
i, org[i], obj[i]);
return 0;
}
}
@ -232,7 +243,7 @@ int nand_program_check(struct nand_in_t *nand_in,
return -1;
}
#if 0
#ifdef CONFIG_NAND_OUT
nand_out->status = status_buf;
for (i = 0; i < nand_in->max_chip; i++)
(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);
/* dump_data(nand_in->buf, 100); */
for (i = 0; i < nand_in->max_chip; i++) {
if ((nand_in->cs_map)[i]==0) continue;
/* page_num = nand_in->length / hand.nand_ps +1; */
if ((nand_in->cs_map)[i]==0)
continue;
if (nand_in->option == NO_OOB) {
page_num = nand_in->length / hand.nand_ps;
if ((nand_in->length % hand.nand_ps) !=0)
page_num++;
/*temp = ((i<<4) & 0xff0) + NAND_PROGRAM; */
} 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)
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_length_to_ingenic(&ingenic_dev, page_num);
usb_ingenic_nand_ops(&ingenic_dev, temp);
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Finish! ");
@ -273,27 +285,45 @@ int nand_program_check(struct nand_in_t *nand_in,
switch (nand_in->option) {
case OOB_ECC:
temp = ((OOB_ECC << 12) & 0xf000) +((i << 4) & 0xff0) + NAND_READ;
break;
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:
;
}
temp = ((OOB_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 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; */
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);
continue;
}
@ -361,15 +391,17 @@ int nand_erase(struct nand_in_t *nand_in)
usb_read_data_from_ingenic(&ingenic_dev, ret, 8);
printf(" Finish!");
}
/* handle_Close(); need to change */
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);
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 );
} else { /* force erase, no bad block infomation can show */
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 );
} else {
/* force erase, no bad block infomation can show */
printf("\n Force erase ,no bad block infomation !" );
}
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;
} else {
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
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); */
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);
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);
nand_in->length = code_len; /* code length,not page number! */
nand_in->buf = code_buf;
@ -456,13 +492,11 @@ int nand_program_file(struct nand_in_t *nand_in,
#ifdef CONFIG_NAND_OUT
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
/* offset += code_len - 1; */
offset += code_len ;
/* start_page += page_num; */
/* nand_in->start += page_num; */
fseek(fp,offset,SEEK_SET);
}
@ -482,7 +516,8 @@ int nand_program_file(struct nand_in_t *nand_in,
#ifdef CONFIG_NAND_OUT
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
}
@ -491,7 +526,17 @@ int nand_program_file(struct nand_in_t *nand_in,
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;
char *image_file;
@ -504,11 +549,7 @@ int nprog(void)
"\n \t-n:\tno oob"
"\n \t-o:\twith oob no ecc"
"\n \t-e:\twith oob and ecc";
nand_in.buf = code_buf;
nand_in.check = error_check;
nand_in.dev = 0;
nand_in.cs_map = cs;
nand_in.max_chip =16;
init_nand_in();
if (com_argc != 6) {
printf("\n not enough argument.");
@ -537,17 +578,70 @@ int nprog(void)
else
nand_program_file(&nand_in,&nand_out, image_file);
#if 0
#ifdef CONFIG_NAND_OUT
printf("\n Flash check result:");
for (i = 0; i < 16; i++)
printf(" %d", (nand_out.status)[i]);
#endif
printf("\n nprog %d %s %d %d %d", nand_in.start,
image_file,
nand_in.dev,
(nand_in.cs_map)[atoi(com_argv[4])],
nand_in.option);
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;
}

View File

@ -27,6 +27,7 @@
#define MAX_COMMAND_LENGTH 100
int boot(char *stage1_path, char *stage2_path);
int nprog(void);
int nand_prog(void);
int nand_query(void);
#endif /* __CMD_H__ */

View File

@ -155,8 +155,11 @@ int command_handle(char *buf)
return -1;
switch (cmd) {
case 6:
nand_query();
break;
case 11:
nprog();
nand_prog();
break;
case 12:
handle_help();

View File

@ -37,7 +37,8 @@ static int get_ingenic_device(struct ingenic_dev *ingenic_dev)
usb_busses = usb_get_busses();
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) &&
(usb_dev->descriptor.idProduct == PRODUCT_ID)) {
@ -66,13 +67,15 @@ static int get_ingenic_interface(struct ingenic_dev *ingenic_dev)
if (!usb_config_desc)
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];
if (!usb_if)
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];
if (!usb_if_desc)
@ -80,7 +83,8 @@ static int get_ingenic_interface(struct ingenic_dev *ingenic_dev)
if ((usb_if_desc->bInterfaceClass == 0xff) &&
(usb_if_desc->bInterfaceSubClass == 0)) {
ingenic_dev->interface = usb_if_desc->bInterfaceNumber;
ingenic_dev->interface =
usb_if_desc->bInterfaceNumber;
return 1;
}
}
@ -109,13 +113,15 @@ int usb_ingenic_init(struct ingenic_dev *ingenic_dev)
}
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;
}
ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev);
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;
}
@ -124,8 +130,10 @@ int usb_ingenic_init(struct ingenic_dev *ingenic_dev)
goto out;
}
if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface) < 0) {
fprintf(stderr, "Error - can't claim Ingenic interface: %s\n", usb_strerror());
if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface)
< 0) {
fprintf(stderr, "Error - can't claim Ingenic interface: %s\n",
usb_strerror());
goto out;
}
@ -153,12 +161,14 @@ int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev)
USB_TIMEOUT);
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;
}
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[2], ingenic_dev->cpu_info_buff[3],
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);
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;
}
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;
/* 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);
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;
}
@ -245,23 +258,26 @@ int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev)
/* 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);
fprintf(stderr, "Error - "
"can't send bulk data to Ingenic CPU: %i\n", status);
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;
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 length */ len,
USB_TIMEOUT);
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;
}
@ -279,7 +295,8 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
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));
printf("\n Download stage %d program and execute at 0x%08x ",
stage, (stage_addr));
usb_send_data_to_ingenic(ingenic_dev);
if (stage == 2) {
@ -298,9 +315,8 @@ int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage)
USB_TIMEOUT);
if (status != 0) {
fprintf(stderr,
"Error - can't start the uploaded binary on the Ingenic device: %i\n",
status);
fprintf(stderr, "Error - can't start the uploaded binary "
"on the Ingenic device: %i\n", 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)
{
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)
usb_close(ingenic_dev->usb_handle);
@ -331,7 +348,8 @@ int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops)
USB_TIMEOUT);
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;
}
@ -351,7 +369,8 @@ int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops)
USB_TIMEOUT);
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;
}

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 len);
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__ */