Low level access to SD card (read and write specific blocks)
Hello All,
I'm trying to read/write specific locations of a SD card using low level functions (without file system, cache, etc...). I have a custom SD card that can be lock/unlock using a custom command. To activate/execute these commands, the application need to read and write in specials locations (with special data). Assuming this, I already develop an application in Windows and Linux with success. For Linux, while I use a SD Reader, I can implement some USB Mass Storage Class commands in userspace application (to avoid the whole file system). Until now, everything is OK. However, If the SD card is connected directly (without the USB SD reader), the same approach cannot be applied. For example, I'm using a Wandboard (iMX6 ARM with native SD support) and I get the same results (not success). When I try to use mmc-utils, the call ioctl get "Connection timed out". Using the following methods doesn't work: - open/read/write functions (c/c++) - open/read/write functions (c/c++) with O_DIRECT flag - open/read/write functions (c/c++) with O_DIRECT flag and flush operations Any suggestions will be appreciated. Thanks |
If you are not accessing the SD device via a USB interface, then using USB Mass Storage Class commands obviously cannot work, because there is no USB device involved.
Under Linux, the raw device is available as a pseudofile, for instance /dev/mmcblk0. Run "sudo dmesg | tail -n 30" after inserting the SD device to see the exact device name. You should be able to open, read, and write this file to access raw device blocks (of the device, not its filesystems). You can also use the "dd" command to access specific blocks from the commandline, if you just want to try it quickly without programming. In either case you will likely need to be the root user. Do you still get errors when accessing it this way? If so, what error? |
And, for what should be obvious reason, superuser privileges will be needed to open the device.
|
Dear ttk, sundialsvcs,
Thanks for the replies. I able to open, read, and write the file "/dev/mmcblk0" to access raw device blocks, however, the custom SD memory not reply as expected. I suppose there is some timeout inside the SD controller that don't allow to use these functions (because the inherent kernel control, cache, etc...). I get working WRITE and READ commands directly to the SD using the current driver and IOCTL calls. Thanks, Julio |
read/write specific locations of a SD card using low level functions
hi,Julio:
I have the same problem about read/write specific locations of a SD card using low level functions,so could you please give me more details about how to solve it,my email whmhyf@163.com,thanks. Quote:
|
Nihao haiming,
Below the function to read on specific address using IOCTL function: Code:
void read_address_ioctl(int fd, void *buffer, int address){ Regards Julio Quote:
|
All times are GMT -5. The time now is 09:31 PM. |