我嘗試使用UIO而不是直接映射/dev/mem
後,無法在Xilinx Zynq上映射物理內存。雖然計劃是以普通用戶身份運行應用程序,而不是root
,但仍以root
運行該應用程序。mmap在UIO設備上出現EINVAL錯誤
顯然,第一次映射是成功的,而其餘完成到相同的文件描述符12
(/dev/uio/ps2pl
)失敗。雖然明顯的差異是偏移量,但它在範圍之內(請參閱設備樹),並且頁面對齊正確。此應用程序與/dev/mem
配合良好。
通過用strace
運行中觀察到的錯誤是:
open("/dev/uio/ps2pl", O_RDWR|O_SYNC) = 12
open("/sys/bus/i2c/devices/0-0050/eeprom", O_RDONLY) = 13
fstat64(13, {st_mode=S_IFREG|0600, st_size=8192, ...}) = 0
_llseek(13, 0, [0], SEEK_SET) = 0
read(13, "\1\1\0\0\0\0\0\0", 8) = 8
read(13, "(\\\217\2(\\\217\00233333333\0\0\0\0\0\0\0\0(\\\217\2(\\\217\2"..., 4096) = 4096
close(13) = 0
mmap2(NULL, 48, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0) = 0xb6f93000
mmap2(NULL, 48, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0x400000) = -1 EINVAL (Invalid argument)
mmap2(NULL, 196608, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0x200000) = -1 EINVAL (Invalid argument)
mmap2(NULL, 196608, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0x100000) = -1 EINVAL (Invalid argument)
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x1f} ---
+++ killed by SIGSEGV +++
Segmentation fault
作爲裝入內核的設備樹:
# /root/dtc/dtc -f -I fs /sys/firmware/devicetree/base/amba_pl/ps2pl\@40000000/
ERROR (name_properties): "name" property in/is incorrect ("ps2pl" instead of base node name)
Warning: Input tree has errors, output forced
/dts-v1/;
/{
reg = <0x40000000 0x40000000>;
name = "ps2pl";
interrupts = <0x0 0x44 0x4>;
compatible = "generic-uio";
interrupt-parent = <0x3>;
};
的UIO映射的尺寸足夠大,以容納上述mmap
尺寸和補償:
# cat /sys/devices/soc0/amba_pl/40000000.ps2pl/uio/uio0/maps/map0/size
0x40000000