[SOLVED] Low level access to SD card (read and write specific blocks)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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?
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:
Originally Posted by jcsistemas2001
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
I suggest to verify the driver code to set the FLAGS properly (idata.flags) according with your needs.
Regards
Julio
Quote:
Originally Posted by wanhaiming
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.