I am working on an embedded application running Debian GNU/Linux 10 (buster) and I want to have direct access (i.e. read and write) to the content available at specific memory addresses in an SD Card.
For the sake of example, suppose that the SD card is visible through the path /dev/mmcblk0p1/.
By "direct access" I mean that I do not want to read or write files to the SD Card, but instead to read/write byte values to offsets from the start memory address of the SD Card, regardless of the file system (e.g. FAT32, NFTS, etc.) to which it is defined.
First of all, are there means to do so? If this is the case, how can I do it?
At the moment, I manage to open the SD Card as a file and get its size (correct value is observed in a debuger), but I do not know how to obtain the pointer (address) to the beginning of the flash memory.
Here it goes what I have so far:
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <unistd.h>
#include <cstdint>
int main(){
uint64_t size;
int fd = open("/dev/mmcblk0p1", O_RDWR);
ioctl(fd, BLKGETSIZE64, &size);
int f_closed = close(fd);
return 0;
}