本次源碼適配項目是在NXP i.MX6ULL EVK評估板所搭載的Linux內(nèi)核源碼(版本為Linux-imx_4.1.15)基礎上進行的,主要目標是通過調(diào)整功能接口引腳配置,使其適應ELF 1開發(fā)板。為了深入闡述這一適配過程,我們將以PWM功能的適配作為具體示例,深入解析整個流程。
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
將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
將arch/arm/boot/dts路徑下的imx6ull-14x14-evk.dts復制一份,命名為imx6ull-elf1-emmc.dts
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
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vi arch/arm/boot/dts/Makefile
建立一個編譯腳本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
從上圖可以看出PWM2連接到了連接器的65腳。接下來我們需要找到這個引腳在軟件上的信號名稱。
打開ELF 1開發(fā)板資料包5-硬件資料5-4 管腳分配表ELF 1引腳復用對照表找到65引腳的信號名稱。
pinctrl_pwm2: pwm2grp {
fsl,pins = <
MX6UL_PAD_GPIO1_IO09__PWM2_OUT 0x110b0
>;
};
在設備樹文件arch/arm/boot/dts/imx6ull.dtsi中已經(jīng)定義好了8路PWM信號的相關(guān)節(jié)點,只需要將PWM2的時鐘配置上即可,將clocks屬性的IMX6UL_CLK_DUMMY更改為IMX6UL_CLK_PWM2。
&pwm2 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_pwm2>;
status = "okay";
};
由于pwm只涉及到設備樹修改,不再使用腳本編譯,單獨編譯設備樹即可。
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 dtbs
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
待開發(fā)板啟動完成,將PWM2設置為輸出
root@ELF1:~#:~# echo 0 > /sys/class/pwm/pwmchip1/export
root@ELF1:~#:~# echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
root@ELF1:~#:~# echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/period
root@ELF1:~#:~# echo 500000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
root@ELF1:~#:~# echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable