io: Open /dev/mem with O_SYNC for uncached access 9549/head
authorHauke Mehrtens <hauke.mehrtens@intel.com>
Mon, 22 Jul 2019 13:03:57 +0000 (15:03 +0200)
committerHauke Mehrtens <hauke.mehrtens@intel.com>
Wed, 24 Jul 2019 11:57:09 +0000 (13:57 +0200)
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 <hauke.mehrtens@intel.com>
utils/io/Makefile
utils/io/src/io.c

index a861e7477e86794a7b0e6cbf210e6c4bad037738..fe3f779b2af107ec09ef9ccd0241dab65649b1ab 100644 (file)
@@ -6,7 +6,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=io
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 include $(INCLUDE_DIR)/package.mk
 
index 257205404925349de34aa397c5a116a5f1e2cf9d..51929121397b1d3fdf4a8971419d8c02b81d52f2 100644 (file)
@@ -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");