[U-Boot] [PATCH 1/2] Changes for auto detection of NAND or OneNAND flash on u-boot
Manikandan Pillai
mani.pillai at ti.com
Mon Mar 23 12:14:03 CET 2009
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.
Signed-off-by: Manikandan Pillai <mani.pillai at ti.com>
---
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(-)
diff --git a/common/Makefile b/common/Makefile
index f13cd11..a6c55d2 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -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
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 68c673e..628bcf4 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -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
+
/************************************************************************
************************************************************************/
diff --git a/common/env_common.c b/common/env_common.c
index 6be3bb0..b692900 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -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
diff --git a/common/env_nand.c b/common/env_nand.c
index 76569da..add74c2 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -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;
diff --git a/common/env_onenand.c b/common/env_onenand.c
index dbccc79..7aaa83c 100644
--- a/common/env_onenand.c
+++ b/common/env_onenand.c
@@ -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];
diff --git a/include/common.h b/include/common.h
index b75ea60..fd3da2c 100644
--- a/include/common.h
+++ b/include/common.h
@@ -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
diff --git a/lib_arm/board.c b/lib_arm/board.c
index 09eaaf2..f52ac00 100644
--- a/lib_arm/board.c
+++ b/lib_arm/board.c
@@ -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();
--
1.5.6
More information about the U-Boot
mailing list