3

I am trying to access the CSD (Card Specific Data) register on a SD card. The only way I know to do this is by having the linux system recognize it as a mmc device (Multi Media Card?) (eg. /dev/mmcblk0). Right now the device is being shown as a scsi disk (eg. /dev/sda).

Is there any way I can access the CSD Register (Card Specific Data) when is is mounted as a scsi disk?

Is there any way I can get the kernel to recognize the device as a mmc?

Thanks.

ChrisVollo
  • 157
  • 1
  • 3
  • 15
  • 1
    How is the card connected to the computer? Many built-in card slots are actually proxied over USB. I *do not know for a fact* if raw MMC-level operations are supported over USB SD/MMC reader chips, but I *suspect* that they often are not. If this is an infrequent thing or you do not need high rate access, you could consider bit-banging the card from a local bus port (if available) or using your own custom adapter based on a USB-enabled microcontroller. – Chris Stratton Oct 07 '14 at 18:16
  • @ChrisStratton USB card readers use the USB Mass Storage standard, and generally do not provide any interface to perform "raw" SD/MMC operations. –  Oct 07 '14 at 18:17
  • Thanks. I have USB adapters. One adapter that I have is "built-in" to my desktop but it does not appear to show with a #lspci command, and does appear to show with a #lsusb . Do you think I could benefit by looking for hardware that connects over Serial or PCI? – ChrisVollo Oct 07 '14 at 18:21
  • PCI might work, but I'd expect it to be uncommon. If this is a one-off you can program something like an Arduino to do this task (or proxy MMC commands) and hang it off the USB. For a product, pick the least expensive micro up to the job. Or if you have a **true** local-bus parallel port, you can bit-bang the card from that. – Chris Stratton Oct 07 '14 at 18:39

2 Answers2

1

At least some of CSD information you should get in /sys/block/diskX directory.

Example: My sd card connected to USB stick is discovered by system as /dev/sdc.

ls -l /sys/block/sdc/queue/
total 0
-rw-r--r-- 1 root root 4096 Oct  7 22:25 add_random
-r--r--r-- 1 root root 4096 Oct  7 22:25 discard_granularity
-r--r--r-- 1 root root 4096 Oct  7 22:25 discard_max_bytes
-r--r--r-- 1 root root 4096 Oct  7 22:25 discard_zeroes_data
-r--r--r-- 1 root root 4096 Oct  7 22:25 hw_sector_size
drwxr-xr-x 2 root root    0 Oct  7 22:24 iosched
-rw-r--r-- 1 root root 4096 Oct  7 22:24 iostats
-r--r--r-- 1 root root 4096 Oct  7 22:25 logical_block_size
-r--r--r-- 1 root root 4096 Oct  7 22:24 max_hw_sectors_kb
-r--r--r-- 1 root root 4096 Oct  7 22:24 max_integrity_segments
-rw-r--r-- 1 root root 4096 Oct  7 22:24 max_sectors_kb
-r--r--r-- 1 root root 4096 Oct  7 22:24 max_segment_size
-r--r--r-- 1 root root 4096 Oct  7 22:24 max_segments
-r--r--r-- 1 root root 4096 Oct  7 22:24 minimum_io_size
-rw-r--r-- 1 root root 4096 Oct  7 22:25 nomerges
-rw-r--r-- 1 root root 4096 Oct  7 22:25 nr_requests
-r--r--r-- 1 root root 4096 Oct  7 22:25 optimal_io_size
-r--r--r-- 1 root root 4096 Oct  7 22:23 physical_block_size
-rw-r--r-- 1 root root 4096 Oct  7 22:25 read_ahead_kb
-rw-r--r-- 1 root root 4096 Oct  7 22:25 rotational
-rw-r--r-- 1 root root 4096 Oct  7 22:25 rq_affinity
-rw-r--r-- 1 root root 4096 Oct  7 22:25 scheduler
RaFD
  • 688
  • 6
  • 14
  • Thanks. Interesting ... I want to look more into this. DO you think it's possible to write to the register? What I want to do is enable temporary write protection. – ChrisVollo Oct 07 '14 at 21:36
  • So I guess what you want is set up TMP_WRITE_PROTECT (CMD 27) bit.? I may be wrong, but I think you will not able to do it without write kernel driver which accesses this register (it seems that sys interface dosen't allow it). Also you have to take into account that some of the command can be only executed in particular states of SD Card. Please read more here: https://www.sdcard.org/downloads/pls/simplified_specs/part1_410.pdf in SD Specifications document. – RaFD Oct 07 '14 at 22:20
  • yes. this is what I want, the TMP_WRITE_PROTECT bit. I believe there is a way to change it, if the sd card is a mmcblk device node. I could be wrong. I did it on my Raspberry pi using a command line tool called sdtool. – ChrisVollo Oct 07 '14 at 22:26
  • so I presumably that software does it by ioctl. Was system did you have on this raspberry? Was it Linux? Then you can debug by strace what exactly is happening when you change this option. – RaFD Oct 07 '14 at 22:33
1

Looking into the Linux kernel sources, you may find that there are rare cases when USB device provide mmcblk device. Realtek chips RTS5129, RTS5139, RTS5179 and RTS5170 provide MMC interface. I have found RTS5129 as integrated part of my laptop, and checked that it correctly handles vendor custom CMD56. Unfortunately, I don't know is it possible to buy external USB SD card reader based on mentioned chips.

0x2207
  • 878
  • 1
  • 6
  • 20