本次源碼適配工作是在NXP i.MX6ULL EVK評估板的Linux內(nèi)核源碼(特定版本:Linux-imx_4.1.15)基礎上進行的。主要目標是調整功能接口引腳配置,以適應ELF 1開發(fā)板。接下來,將以按鍵功能的適配作為具體示例,深入解析整個適配的流程。
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開發(fā)板資料包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
>;
};
效果如下:
在根節(jié)點下添加子節(jié)點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、配置按鍵驅動編譯進內(nèi)核
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開發(fā)板的/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/
保存并重啟開發(fā)板:
root@ELF1~# sync
root@ELF1~# reboot
查看key設備對應的event事件:
root@ELF1:~# cat /proc/bus/input/devices
可以看到其對應的是event2,如果連接了其他設備,比如觸摸屏,event事件可能會有變化,請以實際為準。
終端輸入evtest命令,選擇event number為2,然后分別按下按鍵K1,K2,K3,會看到上報數(shù)據(jù)。
root@ELF1:~# evtest
可以看到KEY1上報的鍵值是28,KEY2上報的鍵值是103,KEY3上報的鍵值是108,與在設備樹中配置的鍵值一致。