Hello all, SRWD bit (along with WP#) provides a way to protect Status and Configuration Registers from been modified unintendedly or by a malicious actor. By default, SRWD bit is 0, which means no protection on registers alternations. Registers can be modified easily by WRR command. (this is most of the application use cases). If set SRWD bit to 1, then when WP# is driven low during WRR command, WRR command will be ignored and Registers can't be modified. This provides a way to protect Registers, meanwhile still reserve the capability to modify Registers when necessary by driving WP# to high during WRR command. Flash data array can be protected by DYB, or PPB, or BP0-2 and TBPROT, or combination of these three methods. These 3 sector protection mechanisms and combinations provide flexibility (different security level) of data protection. If a sector is protected by any of DYB, or PPB, or BP bit, then it is not programmable or erasable. If a sector has none of DYB, PPB, BP bit set, then it is not protected and is programmable and erasable. DYB is volatile bit. It can be easily and fast modified on the fly, and will be set to default value upon power cycle or hardware reset. So it provides least security level protection, normally is used to prevent unintended program/erase commands. It also does not have wear limitation (i.e., unlimited times of alternations). One example of the use case is that set DYB bits to protect all the data array sectors right after system powers on. Whenever program or erase the flash data array, clear the DYB bit (set to unprotect) for the target sector prior to sending program/erase command. After program/erase complete, set the relevant DYB bit to protect the sector again. PPB is non-volatile bit. It is a little difficult to change than DYB. It provides medium security protection level. PPB bits have the same erase/program lifecycles as the flash data array. BP0-2 and TBPROT provide another level of security protection. SRWD bit and WP# can prevent BP0-2 and TBPROT bits to be modified, which can provide one more level of security protection. Best Regards, Yong -----Original Message----- From: Tudor.Ambarus@xxxxxxxxxxxxx <Tudor.Ambarus@xxxxxxxxxxxxx> Sent: Monday, March 11, 2019 10:06 AM To: jonas@xxxxxxxxxxx; James Tomasetta <James.Tomasetta@xxxxxxxxxxx>; Yong Qin <Yong.Qin@xxxxxxxxxxx> Cc: linux-mtd@xxxxxxxxxxxxxxxxxxx; bbrezillon@xxxxxxxxxx; richard@xxxxxx; marek.vasut@xxxxxxxxx; computersforpeace@xxxxxxxxx; dwmw2@xxxxxxxxxxxxx Subject: Re: [PATCH v2 1/3] mtd: spi-nor: always respect write-protect input Hi, Jonas, On 03/10/2019 12:42 PM, Jonas Bonn wrote: > Hi, > > On 10/03/2019 10:58, Tudor.Ambarus@xxxxxxxxxxxxx wrote: >> + James and Yong from Cypress. >> >> Hi, Jonas, James, Yong, >> >> On 01/30/2019 12:07 AM, Jonas Bonn wrote: >>> The status register bit SRWD (status register write disable) is >>> described in many words in the datasheets but effectively boils down to: >>> >>> i) if set, respect WP# when trying to change protection bits; >>> ii) if unset, ignore WP# when trying to change protection bits >>> >>> In short, the bit determines whether the WP# signal is honored or not. >>> >>> It's difficult to imagine the use-case where the WP# is connected >>> and asserted but the user doesn't want to respect its setting. As >>> such, this patch sets the SRWD bit unconditionally so that the WP# >>> is _always_ respected; hardware that doesn't care about WP# normally >>> won't even have it connected. >>> >> >> Always setting SRWD to 1, dismisses the need of a SRWD bit in the first place. >> Do you know why Cypress made this bit configurable and didn't enable it by default? > > I suspect it has some historical relevance; as things currently stand, I don't see how it's useful in its current form. > > We initially thought that the WP# signal turned on/off block protection but that's not the case; the block protection bits BP0-BP2 turn on/off block protection and the WP# signal only protects the BP[0-2] bits from being modified. Turning off the WP# functionality via the SRWD bits means that the BP[0-2] bits are always modifiable and therefore the flash device is never really protected from writes by a malicious actor. > > The key question here is: if the WP# signal is connected, why would you ever want its state to be ignored by the device? De-asserting the signal has the same effect as setting the SRWD bit. And the default state is un-asserted if the signal is not connected, so that case is covered, too. I see no reason not to just always set SRWD and thereby make the WP# signal do what one expects of it, always. > I tend to agree with you. Let's wait for a few days, maybe James or Yong will tell us the Cypress's reasons of making SRWD configurable. In the meantime I'll check the datasheets of the flashes that have SPI_NOR_HAS_LOCK declared, see if SRWD is configurable and what were the reasons of making it so. Cheers, ta This message and any attachments may contain confidential information from Cypress or its subsidiaries. If it has been received in error, please advise the sender and immediately delete this message. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/