RK平台 支持io命令

发布于:2024-04-27 ⋅ 阅读:(24) ⋅ 点赞:(0)

一,io命令简介

“io” 命令通常用于显示 Linux 系统中的 I/O 统计信息。它提供了有关磁盘读写操作的详细信息,包括每个块设备的读写次数、读写扇区数、读写延迟等。io命令可以直接操作某个寄存器,用于查看设置某个GPIO 引脚配置了什么iomux。

二,移植io命令驱动

RK 的 Android 平台,默认有包含 io 工具(源码位置:external\io)。

1. 在 Makefile 中添加mem

kernel/drivers/char/Makefile

增加
+obj-$(CONFIG_DEVMEM)           += mem.o

2. 在 Kconfig 中添加DEVMEM

kernel/drivers/char/Kconfig

改文件已经包含下面信息
  config DEVMEM
      bool "/dev/mem virtual device support"
      default y
      help
      	Say Y here if you want to support the /dev/mem device.
        The /dev/mem device is used to access areas of physical
        memory.
        When in doubt, say "Y".

3. 修改驱动文件

源码路径:
kernel/arch/arm/configs/rockchip_defconfig
kernel/drivers/char/mem.c

diff --git a/kernel/arch/arm/configs/rockchip_defconfig b/kernel/arch/arm/configs/rockchip_defconfig
index 0c930a731b..7116d1eafc 100644
--- a/kernel/arch/arm/configs/rockchip_defconfig
+++ b/kernel/arch/arm/configs/rockchip_defconfig
@@ -417,7 +417,7 @@ CONFIG_INPUT_RK805_PWRKEY=y
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVMEM is not set
+CONFIG_DEVMEM=y
 CONFIG_SERIAL_8250=y
 # CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
 CONFIG_SERIAL_8250_CONSOLE=y
diff --git a/kernel/drivers/char/mem.c b/kernel/drivers/char/mem.c
index 54b86490d9..836b130049 100644
--- a/kernel/drivers/char/mem.c
+++ b/kernel/drivers/char/mem.c
@@ -881,9 +881,7 @@ static const struct memdev {
        const struct file_operations *fops;
        fmode_t fmode;
 } devlist[] = {
-#ifdef CONFIG_DEVMEM
         [1] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
-#endif
 #ifdef CONFIG_DEVKMEM
         [2] = { "kmem", 0, &kmem_fops, FMODE_UNSIGNED_OFFSET },
 #endif

三,调试命令

1. 查看mem字符设备

io命令正是通过以下字符设备来实现寄存器的读写:

rk3568_r:/ # ls -l /dev/mem
crw------- 1 media media 1,   1 2017-08-04 09:00 /dev/mem

2. 命令说明

rk3568_r:/dev # io
io
Raw memory i/o utility - $Revision: 1.5 $

io -v -1|2|4 -r|w [-l <len>] [-f <file>] <addr> [<value>]

    -v         Verbose, asks for confirmation
    -1|2|4     Sets memory access size in bytes (default byte)
    -l <len>   Length in bytes of area to access (defaults to
               one access, or whole file length)
    -r|w       Read from or Write to memory (default read)
    -f <file>  File to write on memory read, or
               to read on memory write
    <addr>     The memory address to access
    <val>      The value to write (implies -w)

Examples:
    io 0x1000                  Reads one byte from 0x1000
    io 0x1000 0x12             Writes 0x12 to location 0x1000
    io -2 -l 8 0x1000          Reads 8 words from 0x1000
    io -r -f dmp -l 100 200    Reads 100 bytes from addr 200 to file
    io -w -f img 0x10000       Writes the whole of file to memory

Note access size (-1|2|4) does not apply to file based accesses.

网站公告

今日签到

点亮在社区的每一天
去签到