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

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@emcraft.com Signed-off-by: Yuri Tikhonov yur@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

Ilya Yanok wrote:
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);
There are other entry points that need to be covered (e.g. do_nandboot, do_onenand, env_nand, jffs2, etc). Probably better to put the call in nand_block_isbad().
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
Is there any reason not to enable this unconditionally?
Also, this patch is whitespace-mangled.
-Scott

Scott Wood wrote:
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);
There are other entry points that need to be covered (e.g. do_nandboot, do_onenand, env_nand, jffs2, etc). Probably better to put the call in nand_block_isbad().
You're right. I've added scanning in nand_block_checkbad.
Is there any reason not to enable this unconditionally?
Don't really know. I've used config option just to provide old behavior.
-- Ilya
From 6f062db5d60215447e9910d6b4a9a220fe02ef44 Mon Sep 17 00:00:00 2001
From: Ilya Yanok yanok@emcraft.com Date: Mon, 30 Jun 2008 15:34:40 +0200 Subject: [PATCH] mtd: CONFIG_NAND_LAZY_SCAN support (2nd rev)
This patch adds support for CONFIG_NAND_LAZY_SCAN configuration option. With this option enabled mtd layer wouldn't scan NAND bbt during boot, bbt will be scanned when first bad block check is performed.
Signed-off-by: Ilya Yanok yanok@emcraft.com --- drivers/mtd/nand/nand_base.c | 12 ++++++++++++ include/linux/mtd/nand.h | 4 ++++ 2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 740d3fc..c90edde 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -525,6 +525,13 @@ static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, i { struct nand_chip *this = mtd->priv;
+#ifdef CONFIG_NAND_LAZY_SCAN + if (!(this->options & NAND_BBT_SCANNED)) { + this->scan_bbt(mtd); + this->options |= NAND_BBT_SCANNED; + } +#endif + if (!this->bbt) return this->block_bad(mtd, ofs, getchip);
@@ -2652,8 +2659,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

In message 4868E96C.6000809@emcraft.com you wrote:
Is there any reason not to enable this unconditionally?
Don't really know. I've used config option just to provide old behavior.
I vote for adding this unconditionally, too.
Best regards,
Wolfgang Denk
participants (3)
-
Ilya Yanok
-
Scott Wood
-
Wolfgang Denk