From 90df0f3e241dc233c3121dfc5e1be937c6c987bc Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Mon, 22 Jul 2019 15:03:57 +0200 Subject: [PATCH] io: Open /dev/mem with O_SYNC for uncached access Only when /dev/mem is opened with O_SYNC the write and *read* is done uncached. We saw wrong values read out from the hardware without setting O_SYNC, the busybox devmem tool showed different values, when O_SYNC is also set for the io tool, it reads out the same values as devmem. When looking at the drivers/char/mem.c file in the kernel it is behaving differently based on the O_DSYNC flag. Signed-off-by: Hauke Mehrtens --- utils/io/Makefile | 2 +- utils/io/src/io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/io/Makefile b/utils/io/Makefile index a861e7477e..fe3f779b2a 100644 --- a/utils/io/Makefile +++ b/utils/io/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=io -PKG_RELEASE:=1 +PKG_RELEASE:=2 include $(INCLUDE_DIR)/package.mk diff --git a/utils/io/src/io.c b/utils/io/src/io.c index 2572054049..5192912139 100644 --- a/utils/io/src/io.c +++ b/utils/io/src/io.c @@ -343,7 +343,7 @@ main (int argc, char **argv) printf("Attempting to map 0x%lx bytes at address 0x%08lx\n", real_len, real_addr); - mfd = open("/dev/mem", (memfunc == MEM_READ) ? O_RDONLY : O_RDWR); + mfd = open("/dev/mem", (memfunc == MEM_READ) ? (O_RDONLY | O_SYNC) : (O_RDWR | O_SYNC)); if (mfd == -1) { perror("open /dev/mem"); fprintf(stderr, "Is CONFIG_DEVMEM activated?\n");