[U-Boot] [PATCH 1/3] nand: allow demand initialization

Many people like the current nand_init() behavior where it is always initialized during boot and the flash size shown, but there are cases where we are willing to forgo this niceness for speed/functionality. So allow nand_init() to be called multiple times, and push this call down to the major NAND entry points rather than requiring the arch board files to call it all the time.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- common/cmd_nand.c | 2 ++ common/env_nand.c | 8 ++++++++ drivers/mtd/nand/nand.c | 7 +++++++ 3 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 3f1d077..e0be7e5 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -309,6 +309,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) goto usage;
+ nand_init(); + if (quiet_str) quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
diff --git a/common/env_nand.c b/common/env_nand.c index 4e8307a..3dffebd 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -359,6 +359,8 @@ void env_relocate_spec(void) return; }
+ nand_init(); + if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) puts("No Valid Environment Area found\n");
@@ -404,6 +406,8 @@ void env_relocate_spec(void) free(tmp_env1); free(tmp_env2);
+#else + nand_init(); #endif /* ! ENV_IS_EMBEDDED */ } #else /* ! CONFIG_ENV_OFFSET_REDUND */ @@ -418,6 +422,8 @@ void env_relocate_spec (void) int ret; char buf[CONFIG_ENV_SIZE];
+ nand_init(); + #if defined(CONFIG_ENV_OFFSET_OOB) ret = get_nand_env_oob(&nand_info[0], &nand_env_oob_offset); /* @@ -439,6 +445,8 @@ void env_relocate_spec (void) }
env_import(buf, 1); +#else + nand_init(); #endif /* ! ENV_IS_EMBEDDED */ } #endif /* CONFIG_ENV_OFFSET_REDUND */ diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 47d6872..4a63d5c 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -81,6 +81,13 @@ void nand_init(void) { int i; unsigned int size = 0; + static uint8_t initialized; + + if (initialized) + return; + initialized = 1; + puts("NAND: "); + for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]); size += nand_info[i].size / 1024;

Add new config options to allow people to control early initialization of NAND. The current behavior (NAND is initialized early) is unchanged, but now people may choose to disable this behavior and only initialize NAND when it would actually be used.
So that we can change the default in the future to not initialize NAND early on, we also introduce a CONFIG_MAYBE_NAND_EARLY_INIT option. If board porters do not make a choice either way, they will get a build warning. This should encourage board porters to opt in to one of the two choices by themselves. After a release or two, we can then force the remaining boards to enable the new config option, delete the compat option, and have the default behavior match the standard U-Boot policy.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- note: has not been compile tested for non-Blackfin boards
arch/arm/lib/board.c | 5 +---- arch/blackfin/lib/board.c | 10 ++-------- arch/m68k/lib/board.c | 6 +++--- arch/mips/lib/board.c | 5 +---- arch/nios2/lib/board.c | 9 ++------- arch/powerpc/lib/board.c | 6 +++--- arch/sh/lib/board.c | 3 ++- doc/feature-removal-schedule.txt | 20 ++++++++++++++++++++ drivers/mtd/nand/nand.c | 4 ++++ include/config_defaults.h | 2 ++ include/nand.h | 5 +++++ 11 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c index 5f2dfd0..eb5e180 100644 --- a/arch/arm/lib/board.c +++ b/arch/arm/lib/board.c @@ -346,10 +346,7 @@ void start_armboot (void) } #endif /* CONFIG_LCD */
-#if defined(CONFIG_CMD_NAND) - puts ("NAND: "); - nand_init(); /* go init the NAND */ -#endif + nand_early_init();
#if defined(CONFIG_CMD_ONENAND) onenand_init(); diff --git a/arch/blackfin/lib/board.c b/arch/blackfin/lib/board.c index fcfd174..5628ff4 100644 --- a/arch/blackfin/lib/board.c +++ b/arch/blackfin/lib/board.c @@ -15,6 +15,7 @@ #include <environment.h> #include <malloc.h> #include <mmc.h> +#include <nand.h> #include <net.h> #include <timestamp.h> #include <status_led.h> @@ -24,10 +25,6 @@ #include <asm/mach-common/bits/mpu.h> #include <kgdb.h>
-#ifdef CONFIG_CMD_NAND -#include <nand.h> /* cannot even include nand.h if it isnt configured */ -#endif - #ifdef CONFIG_BITBANGMII #include <miiphy.h> #endif @@ -345,10 +342,7 @@ void board_init_r(gd_t * id, ulong dest_addr) bd->bi_flashoffset = 0; #endif
-#ifdef CONFIG_CMD_NAND - puts("NAND: "); - nand_init(); /* go init the NAND */ -#endif + nand_early_init();
#ifdef CONFIG_GENERIC_MMC puts("MMC: "); diff --git a/arch/m68k/lib/board.c b/arch/m68k/lib/board.c index eba2435..5eb878b 100644 --- a/arch/m68k/lib/board.c +++ b/arch/m68k/lib/board.c @@ -593,10 +593,10 @@ void board_init_r (gd_t *id, ulong dest_addr) doc_init (); #endif
-#if defined(CONFIG_CMD_NAND) +#if defined(CONFIG_CMD_NAND) && \ + (defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT)) WATCHDOG_RESET (); - puts ("NAND: "); - nand_init(); /* go init the NAND */ + nand_early_init(); #endif
#ifdef CONFIG_BITBANGMII diff --git a/arch/mips/lib/board.c b/arch/mips/lib/board.c index 0044b19..869635f 100644 --- a/arch/mips/lib/board.c +++ b/arch/mips/lib/board.c @@ -330,10 +330,7 @@ void board_init_r (gd_t *id, ulong dest_addr) bd->bi_flashoffset = 0; #endif
-#ifdef CONFIG_CMD_NAND - puts ("NAND: "); - nand_init (); /* go init the NAND */ -#endif + nand_early_init();
#if defined(CONFIG_CMD_ONENAND) onenand_init(); diff --git a/arch/nios2/lib/board.c b/arch/nios2/lib/board.c index f83e691..a1ebcae 100644 --- a/arch/nios2/lib/board.c +++ b/arch/nios2/lib/board.c @@ -36,9 +36,7 @@ #if defined(CONFIG_SYS_NIOS_EPCSBASE) #include <nios2-epcs.h> #endif -#ifdef CONFIG_CMD_NAND -#include <nand.h> /* cannot even include nand.h if it isnt configured */ -#endif +#include <nand.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -130,10 +128,7 @@ void board_init (void) bd->bi_flashsize = flash_init(); #endif
-#ifdef CONFIG_CMD_NAND - puts("NAND: "); - nand_init(); -#endif + nand_early_init();
#ifdef CONFIG_GENERIC_MMC puts("MMC: "); diff --git a/arch/powerpc/lib/board.c b/arch/powerpc/lib/board.c index bfdfa86..163af4a 100644 --- a/arch/powerpc/lib/board.c +++ b/arch/powerpc/lib/board.c @@ -763,10 +763,10 @@ void board_init_r (gd_t *id, ulong dest_addr) spi_init_r (); #endif
-#if defined(CONFIG_CMD_NAND) +#if defined(CONFIG_CMD_NAND) && \ + (defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT)) WATCHDOG_RESET (); - puts ("NAND: "); - nand_init(); /* go init the NAND */ + nand_early_init(); #endif
#ifdef CONFIG_GENERIC_MMC diff --git a/arch/sh/lib/board.c b/arch/sh/lib/board.c index c97e20c..f01fb7d 100644 --- a/arch/sh/lib/board.c +++ b/arch/sh/lib/board.c @@ -51,7 +51,8 @@ static int sh_flash_init(void) return 0; }
-#if defined(CONFIG_CMD_NAND) +#if defined(CONFIG_CMD_NAND) && \ + (defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT)) # include <nand.h> # define INIT_FUNC_NAND_INIT nand_init, #else diff --git a/doc/feature-removal-schedule.txt b/doc/feature-removal-schedule.txt index ffe2615..1c2f6b5 100644 --- a/doc/feature-removal-schedule.txt +++ b/doc/feature-removal-schedule.txt @@ -34,6 +34,26 @@ Why: The implementation of U-Boot for the ARM architecture has
---------------------------
+What: CONFIG_NAND_MAYBE_EARLY_INIT option +When: Release 2011-03 + +Why: U-boot's policy is to initialize hardware only when needed. The + NAND code however predates this and explicitly initializes the hardware + during board init. In order to transition to a sane default (only + initialize NAND when it is going to be used) without breaking existing + boards, this option has been introduced. Board porters should select + one of two options in their board config: + (1) #undef CONFIG_NAND_MAYBE_EARLY_INIT (recommended) + (2) #define CONFIG_NAND_EARLY_INIT + This way people who wish to retain the old behavior may do so, but the + default for new boards follows the standard U-boot policy. Boards which + have not made a decision will have one made for them when this option is + removed in the future. + +Who: Mike Frysinger vapier@gentoo.org + +--------------------------- + What: CONFIG_NET_MULTI option When: Release 2009-11
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 4a63d5c..a8a6292 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -77,6 +77,10 @@ static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
}
+#if defined(CONFIG_NAND_MAYBE_EARLY_INIT) && !defined(CONFIG_NAND_EARLY_INIT) +# warning "Please read CONFIG_NAND_MAYBE_EARLY_INIT in doc/feature-removal-schedule.txt" +#endif + void nand_init(void) { int i; diff --git a/include/config_defaults.h b/include/config_defaults.h index abdf3be..f8de0a5 100644 --- a/include/config_defaults.h +++ b/include/config_defaults.h @@ -18,4 +18,6 @@ #define CONFIG_GZIP 1 #define CONFIG_ZLIB 1
+#define CONFIG_NAND_MAYBE_EARLY_INIT 1 + #endif diff --git a/include/nand.h b/include/nand.h index 8bdf419..bae62d2 100644 --- a/include/nand.h +++ b/include/nand.h @@ -25,6 +25,11 @@ #define _NAND_H_
extern void nand_init(void); +#if defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT) +# define nand_early_init() nand_init() +#else +# define nand_early_init() do {} while (0) +#endif
#include <linux/mtd/compat.h> #include <linux/mtd/mtd.h>

Hello Mike,
I tested this patch series with da850evm plus NAND support; I can confirm that the #warning is issued as expected; furthermore that when configured with environment specified by env.oob the board boots and obtains its environment, as expected , both with '#undef CONFIG_NAND_MAYBE_EARLY_INIT" and "#define CONFIG_NAND_EARLY_INIT"
Tested-by: Ben Gardiner bengardiner@nanometrics.ca
Just one little nitpick:
On Sun, Oct 10, 2010 at 6:40 AM, Mike Frysinger vapier@gentoo.org wrote: [snip]
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 4a63d5c..a8a6292 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -77,6 +77,10 @@ static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
}
+#if defined(CONFIG_NAND_MAYBE_EARLY_INIT) && !defined(CONFIG_NAND_EARLY_INIT) +# warning "Please read CONFIG_NAND_MAYBE_EARLY_INIT in doc/feature-removal-schedule.txt"
checkpatch warns "line over 80 characters"
Best Regards, Ben Gardiner
--- Nanometrics Inc. http://www.nanometrics.ca

Add new config options to allow people to control early initialization of NAND. The current behavior (NAND is initialized early) is unchanged, but now people may choose to disable this behavior and only initialize NAND when it would actually be used.
So that we can change the default in the future to not initialize NAND early on, we also introduce a CONFIG_MAYBE_NAND_EARLY_INIT option. If board porters do not make a choice either way, they will get a build warning. This should encourage board porters to opt in to one of the two choices by themselves. After a release or two, we can then force the remaining boards to enable the new config option, delete the compat option, and have the default behavior match the standard U-Boot policy.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- v2 - appease useless checkpatch warnings
arch/arm/lib/board.c | 5 +---- arch/blackfin/lib/board.c | 10 ++-------- arch/m68k/lib/board.c | 6 +++--- arch/mips/lib/board.c | 5 +---- arch/nios2/lib/board.c | 9 ++------- arch/powerpc/lib/board.c | 6 +++--- arch/sh/lib/board.c | 3 ++- doc/feature-removal-schedule.txt | 20 ++++++++++++++++++++ drivers/mtd/nand/nand.c | 4 ++++ include/config_defaults.h | 2 ++ include/nand.h | 5 +++++ 11 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c index 22bd2c9..7d8ed51 100644 --- a/arch/arm/lib/board.c +++ b/arch/arm/lib/board.c @@ -346,10 +346,7 @@ void start_armboot (void) } #endif /* CONFIG_LCD */
-#if defined(CONFIG_CMD_NAND) - puts ("NAND: "); - nand_init(); /* go init the NAND */ -#endif + nand_early_init();
#if defined(CONFIG_CMD_ONENAND) onenand_init(); diff --git a/arch/blackfin/lib/board.c b/arch/blackfin/lib/board.c index fcfd174..5628ff4 100644 --- a/arch/blackfin/lib/board.c +++ b/arch/blackfin/lib/board.c @@ -15,6 +15,7 @@ #include <environment.h> #include <malloc.h> #include <mmc.h> +#include <nand.h> #include <net.h> #include <timestamp.h> #include <status_led.h> @@ -24,10 +25,6 @@ #include <asm/mach-common/bits/mpu.h> #include <kgdb.h>
-#ifdef CONFIG_CMD_NAND -#include <nand.h> /* cannot even include nand.h if it isnt configured */ -#endif - #ifdef CONFIG_BITBANGMII #include <miiphy.h> #endif @@ -345,10 +342,7 @@ void board_init_r(gd_t * id, ulong dest_addr) bd->bi_flashoffset = 0; #endif
-#ifdef CONFIG_CMD_NAND - puts("NAND: "); - nand_init(); /* go init the NAND */ -#endif + nand_early_init();
#ifdef CONFIG_GENERIC_MMC puts("MMC: "); diff --git a/arch/m68k/lib/board.c b/arch/m68k/lib/board.c index eba2435..5eb878b 100644 --- a/arch/m68k/lib/board.c +++ b/arch/m68k/lib/board.c @@ -593,10 +593,10 @@ void board_init_r (gd_t *id, ulong dest_addr) doc_init (); #endif
-#if defined(CONFIG_CMD_NAND) +#if defined(CONFIG_CMD_NAND) && \ + (defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT)) WATCHDOG_RESET (); - puts ("NAND: "); - nand_init(); /* go init the NAND */ + nand_early_init(); #endif
#ifdef CONFIG_BITBANGMII diff --git a/arch/mips/lib/board.c b/arch/mips/lib/board.c index 0044b19..869635f 100644 --- a/arch/mips/lib/board.c +++ b/arch/mips/lib/board.c @@ -330,10 +330,7 @@ void board_init_r (gd_t *id, ulong dest_addr) bd->bi_flashoffset = 0; #endif
-#ifdef CONFIG_CMD_NAND - puts ("NAND: "); - nand_init (); /* go init the NAND */ -#endif + nand_early_init();
#if defined(CONFIG_CMD_ONENAND) onenand_init(); diff --git a/arch/nios2/lib/board.c b/arch/nios2/lib/board.c index f83e691..a1ebcae 100644 --- a/arch/nios2/lib/board.c +++ b/arch/nios2/lib/board.c @@ -36,9 +36,7 @@ #if defined(CONFIG_SYS_NIOS_EPCSBASE) #include <nios2-epcs.h> #endif -#ifdef CONFIG_CMD_NAND -#include <nand.h> /* cannot even include nand.h if it isnt configured */ -#endif +#include <nand.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -130,10 +128,7 @@ void board_init (void) bd->bi_flashsize = flash_init(); #endif
-#ifdef CONFIG_CMD_NAND - puts("NAND: "); - nand_init(); -#endif + nand_early_init();
#ifdef CONFIG_GENERIC_MMC puts("MMC: "); diff --git a/arch/powerpc/lib/board.c b/arch/powerpc/lib/board.c index bfdfa86..163af4a 100644 --- a/arch/powerpc/lib/board.c +++ b/arch/powerpc/lib/board.c @@ -763,10 +763,10 @@ void board_init_r (gd_t *id, ulong dest_addr) spi_init_r (); #endif
-#if defined(CONFIG_CMD_NAND) +#if defined(CONFIG_CMD_NAND) && \ + (defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT)) WATCHDOG_RESET (); - puts ("NAND: "); - nand_init(); /* go init the NAND */ + nand_early_init(); #endif
#ifdef CONFIG_GENERIC_MMC diff --git a/arch/sh/lib/board.c b/arch/sh/lib/board.c index c97e20c..f01fb7d 100644 --- a/arch/sh/lib/board.c +++ b/arch/sh/lib/board.c @@ -51,7 +51,8 @@ static int sh_flash_init(void) return 0; }
-#if defined(CONFIG_CMD_NAND) +#if defined(CONFIG_CMD_NAND) && \ + (defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT)) # include <nand.h> # define INIT_FUNC_NAND_INIT nand_init, #else diff --git a/doc/feature-removal-schedule.txt b/doc/feature-removal-schedule.txt index ffe2615..1c2f6b5 100644 --- a/doc/feature-removal-schedule.txt +++ b/doc/feature-removal-schedule.txt @@ -34,6 +34,26 @@ Why: The implementation of U-Boot for the ARM architecture has
---------------------------
+What: CONFIG_NAND_MAYBE_EARLY_INIT option +When: Release 2011-03 + +Why: U-boot's policy is to initialize hardware only when needed. The + NAND code however predates this and explicitly initializes the hardware + during board init. In order to transition to a sane default (only + initialize NAND when it is going to be used) without breaking existing + boards, this option has been introduced. Board porters should select + one of two options in their board config: + (1) #undef CONFIG_NAND_MAYBE_EARLY_INIT (recommended) + (2) #define CONFIG_NAND_EARLY_INIT + This way people who wish to retain the old behavior may do so, but the + default for new boards follows the standard U-boot policy. Boards which + have not made a decision will have one made for them when this option is + removed in the future. + +Who: Mike Frysinger vapier@gentoo.org + +--------------------------- + What: CONFIG_NET_MULTI option When: Release 2009-11
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 4a63d5c..8144e3e 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -77,6 +77,10 @@ static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
}
+#if defined(CONFIG_NAND_MAYBE_EARLY_INIT) && !defined(CONFIG_NAND_EARLY_INIT) +# warning Read CONFIG_NAND_MAYBE_EARLY_INIT in doc/feature-removal-schedule.txt +#endif + void nand_init(void) { int i; diff --git a/include/config_defaults.h b/include/config_defaults.h index abdf3be..f8de0a5 100644 --- a/include/config_defaults.h +++ b/include/config_defaults.h @@ -18,4 +18,6 @@ #define CONFIG_GZIP 1 #define CONFIG_ZLIB 1
+#define CONFIG_NAND_MAYBE_EARLY_INIT 1 + #endif diff --git a/include/nand.h b/include/nand.h index a452411..f2ac93d 100644 --- a/include/nand.h +++ b/include/nand.h @@ -25,6 +25,11 @@ #define _NAND_H_
extern void nand_init(void); +#if defined(CONFIG_NAND_MAYBE_EARLY_INIT) || defined(CONFIG_NAND_EARLY_INIT) +# define nand_early_init() nand_init() +#else +# define nand_early_init() do {} while (0) +#endif
#include <linux/mtd/compat.h> #include <linux/mtd/mtd.h>

On Tue, Oct 12, 2010 at 3:35 PM, Mike Frysinger vapier@gentoo.org wrote:
Add new config options to allow people to control early initialization of NAND. The current behavior (NAND is initialized early) is unchanged, but now people may choose to disable this behavior and only initialize NAND when it would actually be used.
So that we can change the default in the future to not initialize NAND early on, we also introduce a CONFIG_MAYBE_NAND_EARLY_INIT option. If board porters do not make a choice either way, they will get a build warning. This should encourage board porters to opt in to one of the two choices by themselves. After a release or two, we can then force the remaining boards to enable the new config option, delete the compat option, and have the default behavior match the standard U-Boot policy.
Signed-off-by: Mike Frysinger vapier@gentoo.org
v2 - appease useless checkpatch warnings
Still working as expected with v2 of 1/3 and 2/3.
Best Regards, Ben Gardiner
--- Nanometrics Inc. http://www.nanometrics.ca

Dear Mike,
is there a patch 3/3, too?
Best regards,
Wolfgang Denk

On Tuesday, October 12, 2010 16:19:20 Wolfgang Denk wrote:
is there a patch 3/3, too?
the Blackfin change is the 3/3, but that is mostly to show an example. the 1/3 and 2/3 are for the nand tree and i'll take care of 3/3 via my tree. i have to double check that some boards dont exceed their reserved 256KiB size. -mike

On Tue, Oct 12, 2010 at 03:35:32PM -0400, Mike Frysinger wrote:
Add new config options to allow people to control early initialization of NAND. The current behavior (NAND is initialized early) is unchanged, but now people may choose to disable this behavior and only initialize NAND when it would actually be used.
So that we can change the default in the future to not initialize NAND early on, we also introduce a CONFIG_MAYBE_NAND_EARLY_INIT option. If board porters do not make a choice either way, they will get a build warning. This should encourage board porters to opt in to one of the two choices by themselves. After a release or two, we can then force the remaining boards to enable the new config option, delete the compat option, and have the default behavior match the standard U-Boot policy.
Signed-off-by: Mike Frysinger vapier@gentoo.org
v2
- appease useless checkpatch warnings
arch/arm/lib/board.c | 5 +---- arch/blackfin/lib/board.c | 10 ++-------- arch/m68k/lib/board.c | 6 +++--- arch/mips/lib/board.c | 5 +---- arch/nios2/lib/board.c | 9 ++------- arch/powerpc/lib/board.c | 6 +++--- arch/sh/lib/board.c | 3 ++- doc/feature-removal-schedule.txt | 20 ++++++++++++++++++++ drivers/mtd/nand/nand.c | 4 ++++ include/config_defaults.h | 2 ++ include/nand.h | 5 +++++ 11 files changed, 45 insertions(+), 30 deletions(-)
Applied to u-boot-nand-flash.
-Scott

Now that the NAND is initialized only when used, we can enable support for it in boards that may have conflicting runtime requirements. This saves on the hassle of recompiling with different settings.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- include/configs/bf526-ezbrd.h | 7 +------ include/configs/bf527-ad7160-eval.h | 4 ---- include/configs/bf527-ezkit.h | 6 +----- include/configs/bf537-stamp.h | 2 +- include/configs/bf548-ezkit.h | 2 +- include/configs/bfin_adi_common.h | 1 + include/configs/cm-bf527.h | 11 +++++------ 7 files changed, 10 insertions(+), 23 deletions(-)
diff --git a/include/configs/bf526-ezbrd.h b/include/configs/bf526-ezbrd.h index 4c30c25..efa320e 100644 --- a/include/configs/bf526-ezbrd.h +++ b/include/configs/bf526-ezbrd.h @@ -58,27 +58,22 @@
/* * NAND Settings - * (can't be used same time as ethernet) */ #if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_NAND) -# define CONFIG_BFIN_NFC # define CONFIG_BFIN_NFC_BOOTROM_ECC #endif -#ifdef CONFIG_BFIN_NFC #define CONFIG_BFIN_NFC_CTL_VAL 0x0033 #define CONFIG_DRIVER_NAND_BFIN #define CONFIG_SYS_NAND_BASE 0 /* not actually used */ #define CONFIG_SYS_MAX_NAND_DEVICE 1 #define NAND_MAX_CHIPS 1 -#define CONFIG_CMD_NAND -#endif
/* * Network Settings */ #if !defined(__ADSPBF522__) && !defined(__ADSPBF523__) && \ - !defined(__ADSPBF524__) && !defined(__ADSPBF525__) && !defined(CONFIG_BFIN_NFC) + !defined(__ADSPBF524__) && !defined(__ADSPBF525__) #define ADI_CMDS_NETWORK 1 #define CONFIG_BFIN_MAC #define CONFIG_RMII diff --git a/include/configs/bf527-ad7160-eval.h b/include/configs/bf527-ad7160-eval.h index 14ade1b..22e6502 100644 --- a/include/configs/bf527-ad7160-eval.h +++ b/include/configs/bf527-ad7160-eval.h @@ -57,19 +57,15 @@
/* * NAND Settings - * (can't be used same time as ethernet) */ #if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_NAND) -# define CONFIG_BFIN_NFC # define CONFIG_BFIN_NFC_BOOTROM_ECC #endif -#ifdef CONFIG_BFIN_NFC #define CONFIG_BFIN_NFC_CTL_VAL 0x0033 #define CONFIG_DRIVER_NAND_BFIN #define CONFIG_SYS_NAND_BASE 0 /* not actually used */ #define CONFIG_SYS_MAX_NAND_DEVICE 1 #define NAND_MAX_CHIPS 1 -#endif
/* diff --git a/include/configs/bf527-ezkit.h b/include/configs/bf527-ezkit.h index 54fc063..2105468 100644 --- a/include/configs/bf527-ezkit.h +++ b/include/configs/bf527-ezkit.h @@ -57,26 +57,22 @@
/* * NAND Settings - * (can't be used same time as ethernet) */ #if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_NAND) -# define CONFIG_BFIN_NFC # define CONFIG_BFIN_NFC_BOOTROM_ECC #endif -#ifdef CONFIG_BFIN_NFC #define CONFIG_BFIN_NFC_CTL_VAL 0x0033 #define CONFIG_DRIVER_NAND_BFIN #define CONFIG_SYS_NAND_BASE 0 /* not actually used */ #define CONFIG_SYS_MAX_NAND_DEVICE 1 #define NAND_MAX_CHIPS 1 -#endif
/* * Network Settings */ #if !defined(__ADSPBF522__) && !defined(__ADSPBF523__) && \ - !defined(__ADSPBF524__) && !defined(__ADSPBF525__) && !defined(CONFIG_BFIN_NFC) + !defined(__ADSPBF524__) && !defined(__ADSPBF525__) #define ADI_CMDS_NETWORK 1 #define CONFIG_BFIN_MAC #define CONFIG_RMII diff --git a/include/configs/bf537-stamp.h b/include/configs/bf537-stamp.h index 22d3150..61f8f1a 100644 --- a/include/configs/bf537-stamp.h +++ b/include/configs/bf537-stamp.h @@ -145,7 +145,7 @@ /* * NAND Settings */ -/* #define CONFIG_NAND_PLAT */ +#define CONFIG_NAND_PLAT #define CONFIG_SYS_NAND_BASE 0x20212000 #define CONFIG_SYS_MAX_NAND_DEVICE 1
diff --git a/include/configs/bf548-ezkit.h b/include/configs/bf548-ezkit.h index 4412177..c883896 100644 --- a/include/configs/bf548-ezkit.h +++ b/include/configs/bf548-ezkit.h @@ -124,10 +124,10 @@ /* * NAND Settings */ -#define CONFIG_BFIN_NFC_CTL_VAL 0x0033 #if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_NAND) # define CONFIG_BFIN_NFC_BOOTROM_ECC #endif +#define CONFIG_BFIN_NFC_CTL_VAL 0x0033 #define CONFIG_DRIVER_NAND_BFIN #define CONFIG_SYS_NAND_BASE 0 /* not actually used */ #define CONFIG_SYS_MAX_NAND_DEVICE 1 diff --git a/include/configs/bfin_adi_common.h b/include/configs/bfin_adi_common.h index 608788a..83597ec 100644 --- a/include/configs/bfin_adi_common.h +++ b/include/configs/bfin_adi_common.h @@ -48,6 +48,7 @@ # if defined(CONFIG_NAND_PLAT) || defined(CONFIG_DRIVER_NAND_BFIN) # define CONFIG_CMD_NAND # define CONFIG_CMD_NAND_LOCK_UNLOCK +# undef CONFIG_NAND_MAYBE_EARLY_INIT # endif # ifdef CONFIG_POST # define CONFIG_CMD_DIAG diff --git a/include/configs/cm-bf527.h b/include/configs/cm-bf527.h index 84c9309..2bf830e 100644 --- a/include/configs/cm-bf527.h +++ b/include/configs/cm-bf527.h @@ -60,23 +60,22 @@
/* * NAND Settings - * (can't be used sametime as ethernet) */ -/* #define CONFIG_BFIN_NFC */ -#ifdef CONFIG_BFIN_NFC +#if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_NAND) +# define CONFIG_BFIN_NFC_BOOTROM_ECC +#endif #define CONFIG_BFIN_NFC_CTL_VAL 0x0033 +#define CONFIG_DRIVER_NAND_BFIN #define CONFIG_SYS_NAND_BASE 0 /* not actually used */ #define CONFIG_SYS_MAX_NAND_DEVICE 1 #define NAND_MAX_CHIPS 1 -#define CONFIG_CMD_NAND -#endif
/* * Network Settings */ #if !defined(__ADSPBF522__) && !defined(__ADSPBF523__) && \ - !defined(__ADSPBF524__) && !defined(__ADSPBF525__) && !defined(CONFIG_BFIN_NFC) + !defined(__ADSPBF524__) && !defined(__ADSPBF525__) #define ADI_CMDS_NETWORK 1 #define CONFIG_BFIN_MAC #define CONFIG_RMII

On Sun, Oct 10, 2010 at 06:37:40AM -0400, Mike Frysinger wrote:
diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 3f1d077..e0be7e5 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -309,6 +309,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) goto usage;
- nand_init();
- if (quiet_str) quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
Also do_nandboot().
diff --git a/common/env_nand.c b/common/env_nand.c index 4e8307a..3dffebd 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -359,6 +359,8 @@ void env_relocate_spec(void) return; }
- nand_init();
- if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) puts("No Valid Environment Area found\n");
@@ -404,6 +406,8 @@ void env_relocate_spec(void) free(tmp_env1); free(tmp_env2);
+#else
- nand_init();
#endif /* ! ENV_IS_EMBEDDED */
Do we really need to initialize NAND if the environment is embedded, or could it be delayed to when the environment is saved?
-Scott

On Monday, October 11, 2010 16:29:41 Scott Wood wrote:
On Sun, Oct 10, 2010 at 06:37:40AM -0400, Mike Frysinger wrote:
--- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -309,6 +309,8 @@
if (argc < 2) goto usage;
- nand_init();
Also do_nandboot().
does it need to be before the mtdparts init stuff, or can it be in nand_load_image() ?
--- a/common/env_nand.c +++ b/common/env_nand.c @@ -359,6 +359,8 @@ void env_relocate_spec(void) return; }
nand_init();
if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) puts("No Valid Environment Area found\n");
@@ -404,6 +406,8 @@ void env_relocate_spec(void) free(tmp_env1); free(tmp_env2);
+#else
- nand_init();
#endif /* ! ENV_IS_EMBEDDED */
Do we really need to initialize NAND if the environment is embedded, or could it be delayed to when the environment is saved?
the reason i picked env_relocate_spec() is because i'd have to push the init into the read/write/save code paths. and those may be executed multiple times while running. the expectation is that if you're putting the env into nand, it's going to get read, so you might as well initialize it. -mike

On Mon, 11 Oct 2010 17:02:00 -0400 Mike Frysinger vapier@gentoo.org wrote:
On Monday, October 11, 2010 16:29:41 Scott Wood wrote:
On Sun, Oct 10, 2010 at 06:37:40AM -0400, Mike Frysinger wrote:
--- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -309,6 +309,8 @@
if (argc < 2) goto usage;
- nand_init();
Also do_nandboot().
does it need to be before the mtdparts init stuff, or can it be in nand_load_image() ?
I think before -- the mtdparts init checks whether an mtd device actually exists. Though in that case, and also for things like mtdparts.spread, nand_init() should go in mtdparts_init(), and also nand_load_image() in case mtdparts aren't enabled.
--- a/common/env_nand.c +++ b/common/env_nand.c @@ -359,6 +359,8 @@ void env_relocate_spec(void) return; }
nand_init();
if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) puts("No Valid Environment Area found\n");
@@ -404,6 +406,8 @@ void env_relocate_spec(void) free(tmp_env1); free(tmp_env2);
+#else
- nand_init();
#endif /* ! ENV_IS_EMBEDDED */
Do we really need to initialize NAND if the environment is embedded, or could it be delayed to when the environment is saved?
the reason i picked env_relocate_spec() is because i'd have to push the init into the read/write/save code paths. and those may be executed multiple times while running. the expectation is that if you're putting the env into nand, it's going to get read, so you might as well initialize it.
If it's embedded, then you've already read the env out of NAND by whatever loaded the U-Boot image. You'd only need to initialize NAND if you're going to write it back, which is probably not the common case. In fact, I'm not sure when I'd use embedded-env with NAND at all unless the environment's completely read-only and thus can share an erase block with the u-boot image.
OTOH, I'm fine with leaving that as a future refinement for someone who is using embedded-env with NAND and cares about the boot time it adds.
-Scott

On Monday, October 11, 2010 17:27:33 Scott Wood wrote:
On Mon, 11 Oct 2010 17:02:00 -0400 Mike Frysinger wrote:
On Monday, October 11, 2010 16:29:41 Scott Wood wrote:
On Sun, Oct 10, 2010 at 06:37:40AM -0400, Mike Frysinger wrote:
--- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -309,6 +309,8 @@
if (argc < 2)
goto usage;
- nand_init();
Also do_nandboot().
does it need to be before the mtdparts init stuff, or can it be in nand_load_image() ?
I think before -- the mtdparts init checks whether an mtd device actually exists. Though in that case, and also for things like mtdparts.spread, nand_init() should go in mtdparts_init(), and also nand_load_image() in case mtdparts aren't enabled.
np
OTOH, I'm fine with leaving that as a future refinement for someone who is using embedded-env with NAND and cares about the boot time it adds.
i'd lean towards this too. i have no way of testing this behavior. -mike

Add new config options to allow people to control early initialization of NAND. The current behavior (NAND is initialized early) is unchanged, but now people may choose to disable this behavior and only initialize NAND when it would actually be used.
So that we can change the default in the future to not initialize NAND early on, we also introduce a CONFIG_MAYBE_NAND_EARLY_INIT option. If board porters do not make a choice either way, they will get a build warning. This should encourage board porters to opt in to one of the two choices by themselves. After a release or two, we can then force the remaining boards to enable the new config option, delete the compat option, and have the default behavior match the standard U-Boot policy.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- v2 - call nand_init() in do_nandboot() too
common/cmd_nand.c | 6 ++++++ common/env_nand.c | 8 ++++++++ drivers/mtd/nand/nand.c | 7 +++++++ 3 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 8a81237..99408b1 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -393,6 +393,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) goto usage;
+ nand_init(); + if (quiet_str) quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
@@ -811,7 +813,11 @@ int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) struct mtd_device *dev; struct part_info *part; u8 pnum; +#endif
+ nand_init(); + +#if defined(CONFIG_CMD_MTDPARTS) if (argc >= 2) { char *p = (argc == 2) ? argv[1] : argv[2]; if (!(str2long(p, &addr)) && (mtdparts_init() == 0) && diff --git a/common/env_nand.c b/common/env_nand.c index 4e8307a..3dffebd 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -359,6 +359,8 @@ void env_relocate_spec(void) return; }
+ nand_init(); + if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) puts("No Valid Environment Area found\n");
@@ -404,6 +406,8 @@ void env_relocate_spec(void) free(tmp_env1); free(tmp_env2);
+#else + nand_init(); #endif /* ! ENV_IS_EMBEDDED */ } #else /* ! CONFIG_ENV_OFFSET_REDUND */ @@ -418,6 +422,8 @@ void env_relocate_spec (void) int ret; char buf[CONFIG_ENV_SIZE];
+ nand_init(); + #if defined(CONFIG_ENV_OFFSET_OOB) ret = get_nand_env_oob(&nand_info[0], &nand_env_oob_offset); /* @@ -439,6 +445,8 @@ void env_relocate_spec (void) }
env_import(buf, 1); +#else + nand_init(); #endif /* ! ENV_IS_EMBEDDED */ } #endif /* CONFIG_ENV_OFFSET_REDUND */ diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 47d6872..4a63d5c 100644 --- a/drivers/mtd/nand/nand.c +++ b/drivers/mtd/nand/nand.c @@ -81,6 +81,13 @@ void nand_init(void) { int i; unsigned int size = 0; + static uint8_t initialized; + + if (initialized) + return; + initialized = 1; + puts("NAND: "); + for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { nand_init_chip(&nand_info[i], &nand_chip[i], base_address[i]); size += nand_info[i].size / 1024;

On Tue, Oct 12, 2010 at 03:35:15PM -0400, Mike Frysinger wrote:
Add new config options to allow people to control early initialization of NAND. The current behavior (NAND is initialized early) is unchanged, but now people may choose to disable this behavior and only initialize NAND when it would actually be used.
So that we can change the default in the future to not initialize NAND early on, we also introduce a CONFIG_MAYBE_NAND_EARLY_INIT option. If board porters do not make a choice either way, they will get a build warning. This should encourage board porters to opt in to one of the two choices by themselves. After a release or two, we can then force the remaining boards to enable the new config option, delete the compat option, and have the default behavior match the standard U-Boot policy.
Signed-off-by: Mike Frysinger vapier@gentoo.org
v2
- call nand_init() in do_nandboot() too
common/cmd_nand.c | 6 ++++++ common/env_nand.c | 8 ++++++++ drivers/mtd/nand/nand.c | 7 +++++++ 3 files changed, 21 insertions(+), 0 deletions(-)
Applied to u-boot-nand-flash.
Changed commit message to the one from v1, as this appears to be an accidental duplication of patch 2/3's commit message.
-Scott

On Friday, October 15, 2010 14:56:36 Scott Wood wrote:
Applied to u-boot-nand-flash.
awesome
Changed commit message to the one from v1, as this appears to be an accidental duplication of patch 2/3's commit message.
you're right of course ... not sure how i screwed that up. looking at my local git tree, both changesets have the right changes<->commit msg. -mike

On Fri, 15 Oct 2010 15:04:47 -0400 Mike Frysinger vapier@gentoo.org wrote:
On Friday, October 15, 2010 14:56:36 Scott Wood wrote:
Applied to u-boot-nand-flash.
awesome
I've removed the patches for now, based on Wolfgang's comments, and the discovery of additional places in the code that need to call nand_init().
-Scott

On Monday, October 18, 2010 16:16:33 Scott Wood wrote:
On Fri, 15 Oct 2010 15:04:47 -0400 Mike Frysinger wrote:
On Friday, October 15, 2010 14:56:36 Scott Wood wrote:
Applied to u-boot-nand-flash.
awesome
I've removed the patches for now, based on Wolfgang's comments
my impression was that there is future work in the mtd layers to be done, but that this didnt preclude fixing the delayed nand init issue
discovery of additional places in the code that need to call nand_init().
err, where ? all ive seen is the mtdparts stuff and you fixed that. -mike

On Tue, 19 Oct 2010 01:40:58 -0400 Mike Frysinger vapier@gentoo.org wrote:
On Monday, October 18, 2010 16:16:33 Scott Wood wrote:
On Fri, 15 Oct 2010 15:04:47 -0400 Mike Frysinger wrote:
On Friday, October 15, 2010 14:56:36 Scott Wood wrote:
Applied to u-boot-nand-flash.
awesome
I've removed the patches for now, based on Wolfgang's comments
my impression was that there is future work in the mtd layers to be done, but that this didnt preclude fixing the delayed nand init issue
discovery of additional places in the code that need to call nand_init().
err, where ? all ive seen is the mtdparts stuff and you fixed that.
http://lists.denx.de/pipermail/u-boot/2010-October/079438.html
-Scott
participants (4)
-
Ben Gardiner
-
Mike Frysinger
-
Scott Wood
-
Wolfgang Denk