nand_base: Add timeout for NAND reset command
Subsystems (2)
PATCH 1/1 nand_base: Add timeout for NAND reset command
Without the timeout present an infinite loop can occur if the NAND device is broken or not present.
--- drivers/mtd/nand/nand_base.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-)
drivers/mtd/nand/nand_base.c +17 -2
@@ -75,6 +75,17 @@#include <jffs2/jffs2.h> #endif +/* +* CONFIG_SYS_NAND_RESET_CNT is used as a timeout mechanism when resetting +* a flash. NAND flash is initialized prior to interrupts so standard timers +* can't be used. CONFIG_SYS_NAND_RESET_CNT should be set to a value +* which is greater than (max NAND reset time / NAND status read time). +* A conservative default of 200000 (500 us / 25 ns) is used as a default. +*/ +#ifndef CONFIG_SYS_NAND_RESET_CNT +#define CONFIG_SYS_NAND_RESET_CNT 200000 +#endif +/* Define default oob placement schemes for large and small page devices */ static struct nand_ecclayout nand_oob_8 = { .eccbytes =3 ,
@@ -524,6 +535,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, { registerstruct nand_chip *chip = mtd->priv;int ctrl =NAND_CTRL_CLE |NAND_CTRL_CHANGE ; +uint32_t rst_sts_cnt =CONFIG_SYS_NAND_RESET_CNT ;/* * Write out the command to the device.
@@ -590,7 +602,8 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, NAND_CTRL_CLE | NAND_CTRL_CHANGE); chip->cmd_ctrl (mtd,NAND_CMD_NONE ,NAND_NCE |NAND_CTRL_CHANGE ); -while (!(chip->read_byte (mtd) &NAND_STATUS_READY )) ; +while (!(chip->read_byte (mtd) &NAND_STATUS_READY ) && + (rst_sts_cnt--));return ;/* This applies to read commands */
@@ -626,6 +639,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, int column, int page_addr) { registerstruct nand_chip *chip = mtd->priv; +uint32_t rst_sts_cnt =CONFIG_SYS_NAND_RESET_CNT ;/* Emulate NAND_CMD_READOOB */ if (command ==NAND_CMD_READOOB ) {
@@ -696,7 +710,8 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); chip->cmd_ctrl (mtd,NAND_CMD_NONE ,NAND_NCE |NAND_CTRL_CHANGE ); -while (!(chip->read_byte (mtd) &NAND_STATUS_READY )) ; +while (!(chip->read_byte (mtd) &NAND_STATUS_READY ) && + (rst_sts_cnt--));return ;case NAND_CMD_RNDOUT :
Signature · 1 line
1.6.0.2.GIT
PATCH 1/1 nand_base: Add timeout for NAND reset command
drivers/mtd/nand/nand_base.c line 87
Quoted 10 lines · Peter Tyser
drivers/mtd/nand/nand_base.c +10
-0+/* +* CONFIG_SYS_NAND_RESET_CNT is used as a timeout mechanism when resetting +* a flash. NAND flash is initialized prior to interrupts so standard timers +* can't be used. CONFIG_SYS_NAND_RESET_CNT should be set to a value +* which is greater than (max NAND reset time / NAND status read time). +* A conservative default of 200000 (500 us / 25 ns) is used as a default. +*/ +#ifndef CONFIG_SYS_NAND_RESET_CNT +#define CONFIG_SYS_NAND_RESET_CNT 200000 +#endif
Where does 25 ns come from? Should the timeout be in terms of real time rather than iterations (we use get_ticks() for this purpose in fsl_elbc_nand.c)?
-Scott
PATCH 1/1 nand_base: Add timeout for NAND reset command
Quoted 15 lines · Scott Wood
drivers/mtd/nand/nand_base.c line 87
Quoted 10 lines · Peter Tyser
drivers/mtd/nand/nand_base.c +10
-0+/* +* CONFIG_SYS_NAND_RESET_CNT is used as a timeout mechanism when resetting +* a flash. NAND flash is initialized prior to interrupts so standard timers +* can't be used. CONFIG_SYS_NAND_RESET_CNT should be set to a value +* which is greater than (max NAND reset time / NAND status read time). +* A conservative default of 200000 (500 us / 25 ns) is used as a default. +*/ +#ifndef CONFIG_SYS_NAND_RESET_CNT +#define CONFIG_SYS_NAND_RESET_CNT 200000 +#endif Where does 25 ns come from? Should the timeout be in terms of real time rather than iterations (we use
get_ticks()for this purpose infsl_elbc_nand.c)?
The 25ns was calculated based on the addition of trp and trhoh from the Micron MT29F8G08 datasheet. Based on the timing diagram for a "Read Status" cycle I thought this would be the minimum cycle time needed to read the chip's status. Other chips (ST, Samsung) I glanced at had > 25 ns read status times as well.
I had tried using get_timer() (I believe nand_wait() would have been perfect to use), but that didn't work due to interrupts being disabled when NAND is probed. I didn't consider using get_ticks()... That seems much better. Is get_ticks() available for all platforms when NAND is initialized?
Assuming get_ticks() is available for all platforms, would you prefer I:
1. re-do the patch using get_ticks()
2. update nand_wait() to use get_ticks instead of get_timer() and use it
Thanks,
Peter
PATCH 1/1 nand_base: Add timeout for NAND reset command
Quoted 11 lines · Peter Tyser
The 25ns was calculated based on the addition of trp and trhoh from the Micron MT29F8G08 datasheet. Based on the timing diagram for a "Read Status" cycle I thought this would be the minimum cycle time needed to read the chip's status. Other chips (ST, Samsung) I glanced at had > 25 ns read status times as well.
I had tried using
get_timer()(I believenand_wait()would have been perfect to use), but that didn't work due to interrupts being disabled when NAND is probed. I didn't consider usingget_ticks()... That seems much better. Isget_ticks()available for all platforms when NAND is initialized?
Probably, but who knows what weirdness is out there.
Quoted 3 lines
Assuming
get_ticks()is available for all platforms, would you prefer I:
1. re-do the patch usingget_ticks()
2. updatenand_wait()to useget_ticksinstead ofget_timer()and use it
#2 looks better.
-Scott
PATCH 1/1 nand_base: Add timeout for NAND reset command
Dear Scott Wood,
Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 6 lines · Peter Tyser
The 25ns was calculated based on the addition of trp and trhoh from the Micron MT29F8G08 datasheet. Based on the timing diagram for a "Read Status" cycle I thought this would be the minimum cycle time needed to read the chip's status. Other chips (ST, Samsung) I glanced at had > 25 ns read status times as well.
Quoted 5 lines
Quoted 5 lines
I had tried using
get_timer()(I believenand_wait()would have been perfect to use), but that didn't work due to interrupts being disabled when NAND is probed. I didn't consider usingget_ticks()... That seems much better. Isget_ticks()available for all platforms when NAND is initialized?
get_ticks() not a public interface. It should not be used in any common code.
Please use get_timer().
Best regards,
Wolfgang Denk
Signature · 5 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 You can do this in a number of ways. IBM chose to do all of them. Why do you find that funny? -- D. Taylor, Computer Science 350
PATCH 1/1 nand_base: Add timeout for NAND reset command
Quoted 16 lines · Wolfgang Denk
Dear Scott Wood,
Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 6 lines · Peter Tyser
The 25ns was calculated based on the addition of trp and trhoh from the Micron MT29F8G08 datasheet. Based on the timing diagram for a "Read Status" cycle I thought this would be the minimum cycle time needed to read the chip's status. Other chips (ST, Samsung) I glanced at had > 25 ns read status times as well.
Quoted 5 lines
Quoted 5 lines
I had tried using
get_timer()(I believenand_wait()would have been perfect to use), but that didn't work due to interrupts being disabled when NAND is probed. I didn't consider usingget_ticks()... That seems much better. Isget_ticks()available for all platforms when NAND is initialized?
Quoted 4 lines
get_ticks()not a public interface. It should not be used in any common code.Please use
get_timer().
The problem is that the NAND code is used prior to interrupts being enabled, thus we can't use get_timer(). I used a hokey delay based on (read times * number of iterations). Whats worse, my hokey loop or get_ticks()?
Thanks,
Peter
PATCH 1/1 nand_base: Add timeout for NAND reset command
Dear Peter Tyser,
Quoted 5 lines · In message <[email protected]> you wrote:
Quoted 5 lines
get_ticks()not a public interface. It should not be used in any common code.Please use
get_timer().
Ah, I see.
Quoted 4 lines
The problem is that the NAND code is used prior to interrupts being enabled, thus we can't use
get_timer(). I used a hokey delay based on (read times * number of iterations). Whats worse, my hokey loop orget_ticks()?
I can't tell. Thing is that get_ticks() may or may not exist. I don't think all architectures have it. I don't see it for ixp, leon*, mcf*, microblaze, mips, nios*, ...
Best regards,
Wolfgang Denk
Signature · 5 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 "There is nothing new under the sun, but there are lots of old things we don't know yet." - Ambrose Bierce
PATCH 1/1 nand_base: Add timeout for NAND reset command
In reply to Wolfgang DenkQuoted 2 lines · Wolfgang Denk
get_ticks()not a public interface. It should not be used in any common code.
Then what is it doing in include/common.h?
Quoted 1 line
Please use
get_timer().
But as was pointed out, that depends on interrupts, and thus does not work until very late in the boot process.
-Scott
PATCH 1/1 nand_base: Add timeout for NAND reset command
Dear Scott,
Quoted 10 lines · In message <[email protected]> you wrote:
Quoted 3 lines
get_ticks()not a public interface. It should not be used in any common code.Then what is it doing in
include/common.h?Quoted 1 line
Please use
get_timer().But as was pointed out, that depends on interrupts, and thus does not work until very late in the boot process.
I see.
But get_ticks() is an internal interface that may, or may not be preset. There are architectures where it does not exist.
Best regards,
Wolfgang Denk
Signature · 5 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 If I ever needed a brain transplant, I'd choose a teenager's because I'd want a brain that had never been used.
PATCH 1/1 nand_base: Add timeout for NAND reset command
Hi Scott,
Quoted 11 lines · Wolfgang Denk
Dear Scott,
Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 3 lines
get_ticks()not a public interface. It should not be used in any common code.Then what is it doing in
include/common.h?Quoted 1 line
Please use
get_timer().
Quoted 7 lines
Quoted 2 lines
But as was pointed out, that depends on interrupts, and thus does not work until very late in the boot process.
I see.
But
get_ticks()is an internal interface that may, or may not be preset. There are architectures where it does not exist.
Since get_ticks() and get_timer() are not available, is the patch (hokey as it is) acceptable?
Thanks,
Peter
PATCH 1/1 nand_base: Add timeout for NAND reset command
Quoted 13 lines · Peter Tyser
Hi Scott,
Quoted 10 lines · Wolfgang Denk
Dear Scott,
Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 2 lines
get_ticks()not a public interface. It should not be used in any common code.Then what is it doing in
include/common.h?Quoted 1 line
Please use
get_timer().But as was pointed out, that depends on interrupts, and thus does not work until very late in the boot process.
Quoted 7 lines
Quoted 4 lines
I see.
But
get_ticks()is an internal interface that may, or may not be preset. There are architectures where it does not exist.Since
get_ticks()andget_timer()are not available, is the patch (hokey as it is) acceptable?
Yes, I'll apply it.
-Scott
PATCH 1/1 nand_base: Add timeout for NAND reset command
In reply to Peter TyserQuoted 4 lines · Peter Tyser
Without the timeout present an infinite loop can occur if the NAND device is broken or not present.
Signed-off-by Peter Tyser <[email protected]>
Applied to u-boot-nand-flash.
-Scott