[U-Boot] [RFC PATCH 1/2 v2] nand: allow delayed initialization

Mike Frysinger vapier at gentoo.org
Sat Oct 2 21:47:20 CEST 2010


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 rather than change the default, introduce a delayed config option
people may enable.  This way the nand is only poked when someone tries
to actually use it.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
v2
	- update to current mainline

 common/cmd_nand.c       |    2 ++
 common/env_nand.c       |    8 ++++++++
 drivers/mtd/nand/nand.c |    9 +++++++++
 include/nand.h          |    5 +++++
 4 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 3f1d077..5409382 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_delayed_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..3d80510 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -359,6 +359,8 @@ void env_relocate_spec(void)
 		return;
 	}
 
+	nand_delayed_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_delayed_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_delayed_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_delayed_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..42ec40a 100644
--- a/drivers/mtd/nand/nand.c
+++ b/drivers/mtd/nand/nand.c
@@ -81,6 +81,15 @@ void nand_init(void)
 {
 	int i;
 	unsigned int size = 0;
+
+#ifdef CONFIG_SYS_NAND_DELAYED_INIT
+	static uint8_t initialized;
+	if (initialized)
+		return;
+	initialized = 1;
+	printf("Delayed NAND init: ");
+#endif
+
 	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;
diff --git a/include/nand.h b/include/nand.h
index 8bdf419..74ef73f 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -25,6 +25,11 @@
 #define _NAND_H_
 
 extern void nand_init(void);
+#ifdef CONFIG_SYS_NAND_DELAYED_INIT
+# define nand_delayed_init() nand_init()
+#else
+# define nand_delayed_init() do { } while (0)
+#endif
 
 #include <linux/mtd/compat.h>
 #include <linux/mtd/mtd.h>
-- 
1.7.3.1



More information about the U-Boot mailing list