In my code I try to call mmap the /dev/mem in Tiny Core Linux.
I able to open the file handle to /dev/mem using open.
However the mmap fails with errno 11. strerror would give the message "Resouce temporarily unavailable." In the dmesg the following entry was found "map pfn expected mapping type uncached-minus for e0000-f0000, got write-back.
I tried the same in micro core too. There also the same error came.
Please do advise if there is some thing I am dong wrong. The code is given below.
////////////////////THE CODE/////////////////////////
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main(void)
{
int mem_fd;
off_t offset = (off_t)0xE0000 & -4096;
size_t len = (((off_t)0xE0000 + 0x10000 + 4096 - 1) & -4096) - offset;
char *mappedAddress = NULL;
if ((mem_fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) {
printf("cannot open /dev/mem\n");
exit(1);
}
mappedAddress = (char *)mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED, mem_fd, offset);
if (mappedAddress == MAP_FAILED) {
perror("mmap failed");
exit(1);
}
printf("mapped address 0x%.16x\n", (unsigned long)mappedAddress);
return 0;
}