Re: [U-Boot-Users] [PATCH] add explicit bbt creation to commandline

2008-07-07 Thread Scott Wood
On Sun, Jul 06, 2008 at 04:04:56PM +0800, Harald Welte wrote:
 - do_nand: ask for confirmation for nand erase

This will break any usage in scripts.  At least, have an explicit command
such as nand erase all that doesn't ask.

 - do_nand: add command nand createbbt to erase NAND and create a new BBT

Please do any new NAND development against the u-boot-nand-flash testing
tree (and CC me and include NAND in the subject on any NAND patches).

-Scott

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users


[U-Boot-Users] [PATCH] add explicit bbt creation to commandline

2008-07-06 Thread Harald Welte
[PATCH] add explicit bbt creation to commandline (nand createbbt command)

This patch adds user-requested BBT creation. It includes the following changes:

- common/cmd_nand.c: move yes/no decision to separate function
- do_nand: ask for confirmation for nand erase
- do_nand: add command nand createbbt to erase NAND and create a new BBT

Signed-off-by: Werner Almesberger [EMAIL PROTECTED]
Signed-off-by: Harald Welte [EMAIL PROTECTED]

---

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index bb46f34..2f41157 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -162,6 +162,17 @@ out:
return 0;
 }
 
+static int yes(void)
+{
+   char c;
+
+   c = getc();
+   if (c != 'y'  c != 'Y')
+   return 0;
+   c = getc();
+   return c == '\r' || c == '\n';
+}
+
 int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
int i, dev, ret;
@@ -231,7 +242,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char 
*argv[])
strncmp(cmd, read, 4) != 0  strncmp(cmd, write, 5) != 0 
strcmp(cmd, scrub) != 0  strcmp(cmd, markbad) != 0 
strcmp(cmd, biterr) != 0 
-   strcmp(cmd, lock) != 0  strcmp(cmd, unlock) != 0 )
+   strcmp(cmd, lock) != 0  strcmp(cmd, unlock) != 0 
+   strcmp(cmd, createbbt) != 0 )
goto usage;
 
/* the following commands operate on the current device */
@@ -286,13 +298,23 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char 
*argv[])
 are sure of what you are doing!\n
 \nReally scrub this NAND flash? y/N\n);
 
-   if (getc() == 'y'  getc() == '\r') {
+   if (yes()) {
opts.scrub = 1;
} else {
puts(scrub aborted\n);
return -1;
}
}
+   else {
+   if (opts.length == nand-size) {
+   puts(Really erase everything ? y/N\n);
+   if (!yes()) {
+   puts(erase aborted\n);
+   return -1;
+   }
+   }
+   }
+
ret = nand_erase_opts(nand, opts);
printf(%s\n, ret ? ERROR : OK);
 
@@ -461,6 +483,33 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char 
*argv[])
return 0;
}
 
+   if (strcmp(cmd, createbbt) == 0) {
+   struct nand_chip *nand_chip = nand-priv;
+   nand_erase_options_t opts;
+
+   puts(Create BBT and erase everything ? y/N\n);
+   if (!yes()) {
+   puts(createbbt aborted\n);
+   return -1;
+   }
+   memset(opts, 0, sizeof(opts));
+   opts.length = nand-size;
+   if (nand_erase_opts(nand, opts)) {
+   puts(Erase failed\n);
+   return 1;
+   }
+   nand_chip-options = ~NAND_DONT_CREATE_BBT;
+   puts(Creating BBT. Please wait ...);
+   if (nand_default_bbt(nand)) {
+   puts(\nFailed\n);
+   return 1;
+   }
+   else {
+   puts(\n);
+   return 0;
+   }
+   }
+
 usage:
printf(Usage:\n%s\n, cmdtp-usage);
return 1;
@@ -481,7 +530,8 @@ U_BOOT_CMD(nand, 5, 1, do_nand,
nand markbad off - mark bad block at offset (UNSAFE)\n
nand biterr off - make a bit error at offset (UNSAFE)\n
nand lock [tight] [status] - bring nand to lock state or display 
locked pages\n
-   nand unlock [offset] [size] - unlock section\n);
+   nand unlock [offset] [size] - unlock section\n
+   nand createbbt - create bad block table\n);
 
 static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
   ulong offset, ulong addr, char *cmd)
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 27d5988..3fdc25a 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -795,7 +795,8 @@ int nand_scan_bbt (struct mtd_info *mtd, struct 
nand_bbt_descr *bd)
 
len = mtd-size  (this-bbt_erase_shift + 2);
/* Allocate memory (2bit per block) */
-   this-bbt = kmalloc (len, GFP_KERNEL);
+   if (!this-bbt)
+   this-bbt = kmalloc (len, GFP_KERNEL);
if (!this-bbt) {
printk (KERN_ERR nand_scan_bbt: Out of memory\n);
return -ENOMEM;
-- 
- Harald Welte [EMAIL PROTECTED]   http://laforge.gnumonks.org/

Privacy in residential applications is a desirable marketing 

Re: [U-Boot-Users] [PATCH] add explicit bbt creation to commandline

2008-07-06 Thread Jean-Christophe PLAGNIOL-VILLARD
On 16:04 Sun 06 Jul , Harald Welte wrote:
 [PATCH] add explicit bbt creation to commandline (nand createbbt command)
 
 This patch adds user-requested BBT creation. It includes the following 
 changes:
 
 - common/cmd_nand.c: move yes/no decision to separate function
 - do_nand: ask for confirmation for nand erase
 - do_nand: add command nand createbbt to erase NAND and create a new BBT
 
 Signed-off-by: Werner Almesberger [EMAIL PROTECTED]
 Signed-off-by: Harald Welte [EMAIL PROTECTED]
 
 ---
 
 diff --git a/common/cmd_nand.c b/common/cmd_nand.c
 index bb46f34..2f41157 100644
 --- a/common/cmd_nand.c
 +++ b/common/cmd_nand.c
 @@ -162,6 +162,17 @@ out:
   return 0;
  }
  
 +static int yes(void)
 +{
 + char c;
 +
 + c = getc();
 + if (c != 'y'  c != 'Y')
 + return 0;
 + c = getc();
 + return c == '\r' || c == '\n';
 +}
 +
It will be good to have it in a re-usable header as inline.

And why not name it as ask_confirm()?

Best Regards,
J.

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users