本次源碼適配工作是在NXP i.MX6ULL EVK評(píng)估板的Linux內(nèi)核源碼(特定版本:Linux-imx_4.1.15)基礎(chǔ)上進(jìn)行的。主要目標(biāo)是調(diào)整功能接口引腳配置,以適應(yīng)ELF 1開(kāi)發(fā)板。接下來(lái),將以按鍵功能的適配作為具體示例,深入解析整個(gè)適配的流程。
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、添加默認(rèn)配置文件
將arch/arm/configs路徑下的imx_v7_mfg_defconfig復(fù)制一份,命名為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
打開(kāi)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、建立交叉編譯腳本
建立一個(gè)編譯腳本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 *
給予腳本權(quán)限:
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腳。接下來(lái)需要找到這幾個(gè)引腳在軟件上的信號(hào)名稱(chēng)。
打開(kāi)ELF 1開(kāi)發(fā)板資料包5-硬件資料5-4 管腳分配表ELF 1引腳復(fù)用對(duì)照表找到22、34、43引腳的信號(hào)名稱(chēng)。
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é)點(diǎn)下添加子節(jié)點(diǎn)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、配置按鍵驅(qū)動(dòng)編譯進(jìn)內(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開(kāi)發(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/
保存并重啟開(kāi)發(fā)板:
root@ELF1~# sync
root@ELF1~# reboot
查看key設(shè)備對(duì)應(yīng)的event事件:
root@ELF1:~# cat /proc/bus/input/devices
可以看到其對(duì)應(yīng)的是event2,如果連接了其他設(shè)備,比如觸摸屏,event事件可能會(huì)有變化,請(qǐng)以實(shí)際為準(zhǔn)。
終端輸入evtest命令,選擇event number為2,然后分別按下按鍵K1,K2,K3,會(huì)看到上報(bào)數(shù)據(jù)。
root@ELF1:~# evtest
可以看到KEY1上報(bào)的鍵值是28,KEY2上報(bào)的鍵值是103,KEY3上報(bào)的鍵值是108,與在設(shè)備樹(shù)中配置的鍵值一致。