Skip to content
Snippets Groups Projects
Commit fcecb4a5 authored by Joe Hershberger's avatar Joe Hershberger Committed by Scott Wood
Browse files

mtd: nand: Check if NAND is locked tight before lock cmds


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: default avatarJoe Hershberger <joe.hershberger@ni.com>
parent ced199dc
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment