Skip to contentSkip to conversation

Changes for auto detection of NAND or OneNAND flash on u-boot

PATCH New Manikandan Pillai 2 participants 2 messages Mar 23, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Changes for auto detection of NAND or OneNAND flash on u-boot

The patch has been broken to 2 files. It has also been tested with NAND and OneNAND configuration on OMAP3 EVM board.

The following changes are for the common files.

---
 common/Makefile      |    1 +
 common/cmd_nvedit.c  |    5 +++++
 common/env_common.c  |    8 +++++++-
 common/env_nand.c    |   33 +++++++++++++++++++++++++++++++--
 common/env_onenand.c |   26 ++++++++++++++++++++++++--
 include/common.h     |   10 +++++++++-
 lib_arm/board.c      |   26 +++++++++++++++++++++++++-
 7 files changed, 102 insertions(+), 7 deletions(-)
common/Makefile +1 -0
index f13cd11..a6c55d2 100644
@@ -58,6 +58,7 @@ COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
 COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
 COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
 COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
+COBJS-$(CONFIG_ENV_IS_RUNTIME_SEL) += env_onenand.o env_nand.o
 
 # command
 COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o
common/cmd_nvedit.c +5 -0
index 68c673e..628bcf4 100644
@@ -59,6 +59,7 @@ DECLARE_GLOBAL_DATA_PTR;
     !defined(CONFIG_ENV_IS_IN_NAND)	&& \
     !defined(CONFIG_ENV_IS_IN_ONENAND)	&& \
     !defined(CONFIG_ENV_IS_IN_SPI_FLASH)	&& \
+    !defined(CONFIG_ENV_IS_RUNTIME_SEL)	&& \
     !defined(CONFIG_ENV_IS_NOWHERE)
 # error Define one of CONFIG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|ONENAND|SPI_FLASH|NOWHERE}
 #endif
@@ -66,6 +67,10 @@ DECLARE_GLOBAL_DATA_PTR;
 #define XMK_STR(x)	#x
 #define MK_STR(x)	XMK_STR(x)
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+extern saveenv_p saveenv;
+#endif
+
 /************************************************************************
 ************************************************************************/
 
common/env_common.c +7 -1
index 6be3bb0..b692900 100644
@@ -46,8 +46,13 @@ DECLARE_GLOBAL_DATA_PTR;
 
 extern env_t *env_ptr;
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+extern env_get_char_spec_p env_get_char_spec;
+extern env_relocate_spec_p env_relocate_spec;
+#else
 extern void env_relocate_spec (void);
 extern uchar env_get_char_spec(int);
+#endif
 
 static uchar env_get_char_init (int index);
 
@@ -140,7 +145,8 @@ uchar default_environment[] = {
 };
 
 #if defined(CONFIG_ENV_IS_IN_NAND)		/* Environment is in Nand Flash */ \
-	|| defined(CONFIG_ENV_IS_IN_SPI_FLASH)
+	|| defined(CONFIG_ENV_IS_IN_SPI_FLASH) \
+	|| (defined(CONFIG_CMD_NAND) && defined(CONFIG_ENV_IS_RUNTIME_SEL))
 int default_environment_size = sizeof(default_environment);
 #endif
 
common/env_nand.c +31 -2
index 76569da..add74c2 100644
@@ -65,17 +65,22 @@ int nand_legacy_rw (struct nand_chip* nand, int cmd,
 extern uchar default_environment[];
 extern int default_environment_size;
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+char *nand_env_name_spec = "NAND";
+#else
 char * env_name_spec = "NAND";
-
+#endif
 
 #ifdef ENV_IS_EMBEDDED
 extern uchar environment[];
 env_t *env_ptr = (env_t *)(&environment[0]);
+#elif defined(CONFIG_ENV_IS_RUNTIME_SEL)
+env_t *nand_env_ptr;
+env_t *env_ptr;
 #else /* ! ENV_IS_EMBEDDED */
 env_t *env_ptr = 0;
 #endif /* ENV_IS_EMBEDDED */
 
-
 /* local functions */
 #if !defined(ENV_IS_EMBEDDED)
 static void use_default(void);
@@ -83,7 +88,11 @@ static void use_default(void);
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+uchar nand_env_get_char_spec(int index)
+#else
 uchar env_get_char_spec (int index)
+#endif
 {
 	return ( *((uchar *)(gd->env_addr + index)) );
 }
@@ -100,7 +109,11 @@ uchar env_get_char_spec (int index)
  * the SPL loads not only the U-Boot image from NAND but also the
  * environment.
  */
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+int nand_env_init(void)
+#else
 int env_init(void)
+#endif
 {
 #if defined(ENV_IS_EMBEDDED)
 	size_t total;
@@ -181,7 +194,11 @@ int writeenv(size_t offset, u_char *buf)
 	return 0;
 }
 #ifdef CONFIG_ENV_OFFSET_REDUND
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+int nand_saveenv(void)
+#else
 int saveenv(void)
+#endif
 {
 	size_t total;
 	int ret = 0;
@@ -224,7 +241,11 @@ int saveenv(void)
 	return ret;
 }
 #else /* ! CONFIG_ENV_OFFSET_REDUND */
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+int nand_saveenv(void)
+#else
 int saveenv(void)
+#endif
 {
 	size_t total;
 	int ret = 0;
@@ -284,7 +305,11 @@ int readenv (size_t offset, u_char * buf)
 }
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+void nand_env_relocate_spec(void)
+#else
 void env_relocate_spec (void)
+#endif
 {
 #if !defined(ENV_IS_EMBEDDED)
 	size_t total;
@@ -343,7 +368,11 @@ void env_relocate_spec (void)
  * The legacy NAND code saved the environment in the first NAND device i.e.,
  * nand_dev_desc + 0. This is also the behaviour using the new NAND code.
  */
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+void nand_env_relocate_spec(void)
+#else
 void env_relocate_spec (void)
+#endif
 {
 #if !defined(ENV_IS_EMBEDDED)
 	int ret;
common/env_onenand.c +24 -2
index dbccc79..7aaa83c 100644
@@ -39,11 +39,19 @@ extern uchar default_environment[];
 
 #define ONENAND_ENV_SIZE(mtd)	(mtd.writesize - ENV_HEADER_SIZE)
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+char *onenand_env_name_spec = "OneNAND";
+#else
 char *env_name_spec = "OneNAND";
+#endif
 
 #ifdef ENV_IS_EMBEDDED
 extern uchar environment[];
 env_t *env_ptr = (env_t *) (&environment[0]);
+#elif defined(CONFIG_ENV_IS_RUNTIME_SEL)
+static unsigned char onenand_env[MAX_ONENAND_PAGESIZE];
+env_t *onenand_env_ptr = (env_t *)&onenand_env[0];
+extern env_t *env_ptr;
 #else /* ! ENV_IS_EMBEDDED */
 static unsigned char onenand_env[MAX_ONENAND_PAGESIZE];
 env_t *env_ptr = (env_t *) onenand_env;
@@ -51,12 +59,20 @@ env_t *env_ptr = (env_t *) onenand_env;
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+uchar onenand_env_get_char_spec(int index)
+#else
 uchar env_get_char_spec(int index)
+#endif
 {
 	return (*((uchar *) (gd->env_addr + index)));
 }
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+void onenand_env_relocate_spec(void)
+#else
 void env_relocate_spec(void)
+#endif
 {
 	unsigned long env_addr;
 	int use_default = 0;
@@ -87,7 +103,11 @@ void env_relocate_spec(void)
 	gd->env_valid = 1;
 }
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+int onenand_saveenv(void)
+#else
 int saveenv(void)
+#endif
 {
 	unsigned long env_addr = CONFIG_ENV_ADDR;
 	struct erase_info instr = {
@@ -102,7 +122,6 @@ int saveenv(void)
 		printf("OneNAND: erase failed at 0x%08lx\n", env_addr);
 		return 1;
 	}
-
 	/* update crc */
 	env_ptr->crc =
 	    crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd));
@@ -112,11 +131,14 @@ int saveenv(void)
 		printf("OneNAND: write failed at 0x%08x\n", instr.addr);
 		return 2;
 	}
-
 	return 0;
 }
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+int onenand_env_init(void)
+#else
 int env_init(void)
+#endif
 {
 	/* use default */
 	gd->env_addr = (ulong) & default_environment[0];
include/common.h +9 -1
index b75ea60..fd3da2c 100644
@@ -243,12 +243,20 @@ extern ulong load_addr;		/* Default Load Address */
 void	doc_probe(unsigned long physadr);
 
 /* common/cmd_nvedit.c */
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+typedef uchar (*env_get_char_spec_p)(int index);
+typedef int (*env_init_p)(void);
+typedef int (*saveenv_p)(void);
+typedef void (*env_relocate_spec_p)(void);
+#else
 int	env_init     (void);
+int     saveenv(void);
+#endif
 void	env_relocate (void);
 int	envmatch     (uchar *, int);
 char	*getenv	     (char *);
 int	getenv_r     (char *name, char *buf, unsigned len);
-int	saveenv	     (void);
+
 #ifdef CONFIG_PPC		/* ARM version to be fixed! */
 int inline setenv   (char *, char *);
 #else
lib_arm/board.c +25 -1
index 09eaaf2..f52ac00 100644
@@ -60,6 +60,11 @@ DECLARE_GLOBAL_DATA_PTR;
 
 ulong monitor_flash_len;
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+extern void gpmc_init_late(void);
+extern void print_board_info(void);
+#endif
+
 #ifdef CONFIG_HAS_DATAFLASH
 extern int  AT91F_DataflashInit(void);
 extern void dataflash_print_info(void);
@@ -259,12 +264,19 @@ static int arm_pci_init(void)
 typedef int (init_fnc_t) (void);
 
 int print_cpuinfo (void); /* test-only */
+#ifdef CONFIG_ENV_IS_RUNTIME_SEL
+extern env_init_p env_init;
+#endif
 
 init_fnc_t *init_sequence[] = {
 	cpu_init,		/* basic cpu dependent setup */
 	board_init,		/* basic board dependent setup */
 	interrupt_init,		/* set up exceptions */
+#ifdef CONFIG_ENV_IS_RUNTIME_SEL
+	NULL,			/* initialize environment */
+#else
 	env_init,		/* initialize environment */
+#endif
 	init_baudrate,		/* initialze baudrate settings */
 	serial_init,		/* serial communications setup */
 	console_init_f,		/* stage 1 init of console */
@@ -350,14 +362,26 @@ void start_armboot (void)
 	/* armboot_start is defined in the board-specific linker script */
 	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN);
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+	gpmc_init_late(); /* in SRAM or SDRAM, finish GPMC */
+	env_init();
+	init_baudrate();        /* initialze baudrate settings */
+	serial_init();          /* serial communications setup */
+	console_init_f();       /* stage 1 init of console */
+	display_banner();
+	print_board_info();
+#else
+
 #if defined(CONFIG_CMD_NAND)
-	puts ("NAND:  ");
+	puts("NAND:    ");
 	nand_init();		/* go init the NAND */
 #endif
 
 #if defined(CONFIG_CMD_ONENAND)
+	puts("OneNAND:  ");
 	onenand_init();
 #endif
+#endif
 
 #ifdef CONFIG_HAS_DATAFLASH
 	AT91F_DataflashInit();
Signature · 1 line
1.5.6
#1 lore raw

PATCH 1/2 Changes for auto detection of NAND or OneNAND flash on u-boot

Quoted 6 lines · Manikandan Pillai

The patch has been broken to 2 files. It has also been tested with NAND and OneNAND configuration on OMAP3 EVM board.

The following changes are for the common files.

This could use a better changelog description -- nothing in here indicates that the change has to do with the environment, much less what the nature of the change is, what situations call for it, etc.

Text like "Changes for..." aren't particularly descriptive, especially in the subject -- *all* changesets have changes in them. :-)

common/Makefile COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o · line 61

Quoted 9 lines
common/Makefile +1 -0
index f13cd11..a6c55d2 100644
@@ -58,6 +58,7 @@ COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
 COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
 COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
 COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
+COBJS-$(CONFIG_ENV_IS_RUNTIME_SEL) += env_onenand.o env_nand.o

That's quite a generic name for something that refers specifically to a choice between OneNAND and NAND, and thus implies that both are selected.

Quoted 13 lines
common/cmd_nvedit.c +1 -0
index 68c673e..628bcf4 100644
@@ -59,6 +59,7 @@ DECLARE_GLOBAL_DATA_PTR;
     !defined(CONFIG_ENV_IS_IN_NAND)	&& \
     !defined(CONFIG_ENV_IS_IN_ONENAND)	&& \
     !defined(CONFIG_ENV_IS_IN_SPI_FLASH)	&& \
+    !defined(CONFIG_ENV_IS_RUNTIME_SEL)	&& \
     !defined(CONFIG_ENV_IS_NOWHERE)
 # error Define one of CONFIG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|ONENAND|SPI_FLASH|NOWHERE}
 #endif

common/cmd_nvedit.c DECLARE_GLOBAL_DATA_PTR; · line 72

Quoted 6 lines
common/cmd_nvedit.c +3 -0
@@ -66,6 +67,10 @@ DECLARE_GLOBAL_DATA_PTR;
 #define XMK_STR(x)	#x
 #define MK_STR(x)	XMK_STR(x)
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+extern saveenv_p saveenv;
+#endif

externs belong in header files.

Quoted 8 lines
common/cmd_nvedit.c +0 -0
 /************************************************************************
 ************************************************************************/
 
common/env_common.c +0 -0
index 6be3bb0..b692900 100644

common/env_common.c DECLARE_GLOBAL_DATA_PTR; · line 55

Quoted 10 lines
common/env_common.c +5 -0
@@ -46,8 +46,13 @@ DECLARE_GLOBAL_DATA_PTR;
 
 extern env_t *env_ptr;
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+extern env_get_char_spec_p env_get_char_spec;
+extern env_relocate_spec_p env_relocate_spec;
+#else
 extern void env_relocate_spec (void);
 extern uchar env_get_char_spec(int);
+#endif

No #ifdef here. The caller interface to the functions should not change just because the implementation is changing (or if it must change, change it for *all* configurations).

In general, this patch has too many #ifdefs. Please try to refactor things into a common way rather than separating things into "that way" and "this way".

common/env_common.c DECLARE_GLOBAL_DATA_PTR;

Quoted 6 lines
common/env_common.c +4 -1
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+char *nand_env_name_spec = "NAND";
+#else
 char * env_name_spec = "NAND";
-
+#endif

This does not need an ifdef. Either namespace-protect the name and provide a weak alias, or (better IMO) just have the NAND env init code store "NAND" into a globally defined env_name_spec (or env->name or similar).

Quoted 12 lines
include/common.h +4 -0
index b75ea60..fd3da2c 100644
@@ -243,12 +243,20 @@ extern ulong load_addr;		/* Default Load Address */
 void	doc_probe(unsigned long physadr);
 
 /* common/cmd_nvedit.c */
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+typedef uchar (*env_get_char_spec_p)(int index);
+typedef int (*env_init_p)(void);
+typedef int (*saveenv_p)(void);

include/common.h extern ulong load_addr; /* Default Load Address */ · line 251

Quoted 10 lines
include/common.h +4 -1
+typedef void (*env_relocate_spec_p)(void);
+#else
 int	env_init     (void);
+int     saveenv(void);
+#endif
 void	env_relocate (void);
 int	envmatch     (uchar *, int);
 char	*getenv	     (char *);
 int	getenv_r     (char *name, char *buf, unsigned len);
-int	saveenv	     (void);

Drop the _p. We don't do hungarian notation.

Might want to group all the things that change based on environment type into one struct.

lib_arm/board.c

Quoted 7 lines
include/common.h +0 -0
 #ifdef CONFIG_PPC		/* ARM version to be fixed! */
 int inline setenv   (char *, char *);
 #else
lib_arm/board.c +0 -0
index 09eaaf2..f52ac00 100644

Is there anything in these changes that would require other architectures to change to keep from breaking?

Quoted 35 lines
lib_arm/board.c +12 -0
@@ -60,6 +60,11 @@ DECLARE_GLOBAL_DATA_PTR;
 
 ulong monitor_flash_len;
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+extern void gpmc_init_late(void);
+extern void print_board_info(void);
+#endif
+
 #ifdef CONFIG_HAS_DATAFLASH
 extern int  AT91F_DataflashInit(void);
 extern void dataflash_print_info(void);
@@ -259,12 +264,19 @@ static int arm_pci_init(void)
 typedef int (init_fnc_t) (void);
 
 int print_cpuinfo (void); /* test-only */
+#ifdef CONFIG_ENV_IS_RUNTIME_SEL
+extern env_init_p env_init;
+#endif
 
 init_fnc_t *init_sequence[] = {
 	cpu_init,		/* basic cpu dependent setup */
 	board_init,		/* basic board dependent setup */
 	interrupt_init,		/* set up exceptions */
+#ifdef CONFIG_ENV_IS_RUNTIME_SEL
+	NULL,			/* initialize environment */
+#else
 	env_init,		/* initialize environment */
+#endif
 	init_baudrate,		/* initialze baudrate settings */
 	serial_init,		/* serial communications setup */
 	console_init_f,		/* stage 1 init of console */
@@ -350,14 +362,26 @@ void start_armboot (void)
 	/* armboot_start is defined in the board-specific linker script */
 	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN);

lib_arm/board.c void start_armboot (void) · line 373

Quoted 10 lines
lib_arm/board.c +9 -0
 
+#if defined(CONFIG_ENV_IS_RUNTIME_SEL)
+	gpmc_init_late(); /* in SRAM or SDRAM, finish GPMC */
+	env_init();
+	init_baudrate();        /* initialze baudrate settings */
+	serial_init();          /* serial communications setup */
+	console_init_f();       /* stage 1 init of console */
+	display_banner();
+	print_board_info();
+#else

You appear to be calling init_baudrate(), etc. twice.

-Scott