算是之前的后续吧……一些调试6UL时遇到的事情,记录一下

解压U-boot格式的initrd

$ mkimage -l uImage

显示镜像信息

$ tail -c+65 < uImage > out

去掉文件头

$ tail -c+65  < uImage | gunzip > out

如果文件是gzip压缩的,可以获得压缩前的数据

如果是initramfs,可以用cpio -t < out 或 pax < out来显示文件系统内容。

另外可以尝试挂载文件系统

$ mount -ro loop out /mnt

将initrd打包成U-boot格式

$ umount /mnt
$ mdconfig -d -u 0

将initrd压缩

$ gzip initrd

创建uboot格式镜像

$ mkimage -A arm -T ramdisk -C none -n ramdisk -d initrd.gz ramdisk.uImage

U-Boot相关

目前已知U-Boot 2015.4版本不能直接在Ubuntu 18.04上编译,更换Ubuntu 16.04.4后正常。U-Boot 2017.04版本可以在Ubuntu 18.04上正常编译。

创建启动脚本

$ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Boot script' -d normal.cmd boot.scr

手动启动

从SD卡

fatload mmc 0:1 0x80800000 bin/zImage
fatload mmc 0:1 0x83000000 bin/imx6ul-14x14-evk.dtb
setenv bootargs console=ttymxc0,115200 cma=64M root=/dev/mmcblk0p2 rootwait
bootz 0x80800000 - 0x83000000

按SD卡脚本

fatload mmc 0 0x80700000 /bin/boot.scr
source 0x80700000

从NAND Flash

nand read 0x80800000 0xa00000 0x800000
nand read 0x83000000 0x700000 0x40000
setenv bootargs console=ttymxc0,115200 cma=64M root=/dev/mtdblock5 rootwait
bootz 0x80800000 - 0x83000000

禁用自动关屏

自动关屏的功能是由vt提供的,可以通过写入控制字来进行调节:

 f = open("/dev/tty0", O_RDWR);
 write(f, "/033[9;0]", 8);
 close(f);

打包SquashFS

将目录打包为镜像文件:

$ mksquashfs /some/dir dir.sqsh

挂载打包后的文件系统:

$ mkdir /mnt/dir
$ mount dir.sqsh /mnt/dir -t squashfs -o loop

直接将目录打包进设备

$ mksquashfs /some/dir /dev/fd0

ADC

ADC这个功能在i.MX6产品线中是只有i.MX6UL和i.MX6SX里才有的。

设备驱动位于配置中的Device Drivers -> Industrial IO -> Analog to Digital devices -> Freescale vf610,启用后在设备树中加入如下内容:

&adc1 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_adc1>;
	vref-supply = <&reg_vref_3v3>;
	status = "okay";
};

pinctrl_adc1: adc1grp {
	fsl,pins = <
		MX6UL_PAD_GPIO1_IO07__GPIO1_IO07 0xb0
	>;
};

测试

$ cat /sys/bus/iio/devices/iio\:device0/in_voltage7_raw

蜂鸣器

蜂鸣器这里直接使用Linux标准的蜂鸣器驱动。虽然说看起来似乎大家都不太喜欢用这个驱动而是喜欢自己魔改pwm-leds驱动或者是直接魔改pwm-backlight驱动,但是总觉得不清真,还是直接用pwm-buzzer最好了吧。

设备驱动位于配置的Device Drivers -> Input Devices -> Misc Devices -> PWM Buzzer,启用后在设备树中加入如下内容:

beeper {
	compatible = "pwm-beeper";
	pwms = <&pwm6 0 50000>;
};


pinctrl_pwm6: pwm6grp {
 	fsl,pins = <
		MX6UL_PAD_CSI_DATA03__SIM2_PORT1_PD		0xb808
		MX6UL_PAD_CSI_DATA04__SIM2_PORT1_CLK		0x11
		MX6UL_PAD_CSI_DATA05__SIM2_PORT1_RST_B		0xb810
		MX6UL_PAD_CSI_DATA06__SIM2_PORT1_SVEN		0xb810
		MX6UL_PAD_CSI_DATA07__SIM2_PORT1_TRXD		0xb811
		MX6UL_PAD_CSI_DATA02__GPIO4_IO23		0x3008
		MX6UL_PAD_ENET1_TX_EN__PWM6_OUT   0x110b0
	>;
};

/* Buzzer */
&pwm6 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_pwm6>;
	status = "okay";
};

另外需要注意的是飞思卡尔的iMX6UL BSP里面给的dtsi里面并没有给PWM2-8分配时钟,需要手动修复一下:

@@ -455,8 +455,8 @@
 				compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";
 				reg = <0x02084000 0x4000>;
 				interrupts = <GIC_SPI 84 IRQ_TYPE_LEVEL_HIGH>;
-				clocks = <&clks IMX6UL_CLK_DUMMY>,
-					 <&clks IMX6UL_CLK_DUMMY>;
+				clocks = <&clks IMX6UL_CLK_PWM2>,
+					 <&clks IMX6UL_CLK_PWM2>;
 				clock-names = "ipg", "per";
 				#pwm-cells = <2>;
 			};
@@ -465,8 +465,8 @@
 				compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";
 				reg = <0x02088000 0x4000>;
 				interrupts = <GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>;
-				clocks = <&clks IMX6UL_CLK_DUMMY>,
-					 <&clks IMX6UL_CLK_DUMMY>;
+				clocks = <&clks IMX6UL_CLK_PWM3>,
+					 <&clks IMX6UL_CLK_PWM3>;
 				clock-names = "ipg", "per";
 				#pwm-cells = <2>;
 			};
@@ -475,8 +475,8 @@
 				compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";
 				reg = <0x0208c000 0x4000>;
 				interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;
-				clocks = <&clks IMX6UL_CLK_DUMMY>,
-					 <&clks IMX6UL_CLK_DUMMY>;
+				clocks = <&clks IMX6UL_CLK_PWM4>,
+					 <&clks IMX6UL_CLK_PWM4>;
 				clock-names = "ipg", "per";
 				#pwm-cells = <2>;
 			};
@@ -811,8 +811,8 @@
 				compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";
 				reg = <0x020f0000 0x4000>;
 				interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH>;
-				clocks = <&clks IMX6UL_CLK_DUMMY>,
-					 <&clks IMX6UL_CLK_DUMMY>;
+				clocks = <&clks IMX6UL_CLK_PWM5>,
+					 <&clks IMX6UL_CLK_PWM5>;
 				clock-names = "ipg", "per";
 				#pwm-cells = <2>;
 			};
@@ -821,8 +821,8 @@
 				compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";
 				reg = <0x020f4000 0x4000>;
 				interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_HIGH>;
-				clocks = <&clks IMX6UL_CLK_DUMMY>,
-					 <&clks IMX6UL_CLK_DUMMY>;
+				clocks = <&clks IMX6UL_CLK_PWM6>,
+					 <&clks IMX6UL_CLK_PWM6>;
 				clock-names = "ipg", "per";
 				#pwm-cells = <2>;
 			};
@@ -831,8 +831,8 @@
 				compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";
 				reg = <0x020f8000 0x4000>;
 				interrupts = <GIC_SPI 116 IRQ_TYPE_LEVEL_HIGH>;
-				clocks = <&clks IMX6UL_CLK_DUMMY>,
-					 <&clks IMX6UL_CLK_DUMMY>;
+				clocks = <&clks IMX6UL_CLK_PWM7>,
+					 <&clks IMX6UL_CLK_PWM7>;
 				clock-names = "ipg", "per";
 				#pwm-cells = <2>;
 			};
@@ -841,8 +841,8 @@
 				compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";
 				reg = <0x020fc000 0x4000>;
 				interrupts = <GIC_SPI 117 IRQ_TYPE_LEVEL_HIGH>;
-				clocks = <&clks IMX6UL_CLK_DUMMY>,
-					 <&clks IMX6UL_CLK_DUMMY>;
+				clocks = <&clks IMX6UL_CLK_PWM8>,
+					 <&clks IMX6UL_CLK_PWM8>;
 				clock-names = "ipg", "per";
 				#pwm-cells = <2>;
 			};

还有一个小问题是usleep_range会出错,这里使用更小时长的udelay代替,但是具体影响未知:

 	} else {
 		writel(MX3_PWMCR_SWR, imx->mmio_base + MX3_PWMCR);
 		do {
-			usleep_range(200, 1000);
+			udelay(10);
+			//usleep_range(200, 1000);
 			cr = readl(imx->mmio_base + MX3_PWMCR);
 		} while ((cr & MX3_PWMCR_SWR) &&
 			 (wait_count++ < MX3_PWM_SWR_LOOP));

启动系统应该可以看见启动log中有一句:

input: pwm-beeper as /devices/platform/beeper/input/input2

说明设备已经注册成功了。测试方法:

echo -ne '\007' > /dev/tty0

LED

LED的使用非常简单,大致来说分为gpio-led和pwm-led两种,pwm-led需要额外的pwm节点控制,方法同上,不再赘述。gpio-led只需要加入对应的IOMUXC节点即可。

leds {
	compatible = "gpio-leds";
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_leds>;

	heartbeat {
		label = "heartbeat";
		gpios = <&gpio5 5 GPIO_ACTIVE_HIGH>;
		linux,default-trigger = "heartbeat";
	};
};

pwmleds {
	compatible = "pwm-leds";
	green {
		label = "green";
		pwms = <&pwm2 0 100000>;
		max-brightness = <255>;
	};

	uv {
		label = "uv";
		pwms = <&pwm4 0 100000>;
		max-brightness = <255>;
	};
};