I am trying to access a physical memory address 0x30000000and I am trying to accomplish this with mmap(). When I map this address to a virtual address pointer, I cannot read the correct value from memory. When I look at memory using a debugger (TI Code Composer Studio w / JTAG), can I see the values ββthat are in memory, but I do not get the same values ββin my code? Am I using it correctly mmap()?
off_t dev_base = 0x30000000;
size_t ldev = 0x3FFFFFF;
int offset = 0x00;
memfd = open("/dev/mem", O_RDWR | O_SYNC);
mapped_base = (int*)mmap(0, ldev, PROT_READ|PROT_WRITE, MAP_SHARED, memfd, dev_base);
if (mapped_base == MAP_FAILED)
{
errx(1, "mmap failure");
}
printf("mapped_base = %08p\n", mapped_base);
printf("The value at address [%08p] = %08p\n", offset + ((int)mapped_base), mapped_base[offset/4]);
munmap(mapped_base, ldev);
close(memfd);
source
share