Electronic – How, could hardware write protect be implemented for flash media

hardwarenon-volatile-memorysdserialusb

I come from a software background, but feel this is a hardware/electronics question.

Looking for a way to hardware-write-protect on flash media, I bought an SDHC card (with a tiny switch labelled "lock") and a cheap USB card reader. I wanted to create a 'read-only' device that I can be certain will not be modified – without having to consider the software on the hosts to which I connect it.

Inserted directly into my Dell laptop, the card can only be written when unlocked… I assumed this meant that the write protect is implemented by the SD card… When I put the SD card into the USB reader, however, the same laptop allows me to write to the locked card. I've now read this question, and this confirmation that I was wrong to assume that the 'lock' switch would provide hardware write protect. I now know that the 'lock' is not a feature of the card in isolation – and that standard 'locked' depends upon OS drivers (which I don't want to be forced to trust.)

I would like to know: What would be a straightforward, simple, reliable, neat and cheap way to implement a hardware write protect switch for flash media? Ideally, I would like to access this media over USB. I assume that I will need a device that can intercept the blocks of data exchanged over the serial interface to either USB or the SD card?

Best Answer

You can mark the SDCard as read only or temporary write protect. You can also hide storage or password protect for write.
If you don't want to modify code/drivers then you could just build an external unit to quickly write protect your SDCards.
See here for one implementation that uses an external ATTiny85 micro as man-in-the-middle.

You should read the simplified specs

You will find general discussion in Physical Layer 5.0 You can permanently and irrevocably mark a storage area as Read Only.

4.3.6 Write Protect Management
Three write protect methods are supported in the SD Memory Card as follows:
- Mechanical write protect switch (Host responsibility only)
- Card internal write protect (Card's responsibility)
- Password protection card lock operation.

Password Card Lock looks like it would be the best bet for you.

4.3.7 Card Lock/Unlock Operation
The password protection feature enables the host to lock a card while providing a password, which later will be used for unlocking the card. The password and its size are kept in a 128-bit PWD and 8-bit PWD_LEN registers, respectively. These registers are non-volatile so that a power cycle will not erase them.

Be aware (from Ali Chen's discourse) that not all SDCards you buy have all features of the spec implemented. YMMV depending on what you buy. If you wanted to be thorough, I'd drop an email to Sandisk or others and ask if they support this feature.

Look at these two projects:

  1. http://www.seanet.com/~karllunt/sdlocker.html This shows you how to set PERM_WRITE_PROTECT ....no way back...permanently write protected.
  2. http://www.seanet.com/~karllunt/sdlocker2.html This shows you how to set the TMP_Write_Protect bit and the Password protection.

Samsung definitely support PERM_WRITE_PROTECT as shown in their spec for the CSD register. It correctly shows it as (W)1 ...a write once value.

From these you should be able to find a solution that meets your needs.