[U-Boot] [PATCH 1/5] sf: Add status register protection mechanism

George McCollister george.mccollister at gmail.com
Mon Oct 10 20:57:57 CEST 2016


Many SPI NOR flash devices support status register protection through
one or two status register protection bits. Status register protection
enables protection of block protect and other bits from manipulation.

So far, four different status register protection methods have been
observed:

 Software         - Writes to the status register are blocked until
                    a write enable bit is set by software.
 Hardware         - Writes to the status register are blocked while
                    a pin is in a certain state.
 Power            - Writes to the status register are blocked until
                    the next power-down.
 One Time Program - Writes to the status register are permanently
                    blocked.

Signed-off-by: George McCollister <george.mccollister at gmail.com>
---
 include/spi_flash.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/spi_flash.h b/include/spi_flash.h
index be2fe3f..d1f63c7 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -26,6 +26,13 @@
 # define CONFIG_SF_DEFAULT_BUS		0
 #endif
 
+enum srp_method {
+	SRP_SOFTWARE,
+	SRP_HARDWARE,
+	SRP_POWER,
+	SRP_OTP,
+};
+
 struct spi_slave;
 
 /**
@@ -89,6 +96,7 @@ struct spi_flash {
 	int (*flash_lock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_unlock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_is_locked)(struct spi_flash *flash, u32 ofs, size_t len);
+	int (*sr_protect)(struct spi_flash *flash, enum srp_method method);
 #ifndef CONFIG_DM_SPI_FLASH
 	/*
 	 * These are not strictly needed for driver model, but keep them here
@@ -239,4 +247,13 @@ static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
 		return flash->flash_unlock(flash, ofs, len);
 }
 
+static inline int spi_flash_sr_protect(struct spi_flash *flash,
+		enum srp_method method)
+{
+	if (!flash->sr_protect)
+		return -EOPNOTSUPP;
+
+	return flash->sr_protect(flash, method);
+}
+
 #endif /* _SPI_FLASH_H_ */
-- 
2.9.3



More information about the U-Boot mailing list