s25fl1: When unprotecting, handle case where protection bits are inverted. Add option to s25flinitilize() to unprotected on power up

This commit is contained in:
Gregory Nutt 2015-11-10 11:33:35 -06:00
parent 1ed69cd535
commit 965addb397
4 changed files with 22 additions and 7 deletions

2
arch

@ -1 +1 @@
Subproject commit 0295d52281bd513853b347afe64ee34db51199cc
Subproject commit a91eb08c8abc2cbcd3b72732dbc2ac0dfa2f2f61

@ -1 +1 @@
Subproject commit 8c8d6ec2de52b4a8e10abc0d36f6ac4391a1f202
Subproject commit a1a06e149f09bc7b1cb7317ba8dc50c730634558

View File

@ -712,7 +712,8 @@ static int s25fl1_unprotect(FAR struct s25fl1_dev_s *priv,
priv->cmdbuf[1] = sf25fl1_read_status2(priv);
priv->cmdbuf[2] = sf25fl1_read_status3(priv);
if ((priv->cmdbuf[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE)
if ((priv->cmdbuf[0] & STATUS1_BP_MASK) == STATUS1_BP_NONE &&
(priv->cmdbuf[1] & STATUS2_CMP_MASK) == 0)
{
/* Protection already disabled */
@ -729,13 +730,14 @@ static int s25fl1_unprotect(FAR struct s25fl1_dev_s *priv,
s25fl1_write_status(priv);
}
/* Set the protection mask to zero.
/* Set the protection mask to zero (and not complemented).
* REVISIT: This logic should really just re-write the BP bits as
* necessary to unprotect the range of sectors.
*/
priv->cmdbuf[0] &= ~STATUS1_BP_MASK;
s25fl1_write_status(priv);
priv->cmdbuf[1] &= ~STATUS2_CMP_MASK;
s25fl1_write_status(priv);
/* Check the new status */
@ -1422,7 +1424,7 @@ static int s25fl1_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
*
************************************************************************************/
FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi)
FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi, bool unprotect)
{
FAR struct s25fl1_dev_s *priv;
int ret;
@ -1494,6 +1496,17 @@ FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi)
usleep(50*1000);
}
/* Unprotect FLASH sectors if so requested. */
if (unprotect)
{
ret = s25fl1_unprotect(priv, 0, priv->nsectors - 1);
if (ret < 0)
{
fdbg("ERROR: Sector unprotect failed\n");
}
}
#ifdef CONFIG_S25FL1_SECTOR512 /* Simulate a 512 byte sector */
/* Allocate a buffer for the erase block cache */

View File

@ -45,6 +45,7 @@
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/fs/ioctl.h>
@ -484,7 +485,8 @@ FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev);
****************************************************************************/
struct qspi_dev_s; /* Forward reference */
FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi);
FAR struct mtd_dev_s *s25fl1_initialize(FAR struct qspi_dev_s *qspi,
bool unprotect);
/****************************************************************************
* Name: up_flashinitialize