自学内容网 自学内容网

linux 的devmem2 调式使用说明

devmem2的方式是提供给驱动开发人员,在应用层能够侦测内存地址中的数据变化,以此来检测驱动中对内存或者相关配置的正确性验证。基本原理通过设备文件/dev/mem 实现对物理内存的读写,如果没有dev/mem,这时需要安装devmem2。

1,安装devmem2:

sudo apt install devmem2

lark@ubuntu:~$ devmem2 

Usage:    devmem2 { address } [ type [ data ] ]
 address : memory address to act upon
type    : access operation type : [b]yte, [h]alfword, [w]ord
data    : data to be written

安装成功后会有/dev/mem 这个目录。

lark@ubuntu:~$ ls /dev/mem 
/dev/mem

2,读写测试

a,读数据:

devmem2 reg-addr b/h/w(1/2/4) 

b,写数据:

devmem2 reg-addr b/h/w(1/2/value

(1)单字节读写(8位):

lark@ubuntu:~$ sudo devmem2 0x1234 b 0x11
/dev/mem opened.
Memory mapped at address 0x7f659293d000.
Value at address 0x1234 (0x7f659293d234): 0x78
Written 0x11; readback 0x11


lark@ubuntu:~$ sudo devmem2 0x1234 b 
/dev/mem opened.
Memory mapped at address 0x7fd47bed1000.
Value at address 0x1234 (0x7fd47bed1234): 0x11

(2)双字节读写(16位):

lark@ubuntu:~$ sudo devmem2 0x1234 b 
/dev/mem opened.
Memory mapped at address 0x7fd47bed1000.
Value at address 0x1234 (0x7fd47bed1234): 0x11
lark@ubuntu:~$ sudo devmem2 0x1234 h 0x1122
/dev/mem opened.
Memory mapped at address 0x7f218fb9b000.
Value at address 0x1234 (0x7f218fb9b234): 0x5611
Written 0x1122; readback 0x1122


lark@ubuntu:~$ sudo devmem2 0x1234 h
/dev/mem opened.
Memory mapped at address 0x7feaa9be3000.
Value at address 0x1234 (0x7feaa9be3234): 0x1122
 

(3)四字节速写(四字节):

lark@ubuntu:~$ sudo devmem2 0x1234 w 0x12345678
/dev/mem opened.
Memory mapped at address 0x7f2d21327000.
Value at address 0x1234 (0x7f2d21327234): 0xBC614E
Written 0x12345678; readback 0x12345678


lark@ubuntu:~$ sudo devmem2 0x1234 w
/dev/mem opened.
Memory mapped at address 0x7f31ad806000.
Value at address 0x1234 (0x7f31ad806234): 0x12345678

lark@ubuntu:~$ sudo devmem2 0x1234 h
/dev/mem opened.
Memory mapped at address 0x7fd131870000.
Value at address 0x1234 (0x7fd131870234): 0x5678


lark@ubuntu:~$ sudo devmem2 0x1234 b
/dev/mem opened.
Memory mapped at address 0x7f2fe1866000.
Value at address 0x1234 (0x7f2fe1866234): 0x78


原文地址:https://blog.csdn.net/qq_40008325/article/details/143462487

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!