From d23222a96caeca5f83d22ffd55e210da30eaa379 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Fri, 23 Nov 2018 10:33:24 +0100 Subject: [PATCH] imx6: Add support for Toradex Apalis family of CoMs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch adds support for the following computer on modules (CoM) from Toradex[A]: Apalis iMX6 Quad 2GB IT - i.MX 6Quad 800MHz, 2GB DDR3, 4GB eMMC -40° to +85° C Temp Apalis iMX6 Quad 1GB - i.MX 6Quad 1GHz, 1GB DDR3, 4GB eMMC 0° to +70° C Temp Apalis iMX6 Dual 1GB IT - i.MX 6Dual 800MHz, 1GB DDR3, 4GB eMMC -40° to +85° C Temp Apalis iMX6 Dual 512MB - i.MX 6Dual 1GHz, 512MB DDR3, 4GB eMMC 0° to +70° C Temp I've developed and tested it on Quad 2GB IT v1.1A and Dual 512MB v1.1A CoMs, using Ixora[B] carrier board v1.0A, but it should hopefuly work on Eval[C] board as well. A. https://www.toradex.com/computer-on-modules/apalis-arm-family/nxp-freescale-imx-6 B. https://www.toradex.com/products/carrier-board/ixora-carrier-board C. https://www.toradex.com/products/carrier-board/apalis-evaluation-board Flashing/recovery instructions: 1. Download and compile imx_loader for OpenWrt from https://github.com/ynezz/imx_loader 2. Enter recovery mode as desribed in https://developer.toradex.com/knowledge-base/imx-recovery-mode 3. Connect board via USB to the host computer, check that it's connected by lsusb: 15a2:0054 Freescale Semiconductor, Inc. i.MX 6Dual/6Quad SystemOnChip in RecoveryMode 4. Copy following OpenWrt images to imx_loader directory: SPL u-boot.img u-boot-with-spl.imx openwrt-imx6-apalis-recovery.scr openwrt-imx6-apalis-squashfs.combined.bin 5. Run imx_usb in imx_loader directory Signed-off-by: Petr Štetiar --- target/linux/imx6/Makefile | 2 +- target/linux/imx6/base-files/lib/imx6.sh | 36 ++++++++ .../base-files/lib/preinit/79_move_config | 20 +++++ .../imx6/base-files/lib/upgrade/platform.sh | 47 ++++++++++ target/linux/imx6/image/Makefile | 33 +++++++ target/linux/imx6/image/bootscript-apalis | 20 +++++ target/linux/imx6/image/recovery-apalis | 14 +++ .../301-apalis-ixora-dts-leds.patch | 86 +++++++++++++++++++ .../302-apalis-ixora-dts-reset-button.patch | 76 ++++++++++++++++ .../301-apalis-ixora-dts-leds.patch | 86 +++++++++++++++++++ .../302-apalis-ixora-dts-reset-button.patch | 76 ++++++++++++++++ 11 files changed, 495 insertions(+), 1 deletion(-) create mode 100644 target/linux/imx6/base-files/lib/preinit/79_move_config create mode 100644 target/linux/imx6/image/bootscript-apalis create mode 100644 target/linux/imx6/image/recovery-apalis create mode 100644 target/linux/imx6/patches-4.14/301-apalis-ixora-dts-leds.patch create mode 100644 target/linux/imx6/patches-4.14/302-apalis-ixora-dts-reset-button.patch create mode 100644 target/linux/imx6/patches-4.19/301-apalis-ixora-dts-leds.patch create mode 100644 target/linux/imx6/patches-4.19/302-apalis-ixora-dts-reset-button.patch diff --git a/target/linux/imx6/Makefile b/target/linux/imx6/Makefile index 73512ca986..49e4487026 100644 --- a/target/linux/imx6/Makefile +++ b/target/linux/imx6/Makefile @@ -20,6 +20,6 @@ include $(INCLUDE_DIR)/target.mk KERNELNAME:=zImage dtbs -DEFAULT_PACKAGES += uboot-envtools mkf2fs e2fsprogs +DEFAULT_PACKAGES += uboot-envtools mkf2fs e2fsprogs blkid $(eval $(call BuildTarget)) diff --git a/target/linux/imx6/base-files/lib/imx6.sh b/target/linux/imx6/base-files/lib/imx6.sh index 1bf1439523..68caaff15f 100755 --- a/target/linux/imx6/base-files/lib/imx6.sh +++ b/target/linux/imx6/base-files/lib/imx6.sh @@ -6,6 +6,33 @@ IMX6_BOARD_NAME= IMX6_MODEL= +rootpartuuid() { + local cmdline=$(cat /proc/cmdline) + local bootpart=${cmdline##*root=} + bootpart=${bootpart%% *} + local uuid=${bootpart#PARTUUID=} + echo ${uuid%-02} +} + +bootdev_from_uuid() { + blkid | grep "PTUUID=\"$(rootpartuuid)\"" | cut -d : -f1 +} + +bootpart_from_uuid() { + blkid | grep $(rootpartuuid)-01 | cut -d : -f1 +} + +rootpart_from_uuid() { + blkid | grep $(rootpartuuid)-02 | cut -d : -f1 +} + +apalis_mount_boot() { + mkdir -p /boot + [ -f /boot/uImage ] || { + mount -o rw,noatime $(bootpart_from_uuid) /boot > /dev/null + } +} + imx6_board_detect() { local machine local name @@ -59,6 +86,15 @@ imx6_board_detect() { name="cubox-i" ;; + "Toradex Apalis iMX6Q/D Module on Ixora Carrier Board" |\ + "Toradex Apalis iMX6Q/D Module on Ixora Carrier Board V1.1") + name="apalis,ixora" + ;; + + "Toradex Apalis iMX6Q/D Module on Apalis Evaluation Board") + name="apalis,eval" + ;; + "Wandboard i.MX6 Dual Lite Board") name="wandboard" ;; diff --git a/target/linux/imx6/base-files/lib/preinit/79_move_config b/target/linux/imx6/base-files/lib/preinit/79_move_config new file mode 100644 index 0000000000..6b66fbd42d --- /dev/null +++ b/target/linux/imx6/base-files/lib/preinit/79_move_config @@ -0,0 +1,20 @@ +#!/bin/sh + +. /lib/imx6.sh +. /lib/functions.sh + +move_config() { + local board=$(board_name) + + case "$board" in + apalis*) + if [ -b $(bootpart_from_uuid) ]; then + apalis_mount_boot + [ -f /boot/sysupgrade.tgz ] && mv -f /boot/sysupgrade.tgz / + umount /boot + fi + ;; + esac +} + +boot_hook_add preinit_mount_root move_config diff --git a/target/linux/imx6/base-files/lib/upgrade/platform.sh b/target/linux/imx6/base-files/lib/upgrade/platform.sh index ab52291109..2d76b6b4af 100755 --- a/target/linux/imx6/base-files/lib/upgrade/platform.sh +++ b/target/linux/imx6/base-files/lib/upgrade/platform.sh @@ -2,10 +2,44 @@ # Copyright (C) 2010-2015 OpenWrt.org # +. /lib/imx6.sh + +RAMFS_COPY_BIN='blkid' + +enable_image_metadata_check() { + case "$(board_name)" in + apalis*) + REQUIRE_IMAGE_METADATA=1 + ;; + esac +} +enable_image_metadata_check + +apalis_copy_config() { + apalis_mount_boot + cp -af "$CONF_TAR" /boot/ + sync + umount /boot +} + +apalis_do_upgrade() { + local board_name=$(board_name) + board_name=${board_name/,/_} + + apalis_mount_boot + get_image "$1" | tar Oxf - sysupgrade-${board_name}/kernel > /boot/uImage + get_image "$1" | tar Oxf - sysupgrade-${board_name}/root > $(rootpart_from_uuid) + sync + umount /boot +} + platform_check_image() { local board=$(board_name) case "$board" in + apalis*) + return 0 + ;; *gw5*) nand_do_platform_check $board $1 return $?; @@ -20,8 +54,21 @@ platform_do_upgrade() { local board=$(board_name) case "$board" in + apalis*) + apalis_do_upgrade "$1" + ;; *gw5*) nand_do_upgrade "$1" ;; esac } + +platform_copy_config() { + local board=$(board_name) + + case "$board" in + apalis*) + apalis_copy_config + ;; + esac +} diff --git a/target/linux/imx6/image/Makefile b/target/linux/imx6/image/Makefile index fa10b756a1..85d6823021 100644 --- a/target/linux/imx6/image/Makefile +++ b/target/linux/imx6/image/Makefile @@ -58,6 +58,12 @@ define Build/boot-scr $(BIN_DIR)/boot.scr endef +define Build/recovery-scr + mkimage -A arm -O linux -T script -C none -a 0 -e 0 \ + -n '$(DEVICE_ID) OpenWrt recovery bootscript' \ + -d ./recovery-$(DEVICE_NAME) $@ +endef + define Build/imx6-combined-image-prepare rm -rf $@.boot mkdir -p $@.boot @@ -101,6 +107,10 @@ define Build/imx6-sdcard $(Build/imx6-combined-image-clean) endef +define Build/apalis-emmc + $(Build/imx6-combined-image-prepare) + $(Build/imx6-combined-image) + $(Build/imx6-combined-image-clean) endef ################################################# @@ -190,4 +200,27 @@ define Device/cubox-i endef TARGET_DEVICES += cubox-i +define Device/apalis + DEVICE_TITLE := Toradex Apalis family + SUPPORTED_DEVICES := apalis,ixora apalis,eval + DEVICE_DTS := \ + imx6q-apalis-eval \ + imx6q-apalis-ixora \ + imx6q-apalis-ixora-v1.1 + DEVICE_PACKAGES := \ + kmod-can kmod-can-flexcan kmod-can-raw \ + kmod-leds-gpio kmod-gpio-button-hotplug \ + kmod-pps-gpio kmod-rtc-ds1307 + BOOT_SCRIPT := bootscript-apalis + UBOOT := apalis_imx6 + FILESYSTEMS := squashfs + IMAGES := combined.bin sysupgrade.bin + IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1).$$(2) + IMAGE/combined.bin := append-rootfs | pad-extra 128k | apalis-emmc + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata + ARTIFACTS := recovery.scr + ARTIFACT/recovery.scr := recovery-scr +endef +TARGET_DEVICES += apalis + $(eval $(call BuildImage)) diff --git a/target/linux/imx6/image/bootscript-apalis b/target/linux/imx6/image/bootscript-apalis new file mode 100644 index 0000000000..81a501cc63 --- /dev/null +++ b/target/linux/imx6/image/bootscript-apalis @@ -0,0 +1,20 @@ +echo "Toradex Apalis OpenWrt Boot script v1.0" + +run finduuid + +setenv nextcon 0 +setenv fdt_file imx6q-apalis-ixora.dtb +setenv root root=PARTUUID=${uuid} rootfstype=squashfs rootwait +setenv bootargs earlyprintk console=${console},${baudrate}n8 ${root} +setenv fsload ext4load mmc ${mmcbootdev}:${bootpart} + +if ${fsload} ${kernel_addr_r} ${boot_file}; then + if ${fsload} ${fdt_addr_r} ${fdt_file}; then + test -n "$fdt_fixup" && run fdt_fixup + bootm ${kernel_addr_r} - ${fdt_addr_r} + else + echo "Error loading device-tree" + fi +else + echo "Error loading kernel image" +fi diff --git a/target/linux/imx6/image/recovery-apalis b/target/linux/imx6/image/recovery-apalis new file mode 100644 index 0000000000..c1c5a3f5d6 --- /dev/null +++ b/target/linux/imx6/image/recovery-apalis @@ -0,0 +1,14 @@ +# flash u-boot-with-spl.imx +# using fixed size of 1M for U-Boot + SPL +mmc dev 0 1 +mmc write 0x12100000 0x2 0x800 + +# flash openwrt-imx6-apalis-squashfs.combined.bin +run set_blkcnt +mmc dev 0 0 +mmc write 0x12500000 0 ${blkcnt} + +env default -f -a +saveenv + +reset diff --git a/target/linux/imx6/patches-4.14/301-apalis-ixora-dts-leds.patch b/target/linux/imx6/patches-4.14/301-apalis-ixora-dts-leds.patch new file mode 100644 index 0000000000..acec1e8e3d --- /dev/null +++ b/target/linux/imx6/patches-4.14/301-apalis-ixora-dts-leds.patch @@ -0,0 +1,86 @@ +arm: dts: apalis-ixora: Add status LEDs aliases + +Signed-off-by: Petr Štetiar + +--- a/arch/arm/boot/dts/imx6q-apalis-ixora.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora.dts +@@ -60,6 +60,10 @@ + i2c2 = &i2c2; + rtc0 = &rtc_i2c; + rtc1 = &snvs_rtc; ++ led-boot = &led_boot; ++ led-failsafe = &led_failsafe; ++ led-running = &led_running; ++ led-upgrade = &led_upgrade; + }; + + gpio-keys { +@@ -123,22 +127,22 @@ + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_leds_ixora>; + +- led4-green { ++ led_running: led4-green { + label = "LED_4_GREEN"; + gpios = <&gpio1 17 GPIO_ACTIVE_HIGH>; + }; + +- led4-red { ++ led_upgrade: led4-red { + label = "LED_4_RED"; + gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>; + }; + +- led5-green { ++ led_boot: led5-green { + label = "LED_5_GREEN"; + gpios = <&gpio2 1 GPIO_ACTIVE_HIGH>; + }; + +- led5-red { ++ led_failsafe: led5-red { + label = "LED_5_RED"; + gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>; + }; +--- a/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts +@@ -61,6 +61,10 @@ + i2c2 = &i2c2; + rtc0 = &rtc_i2c; + rtc1 = &snvs_rtc; ++ led-boot = &led_boot; ++ led-failsafe = &led_failsafe; ++ led-running = &led_running; ++ led-upgrade = &led_upgrade; + }; + + gpio-keys { +@@ -124,22 +128,22 @@ + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_leds_ixora>; + +- led4-green { ++ led_running: led4-green { + label = "LED_4_GREEN"; +- gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>; ++ gpios = <&gpio1 17 GPIO_ACTIVE_HIGH>; + }; + +- led4-red { ++ led_upgrade: led4-red { + label = "LED_4_RED"; +- gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>; ++ gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>; + }; + +- led5-green { ++ led_boot: led5-green { + label = "LED_5_GREEN"; + gpios = <&gpio2 1 GPIO_ACTIVE_HIGH>; + }; + +- led5-red { ++ led_failsafe: led5-red { + label = "LED_5_RED"; + gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>; + }; diff --git a/target/linux/imx6/patches-4.14/302-apalis-ixora-dts-reset-button.patch b/target/linux/imx6/patches-4.14/302-apalis-ixora-dts-reset-button.patch new file mode 100644 index 0000000000..ede872fb62 --- /dev/null +++ b/target/linux/imx6/patches-4.14/302-apalis-ixora-dts-reset-button.patch @@ -0,0 +1,76 @@ +arm: dts: apalis-ixora: Add switch3 as reset button + +Signed-off-by: Petr Štetiar + +--- a/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts +@@ -70,7 +70,7 @@ + gpio-keys { + compatible = "gpio-keys"; + pinctrl-names = "default"; +- pinctrl-0 = <&pinctrl_gpio_keys>; ++ pinctrl-0 = <&pinctrl_gpio_keys &pinctrl_switch3_ixora>; + + wakeup { + label = "Wake-Up"; +@@ -79,6 +79,13 @@ + debounce-interval = <10>; + wakeup-source; + }; ++ ++ reset { ++ label = "reset"; ++ gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; ++ linux,code = ; ++ debounce-interval = <10>; ++ }; + }; + + lcd_display: display@di0 { +@@ -292,4 +299,10 @@ + MX6QDL_PAD_NANDF_D2__GPIO2_IO02 0x1b0b0 + >; + }; ++ ++ pinctrl_switch3_ixora: switch3ixora { ++ fsl,pins = < ++ MX6QDL_PAD_SD1_DAT0__GPIO1_IO16 0x1b0b0 ++ >; ++ }; + }; +--- a/arch/arm/boot/dts/imx6q-apalis-ixora.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora.dts +@@ -69,7 +69,7 @@ + gpio-keys { + compatible = "gpio-keys"; + pinctrl-names = "default"; +- pinctrl-0 = <&pinctrl_gpio_keys>; ++ pinctrl-0 = <&pinctrl_gpio_keys &pinctrl_switch3_ixora>; + + wakeup { + label = "Wake-Up"; +@@ -78,6 +78,13 @@ + debounce-interval = <10>; + wakeup-source; + }; ++ ++ reset { ++ label = "reset"; ++ gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; ++ linux,code = ; ++ debounce-interval = <10>; ++ }; + }; + + lcd_display: display@di0 { +@@ -293,4 +300,10 @@ + MX6QDL_PAD_NANDF_D2__GPIO2_IO02 0x1b0b0 + >; + }; ++ ++ pinctrl_switch3_ixora: switch3ixora { ++ fsl,pins = < ++ MX6QDL_PAD_SD1_DAT0__GPIO1_IO16 0x1b0b0 ++ >; ++ }; + }; diff --git a/target/linux/imx6/patches-4.19/301-apalis-ixora-dts-leds.patch b/target/linux/imx6/patches-4.19/301-apalis-ixora-dts-leds.patch new file mode 100644 index 0000000000..acec1e8e3d --- /dev/null +++ b/target/linux/imx6/patches-4.19/301-apalis-ixora-dts-leds.patch @@ -0,0 +1,86 @@ +arm: dts: apalis-ixora: Add status LEDs aliases + +Signed-off-by: Petr Štetiar + +--- a/arch/arm/boot/dts/imx6q-apalis-ixora.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora.dts +@@ -60,6 +60,10 @@ + i2c2 = &i2c2; + rtc0 = &rtc_i2c; + rtc1 = &snvs_rtc; ++ led-boot = &led_boot; ++ led-failsafe = &led_failsafe; ++ led-running = &led_running; ++ led-upgrade = &led_upgrade; + }; + + gpio-keys { +@@ -123,22 +127,22 @@ + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_leds_ixora>; + +- led4-green { ++ led_running: led4-green { + label = "LED_4_GREEN"; + gpios = <&gpio1 17 GPIO_ACTIVE_HIGH>; + }; + +- led4-red { ++ led_upgrade: led4-red { + label = "LED_4_RED"; + gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>; + }; + +- led5-green { ++ led_boot: led5-green { + label = "LED_5_GREEN"; + gpios = <&gpio2 1 GPIO_ACTIVE_HIGH>; + }; + +- led5-red { ++ led_failsafe: led5-red { + label = "LED_5_RED"; + gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>; + }; +--- a/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts +@@ -61,6 +61,10 @@ + i2c2 = &i2c2; + rtc0 = &rtc_i2c; + rtc1 = &snvs_rtc; ++ led-boot = &led_boot; ++ led-failsafe = &led_failsafe; ++ led-running = &led_running; ++ led-upgrade = &led_upgrade; + }; + + gpio-keys { +@@ -124,22 +128,22 @@ + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_leds_ixora>; + +- led4-green { ++ led_running: led4-green { + label = "LED_4_GREEN"; +- gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>; ++ gpios = <&gpio1 17 GPIO_ACTIVE_HIGH>; + }; + +- led4-red { ++ led_upgrade: led4-red { + label = "LED_4_RED"; +- gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>; ++ gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>; + }; + +- led5-green { ++ led_boot: led5-green { + label = "LED_5_GREEN"; + gpios = <&gpio2 1 GPIO_ACTIVE_HIGH>; + }; + +- led5-red { ++ led_failsafe: led5-red { + label = "LED_5_RED"; + gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>; + }; diff --git a/target/linux/imx6/patches-4.19/302-apalis-ixora-dts-reset-button.patch b/target/linux/imx6/patches-4.19/302-apalis-ixora-dts-reset-button.patch new file mode 100644 index 0000000000..ede872fb62 --- /dev/null +++ b/target/linux/imx6/patches-4.19/302-apalis-ixora-dts-reset-button.patch @@ -0,0 +1,76 @@ +arm: dts: apalis-ixora: Add switch3 as reset button + +Signed-off-by: Petr Štetiar + +--- a/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora-v1.1.dts +@@ -70,7 +70,7 @@ + gpio-keys { + compatible = "gpio-keys"; + pinctrl-names = "default"; +- pinctrl-0 = <&pinctrl_gpio_keys>; ++ pinctrl-0 = <&pinctrl_gpio_keys &pinctrl_switch3_ixora>; + + wakeup { + label = "Wake-Up"; +@@ -79,6 +79,13 @@ + debounce-interval = <10>; + wakeup-source; + }; ++ ++ reset { ++ label = "reset"; ++ gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; ++ linux,code = ; ++ debounce-interval = <10>; ++ }; + }; + + lcd_display: display@di0 { +@@ -292,4 +299,10 @@ + MX6QDL_PAD_NANDF_D2__GPIO2_IO02 0x1b0b0 + >; + }; ++ ++ pinctrl_switch3_ixora: switch3ixora { ++ fsl,pins = < ++ MX6QDL_PAD_SD1_DAT0__GPIO1_IO16 0x1b0b0 ++ >; ++ }; + }; +--- a/arch/arm/boot/dts/imx6q-apalis-ixora.dts ++++ b/arch/arm/boot/dts/imx6q-apalis-ixora.dts +@@ -69,7 +69,7 @@ + gpio-keys { + compatible = "gpio-keys"; + pinctrl-names = "default"; +- pinctrl-0 = <&pinctrl_gpio_keys>; ++ pinctrl-0 = <&pinctrl_gpio_keys &pinctrl_switch3_ixora>; + + wakeup { + label = "Wake-Up"; +@@ -78,6 +78,13 @@ + debounce-interval = <10>; + wakeup-source; + }; ++ ++ reset { ++ label = "reset"; ++ gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; ++ linux,code = ; ++ debounce-interval = <10>; ++ }; + }; + + lcd_display: display@di0 { +@@ -293,4 +300,10 @@ + MX6QDL_PAD_NANDF_D2__GPIO2_IO02 0x1b0b0 + >; + }; ++ ++ pinctrl_switch3_ixora: switch3ixora { ++ fsl,pins = < ++ MX6QDL_PAD_SD1_DAT0__GPIO1_IO16 0x1b0b0 ++ >; ++ }; + }; -- 2.25.1