3

I want to set the TMP_WRITE_PROTECT (temporary write protection) bit on my sdcard /dev/mmcblk0. I think this can be done by rewriting the CSD (card specific data) at /sys/block/mmcblk0/device/csd, but surely there's already a Linux tool to do all that bit-banging and recalculate the CRC?

I've found mmc-utils, but it seems to use an incompatible interface:

# mmc extcsd read /dev/mmcblk0
ioctl: Connection timed out
Could not read EXT_CSD from /dev/mmcblk0
# mmc writeprotect get /dev/mmcblk0 
ioctl: Connection timed out
Could not read EXT_CSD from /dev/mmcblk0

And a Stack Overflow comment mentioned a command line tool called sdtool, but does not provide a URL...

3

That mysterious sdtool you cannot find is hosted here, and you can indeed use it to enable temporary write protection on your card:

sudo umount /dev/mmcblk0p*
sudo sdtool /dev/mmcblk0 lock
sudo sdtool /dev/mmcblk0 reset

Similarly, unlock will remove the write protection.

A word of warning: my system is not able to recognize that the flag is set, so it's up to me to remount the filesystem as read-only. Mounting write-protected card as rw will silently allow writes which in reality won't take place, resulting in weird filesystem errors (which fortunately won't affect the SD card but still can hand up programs on your computer).

  • Does sdtool build for x86? – Melab Dec 3 '15 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.