本次源码适配项目是在NXP i.MX6ULL EVK评估板所搭载的Linux内核源码(版本为Linux-imx_4.1.15)基础上进行的,主要目标是通过调整功能接口引脚配置,使其适应ELF 1开发板。为了深入阐述这一适配过程,我们将以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开发板资料包5-硬件资料5-4 管脚分配表ELF 1引脚复用对照表找到65引脚的信号名称。
pinctrl_pwm2: pwm2grp {
fsl,pins = <
MX6UL_PAD_GPIO1_IO09__PWM2_OUT 0x110b0
>;
};
在设备树文件arch/arm/boot/dts/imx6ull.dtsi中已经定义好了8路PWM信号的相关节点,只需要将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
待开发板启动完成,将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