From 5941e09d37ad7e8ac4e062b69e1381cd1fa96b8d Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Wed, 12 Jul 2017 00:19:06 +0100 Subject: [PATCH] yeah, devmem already exists with almost same name and correct :-) --- buildroot_config_fragment | 18 +++++++++++++ kernel_module/user/README.md | 1 - kernel_module/user/devmem.c | 49 ------------------------------------ 3 files changed, 18 insertions(+), 50 deletions(-) delete mode 100644 kernel_module/user/devmem.c diff --git a/buildroot_config_fragment b/buildroot_config_fragment index a01000a..ce48faf 100644 --- a/buildroot_config_fragment +++ b/buildroot_config_fragment @@ -45,3 +45,21 @@ BR2_PACKAGE_LINUX_TOOLS_GPIO=y BR2_PACKAGE_DTC=y BR2_PACKAGE_DTC_PROGRAMS=y BR2_PACKAGE_HOST_DTC=y + +# On ARM, with our lkmc_platform_device: +# +# devmem2 0x101e9000 w 0x12345678 +# +# Then on QEMU monitor, notice that the registers don't actually change value: +# +# xp/4 0x101e9000 +# +# Uses /dev/mem: +# +# - https://superuser.com/questions/71389/what-is-dev-mem/1214662#1214662 +# - https://unix.stackexchange.com/questions/4948/shell-command-to-read-device-registers +# +# TODO: why with mmap MAP_PRIVATE (used in my previous custom naive version), +# the entire register page is read?; +# +BR2_PACKAGE_DEVMEM2=y diff --git a/kernel_module/user/README.md b/kernel_module/user/README.md index 36ffb34..2e66dc7 100644 --- a/kernel_module/user/README.md +++ b/kernel_module/user/README.md @@ -11,7 +11,6 @@ These programs can also be compiled and used on host. 1. Standalone 1. [myinsmod](myinsmod.c) 1. [myrmmod](myrmmod.c) - 1. [devmem](devmem.c) 1. [init_hello](init_hello.c) 1. Module tests 1. [anonymous_inode](anonymous_inode.c) diff --git a/kernel_module/user/devmem.c b/kernel_module/user/devmem.c deleted file mode 100644 index ddca707..0000000 --- a/kernel_module/user/devmem.c +++ /dev/null @@ -1,49 +0,0 @@ -/* -https://stackoverflow.com/questions/12040303/accessing-physical-address-from-user-space - -Sample call: - - /phys.out 0 16 - -Confirm memory from QEMU monitor with: - - xp/0 16 -*/ - -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) { - if (argc < 3) { - printf("Usage: %s \n", argv[0]); - return 0; - } - off_t offset = strtoul(argv[1], NULL, 0); - size_t len = strtoul(argv[2], NULL, 0); - - size_t pagesize = sysconf(_SC_PAGE_SIZE); - off_t page_base = (offset / pagesize) * pagesize; - off_t page_offset = offset - page_base; - int fd = open("/dev/mem", O_SYNC); - size_t reallen = page_offset + len; - unsigned char *mem = mmap(NULL, reallen, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, page_base); - if (mem == MAP_FAILED) { - /* TODO why does it fail for some addreses but not for others? */ - perror("mmap"); - exit(EXIT_FAILURE); - } - for (size_t i = 0; i < len; ++i) { - printf("%02x ", (unsigned int)mem[page_offset + i]); - /* TODO can't edit memory? */ - mem[page_offset + i] = i % 256; - } - puts(""); - if (munmap(mem, reallen) == -1) { - perror("munmap"); - exit(EXIT_FAILURE); - } - return EXIT_SUCCESS; -}