5

I am trying to access physical memory address 0x30000000 and I am trying to accomplish this using mmap(). When I map this address to a virtual address pointer I am unable to read the correct value from memory. When I look at the memory using a debugger (TI Code Composer Studio w/ JTAG) I am able to see the values that are in memory but am not getting the same values in my code? Am I using mmap() correctly?

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);
whh4000
  • 905
  • 1
  • 12
  • 30

1 Answers1

0

offset passed to mmap call should be in page units , this is the difference in new mmap2 system call.

mmap man page.

http://man7.org/linux/man-pages/man2/mmap.2.html.

AnshuMan Gupta
  • 323
  • 3
  • 14