public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] nios2: reset cfi flash before reading env
@ 2011-01-05  7:17 Thomas Chou
  2011-01-05  8:15 ` Wolfgang Denk
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Chou @ 2011-01-05  7:17 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
 board/altera/nios2-generic/nios2-generic.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c
index 89848cf..b76e479 100644
--- a/board/altera/nios2-generic/nios2-generic.c
+++ b/board/altera/nios2-generic/nios2-generic.c
@@ -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;
 }
 
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH] nios2: reset cfi flash before reading env
  2011-01-05  7:17 [U-Boot] [PATCH] nios2: reset cfi flash before reading env Thomas Chou
@ 2011-01-05  8:15 ` Wolfgang Denk
  2011-01-06  2:36   ` Thomas Chou
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Denk @ 2011-01-05  8:15 UTC (permalink / raw)
  To: u-boot

Dear Thomas Chou,

In message <1294211855-18584-1-git-send-email-thomas@wytron.com.tw> 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.
> 
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
>  board/altera/nios2-generic/nios2-generic.c |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c
> index 89848cf..b76e479 100644
> --- a/board/altera/nios2-generic/nios2-generic.c
> +++ b/board/altera/nios2-generic/nios2-generic.c
> @@ -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

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

-- 
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH] nios2: reset cfi flash before reading env
  2011-01-05  8:15 ` Wolfgang Denk
@ 2011-01-06  2:36   ` Thomas Chou
  2011-01-17 21:02     ` Wolfgang Denk
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Chou @ 2011-01-06  2:36 UTC (permalink / raw)
  To: u-boot

On 01/05/2011 04:15 PM, Wolfgang Denk wrote:
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH] nios2: reset cfi flash before reading env
  2011-01-06  2:36   ` Thomas Chou
@ 2011-01-17 21:02     ` Wolfgang Denk
  2011-01-18  2:05       ` Thomas Chou
  2011-01-18  3:13       ` [U-Boot] [PATCH v2] " Thomas Chou
  0 siblings, 2 replies; 7+ messages in thread
From: Wolfgang Denk @ 2011-01-17 21:02 UTC (permalink / raw)
  To: u-boot

Dear Thomas Chou,

In message <4D252AAB.6040308@wytron.com.tw> you wrote:
>
> > 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.
...
> 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

-- 
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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH] nios2: reset cfi flash before reading env
  2011-01-17 21:02     ` Wolfgang Denk
@ 2011-01-18  2:05       ` Thomas Chou
  2011-01-18  3:13       ` [U-Boot] [PATCH v2] " Thomas Chou
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Chou @ 2011-01-18  2:05 UTC (permalink / raw)
  To: u-boot

Dear Wolfgang,

On 01/18/2011 05:02 AM, Wolfgang Denk wrote:
>> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2] nios2: reset cfi flash before reading env
  2011-01-17 21:02     ` Wolfgang Denk
  2011-01-18  2:05       ` Thomas Chou
@ 2011-01-18  3:13       ` Thomas Chou
  2011-03-26 14:47         ` Scott McNutt
  1 sibling, 1 reply; 7+ messages in thread
From: Thomas Chou @ 2011-01-18  3:13 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
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(-)

diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c
index 89848cf..220a4c4 100644
--- a/board/altera/nios2-generic/nios2-generic.c
+++ b/board/altera/nios2-generic/nios2-generic.c
@@ -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;
 }
 
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2] nios2: reset cfi flash before reading env
  2011-01-18  3:13       ` [U-Boot] [PATCH v2] " Thomas Chou
@ 2011-03-26 14:47         ` Scott McNutt
  0 siblings, 0 replies; 7+ messages in thread
From: Scott McNutt @ 2011-03-26 14:47 UTC (permalink / raw)
  To: u-boot

Applied to:

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

Thanks,
--Scott

Thomas Chou 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.
> 
> We cannot use generic cfi flash routines, because flash_init() is
> not run yet.
> 
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> 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(-)
> 
> diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c
> index 89848cf..220a4c4 100644
> --- a/board/altera/nios2-generic/nios2-generic.c
> +++ b/board/altera/nios2-generic/nios2-generic.c
> @@ -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;
>  }
>  

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-03-26 14:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-05  7:17 [U-Boot] [PATCH] nios2: reset cfi flash before reading env Thomas Chou
2011-01-05  8:15 ` Wolfgang Denk
2011-01-06  2:36   ` Thomas Chou
2011-01-17 21:02     ` Wolfgang Denk
2011-01-18  2:05       ` Thomas Chou
2011-01-18  3:13       ` [U-Boot] [PATCH v2] " Thomas Chou
2011-03-26 14:47         ` Scott McNutt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox