From 5ade9f115b3aaa86b8df85d85bd4c6dd39946676 Mon Sep 17 00:00:00 2001 From: Xiangfu Date: Fri, 9 Nov 2012 12:55:57 +0800 Subject: [PATCH] Fix compile warnings --- jzboot/src/debug.c | 1 + usbboot/src/Makefile.am | 7 +- usbboot/src/cmd.c | 245 +++++++++++++--------------- usbboot/src/cmd.h | 26 ++- usbboot/src/command_line.c | 50 +++--- usbboot/src/command_line.h | 8 + usbboot/src/ingenic_cfg.c | 150 +++++++++--------- usbboot/src/ingenic_cfg.h | 1 + usbboot/src/ingenic_usb.c | 282 ++++++++++++++++----------------- usbboot/src/ingenic_usb.h | 26 +-- usbboot/src/main.c | 2 +- usbboot/src/usb_boot_defines.h | 2 +- xbboot/host-app/Makefile.am | 2 +- xbboot/host-app/host_main.c | 1 + 14 files changed, 402 insertions(+), 401 deletions(-) diff --git a/jzboot/src/debug.c b/jzboot/src/debug.c index d9fa13b..b02d403 100644 --- a/jzboot/src/debug.c +++ b/jzboot/src/debug.c @@ -18,6 +18,7 @@ #include #include +#include #include "debug.h" diff --git a/usbboot/src/Makefile.am b/usbboot/src/Makefile.am index ea0f7ca..f93af97 100644 --- a/usbboot/src/Makefile.am +++ b/usbboot/src/Makefile.am @@ -1,4 +1,9 @@ -AM_CFLAGS = -pedantic -Wall -W -DCFGDIR=\"$(cfgdir)\" -DDATADIR=\"$(pkgdatadir)\" +AM_CFLAGS = -DCFGDIR=\"$(cfgdir)\" -DDATADIR=\"$(pkgdatadir)\" \ + -std=gnu99 \ + -Wall -Wshadow -Wmissing-prototypes \ + -Wmissing-declarations -Wno-format-zero-length \ + -Wno-unused -Wno-implicit-function-declaration \ + -Wno-missing-prototypes -Wno-missing-declarations bin_PROGRAMS = usbboot usbboot_SOURCES = cmd.c command_line.c ingenic_cfg.c \ diff --git a/usbboot/src/cmd.c b/usbboot/src/cmd.c index c1e5722..4e4120b 100644 --- a/usbboot/src/cmd.c +++ b/usbboot/src/cmd.c @@ -28,38 +28,19 @@ #include #include #include "cmd.h" +#include "command_line.h" #include "ingenic_cfg.h" #include "ingenic_usb.h" #include "ingenic_request.h" #include "usb_boot_defines.h" -extern int com_argc; -extern char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH]; -extern char * stage1; - -struct ingenic_dev ingenic_dev; -struct hand hand; -struct sdram_in sdram_in; -struct nand_in nand_in; - -unsigned int total_size; -unsigned char code_buf[4 * 512 * 1024]; -unsigned char check_buf[4 * 512 * 1024]; -unsigned char cs[16]; -unsigned char ret[8]; - -static const char IMAGE_TYPE[][30] = { - "with oob and ecc", - "with oob and without ecc", - "without oob", -}; - -static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path) +static int load_file(struct ingenic_dev *id, const char *file_path) { - struct stat fstat; + struct stat fst; + struct fw_args *fw_args_copy; int fd, status, res = -1; - status = stat(file_path, &fstat); + status = stat(file_path, &fst); if (status < 0) { fprintf(stderr, "Error - can't get file size from '%s': %s\n", @@ -67,8 +48,8 @@ static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path) goto out; } - ingenic_dev->file_len = fstat.st_size; - ingenic_dev->file_buff = code_buf; + id->file_len = fst.st_size; + id->file_buff = code_buf; fd = open(file_path, O_RDONLY); @@ -78,15 +59,15 @@ static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path) goto out; } - status = read(fd, ingenic_dev->file_buff, ingenic_dev->file_len); + status = read(fd, id->file_buff, id->file_len); - if (status < ingenic_dev->file_len) { + if (status < id->file_len) { fprintf(stderr, "Error - can't read file '%s': %s\n", file_path, strerror(errno)); goto close; } - struct fw_args *fw_args_copy = malloc(sizeof(struct fw_args)); + fw_args_copy = malloc(sizeof(struct fw_args)); if (!fw_args_copy) goto close; @@ -100,7 +81,7 @@ static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path) #endif /* write args to code */ - memcpy(ingenic_dev->file_buff + 8, fw_args_copy, + memcpy(id->file_buff + 8, fw_args_copy, sizeof(struct fw_args)); free(fw_args_copy); @@ -145,16 +126,17 @@ int get_ingenic_cpu() return status; } -/* after upload stage2. must init device */ +/* After upload stage2. we have to init the device */ void init_cfg() { + struct hand *hand_copy; int cpu = get_ingenic_cpu(); if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) { printf(" Device unboot! boot it first!\n"); return; } - struct hand *hand_copy = malloc(sizeof(struct hand)); + hand_copy = malloc(sizeof(struct hand)); if (!hand_copy) goto xout; @@ -184,7 +166,7 @@ void init_cfg() #endif - ingenic_dev.file_buff = hand_copy; + ingenic_dev.file_buff = (unsigned char *)hand_copy; ingenic_dev.file_len = sizeof(struct hand); if (usb_send_data_to_ingenic(&ingenic_dev) != 1) goto xout; @@ -246,7 +228,7 @@ int error_check(unsigned char *org,unsigned char * obj,unsigned int size) printf(" Comparing %d bytes - ", size); for (i = 0; i < size; i++) { if (org[i] != obj[i]) { - unsigned int s = (i < 8) ? i : i - 8; // start_dump + unsigned int s = (i < 8) ? i : i - 8; printf("FAIL at off %d, wrote 0x%x, read 0x%x\n", i, org[i], obj[i]); printf(" off %d write: %02x %02x %02x %02x %02x %02x %02x %02x" " %02x %02x %02x %02x %02x %02x %02x %02x\n", s, @@ -265,15 +247,15 @@ int error_check(unsigned char *org,unsigned char * obj,unsigned int size) return 1; } -int nand_markbad(struct nand_in *nand_in) +int nand_markbad(struct nand_in *ni) { int cpu = get_ingenic_cpu(); if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) { printf(" Device unboot! boot it first!\n"); return -1; } - printf(" Mark bad block : %d\n",nand_in->start); - usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start); + printf(" Mark bad block : %d\n",ni->start); + usb_send_data_address_to_ingenic(&ingenic_dev, ni->start); usb_ingenic_nand_ops(&ingenic_dev, NAND_MARK_BAD); usb_read_data_from_ingenic(&ingenic_dev, ret, 8); printf(" Mark bad block at %d\n",((ret[3] << 24) | @@ -283,44 +265,45 @@ int nand_markbad(struct nand_in *nand_in) return 0; } -int nand_program_check(struct nand_in *nand_in, unsigned int *start_page) +int nand_program_check(struct nand_in *ni, unsigned int *start_page) { unsigned int i, page_num, cur_page = -1; unsigned int start_addr; unsigned short temp; + int cpu; int status = -1; - printf(" Writing NAND page %d len %d...\n", nand_in->start, nand_in->length); - if (nand_in->length > (unsigned int)MAX_TRANSFER_SIZE) { + printf(" Writing NAND page %d len %d...\n", ni->start, ni->length); + if (ni->length > (unsigned int)MAX_TRANSFER_SIZE) { printf(" Buffer size too long!\n"); goto err; } - int cpu = get_ingenic_cpu(); + cpu = get_ingenic_cpu(); if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) { printf(" Device unboot! boot it first!\n"); goto err; } - ingenic_dev.file_buff = nand_in->buf; - ingenic_dev.file_len = nand_in->length; + ingenic_dev.file_buff = ni->buf; + ingenic_dev.file_len = ni->length; usb_send_data_to_ingenic(&ingenic_dev); - for (i = 0; i < nand_in->max_chip; i++) { - if ((nand_in->cs_map)[i] == 0) + for (i = 0; i < ni->max_chip; i++) { + if ((ni->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) + if (ni->option == NO_OOB) { + page_num = ni->length / hand.nand_ps; + if ((ni->length % hand.nand_ps) !=0) page_num++; } else { - page_num = nand_in->length / + page_num = ni->length / (hand.nand_ps + hand.nand_os); - if ((nand_in->length% (hand.nand_ps + hand.nand_os)) !=0) + if ((ni->length% (hand.nand_ps + hand.nand_os)) !=0) page_num++; } - temp = ((nand_in->option << 12) & 0xf000) + + temp = ((ni->option << 12) & 0xf000) + ((i<<4) & 0xff0) + NAND_PROGRAM; - if (usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start) != 1) + if (usb_send_data_address_to_ingenic(&ingenic_dev, ni->start) != 1) goto err; if (usb_send_data_length_to_ingenic(&ingenic_dev, page_num) != 1) goto err; @@ -330,13 +313,13 @@ int nand_program_check(struct nand_in *nand_in, unsigned int *start_page) goto err; printf(" Finish! (len %d start_page %d page_num %d)\n", - nand_in->length, nand_in->start, page_num); + ni->length, ni->start, page_num); /* Read back to check! */ - usb_send_data_address_to_ingenic(&ingenic_dev, nand_in->start); + usb_send_data_address_to_ingenic(&ingenic_dev, ni->start); usb_send_data_length_to_ingenic(&ingenic_dev, page_num); - switch (nand_in->option) { + switch (ni->option) { case OOB_ECC: temp = ((OOB_ECC << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ; @@ -348,15 +331,14 @@ int nand_program_check(struct nand_in *nand_in, unsigned int *start_page) start_addr = page_num * (hand.nand_ps + hand.nand_os); break; case NO_OOB: + default: temp = ((NO_OOB << 12) & 0xf000) + ((i << 4) & 0xff0) + NAND_READ; start_addr = page_num * hand.nand_ps; break; - default: - ; } - printf(" Checking %d bytes...", nand_in->length); + printf(" Checking %d bytes...", ni->length); usb_ingenic_nand_ops(&ingenic_dev, temp); usb_read_data_from_ingenic(&ingenic_dev, check_buf, start_addr); usb_read_data_from_ingenic(&ingenic_dev, ret, 8); @@ -364,17 +346,19 @@ int nand_program_check(struct nand_in *nand_in, unsigned int *start_page) cur_page = (ret[3] << 24) | (ret[2] << 16) | (ret[1] << 8) | (ret[0] << 0); - if (nand_in->start == 0 && hand.nand_ps == 4096 && + if (ni->start == 0 && hand.nand_ps == 4096 && hand.fw_args.cpu_id == 0x4740) { printf(" No check! end at page: %d\n", cur_page); fflush(NULL); continue; } - if (!nand_in->check(nand_in->buf, check_buf, nand_in->length)) { + if (!ni->check(ni->buf, check_buf, ni->length)) { struct nand_in bad; - // tbd: doesn't the other side skip bad blocks too? Can we just deduct 1 from cur_page? - // tbd: why do we only mark a block as bad if the last page in the block was written? + /* + * tbd: doesn't the other side skip bad blocks too? Can we just deduct 1 from cur_page? + * tbd: why do we only mark a block as bad if the last page in the block was written? + */ bad.start = (cur_page - 1) / hand.nand_ppb; if (cur_page % hand.nand_ppb == 0) nand_markbad(&bad); @@ -391,13 +375,15 @@ err: return status; } -int nand_erase(struct nand_in *nand_in) +int nand_erase(struct nand_in *ni) { unsigned int start_blk, blk_num, end_block; + unsigned short temp; + int cpu; int i; - start_blk = nand_in->start; - blk_num = nand_in->length; + start_blk = ni->start; + blk_num = ni->length; if (start_blk > (unsigned int)NAND_MAX_BLK_NUM) { printf(" Start block number overflow!\n"); return -1; @@ -407,22 +393,22 @@ int nand_erase(struct nand_in *nand_in) return -1; } - int cpu = get_ingenic_cpu(); + cpu = get_ingenic_cpu(); if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) { printf(" Device unboot! boot it first!\n"); return -1; } - for (i = 0; i < nand_in->max_chip; i++) { - if ((nand_in->cs_map)[i]==0) + for (i = 0; i < ni->max_chip; i++) { + if ((ni->cs_map)[i]==0) continue; printf(" Erasing No.%d device No.%d flash (start_blk %u blk_num %u)......\n", - nand_in->dev, i, start_blk, blk_num); + ni->dev, i, start_blk, blk_num); usb_send_data_address_to_ingenic(&ingenic_dev, start_blk); usb_send_data_length_to_ingenic(&ingenic_dev, blk_num); - unsigned short temp = ((i << 4) & 0xff0) + NAND_ERASE; + temp = ((i << 4) & 0xff0) + NAND_ERASE; usb_ingenic_nand_ops(&ingenic_dev, temp); usb_read_data_from_ingenic(&ingenic_dev, ret, 8); @@ -446,23 +432,23 @@ int nand_erase(struct nand_in *nand_in) return 1; } -int nand_program_file(struct nand_in *nand_in, char *fname) +int nand_program_file(struct nand_in *ni, char *fname) { int flen, m, j, k; - unsigned int start_page = 0, page_num, code_len, offset, transfer_size; + unsigned int start_page = 0, code_len, offset, transfer_size; int fd, status; - struct stat fstat; + struct stat fst; struct nand_in n_in; - status = stat(fname, &fstat); + status = stat(fname, &fst); if (status < 0) { fprintf(stderr, "Error - can't get file size from '%s': %s\n", fname, strerror(errno)); return -1; } - flen = fstat.st_size; + flen = fst.st_size; fd = open(fname, O_RDONLY); if (fd < 0) { @@ -471,9 +457,9 @@ int nand_program_file(struct nand_in *nand_in, char *fname) return -1; } - printf(" Programing No.%d device, flen %d, start page %d...\n",nand_in->dev, flen, nand_in->start); - n_in.start = nand_in->start / hand.nand_ppb; - if (nand_in->option == NO_OOB) { + printf(" Programing No.%d device, flen %d, start page %d...\n",ni->dev, flen, ni->start); + n_in.start = ni->start / hand.nand_ppb; + if (ni->option == NO_OOB) { if (flen % (hand.nand_ppb * hand.nand_ps) == 0) n_in.length = flen / (hand.nand_ps * hand.nand_ppb); else @@ -487,12 +473,12 @@ int nand_program_file(struct nand_in *nand_in, char *fname) ((hand.nand_ps + hand.nand_os) * hand.nand_ppb) + 1; } - n_in.cs_map = nand_in->cs_map; - n_in.dev = nand_in->dev; - n_in.max_chip = nand_in->max_chip; + n_in.cs_map = ni->cs_map; + n_in.dev = ni->dev; + n_in.max_chip = ni->max_chip; if (nand_erase(&n_in) != 1) return -1; - if (nand_in->option == NO_OOB) + if (ni->option == NO_OOB) transfer_size = (hand.nand_ppb * hand.nand_ps); else transfer_size = (hand.nand_ppb * (hand.nand_ps + hand.nand_os)); @@ -500,17 +486,12 @@ int nand_program_file(struct nand_in *nand_in, char *fname) m = flen / transfer_size; j = flen % transfer_size; printf(" Size to send %d, transfer_size %d\n", flen, transfer_size); - printf(" Image type : %s\n", IMAGE_TYPE[nand_in->option]); + printf(" Image type : %s\n", IMAGE_TYPE[ni->option]); printf(" It will cause %d times buffer transfer.\n", j == 0 ? m : m + 1); fflush(NULL); offset = 0; for (k = 0; k < m; k++) { - if (nand_in->option == NO_OOB) - page_num = transfer_size / hand.nand_ps; - else - page_num = transfer_size / (hand.nand_ps + hand.nand_os); - code_len = transfer_size; status = read(fd, code_buf, code_len); if (status < code_len) { @@ -519,14 +500,14 @@ int nand_program_file(struct nand_in *nand_in, char *fname) return -1; } - nand_in->length = code_len; /* code length,not page number! */ - nand_in->buf = code_buf; - if (nand_program_check(nand_in, &start_page) == -1) + ni->length = code_len; /* code length,not page number! */ + ni->buf = code_buf; + if (nand_program_check(ni, &start_page) == -1) return -1; - if (start_page - nand_in->start > hand.nand_ppb) + if (start_page - ni->start > hand.nand_ppb) printf(" Info - skip bad block!\n"); - nand_in->start = start_page; + ni->start = start_page; offset += code_len ; } @@ -545,12 +526,12 @@ int nand_program_file(struct nand_in *nand_in, char *fname) return -1; } - nand_in->length = j; - nand_in->buf = code_buf; - if (nand_program_check(nand_in, &start_page) == -1) + ni->length = j; + ni->buf = code_buf; + if (nand_program_check(ni, &start_page) == -1) return -1; - if (start_page - nand_in->start > hand.nand_ppb) + if (start_page - ni->start > hand.nand_ppb) printf(" Info - skip bad block!"); } @@ -559,12 +540,6 @@ int nand_program_file(struct nand_in *nand_in, char *fname) return 1; } -int nand_program_file_planes(struct nand_in *nand_in, char *fname) -{ - printf(" not implement yet !\n"); - return -1; -} - int init_nand_in(void) { nand_in.buf = code_buf; @@ -612,20 +587,19 @@ int nand_prog(void) else printf("%s", help); - if (hand.nand_plane > 1) - nand_program_file_planes(&nand_in, image_file); - else + if (hand.nand_plane == 1) nand_program_file(&nand_in, image_file); status = 1; -err: + return status; } int nand_query(void) { - int i; + int cpu, i; unsigned char csn; + unsigned short ops; if (com_argc < 3) { printf(" Usage: nquery (1) (2)\n" @@ -645,7 +619,7 @@ int nand_query(void) if (i >= nand_in.max_chip) return -1; - int cpu = get_ingenic_cpu(); + cpu = get_ingenic_cpu(); if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) { printf(" Device unboot! boot it first!\n"); return -1; @@ -654,7 +628,7 @@ int nand_query(void) csn = i; printf(" ID of No.%d device No.%d flash: \n", nand_in.dev, csn); - unsigned short ops = ((csn << 4) & 0xff0) + NAND_QUERY; + ops = ((csn << 4) & 0xff0) + NAND_QUERY; usb_ingenic_nand_ops(&ingenic_dev, ops); usb_read_data_from_ingenic(&ingenic_dev, ret, 8); printf(" Vendor ID :0x%x \n",(unsigned char)ret[0]); @@ -670,7 +644,7 @@ int nand_query(void) int nand_read(int mode) { - unsigned int i, j, cpu; + unsigned int cpu, j; unsigned int start_addr, length, page_num; unsigned char csn; unsigned short temp = 0; @@ -752,7 +726,7 @@ int nand_read(int mode) return 1; } -int debug_memory(int obj, unsigned int start, unsigned int size) +int debug_memory(unsigned int start, unsigned int size) { unsigned int buffer[8],tmp; @@ -790,7 +764,7 @@ int debug_memory(int obj, unsigned int start, unsigned int size) return -1; usleep(100); - usb_read_data_from_ingenic(&ingenic_dev, buffer, 8); + usb_read_data_from_ingenic(&ingenic_dev, (unsigned char *)buffer, 8); if (buffer[0] != 0) printf(" Test memory fail! Last error address is 0x%x !\n", buffer[0]); @@ -800,7 +774,7 @@ int debug_memory(int obj, unsigned int start, unsigned int size) return 1; } -int debug_gpio(int obj, unsigned char ops, unsigned char pin) +int debug_gpio(unsigned char ops, unsigned char pin) { unsigned int tmp; @@ -847,7 +821,7 @@ int debug_gpio(int obj, unsigned char ops, unsigned char pin) int debug_go(void) { - unsigned int addr,obj; + unsigned int addr, obj; if (com_argc<3) { printf(" Usage: go (1) (2) \n" " 1:start SDRAM address\n" @@ -866,7 +840,7 @@ int debug_go(void) return 1; } -int sdram_load(struct sdram_in *sdram_in) +int sdram_load(struct sdram_in *si) { int cpu = get_ingenic_cpu(); if (cpu != BOOT4740 && cpu != BOOT4750 && cpu != BOOT4760) { @@ -874,17 +848,17 @@ int sdram_load(struct sdram_in *sdram_in) return -1; } - if (sdram_in->length > (unsigned int) MAX_LOAD_SIZE) { + if (si->length > (unsigned int) MAX_LOAD_SIZE) { printf(" Image length too long!\n"); return -1; } - ingenic_dev.file_buff = sdram_in->buf; - ingenic_dev.file_len = sdram_in->length; + ingenic_dev.file_buff = si->buf; + ingenic_dev.file_len = si->length; usb_send_data_to_ingenic(&ingenic_dev); - usb_send_data_address_to_ingenic(&ingenic_dev, sdram_in->start); - usb_send_data_length_to_ingenic(&ingenic_dev, sdram_in->length); - usb_ingenic_sdram_ops(&ingenic_dev, sdram_in); + usb_send_data_address_to_ingenic(&ingenic_dev, si->start); + usb_send_data_length_to_ingenic(&ingenic_dev, si->length); + usb_ingenic_sdram_ops(&ingenic_dev, SDRAM_LOAD); usb_read_data_from_ingenic(&ingenic_dev, ret, 8); printf(" Load last address at 0x%x\n", @@ -893,19 +867,19 @@ int sdram_load(struct sdram_in *sdram_in) return 1; } -int sdram_load_file(struct sdram_in *sdram_in, char *file_path) +int sdram_load_file(struct sdram_in *si, char *file_path) { - struct stat fstat; - unsigned int flen,m,j,offset,k; + struct stat fst; + unsigned int flen, m, j, k; int fd, status, res = -1; - status = stat(file_path, &fstat); + status = stat(file_path, &fst); if (status < 0) { fprintf(stderr, "Error - can't get file size from '%s': %s\n", file_path, strerror(errno)); goto out; } - flen = fstat.st_size; + flen = fst.st_size; fd = open(file_path, O_RDONLY); if (fd < 0) { @@ -916,40 +890,39 @@ int sdram_load_file(struct sdram_in *sdram_in, char *file_path) m = flen / MAX_LOAD_SIZE; j = flen % MAX_LOAD_SIZE; - offset = 0; printf(" Total size to send in byte is :%d\n", flen); printf(" Loading data to SDRAM :\n"); for (k = 0; k < m; k++) { - status = read(fd, sdram_in->buf, MAX_LOAD_SIZE); + status = read(fd, si->buf, MAX_LOAD_SIZE); if (status < MAX_LOAD_SIZE) { fprintf(stderr, "Error - can't read file '%s': %s\n", file_path, strerror(errno)); goto close; } - sdram_in->length = MAX_LOAD_SIZE; - if (sdram_load(sdram_in) < 1) + si->length = MAX_LOAD_SIZE; + if (sdram_load(si) < 1) goto close; - sdram_in->start += MAX_LOAD_SIZE; + si->start += MAX_LOAD_SIZE; if ( k % 60 == 0) - printf(" 0x%x \n", sdram_in->start); + printf(" 0x%x \n", si->start); } if (j) { if (j % 4 !=0) j += 4 - (j % 4); - status = read(fd, sdram_in->buf, j); + status = read(fd, si->buf, j); if (status < j) { fprintf(stderr, "Error - can't read file '%s': %s\n", file_path, strerror(errno)); goto close; } - sdram_in->length = j; - if (sdram_load(sdram_in) < 1) + si->length = j; + if (sdram_load(si) < 1) goto close; } diff --git a/usbboot/src/cmd.h b/usbboot/src/cmd.h index b1259ab..74729fd 100644 --- a/usbboot/src/cmd.h +++ b/usbboot/src/cmd.h @@ -22,17 +22,35 @@ #include "usb_boot_defines.h" #define COMMAND_NUM 31 -#define MAX_ARGC 10 -#define MAX_COMMAND_LENGTH 100 + +struct ingenic_dev ingenic_dev; +struct hand hand; +struct sdram_in sdram_in; +struct nand_in nand_in; + +unsigned int total_size; +unsigned char code_buf[4 * 512 * 1024]; +unsigned char check_buf[4 * 512 * 1024]; +unsigned char cs[16]; +unsigned char ret[8]; + +static const char IMAGE_TYPE[][30] = { + "with oob and ecc", + "with oob and without ecc", + "without oob", +}; int boot(char *stage1_path, char *stage2_path); int init_nand_in(); +int nand_read(int mode); int nand_prog(void); int nand_query(void); int nand_erase(struct nand_in *nand_in); -int debug_memory(int obj, unsigned int start, unsigned int size); -int debug_gpio(int obj, unsigned char ops, unsigned char pin); +int debug_memory(unsigned int start, unsigned int size); +int debug_gpio(unsigned char ops, unsigned char pin); int debug_go(void); int device_reset(int ops); +int nand_markbad(struct nand_in *nand_in); +int sdram_load_file(struct sdram_in *sdram_in, char *file_path); #endif /* __CMD_H__ */ diff --git a/usbboot/src/command_line.c b/usbboot/src/command_line.c index a6dd12a..dd4a903 100644 --- a/usbboot/src/command_line.c +++ b/usbboot/src/command_line.c @@ -21,36 +21,28 @@ #include #include "usb_boot_defines.h" #include "ingenic_usb.h" +#include "command_line.h" #include "cmd.h" -extern struct nand_in nand_in; -extern struct sdram_in sdram_in; -extern unsigned char code_buf[4 * 512 * 1024]; - -int com_argc; -char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH]; -char * stage1; -char * stage2; - static int handle_help(void) { printf( - " boot boot device and make it in stage2\n" - " reset reset device\n" - " nprog program NAND flash\n" - " nquery query NAND flash info\n" - " nerase erase NAND flash\n" - " nmark mark a bad block in NAND flash\n" - " nread read NAND flash data with checking bad block and ECC\n" - " nreadraw read NAND flash data without checking bad block and ECC\n" - " nreadoob read NAND flash oob\n" - " gpios set one GPIO to high level\n" - " gpioc set one GPIO to low level\n" - " load load file data to SDRAM\n" - " go execute program in SDRAM\n" - " memtest memory test\n" - " help print this help\n" - " exit \n"); + " boot boot device and make it in stage2\n" + " reset reset device\n" + " nquery query NAND flash info\n" + " nprog program NAND flash\n" + " nerase erase NAND flash\n" + " nmark mark a bad block in NAND flash\n" + " nread read NAND flash data with checking bad block and ECC\n" + " nreadraw read NAND flash data without checking bad block and ECC\n" + " nreadoob read NAND flash oob\n" + " gpios set one GPIO to high level\n" + " gpioc set one GPIO to low level\n" + " load load file data to SDRAM\n" + " go execute program in SDRAM\n" + " memtest memory test\n" + " help print this help\n" + " exit\n"); return 0; } @@ -128,7 +120,7 @@ int handle_memtest(void) size = 0; } - debug_memory(atoi(com_argv[1]), start, size); + debug_memory(start, size); return 0; } @@ -142,7 +134,7 @@ int handle_gpio(int mode) return -1; } - debug_gpio(atoi(com_argv[2]), mode, atoi(com_argv[1])); + debug_gpio(mode, atoi(com_argv[1])); return 0; } @@ -175,7 +167,7 @@ int command_handle(char *buf) com_argc = 0; strcpy(com_argv[com_argc++], p); - while (p = strtok(NULL, "\n ")) + while ((p = strtok(NULL, "\n ")) != NULL) strcpy(com_argv[com_argc++], p); if (!strcmp("boot", com_argv[0])) @@ -211,7 +203,7 @@ int command_handle(char *buf) else if (!strcmp("exit", com_argv[0])) return -1; else - printf(" type `help` show all commands\n", com_argv[0]); + printf(" type `help` show all commands\n"); return 0; } diff --git a/usbboot/src/command_line.h b/usbboot/src/command_line.h index f5be524..37b09e7 100644 --- a/usbboot/src/command_line.h +++ b/usbboot/src/command_line.h @@ -19,6 +19,14 @@ #ifndef __COMMAND_LINE_H__ #define __COMMAND_LINE_H__ +#define MAX_ARGC 10 +#define MAX_COMMAND_LENGTH 100 + +int com_argc; +char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH]; +char *stage1; +char *stage2; + int command_handle(char *buf); #endif /* __COMMAND_LINE_H__ */ diff --git a/usbboot/src/ingenic_cfg.c b/usbboot/src/ingenic_cfg.c index c8c4f6e..885cc71 100644 --- a/usbboot/src/ingenic_cfg.c +++ b/usbboot/src/ingenic_cfg.c @@ -18,67 +18,67 @@ #include #include -#include +#include #include #include "ingenic_cfg.h" #include "usb_boot_defines.h" extern unsigned int total_size; -int check_dump_cfg(struct hand *hand) +int check_dump_cfg(struct hand *h) { printf("Now checking whether all configure args valid:"); /* check PLL */ - if (hand->fw_args.ext_clk > 27 || hand->fw_args.ext_clk < 12) { + if (h->fw_args.ext_clk > 27 || h->fw_args.ext_clk < 12) { printf(" EXTCLK setting invalid!\n"); return 0; } - if (hand->fw_args.phm_div > 32 || hand->fw_args.ext_clk < 2) { + if (h->fw_args.phm_div > 32 || h->fw_args.ext_clk < 2) { printf(" PHMDIV setting invalid!\n"); return 0; } - if ((hand->fw_args.cpu_speed * hand->fw_args.ext_clk ) % 12 != 0) { + if ((h->fw_args.cpu_speed * h->fw_args.ext_clk ) % 12 != 0) { printf(" CPUSPEED setting invalid!\n"); return 0; } /* check SDRAM */ - if (hand->fw_args.bus_width > 1 ) { + if (h->fw_args.bus_width > 1 ) { printf(" SDRAMWIDTH setting invalid!\n"); return 0; } - if (hand->fw_args.bank_num > 1 ) { + if (h->fw_args.bank_num > 1 ) { printf(" BANKNUM setting invalid!\n"); return 0; } - if (hand->fw_args.row_addr > 13 && hand->fw_args.row_addr < 11 ) { + if (h->fw_args.row_addr > 13 && h->fw_args.row_addr < 11 ) { printf(" ROWADDR setting invalid!\n"); return 0; } - if (hand->fw_args.col_addr > 13 && hand->fw_args.col_addr < 11 ) { + if (h->fw_args.col_addr > 13 && h->fw_args.col_addr < 11 ) { printf(" COLADDR setting invalid!\n"); return 0; } /* check NAND */ - if (hand->nand_ps < 2048 && hand->nand_os > 16) { + if (h->nand_ps < 2048 && h->nand_os > 16) { printf(" PAGESIZE or OOBSIZE setting invalid!\n"); - printf(" PAGESIZE is %d,\t OOBSIZE is %d\n", - hand->nand_ps, hand->nand_os); + printf(" PAGESIZE is %d,\t OOBSIZE is %d\n", + h->nand_ps, h->nand_os); return 0; } - if (hand->nand_ps < 2048 && hand->nand_ppb > 32) { + if (h->nand_ps < 2048 && h->nand_ppb > 32) { printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n"); return 0; } - if (hand->nand_ps > 512 && hand->nand_os <= 16) { + if (h->nand_ps > 512 && h->nand_os <= 16) { printf(" PAGESIZE or OOBSIZE setting invalid!\n"); - printf(" PAGESIZE is %d,\t OOBSIZE is %d\n", - hand->nand_ps, hand->nand_os); + printf(" PAGESIZE is %d,\t OOBSIZE is %d\n", + h->nand_ps, h->nand_os); return 0; } - if (hand->nand_ps > 512 && hand->nand_ppb < 64) { + if (h->nand_ps > 512 && h->nand_ppb < 64) { printf(" PAGESIZE or PAGEPERBLOCK setting invalid!\n"); return 0; } @@ -86,13 +86,13 @@ int check_dump_cfg(struct hand *hand) printf("Current device setup information:\n"); printf("Crystal work at %dMHz, the CCLK up to %dMHz and PMH_CLK up to %dMHz\n", - hand->fw_args.ext_clk, - (unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk, - ((unsigned int)hand->fw_args.cpu_speed * hand->fw_args.ext_clk) / hand->fw_args.phm_div); + h->fw_args.ext_clk, + (unsigned int)h->fw_args.cpu_speed * h->fw_args.ext_clk, + ((unsigned int)h->fw_args.cpu_speed * h->fw_args.ext_clk) / h->fw_args.phm_div); printf("SDRAM Total size is %d MB, work in %d bank and %d bit mode\n", - total_size / 0x100000, 2 * (hand->fw_args.bank_num + 1), - 16 * (2 - hand->fw_args.bus_width)); + total_size / 0x100000, 2 * (h->fw_args.bank_num + 1), + 16 * (2 - h->fw_args.bus_width)); printf("Nand page per block %d, " "Nand page size %d, " @@ -100,23 +100,18 @@ int check_dump_cfg(struct hand *hand) "bad block offset in OOB %d, " "bad block page %d, " "use %d plane mode\n", - hand->nand_ppb, - hand->nand_ps, - hand->nand_eccpos, - hand->nand_bbpos, - hand->nand_bbpage, - hand->nand_plane); + h->nand_ppb, + h->nand_ps, + h->nand_eccpos, + h->nand_bbpos, + h->nand_bbpage, + h->nand_plane); return 1; } -int parse_configure(struct hand *hand, char * file_path) +int parse_configure(struct hand *h, char * file_path) { - if (access(file_path, F_OK)) { - fprintf(stderr, "Error - can't read configure file %s.\n", - file_path); - return -1; - } - + cfg_t *cfg; cfg_opt_t opts[] = { CFG_INT("BOUDRATE", 57600, CFGF_NONE), CFG_INT("EXTCLK", 0, CFGF_NONE), @@ -153,58 +148,63 @@ int parse_configure(struct hand *hand, char * file_path) CFG_END() }; - cfg_t *cfg; + if (access(file_path, F_OK)) { + fprintf(stderr, "Error - can't read configure file %s.\n", + file_path); + return -1; + } + cfg = cfg_init(opts, 0); if (cfg_parse(cfg, file_path) == CFG_PARSE_ERROR) return -1; - hand->fw_args.boudrate = cfg_getint(cfg, "BOUDRATE"); - hand->fw_args.ext_clk = cfg_getint(cfg, "EXTCLK"); - hand->fw_args.cpu_speed = cfg_getint(cfg, "CPUSPEED"); - hand->fw_args.phm_div = cfg_getint(cfg, "PHMDIV"); - hand->fw_args.use_uart = cfg_getint(cfg, "USEUART"); + h->fw_args.boudrate = cfg_getint(cfg, "BOUDRATE"); + h->fw_args.ext_clk = cfg_getint(cfg, "EXTCLK"); + h->fw_args.cpu_speed = cfg_getint(cfg, "CPUSPEED"); + h->fw_args.phm_div = cfg_getint(cfg, "PHMDIV"); + h->fw_args.use_uart = cfg_getint(cfg, "USEUART"); - hand->fw_args.bus_width = cfg_getint(cfg, "BUSWIDTH"); - hand->fw_args.bank_num = cfg_getint(cfg, "BANKS"); - hand->fw_args.row_addr = cfg_getint(cfg, "ROWADDR"); - hand->fw_args.col_addr = cfg_getint(cfg, "COLADDR"); + h->fw_args.bus_width = cfg_getint(cfg, "BUSWIDTH"); + h->fw_args.bank_num = cfg_getint(cfg, "BANKS"); + h->fw_args.row_addr = cfg_getint(cfg, "ROWADDR"); + h->fw_args.col_addr = cfg_getint(cfg, "COLADDR"); - hand->fw_args.is_mobile = cfg_getint(cfg, "ISMOBILE"); - hand->fw_args.is_busshare = cfg_getint(cfg, "ISBUSSHARE"); - hand->fw_args.debug_ops = cfg_getint(cfg, "DEBUGOPS"); - hand->fw_args.pin_num = cfg_getint(cfg, "PINNUM"); - hand->fw_args.start = cfg_getint(cfg, "START"); - hand->fw_args.size = cfg_getint(cfg, "SIZE"); + h->fw_args.is_mobile = cfg_getint(cfg, "ISMOBILE"); + h->fw_args.is_busshare = cfg_getint(cfg, "ISBUSSHARE"); + h->fw_args.debug_ops = cfg_getint(cfg, "DEBUGOPS"); + h->fw_args.pin_num = cfg_getint(cfg, "PINNUM"); + h->fw_args.start = cfg_getint(cfg, "START"); + h->fw_args.size = cfg_getint(cfg, "SIZE"); - hand->nand_bw = cfg_getint(cfg, "NAND_BUSWIDTH"); - hand->nand_rc = cfg_getint(cfg, "NAND_ROWCYCLES"); - hand->nand_ps = cfg_getint(cfg, "NAND_PAGESIZE"); - hand->nand_ppb = cfg_getint(cfg, "NAND_PAGEPERBLOCK"); - hand->nand_force_erase = cfg_getint(cfg, "NAND_FORCEERASE"); - hand->nand_os = cfg_getint(cfg, "NAND_OOBSIZE"); - hand->nand_eccpos = cfg_getint(cfg, "NAND_ECCPOS"); - hand->nand_bbpos = cfg_getint(cfg, "NAND_BADBLOCKPOS"); - hand->nand_bbpage = cfg_getint(cfg, "NAND_BADBLOCKPAGE"); - hand->nand_plane = cfg_getint(cfg, "NAND_PLANENUM"); - hand->nand_bchbit = cfg_getint(cfg, "NAND_BCHBIT"); - hand->nand_wppin = cfg_getint(cfg, "NAND_WPPIN"); - hand->nand_bpc = cfg_getint(cfg, "NAND_BLOCKPERCHIP"); + h->nand_bw = cfg_getint(cfg, "NAND_BUSWIDTH"); + h->nand_rc = cfg_getint(cfg, "NAND_ROWCYCLES"); + h->nand_ps = cfg_getint(cfg, "NAND_PAGESIZE"); + h->nand_ppb = cfg_getint(cfg, "NAND_PAGEPERBLOCK"); + h->nand_force_erase = cfg_getint(cfg, "NAND_FORCEERASE"); + h->nand_os = cfg_getint(cfg, "NAND_OOBSIZE"); + h->nand_eccpos = cfg_getint(cfg, "NAND_ECCPOS"); + h->nand_bbpos = cfg_getint(cfg, "NAND_BADBLOCKPOS"); + h->nand_bbpage = cfg_getint(cfg, "NAND_BADBLOCKPAGE"); + h->nand_plane = cfg_getint(cfg, "NAND_PLANENUM"); + h->nand_bchbit = cfg_getint(cfg, "NAND_BCHBIT"); + h->nand_wppin = cfg_getint(cfg, "NAND_WPPIN"); + h->nand_bpc = cfg_getint(cfg, "NAND_BLOCKPERCHIP"); cfg_free(cfg); - if (hand->fw_args.bus_width == 32) - hand->fw_args.bus_width = 0; + if (h->fw_args.bus_width == 32) + h->fw_args.bus_width = 0; else - hand->fw_args.bus_width = 1; - hand->fw_args.bank_num = hand->fw_args.bank_num / 4; - hand->fw_args.cpu_speed = hand->fw_args.cpu_speed / hand->fw_args.ext_clk; - - total_size = (unsigned int) - (2 << (hand->fw_args.row_addr + hand->fw_args.col_addr - 1)) * 2 - * (hand->fw_args.bank_num + 1) * 2 - * (2 - hand->fw_args.bus_width); + h->fw_args.bus_width = 1; + h->fw_args.bank_num = h->fw_args.bank_num / 4; + h->fw_args.cpu_speed = h->fw_args.cpu_speed / h->fw_args.ext_clk; - if (check_dump_cfg(hand) < 1) + total_size = (unsigned int) + (2 << (h->fw_args.row_addr + h->fw_args.col_addr - 1)) * 2 + * (h->fw_args.bank_num + 1) * 2 + * (2 - h->fw_args.bus_width); + + if (check_dump_cfg(h) < 1) return -1; return 1; diff --git a/usbboot/src/ingenic_cfg.h b/usbboot/src/ingenic_cfg.h index 4488d62..d5c98fa 100644 --- a/usbboot/src/ingenic_cfg.h +++ b/usbboot/src/ingenic_cfg.h @@ -20,6 +20,7 @@ #define __INGENIC_CFG_H__ #include "usb_boot_defines.h" +#include "ingenic_usb.h" int hand_init_def(struct hand *hand); int check_dump_cfg(struct hand *hand); diff --git a/usbboot/src/ingenic_usb.c b/usbboot/src/ingenic_usb.c index 36db64a..00e7301 100644 --- a/usbboot/src/ingenic_usb.c +++ b/usbboot/src/ingenic_usb.c @@ -2,7 +2,7 @@ * Copyright(C) 2009 Qi Hardware Inc., * Authors: Xiangfu Liu * Marek Lindner - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -26,22 +26,22 @@ extern unsigned int total_size; -static int get_ingenic_device(struct ingenic_dev *ingenic_dev) +static int get_ingenic_device(struct ingenic_dev *id) { - struct usb_bus *usb_busses, *usb_bus; + struct usb_bus *ub, *usb_bus; struct usb_device *usb_dev; int count = 0; - usb_busses = usb_get_busses(); + ub = 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; + for (usb_bus = ub; usb_bus != NULL; usb_bus = usb_bus->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_4740 || usb_dev->descriptor.idProduct == PRODUCT_ID_4760)) { - ingenic_dev->usb_dev = usb_dev; + id->usb_dev = usb_dev; count++; } @@ -51,22 +51,22 @@ static int get_ingenic_device(struct ingenic_dev *ingenic_dev) return count; } -static int get_ingenic_interface(struct ingenic_dev *ingenic_dev) +static int get_ingenic_interface(struct ingenic_dev *id) { struct usb_config_descriptor *usb_config_desc; struct usb_interface_descriptor *usb_if_desc; struct usb_interface *usb_if; int config_index, if_index, alt_index; - for (config_index = 0; - config_index < ingenic_dev->usb_dev->descriptor.bNumConfigurations; + for (config_index = 0; + config_index < id->usb_dev->descriptor.bNumConfigurations; config_index++) { - usb_config_desc = &ingenic_dev->usb_dev->config[config_index]; + usb_config_desc = &id->usb_dev->config[config_index]; if (!usb_config_desc) return 0; - for (if_index = 0; if_index < usb_config_desc->bNumInterfaces; + for (if_index = 0; if_index < usb_config_desc->bNumInterfaces; if_index++) { usb_if = &usb_config_desc->interface[if_index]; @@ -82,7 +82,7 @@ static int get_ingenic_interface(struct ingenic_dev *ingenic_dev) if ((usb_if_desc->bInterfaceClass == 0xff) && (usb_if_desc->bInterfaceSubClass == 0)) { - ingenic_dev->interface = + id->interface = usb_if_desc->bInterfaceNumber; return 1; } @@ -93,18 +93,18 @@ static int get_ingenic_interface(struct ingenic_dev *ingenic_dev) return 0; } -int usb_ingenic_init(struct ingenic_dev *ingenic_dev) +int usb_ingenic_init(struct ingenic_dev *id) { int num_ingenic, status = -1; - memset(ingenic_dev, 0, sizeof(struct ingenic_dev)); + memset(id, 0, sizeof(struct ingenic_dev)); usb_init(); /* usb_set_debug(255); */ usb_find_busses(); usb_find_devices(); - num_ingenic = get_ingenic_device(ingenic_dev); + num_ingenic = get_ingenic_device(id); if (num_ingenic == 0) { fprintf(stderr, "Error - no XBurst device found\n"); @@ -117,19 +117,19 @@ int usb_ingenic_init(struct ingenic_dev *ingenic_dev) goto out; } - ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev); - if (!ingenic_dev->usb_handle) { + id->usb_handle = usb_open(id->usb_dev); + if (!id->usb_handle) { fprintf(stderr, "Error - can't open XBurst device: %s\n", usb_strerror()); goto out; } - if (get_ingenic_interface(ingenic_dev) < 1) { + if (get_ingenic_interface(id) < 1) { fprintf(stderr, "Error - can't find XBurst interface\n"); goto out; } - if (usb_claim_interface(ingenic_dev->usb_handle, ingenic_dev->interface) + if (usb_claim_interface(id->usb_handle, id->interface) < 0) { fprintf(stderr, "Error - can't claim XBurst interface: %s\n", usb_strerror()); @@ -142,54 +142,54 @@ out: return status; } -int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev) +int usb_get_ingenic_cpu(struct ingenic_dev *id) { int status; - memset(&ingenic_dev->cpu_info_buff, 0, - ARRAY_SIZE(ingenic_dev->cpu_info_buff)); + memset(&id->cpu_info_buff, 0, + ARRAY_SIZE(id->cpu_info_buff)); sleep(1); - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_IN | USB_TYPE_VENDOR |USB_RECIP_DEVICE, - /* bRequest */ VR_GET_CPU_INFO, - /* wValue */ 0, - /* wIndex */ 0, - /* Data */ ingenic_dev->cpu_info_buff, - /* wLength */ 8, - USB_TIMEOUT); + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_IN | USB_TYPE_VENDOR |USB_RECIP_DEVICE, + /* bRequest */ VR_GET_CPU_INFO, + /* wValue */ 0, + /* wIndex */ 0, + /* Data */ id->cpu_info_buff, + /* wLength */ 8, + USB_TIMEOUT); - if (status != sizeof(ingenic_dev->cpu_info_buff) - 1 ) { + if (status != sizeof(id->cpu_info_buff) - 1 ) { fprintf(stderr, "Error - " "can't retrieve XBurst CPU information: %i\n", status); return status; } - ingenic_dev->cpu_info_buff[8] = '\0'; - printf(" CPU data: %s\n", ingenic_dev->cpu_info_buff); + id->cpu_info_buff[8] = '\0'; + printf(" CPU data: %s\n", id->cpu_info_buff); - if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4740V1")) return JZ4740V1; - if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4750V1")) return JZ4750V1; - if (!strcmp(ingenic_dev->cpu_info_buff,"JZ4760V1")) return JZ4760V1; - if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4740")) return BOOT4740; - if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4750")) return BOOT4750; - if (!strcmp(ingenic_dev->cpu_info_buff,"Boot4760")) return BOOT4760; + if (!strcmp(id->cpu_info_buff,"JZ4740V1")) return JZ4740V1; + if (!strcmp(id->cpu_info_buff,"JZ4750V1")) return JZ4750V1; + if (!strcmp(id->cpu_info_buff,"JZ4760V1")) return JZ4760V1; + if (!strcmp(id->cpu_info_buff,"Boot4740")) return BOOT4740; + if (!strcmp(id->cpu_info_buff,"Boot4750")) return BOOT4750; + if (!strcmp(id->cpu_info_buff,"Boot4760")) return BOOT4760; return -1; } -int usb_ingenic_flush_cache(struct ingenic_dev *ingenic_dev) +int usb_ingenic_flush_cache(struct ingenic_dev *id) { int status; - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - /* bRequest */ VR_FLUSH_CACHES, - /* wValue */ 0, - /* wIndex */ 0, - /* Data */ 0, - /* wLength */ 0, - USB_TIMEOUT); + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + /* bRequest */ VR_FLUSH_CACHES, + /* wValue */ 0, + /* wIndex */ 0, + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); if (status != 0) { fprintf(stderr, "Error - can't flush cache: %i\n", status); @@ -199,18 +199,18 @@ int usb_ingenic_flush_cache(struct ingenic_dev *ingenic_dev) return 1; } -int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, int len) +int usb_send_data_length_to_ingenic(struct ingenic_dev *id, int len) { int status; /* tell the device the length of the file to be uploaded */ - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - /* bRequest */ VR_SET_DATA_LENGTH, - /* wValue */ STAGE_ADDR_MSB(len), - /* wIndex */ STAGE_ADDR_LSB(len), - /* Data */ 0, - /* wLength */ 0, - USB_TIMEOUT); + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + /* bRequest */ VR_SET_DATA_LENGTH, + /* wValue */ STAGE_ADDR_MSB(len), + /* wIndex */ STAGE_ADDR_LSB(len), + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); if (status != 0) { fprintf(stderr, "Error - " @@ -221,19 +221,19 @@ int usb_send_data_length_to_ingenic(struct ingenic_dev *ingenic_dev, int len) return 1; } -int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, +int usb_send_data_address_to_ingenic(struct ingenic_dev *id, unsigned int stage_addr) { int status; /* tell the device the RAM address to store the file */ - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - /* bRequest */ VR_SET_DATA_ADDRESS, - /* wValue */ STAGE_ADDR_MSB(stage_addr), - /* wIndex */ STAGE_ADDR_LSB(stage_addr), - /* Data */ 0, - /* wLength */ 0, - USB_TIMEOUT); + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + /* bRequest */ VR_SET_DATA_ADDRESS, + /* wValue */ STAGE_ADDR_MSB(stage_addr), + /* wIndex */ STAGE_ADDR_LSB(stage_addr), + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); if (status != 0) { fprintf(stderr, "Error - " @@ -244,15 +244,15 @@ int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, return 1; } -int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev) +int usb_send_data_to_ingenic(struct ingenic_dev *id) { int status; - status = usb_bulk_write(ingenic_dev->usb_handle, + status = usb_bulk_write(id->usb_handle, /* endpoint */ INGENIC_OUT_ENDPOINT, - /* bulk data */ ingenic_dev->file_buff, - /* bulk data length */ ingenic_dev->file_len, - USB_TIMEOUT); - if (status < (int)ingenic_dev->file_len) { + /* bulk data */ (char *)id->file_buff, + /* bulk data length */ id->file_len, + USB_TIMEOUT); + if (status < (int)id->file_len) { fprintf(stderr, "Error - " "can't send bulk data to Ingenic CPU: %i %s\n", status, usb_strerror()); return -1; @@ -261,15 +261,15 @@ int usb_send_data_to_ingenic(struct ingenic_dev *ingenic_dev) return 1; } -int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev, +int usb_read_data_from_ingenic(struct ingenic_dev *id, unsigned char *buff, unsigned int len) { int status; - status = usb_bulk_read(ingenic_dev->usb_handle, - /* endpoint */ INGENIC_IN_ENDPOINT, - /* bulk data */ buff, + status = usb_bulk_read(id->usb_handle, + /* endpoint */ INGENIC_IN_ENDPOINT, + /* bulk data */ (char *)buff, /* bulk data length */ len, - USB_TIMEOUT); + USB_TIMEOUT); if (status < (int)len) { fprintf(stderr, "Error - " @@ -280,19 +280,19 @@ int usb_read_data_from_ingenic(struct ingenic_dev *ingenic_dev, return 1; } -int usb_ingenic_start(struct ingenic_dev *ingenic_dev, int rqst, int stage_addr) +int usb_ingenic_start(struct ingenic_dev *id, int rqst, unsigned int stage_addr) { int status; /* tell the device to start the uploaded device */ - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, /* bRequest */ rqst, - /* wValue */ STAGE_ADDR_MSB(stage_addr), - /* wIndex */ STAGE_ADDR_LSB(stage_addr), - /* Data */ 0, - /* wLength */ 0, - USB_TIMEOUT); + /* wValue */ STAGE_ADDR_MSB(stage_addr), + /* wIndex */ STAGE_ADDR_LSB(stage_addr), + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); if (status != 0) { fprintf(stderr, "Error - can't start the uploaded binary " @@ -302,60 +302,58 @@ int usb_ingenic_start(struct ingenic_dev *ingenic_dev, int rqst, int stage_addr) return 1; } -int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage) +int usb_ingenic_upload(struct ingenic_dev *id, int stage) { - int status; - + unsigned int stage_addr; unsigned int stage2_addr; - stage2_addr = total_size + 0x80000000; - stage2_addr -= CODE_SIZE; - - unsigned int stage_addr = (stage == 1 ? 0x80002000 : stage2_addr); int rqst = VR_PROGRAM_START1; - usb_send_data_address_to_ingenic(ingenic_dev, stage_addr); - printf(" Download stage %d program and execute at 0x%08x\n", + stage2_addr = 0x80000000 + total_size - CODE_SIZE; + stage_addr = (stage == 1 ? 0x80002000 : stage2_addr); + + usb_send_data_address_to_ingenic(id, stage_addr); + printf(" Download stage %d program and execute at 0x%08x\n", stage, (stage_addr)); - usb_send_data_to_ingenic(ingenic_dev); + usb_send_data_to_ingenic(id); if (stage == 2) { - if (usb_get_ingenic_cpu(ingenic_dev) < 1) + if (usb_get_ingenic_cpu(id) < 1) return -1; - usb_ingenic_flush_cache(ingenic_dev); + usb_ingenic_flush_cache(id); rqst = VR_PROGRAM_START2; } usleep(100); - if (usb_ingenic_start(ingenic_dev, rqst, stage_addr) < 1) + if (usb_ingenic_start(id, rqst, stage_addr) < 1) return -1; usleep(100); - if (usb_get_ingenic_cpu(ingenic_dev) < 1) + if (usb_get_ingenic_cpu(id) < 1) return -1; return 1; } -void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev) +void usb_ingenic_cleanup(struct ingenic_dev *id) { - if ((ingenic_dev->usb_handle) && (ingenic_dev->interface)) - usb_release_interface(ingenic_dev->usb_handle, - ingenic_dev->interface); + if ((id->usb_handle) && (id->interface)) + usb_release_interface(id->usb_handle, + id->interface); - if (ingenic_dev->usb_handle) - usb_close(ingenic_dev->usb_handle); + if (id->usb_handle) + usb_close(id->usb_handle); } -int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops) +int usb_ingenic_nand_ops(struct ingenic_dev *id, int ops) { int status; - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - /* bRequest */ VR_NAND_OPS, - /* wValue */ ops & 0xffff, - /* wIndex */ 0, - /* Data */ 0, - /* wLength */ 0, - USB_TIMEOUT); + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + /* bRequest */ VR_NAND_OPS, + /* wValue */ ops & 0xffff, + /* wIndex */ 0, + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); if (status != 0) { fprintf(stderr, "Error - " @@ -366,17 +364,17 @@ int usb_ingenic_nand_ops(struct ingenic_dev *ingenic_dev, int ops) return 1; } -int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops) +int usb_ingenic_configration(struct ingenic_dev *id, 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); + status = usb_control_msg(id->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 - " @@ -387,17 +385,17 @@ int usb_ingenic_configration(struct ingenic_dev *ingenic_dev, int ops) return 1; } -int usb_ingenic_sdram_ops(struct ingenic_dev *ingenic_dev, int ops) +int usb_ingenic_sdram_ops(struct ingenic_dev *id, int ops) { int status; - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - /* bRequest */ VR_SDRAM_OPS, - /* wValue */ ops, - /* wIndex */ 0, - /* Data */ 0, - /* wLength */ 0, - USB_TIMEOUT); + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + /* bRequest */ VR_SDRAM_OPS, + /* wValue */ ops, + /* wIndex */ 0, + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); if (status != 0) { fprintf(stderr, "Error - " @@ -408,17 +406,17 @@ int usb_ingenic_sdram_ops(struct ingenic_dev *ingenic_dev, int ops) return 1; } -int usb_ingenic_reset(struct ingenic_dev *ingenic_dev, int ops) +int usb_ingenic_reset(struct ingenic_dev *id, int ops) { int status; - status = usb_control_msg(ingenic_dev->usb_handle, - /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - /* bRequest */ VR_RESET, - /* wValue */ ops, - /* wIndex */ 0, - /* Data */ 0, - /* wLength */ 0, - USB_TIMEOUT); + status = usb_control_msg(id->usb_handle, + /* bmRequestType */ USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + /* bRequest */ VR_RESET, + /* wValue */ ops, + /* wIndex */ 0, + /* Data */ 0, + /* wLength */ 0, + USB_TIMEOUT); if (status != 0) { fprintf(stderr, "Error - " diff --git a/usbboot/src/ingenic_usb.h b/usbboot/src/ingenic_usb.h index 5a1c4b1..b42aba1 100644 --- a/usbboot/src/ingenic_usb.h +++ b/usbboot/src/ingenic_usb.h @@ -21,6 +21,7 @@ #define __INGENIC_USB_H__ #include +#include "cmd.h" #define INGENIC_OUT_ENDPOINT 0x01 #define INGENIC_IN_ENDPOINT 0x81 @@ -50,21 +51,24 @@ struct ingenic_dev { struct usb_dev_handle *usb_handle; uint8_t interface; char cpu_info_buff[9]; - char *file_buff; + unsigned char *file_buff; unsigned int file_len; }; -int usb_ingenic_init(struct ingenic_dev *ingenic_dev); -int usb_get_ingenic_cpu(struct ingenic_dev *ingenic_dev); -int usb_ingenic_upload(struct ingenic_dev *ingenic_dev, int stage); -void usb_ingenic_cleanup(struct ingenic_dev *ingenic_dev); -int usb_send_data_address_to_ingenic(struct ingenic_dev *ingenic_dev, +int usb_ingenic_init(struct ingenic_dev *id); +int usb_get_ingenic_cpu(struct ingenic_dev *id); +int usb_ingenic_upload(struct ingenic_dev *id, int stage); +void usb_ingenic_cleanup(struct ingenic_dev *id); +int usb_send_data_address_to_ingenic(struct ingenic_dev *id, unsigned int stage_addr); -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_to_ingenic(struct ingenic_dev *id); +int usb_send_data_length_to_ingenic(struct ingenic_dev *id, 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,unsigned char *buff, unsigned int len); -int usb_ingenic_reset(struct ingenic_dev *ingenic_dev, int ops); +int usb_ingenic_nand_ops(struct ingenic_dev *id, int ops); +int usb_ingenic_sdram_ops(struct ingenic_dev *id, int ops); +int usb_read_data_from_ingenic(struct ingenic_dev *id, unsigned char *buff, unsigned int len); +int usb_ingenic_reset(struct ingenic_dev *id, int ops); +int usb_ingenic_start(struct ingenic_dev *id, int rqst, unsigned int stage_addr); +int usb_ingenic_configration(struct ingenic_dev *id, int ops); #endif /* __INGENIC_USB_H__ */ diff --git a/usbboot/src/main.c b/usbboot/src/main.c index c5a12af..41bb543 100644 --- a/usbboot/src/main.c +++ b/usbboot/src/main.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) int i, loop = 0; sub_cmd[loop++] = strtok(cmdpt, ";"); - while (sub_cmd[loop++] = strtok(NULL, ";")) + while ((sub_cmd[loop++] = strtok(NULL, ";")) != NULL) if (loop >= MAX_COMMANDS) { printf(" -c only support 10 commands\n"); break; diff --git a/usbboot/src/usb_boot_defines.h b/usbboot/src/usb_boot_defines.h index 609a02a..e3fcbb3 100644 --- a/usbboot/src/usb_boot_defines.h +++ b/usbboot/src/usb_boot_defines.h @@ -83,7 +83,7 @@ enum SDRAM_OPS_TYPE { }; enum DATA_STRUCTURE_OB { - DS_flash_info , + DS_flash_info = 0, DS_hand }; diff --git a/xbboot/host-app/Makefile.am b/xbboot/host-app/Makefile.am index 96f91b9..934346e 100644 --- a/xbboot/host-app/Makefile.am +++ b/xbboot/host-app/Makefile.am @@ -1,4 +1,4 @@ -AM_CFLAGS = -pedantic -Wall -W -std=gnu99 -DDATADIR=\"$(pkgdatadir)\" +AM_CFLAGS = -Wall -W -std=gnu99 -DDATADIR=\"$(pkgdatadir)\" bin_PROGRAMS = xbboot xbboot_SOURCES = host_main.c diff --git a/xbboot/host-app/host_main.c b/xbboot/host-app/host_main.c index c834abb..f7016e2 100644 --- a/xbboot/host-app/host_main.c +++ b/xbboot/host-app/host_main.c @@ -70,6 +70,7 @@ int main(int argc, char** argv) return EXIT_SUCCESS; } + xburst_h = NULL; if (!strcmp(argv[1], "-u") || !strcmp(argv[1], "--upload")) { if (argc != 4) { show_help();