[U-Boot-Users] [PATCH] mtd: CONFIG_NAND_LAZY_SCAN option support

Ilya Yanok yanok at emcraft.com
Thu Jun 26 11:50:02 CEST 2008


 With this option set, the nand_init() doesn't scan NAND for bad blocks.
This allows one to avoid boot delays caused by the scanning procedure for
the boards which do not need NAND for booting.

 To work with NAND having this option set, one should explicitely call
nand_lazy_scan_finish() before using the NAND chip. This function
automatically
called at the first access to NAND chip from the U-Boot command line.

Signed-off-by: Ilya Yanok <yanok at emcraft.com>
Signed-off-by: Yuri Tikhonov <yur at emcraft.com>
---
 common/cmd_nand.c            |    2 ++
 drivers/mtd/nand/nand_base.c |    5 +++++
 include/linux/mtd/nand.h     |    4 ++++
 include/nand.h               |   14 ++++++++++++++
 4 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 37eb41b..6f5d13d 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -236,6 +236,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc,
char *argv[])
     }
     nand = &nand_info[nand_curr_device];

+    nand_lazy_scan_finish(nand);
+
     if (strcmp(cmd, "bad") == 0) {
         printf("\nDevice %d bad blocks:\n", nand_curr_device);
         for (off = 0; off < nand->size; off += nand->erasesize)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 740d3fc..f3ee705 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2652,8 +2652,13 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
 #if 0
     mtd->owner = THIS_MODULE;
 #endif
+#ifdef CONFIG_NAND_LAZY_SCAN
+    this->options &= ~NAND_BBT_SCANNED;
+    return 0;
+#else
     /* Build bad block table */
     return this->scan_bbt (mtd);
+#endif
 }

 /**
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 4cc4a7d..8a6d69e 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -450,6 +450,10 @@ struct nand_bbt_descr {
 #define NAND_BBT_SAVECONTENT    0x00002000
 /* Search good / bad pattern on the first and the second page */
 #define NAND_BBT_SCAN2NDPAGE    0x00004000
+#ifdef CONFIG_NAND_LAZY_SCAN
+/* bbt is already read */
+#define NAND_BBT_SCANNED    0x80000000
+#endif

 /* The maximum number of blocks to scan for a bbt */
 #define NAND_BBT_SCAN_MAXBLOCKS 4
diff --git a/include/nand.h b/include/nand.h
index 247d346..6d3e91a 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -122,4 +122,18 @@ int nand_get_lock_status(nand_info_t *meminfo,
ulong offset);
 void board_nand_select_device(struct nand_chip *nand, int chip);
 #endif

+#ifdef CONFIG_NAND_LAZY_SCAN
+static inline void nand_lazy_scan_finish(nand_info_t *info)
+{
+    struct nand_chip *chip = info->priv;
+
+    if (!(chip->options & NAND_BBT_SCANNED)) {
+        chip->scan_bbt(info);
+        chip->options |= NAND_BBT_SCANNED;
+    }
+}
+#else
+#define nand_lazy_scan_finish(info)    do {} while(0)
+#endif
+
 #endif
-- 
1.5.4.2






More information about the U-Boot mailing list