Skip to contentSkip to conversation

nios2: reset cfi flash before reading env

PATCH New Thomas Chou 3 participants 7 messages Jan 5, 2011 – Mar 26, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nios2: reset cfi flash before reading env

Flash might be in unknown state when u-boot is started with jtag. And got wrong env data. So reset it in board early init.

---
 board/altera/nios2-generic/nios2-generic.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
board/altera/nios2-generic/nios2-generic.c +6 -0
index 89848cf..b76e479 100644
@@ -24,12 +24,18 @@
 
 #include <common.h>
 #include <netdev.h>
+#include <mtd/cfi_flash.h>
+#include <asm/io.h>
 
 void text_base_hook(void); /* nop hook for text_base.S */
 
 int board_early_init_f(void)
 {
 	text_base_hook();
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_SYS_FLASH_BASE)
+	writeb(AMD_CMD_RESET, CONFIG_SYS_FLASH_BASE);
+	writeb(FLASH_CMD_RESET, CONFIG_SYS_FLASH_BASE);
+#endif
 	return 0;
 }
 
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/1 nios2: reset cfi flash before reading env

Dear Thomas Chou,

Quoted 18 lines · In message <[email protected]> you wrote:

Flash might be in unknown state when u-boot is started with jtag. And got wrong env data. So reset it in board early init.

---
 board/altera/nios2-generic/nios2-generic.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
board/altera/nios2-generic/nios2-generic.c +2 -0
index 89848cf..b76e479 100644
@@ -24,12 +24,18 @@
 
 #include <common.h>
 #include <netdev.h>
+#include <mtd/cfi_flash.h>
+#include <asm/io.h>

board/altera/nios2-generic/nios2-generic.c line 38

Quoted 10 lines
board/altera/nios2-generic/nios2-generic.c +4 -0
 
 void text_base_hook(void); /* nop hook for text_base.S */
 
 int board_early_init_f(void)
 {
 	text_base_hook();
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_SYS_FLASH_BASE)
+	writeb(AMD_CMD_RESET, CONFIG_SYS_FLASH_BASE);
+	writeb(FLASH_CMD_RESET, CONFIG_SYS_FLASH_BASE);
+#endif

Instead of making fixed assumptions about flash type and it's properties here you should use generic routines from the CFI driver to do the reset.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
How many seconds are there in a year? If I tell you there are 3.155 x
10^7, you won't even try to remember it. On the other hand, who could
forget that, to within half a percent, pi seconds is  a  nanocentury.
                                               -- Tom Duff, Bell Labs
#2 lore raw

PATCH 1/1 nios2: reset cfi flash before reading env

Quoted 4 lines · Wolfgang Denk

Instead of making fixed assumptions about flash type and it's properties here you should use generic routines from the CFI driver to do the reset.

Dear Wolfgang,

env_init() goes before flash_init() in board.c. So we don't know the flash type and cannot use those generic cfi routines based on flash_info.

I followed this in cfi_flash.c

void __flash_cmd_reset(flash_info_t *info)

{
	/*
	 * We do not yet know what kind of commandset to use, so we issue
	 * the reset command in both Intel and AMD variants, in the hope
	 * that AMD flash roms ignore the Intel command.
	 */
	flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
	flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
}

I am not sure if this thing should be added to generic code, because I found powerpc skiped flash_init when board_flash_wp_on in board.c.

Best regards,
Thomas

#3 lore raw

PATCH 1/1 nios2: reset cfi flash before reading env

Dear Thomas Chou,

Quoted 4 lines · In message <[email protected]> you wrote:
Quoted 4 lines

Instead of making fixed assumptions about flash type and it's properties here you should use generic routines from the CFI driver to do the reset.

...

Quoted 6 lines

env_init() goes before flash_init() in board.c. So we don't know the flash type and cannot use those generic cfi routines based on flash_info.

I followed this in cfi_flash.c

void __flash_cmd_reset(flash_info_t *info)

I recommend you have a second, closer look. Notice that flash_cmd_reset() comes with __attribute__ weak, because it does not work as a general solution - it may work here, but other code may be needed on other flash chips.

Your code does not provide such an option.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
God is real, unless declared integer.
#4 lore raw

PATCH 1/1 nios2: reset cfi flash before reading env

Dear Wolfgang,

Quoted 8 lines · Wolfgang Denk
Quoted 1 line

void __flash_cmd_reset(flash_info_t *info)

I recommend you have a second, closer look. Notice that flash_cmd_reset() comes with __attribute__ weak, because it does not work as a general solution - it may work here, but other code may be needed on other flash chips.

Your code does not provide such an option.

Thanks a lot. I will add a weak attribute.

Best regards,
Thomas

#5 lore raw

PATCH v2 1/1 nios2: reset cfi flash before reading env

In reply to Wolfgang Denk

Flash might be in unknown state when u-boot is started with jtag. And got wrong env data. So reset it in board early init.

We cannot use generic cfi flash routines, because flash_init() is not run yet.

---
v2 use weak func to reset flash, as Wolfgang suggested.
reset the chip where env is located.

 board/altera/nios2-generic/nios2-generic.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
board/altera/nios2-generic/nios2-generic.c +16 -0
index 89848cf..220a4c4 100644
@@ -24,12 +24,28 @@
 
 #include <common.h>
 #include <netdev.h>
+#include <mtd/cfi_flash.h>
+#include <asm/io.h>
 
 void text_base_hook(void); /* nop hook for text_base.S */
 
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR)
+static void __early_flash_cmd_reset(void)
+{
+	/* reset flash before we read env */
+	writeb(AMD_CMD_RESET, CONFIG_ENV_ADDR);
+	writeb(FLASH_CMD_RESET, CONFIG_ENV_ADDR);
+}
+void early_flash_cmd_reset(void)
+	__attribute__((weak,alias("__early_flash_cmd_reset")));
+#endif
+
 int board_early_init_f(void)
 {
 	text_base_hook();
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR)
+	early_flash_cmd_reset();
+#endif
 	return 0;
 }
 
Signature · 1 line
1.7.3.4
#6 lore raw

PATCH v2 1/1 nios2: reset cfi flash before reading env

Applied to:

git://git.denx.de/u-boot-nios next

Thanks,
--Scott

Quoted 47 lines · Thomas Chou

Flash might be in unknown state when u-boot is started with jtag. And got wrong env data. So reset it in board early init.

We cannot use generic cfi flash routines, because flash_init() is not run yet.

---
v2 use weak func to reset flash, as Wolfgang suggested.
reset the chip where env is located.

 board/altera/nios2-generic/nios2-generic.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
board/altera/nios2-generic/nios2-generic.c +16 -0
index 89848cf..220a4c4 100644
@@ -24,12 +24,28 @@
 
 #include <common.h>
 #include <netdev.h>
+#include <mtd/cfi_flash.h>
+#include <asm/io.h>
 
 void text_base_hook(void); /* nop hook for text_base.S */
 
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR)
+static void __early_flash_cmd_reset(void)
+{
+	/* reset flash before we read env */
+	writeb(AMD_CMD_RESET, CONFIG_ENV_ADDR);
+	writeb(FLASH_CMD_RESET, CONFIG_ENV_ADDR);
+}
+void early_flash_cmd_reset(void)
+	__attribute__((weak,alias("__early_flash_cmd_reset")));
+#endif
+
 int board_early_init_f(void)
 {
 	text_base_hook();
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR)
+	early_flash_cmd_reset();
+#endif
 	return 0;
 }