From 664f9a743fec6c0eb4a253b52d9492923294d16f Mon Sep 17 00:00:00 2001 From: xiangfu Date: Mon, 8 Jun 2009 08:52:39 +0000 Subject: [PATCH] add nand erase (nerase) command --- flash-tool/cmd.c | 11 ++++------- flash-tool/cmd.h | 3 +++ flash-tool/command_line.c | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/flash-tool/cmd.c b/flash-tool/cmd.c index ee10735..2772a60 100644 --- a/flash-tool/cmd.c +++ b/flash-tool/cmd.c @@ -40,7 +40,7 @@ extern char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH]; struct ingenic_dev ingenic_dev; struct hand hand; -static struct nand_in nand_in; +struct nand_in nand_in; static struct nand_out nand_out; unsigned int total_size; unsigned char code_buf[4 * 512 * 1024]; @@ -544,6 +544,8 @@ int init_nand_in(void) nand_in.check = error_check; nand_in.dev = 0; nand_in.cs_map = cs; + memset(nand_in.cs_map, 0, MAX_DEV_NUM); + nand_in.max_chip = 16; return 0; } @@ -561,7 +563,6 @@ int nand_prog(void) "\n \t-n:\tno oob" "\n \t-o:\twith oob no ecc" "\n \t-e:\twith oob and ecc"; - init_nand_in(); if (com_argc != 6) { printf("\n not enough argument."); @@ -569,8 +570,7 @@ int nand_prog(void) return 0; } - for (i = 0; i < MAX_DEV_NUM; i++) - (nand_in.cs_map)[i] = 0; + init_nand_in(); nand_in.start = atoi(com_argv[1]); image_file = com_argv[2]; @@ -613,9 +613,6 @@ int nand_query(void) } 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; diff --git a/flash-tool/cmd.h b/flash-tool/cmd.h index 6e8fcc2..57d7fa4 100644 --- a/flash-tool/cmd.h +++ b/flash-tool/cmd.h @@ -22,6 +22,8 @@ #ifndef __CMD_H__ #define __CMD_H__ +#include "usb_boot_defines.h" + #define COMMAND_NUM 31 #define MAX_ARGC 10 #define MAX_COMMAND_LENGTH 100 @@ -29,5 +31,6 @@ int boot(char *stage1_path, char *stage2_path); int nand_prog(void); int nand_query(void); +int nand_erase(struct nand_in *nand_in); #endif /* __CMD_H__ */ diff --git a/flash-tool/command_line.c b/flash-tool/command_line.c index bc09093..922b013 100644 --- a/flash-tool/command_line.c +++ b/flash-tool/command_line.c @@ -27,6 +27,7 @@ #include "cmd.h" #include "config.h" +extern struct nand_in nand_in; int com_argc; char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH]; @@ -42,7 +43,7 @@ static const char COMMAND[][30]= "nerase", "nread", "nreadraw", - "nreadoob", + "nreadoob", /* index 10 */ "nprog", "help", "version", @@ -52,7 +53,7 @@ static const char COMMAND[][30]= "readnand", "gpios", "gpioc", - "boot", + "boot", /* index 20 */ "list", "select", "unselect", @@ -110,6 +111,37 @@ static int handle_fconfig(void) return 1; } +/* need transfer two para :blk_num ,start_blk */ +int handle_nerase(void) +{ + int i; + if (com_argc < 5) { + printf("\n Usage:"); + printf(" nerase (1) (2) (3) (4) "); + printf("\n 1:start block number" + "\n 2:block length" + "\n 3:device index number" + "\n 4:flash chip index number"); + return -1; + } + + init_nand_in(); + + nand_in.start = atoi(com_argv[1]); + nand_in.length = atoi(com_argv[2]); + nand_in.dev = atoi(com_argv[3]); + 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; + + if (nand_erase(&nand_in) < 1) + return -1; + + return 1; +} + int command_interpret(char * com_buf) { char *buf = com_buf; @@ -158,6 +190,9 @@ int command_handle(char *buf) case 6: nand_query(); break; + case 7: + handle_nerase(); + break; case 11: nand_prog(); break;