diff --git a/flash-tool/Makefile b/flash-tool/Makefile index 8b96898..2b9fbff 100644 --- a/flash-tool/Makefile +++ b/flash-tool/Makefile @@ -34,7 +34,7 @@ CFLAGS += -pedantic -Wall -W -O1 -g3 -std=gnu99 LDFLAGS += -lusb -lconfuse BINARY_NAME = inflash -SRC_C= main.c usb.c cmd_boot.c command_line.c +SRC_C= main.c usb.c cmd.c command_line.c SRC_H= ingenic_usb.h usb_boot_defines.h command_line.h cmd.h config.h SRC_O= $(SRC_C:.c=.o) diff --git a/flash-tool/cmd_boot.c b/flash-tool/cmd.c similarity index 83% rename from flash-tool/cmd_boot.c rename to flash-tool/cmd.c index 0b1db74..221f173 100644 --- a/flash-tool/cmd_boot.c +++ b/flash-tool/cmd.c @@ -32,8 +32,10 @@ #include #include +struct nand_in nand_in; +struct nand_out nand_out; +struct fw_args_t fw_args; unsigned int total_size; -fw_args_t fw_args; static int parse_configure(char * file_path) { @@ -199,7 +201,7 @@ static int load_file(struct ingenic_dev *ingenic_dev, const char *file_path) goto close; } - memcpy(ingenic_dev->file_buff + 8, &fw_args, sizeof(fw_args_t)); + memcpy(ingenic_dev->file_buff + 8, &fw_args, sizeof(struct fw_args_t)); res = 1; @@ -216,7 +218,7 @@ int boot(char *stage1_path, char *stage2_path, char *config_path ){ int status; memset(&ingenic_dev, 0, sizeof(struct ingenic_dev)); - memset(&fw_args, 0, sizeof(fw_args_t)); + memset(&fw_args, 0, sizeof(struct fw_args_t)); if (parse_configure(config_path) < 1) goto out; @@ -281,3 +283,49 @@ out: usb_ingenic_cleanup(&ingenic_dev); return res; } +int nprog(int com_argc, char **com_argv) +{ +#if 0 + unsigned int i; + if (com_argc < 6) + { + printf("\n Usage:" + " nprog (1) (2) (3) (4) (5) " + "\n 1:start page number" + "\n 2:image file name" + "\n 3:device index number" + "\n 4:flash index number" + "\n 5:image type -n:no oob,-o:with oob no ecc,-e:with oob and ecc"); + + return 0; + } + for (i = 0; i < MAX_DEV_NUM; i++) + (nand_in.cs_map)[i] = 0; + if (atoi(com_argv[4]) >= MAX_DEV_NUM) { + printf("\n Flash index number overflow!"); + return -1; + } + (nand_in.cs_map)[atoi(com_argv[4])] = 1; + nand_in.start = atoi(com_argv[1]); + nand_in.dev = atoi(com_argv[3]); + + if (!strcmp(com_argv[5],"-e")) + nand_in.option = OOB_ECC; + else if (!strcmp(com_argv[5],"-o")) + nand_in.option = OOB_NO_ECC; + else + nand_in.option = NO_OOB; + + if (Hand.nand_plane > 1) + /* API_Nand_Program_File_Planes(&nand_in,&nand_out,com_argv[2]); */ + else + /* API_Nand_Program_File(&nand_in,&nand_out,com_argv[2]); */ +#if 0 + printf("\n Flash check result:"); + for (i = 0; i < 16; i++) + printf(" %d", (nand_out.status)[i]); +#endif +#endif + printf("\n not implement yet!!"); + return 1; +} diff --git a/flash-tool/cmd.h b/flash-tool/cmd.h index 1d9725f..0588e33 100644 --- a/flash-tool/cmd.h +++ b/flash-tool/cmd.h @@ -23,5 +23,6 @@ #define __CMD_H__ int boot(char *stage1_path, char *stage2_path, char *config_path); +int nprog(int com_argc, char **com_argv); #endif /* __CMD_H__ */ diff --git a/flash-tool/command_line.c b/flash-tool/command_line.c index ea999bf..aa0e62d 100644 --- a/flash-tool/command_line.c +++ b/flash-tool/command_line.c @@ -64,18 +64,6 @@ static const char COMMAND[][30]= "run" }; -void handle_exit(int res) -{ - printf("\n exiting inflash software\n"); - exit(res); -} - -int handle_nprog(void) -{ - printf("\n not implement"); - return 1; -} - int handle_help(void) { printf("\n Command support in current version:" @@ -122,11 +110,6 @@ int handle_fconfig(void) return 1; } -int handle_boot(void) -{ - return boot(STAGE1_FILE_PATH, STAGE2_FILE_PATH, CONFIG_FILE_PATH); -} - int command_input(char *buf) { char *cptr; @@ -181,20 +164,18 @@ int command_handle(char *buf) if (!cmd) return -1; switch (cmd) { case 11: - handle_nprog(); - break; + return nprog(com_argc, com_argv); case 12: handle_help(); break; case 13: handle_version(); break; - case 16: - handle_exit(0); - break; + case 16: /* exit */ + printf("\n exiting inflash software\n"); + exit(EXIT_SUCCESS); case 20: - handle_boot(); - break; + return boot(STAGE1_FILE_PATH, STAGE2_FILE_PATH, CONFIG_FILE_PATH); default: printf("\n Command not support!"); return -1; diff --git a/flash-tool/usb_boot_defines.h b/flash-tool/usb_boot_defines.h index b90a166..17e7b24 100644 --- a/flash-tool/usb_boot_defines.h +++ b/flash-tool/usb_boot_defines.h @@ -1,3 +1,24 @@ +/* + * "Ingenic flash tool" - flash the Ingenic CPU via USB + * + * (C) Copyright 2009 + * Author: Marek Lindner + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 3 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + #ifndef __JZ4740_USBDEFINES__H_ #define __JZ4740_USBDEFINES__H_ @@ -18,29 +39,25 @@ #define IOCTL_OUTBUF_SIZE 512 #define MAX_DEV_NUM 16 -enum CPUTYPE -{ +enum CPUTYPE { JZ4740, JZ4750, }; -enum USB_Boot_State -{ +enum USB_Boot_State { DISCONNECT, CONNECT, BOOT, UNBOOT }; -enum OPTION -{ +enum OPTION { OOB_ECC, OOB_NO_ECC, NO_OOB, }; -enum NOR_OPS_TYPE -{ +enum NOR_OPS_TYPE { NOR_INIT = 0, NOR_QUERY, NOR_WRITE, @@ -56,8 +73,7 @@ enum NOR_FLASH_TYPE NOR_SST39x8 }; -enum NAND_OPS_TYPE -{ +enum NAND_OPS_TYPE { NAND_QUERY = 0, NAND_INIT, NAND_MARK_BAD, @@ -69,20 +85,19 @@ enum NAND_OPS_TYPE NAND_READ_TO_RAM }; -enum SDRAM_OPS_TYPE -{ +enum SDRAM_OPS_TYPE { SDRAM_LOAD, }; -enum DATA_STRUCTURE_OB -{ +enum DATA_STRUCTURE_OB { DS_flash_info , DS_hand }; -typedef struct { +struct fw_args_t { /* CPU ID */ unsigned int cpu_id; + /* PLL args */ unsigned char ext_clk; unsigned char cpu_speed; @@ -107,9 +122,9 @@ typedef struct { /* for align */ /* unsigned char align1; */ /* unsigned char align2; */ -} __attribute__((packed)) fw_args_t; +} __attribute__((packed)); -typedef struct { +struct hand_t { /* nand flash info */ int pt; /* cpu type */ @@ -128,8 +143,31 @@ typedef struct { int nand_wppin; int nand_bpc; /* block number per chip */ - fw_args_t fw_args; + struct fw_args_t fw_args; +} __attribute__((packed)); -} __attribute__((packed)) hand_t; +struct nand_in { + unsigned char dev; + unsigned char max_chip; + unsigned char *buf; + unsigned char *cs_map; + unsigned int start; + unsigned int length; + unsigned int option; + + int (* check) (unsigned char *,unsigned char *,unsigned int); +}; + +struct nand_out { + unsigned char *status; +}; + +struct sdram_in { + unsigned char dev; + unsigned char *buf; + unsigned int start; + unsigned int length; + unsigned int option; +}; #endif /* __JZ4740_USBDEFINES__H_ */