本次源码适配工作是在NXP i.MX6ULL EVK评估板的Linux内核源码(特定版本:Linux-imx_4.1.15)基础上进行的。主要目标是调整功能接口引脚配置,以适应ELF 1开发板。接下来,将以按键功能的适配作为具体示例,深入解析整个适配的流程。
elf@ubuntu:~/work$ tar jvxf linux-imx-imx_4.1.15_2.0.0_ga.tar.bz2
elf@ubuntu:~/work$ cd linux-imx-imx_4.1.15_2.0.0_ga/
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ ls
2、添加默认配置文件
将arch/arm/configs路径下的imx_v7_mfg_defconfig复制一份,命名为imx6ull_elf1_defconfig:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ cp arch/arm/configs/imx_v7_mfg_defconfig arch/arm/configs/imx6ull_elf1_defconfig
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ cp arch/arm/boot/dts/imx6ull-14x14-evk.dts arch/arm/boot/dts/imx6ull-elf1-emmc.dts
打开arch/arm/boot/dts/Makefile,找到CONFIG_SOC_IMX6ULL,将imx6ull-elf1-emmc.dts添加到Makefile中:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vi arch/arm/boot/dts/Makefile
4、建立交叉编译脚本
建立一个编译脚本build.sh:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vim build.sh
#!/bin/bash
export CPUS=`grep -c processor /proc/cpuinfo`
source /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
make distclean
make imx6ull_elf1_defconfig
make -j${CPUS}
rm -rf ./.tmp
make modules_install INSTALL_MOD_PATH=./.tmp/rootfs/
cd .tmp/rootfs/
tar -jcvf modules.tar.bz2 *
给予脚本权限:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ chmod 777 build.sh
从上图可以看出GPIO5_4连接到了连接器的22脚,GPIO5_2连到了34脚,GPIO5_9连接到了43脚。接下来需要找到这几个引脚在软件上的信号名称。
打开ELF 1开发板资料包5-硬件资料5-4 管脚分配表ELF 1引脚复用对照表找到22、34、43引脚的信号名称。
pinctrl_keys: keysgrp {
fsl,pins = <
MX6ULL_PAD_SNVS_TAMPER4__GPIO5_IO04 0x80000000
MX6ULL_PAD_SNVS_TAMPER2__GPIO5_IO02 0x80000000
MX6ULL_PAD_SNVS_TAMPER9__GPIO5_IO09 0x80000000
>;
};
效果如下:
在根节点下添加子节点gpio-keys:
gpio-keys {
compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_keys>;
#address-cells = <1>;
#size-cells = <0>;
autorepeat;
key1 {
label = "KEY1";
linux,code = <KEY_ENTER>;
gpios = <&gpio5 4 GPIO_ACTIVE_LOW>;
};
key2 {
label = "KEY2";
linux,code = <KEY_UP>;
gpios = <&gpio5 2 GPIO_ACTIVE_LOW>;
};
key3 {
label = "KEY3";
linux,code = <KEY_DOWN>;
gpios = <&gpio5 9 GPIO_ACTIVE_LOW>;
};
};
4、配置按键驱动编译进内核
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ make imx6ull_elf1_defconfig
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ make menuconfig
-> Device Drivers
->Input device support
->Keyboards
5、编译
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ ./build.sh
将编译生成的zImage和imx6ull-elf-emmc.dtb拷贝到ELF 1开发板的/run/media/mmcblk1p1 路径下:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ scp arch/arm/boot/zImage root@172.16.0.175:/run/media/mmcblk1p1/
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ scp arch/arm/boot/dts/imx6ull-elf1-emmc.dtb root@172.16.0.175:/run/media/mmcblk1p1/
保存并重启开发板:
root@ELF1~# sync
root@ELF1~# reboot
查看key设备对应的event事件:
root@ELF1:~# cat /proc/bus/input/devices
可以看到其对应的是event2,如果连接了其他设备,比如触摸屏,event事件可能会有变化,请以实际为准。
终端输入evtest命令,选择event number为2,然后分别按下按键K1,K2,K3,会看到上报数据。
root@ELF1:~# evtest
可以看到KEY1上报的键值是28,KEY2上报的键值是103,KEY3上报的键值是108,与在设备树中配置的键值一致。