![]() ![]() Usually, device files are mappings of physical memory to the file system. You can map a device file to a user process memory using mmap(2) system call. Is there any API for determining the physical address from virtual address in Linux? watch printfs come out of the virtual device in responseīonus: determine the physical address for a virtual address.create a platform device with known physical register addresses.IO mem and QEMU virtual platform device.modify the physical address with devmem.get the physical address with virt_to_phys and pass it back to userland.modify the value at the physical address with devmem, and watch the userland process react.get the physical address with /proc//maps + /proc//pagemap.allocate volatile variable on an userland process.This can't be observed in QEMU unfortunately, since QEMU does not simulate caches. So maybe /dev/mem can't be used reliably to pass memory buffers to devices? Is it possible to allocate, in user space, a non cacheable block of memory on Linux?.How to flush the CPU cache for a region of address space in Linux?.How to write kernel space memory (physical address) to a file using O_DIRECT?.If you try to write to RAM instead of a register, the memory may be cached by the CPU: How to flush the CPU cache for a region of address space in Linux? and I don't see a very portable / easy way to flush it or mark the region as uncacheable: See also: mmap of /dev/mem fails with invalid argument for virt_to_phys address, but address is page aligned pass the nopat kernel command line option for x86.disable CONFIG_STRICT_DEVMEM (set by default on Ubuntu 17.04). ![]() To use /dev/mem to view and modify regular RAM on kernel v4.9, you must fist: MAP_SHARED makes writes go to physical memory immediately, which makes it easier to observe, and makes more sense for hardware register writes. Mmap(., PROT_READ | PROT_WRITE, MAP_SHARED. When mmapping /dev/mem, you likely want to use: open("/dev/mem", O_RDWR | O_SYNC) Write 0x9abcdef0 to that address: sudo busybox devmem 0x12345678 w 0x9abcdef0 Usage: read 4 bytes from the physical address 0x12345678: sudo busybox devmem 0x12345678 You can get it in Ubuntu with: sudo apt-get install busybox Busybox devmem is a tiny CLI utility that mmaps /dev/mem. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |