All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] mtd: nand: Check if NAND is locked tight before lock cmds
@ 2013-02-08 19:27 Joe Hershberger
  2013-02-23  1:14 ` [U-Boot] " Scott Wood
  0 siblings, 1 reply; 2+ messages in thread
From: Joe Hershberger @ 2013-02-08 19:27 UTC (permalink / raw)
  To: u-boot

If the NAND is locked tight, commands such as lock and unlock will not
work, but the NAND chip may not report an error.  Check the lock tight
status before attempting such operations so that an error status can be
reported if we know the operation will not succeed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---
 drivers/mtd/nand/nand_util.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 2ba0c5e..ff2d348 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -237,6 +237,14 @@ int nand_lock(struct mtd_info *mtd, int tight)
 	/* select the NAND device */
 	chip->select_chip(mtd, 0);
 
+	/* check the Lock Tight Status */
+	chip->cmdfunc(mtd, NAND_CMD_LOCK_STATUS, -1, 0);
+	if (chip->read_byte(mtd) & NAND_LOCK_STATUS_TIGHT) {
+		printf("nand_lock: Device is locked tight!\n");
+		ret = -1;
+		goto out;
+	}
+
 	chip->cmdfunc(mtd,
 		      (tight ? NAND_CMD_LOCK_TIGHT : NAND_CMD_LOCK),
 		      -1, -1);
@@ -249,6 +257,7 @@ int nand_lock(struct mtd_info *mtd, int tight)
 		ret = -1;
 	}
 
+ out:
 	/* de-select the NAND device */
 	chip->select_chip(mtd, -1);
 	return ret;
@@ -337,6 +346,15 @@ int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length,
 		goto out;
 	}
 
+	/* check the Lock Tight Status */
+	page = (int)(start >> chip->page_shift);
+	chip->cmdfunc(mtd, NAND_CMD_LOCK_STATUS, -1, page & chip->pagemask);
+	if (chip->read_byte(mtd) & NAND_LOCK_STATUS_TIGHT) {
+		printf("nand_unlock: Device is locked tight!\n");
+		ret = -1;
+		goto out;
+	}
+
 	if ((start & (mtd->erasesize - 1)) != 0) {
 		printf("nand_unlock: Start address must be beginning of "
 			"nand block!\n");
@@ -358,7 +376,6 @@ int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length,
 	length -= mtd->erasesize;
 
 	/* submit address of first page to unlock */
-	page = (int)(start >> chip->page_shift);
 	chip->cmdfunc(mtd, NAND_CMD_UNLOCK1, -1, page & chip->pagemask);
 
 	/* submit ADDRESS of LAST page to unlock */
-- 
1.7.11.5

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

* [U-Boot] mtd: nand: Check if NAND is locked tight before lock cmds
  2013-02-08 19:27 [U-Boot] [PATCH] mtd: nand: Check if NAND is locked tight before lock cmds Joe Hershberger
@ 2013-02-23  1:14 ` Scott Wood
  0 siblings, 0 replies; 2+ messages in thread
From: Scott Wood @ 2013-02-23  1:14 UTC (permalink / raw)
  To: u-boot

On Fri, Feb 08, 2013 at 09:27:19AM -0000, Joe Hershberger wrote:
> If the NAND is locked tight, commands such as lock and unlock will not
> work, but the NAND chip may not report an error.  Check the lock tight
> status before attempting such operations so that an error status can be
> reported if we know the operation will not succeed.
> 
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
> 
> ---
> drivers/mtd/nand/nand_util.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)

Applied to u-boot-nand-flash

-Scott

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

end of thread, other threads:[~2013-02-23  1:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-08 19:27 [U-Boot] [PATCH] mtd: nand: Check if NAND is locked tight before lock cmds Joe Hershberger
2013-02-23  1:14 ` [U-Boot] " Scott Wood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.