[OpenWrt-Devel] [PATCH v2] imx6: Adding Ka-Ro electronics TX6U-8033 Module on MB7 baseboard support

Linus Lüssing linus.luessing at c0d3.blue
Wed Dec 4 13:14:30 EST 2019


From: Linus Lüssing <ll at simonwunderlich.de>

This adds support for the Ka-Ro MB7 board with a TX6U-8033 module.

Specification, according to Linux DTS commit:

    TX6U-8033:
    Processor    Freescale i.MX 6 Dual Lite, 800MHz
    RAM          1GiB DDR3 SDRAM
    ROM          4GiB eMMC
    Power supply Single 3.1V to 5.5V
    Size         31mm SO-DIMM
    Temp. Range  industrial grade (-40°C/-25°C to 105°C Tj)

The u-boot shipped by the vendor by default expects the following partition
layout:

MBR/MSDOS, disk-id '0cc66cc0' {
	0cc66cc0-01 => ext2, /vmlinuz
	0cc66cc0-02 => ext4, rootfs
}

TX6DL U-Boot > env print
append_bootargs=rootfstype=ext4
[...]
bootcmd_mmc=setenv autostart no;run bootargs_mmc;ext2load mmc 0 ${kerneladdr} vmlinuz
[...]
rootpart_uuid=0cc66cc0-02
[...]

This is also one of the reasons, why only ext4 rootfs support was added
and tested so far. No squashfs support yet.

Other than that, nothing fancy needs to be added or preserved on the
eMMC.

Cc: Simon Wunderlich <sw at simonwunderlich.de>
Signed-off-by: Linus Lüssing <ll at simonwunderlich.de>
---

Changelog v2:
* removed wildcard board names

 target/linux/imx6/Makefile                    |   2 +-
 .../imx6/base-files/etc/board.d/02_network    |   3 +-
 target/linux/imx6/base-files/lib/imx6.sh      |   4 +
 .../base-files/lib/preinit/79_move_config     |   9 ++
 .../imx6/base-files/lib/upgrade/platform.sh   | 108 +++++++++++++++++-
 target/linux/imx6/image/Makefile              |  34 ++++++
 .../linux/imx6/image/gen_karo_sdcard_img.sh   |  26 +++++
 .../imx6/patches-4.14/100-bootargs.patch      |  13 +++
 tools/Makefile                                |   1 +
 9 files changed, 197 insertions(+), 3 deletions(-)
 create mode 100755 target/linux/imx6/image/gen_karo_sdcard_img.sh

diff --git a/target/linux/imx6/Makefile b/target/linux/imx6/Makefile
index ac4300f7eb..8083a54e16 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 blkid
+DEFAULT_PACKAGES += uboot-envtools mkf2fs e2fsprogs blkid partx-utils
 
 $(eval $(call BuildTarget))
diff --git a/target/linux/imx6/base-files/etc/board.d/02_network b/target/linux/imx6/base-files/etc/board.d/02_network
index 6ec667346d..c662be72b7 100755
--- a/target/linux/imx6/base-files/etc/board.d/02_network
+++ b/target/linux/imx6/base-files/etc/board.d/02_network
@@ -21,7 +21,8 @@ cubox-i |\
 *gw552x)
 	ucidef_set_interfaces_lan_wan 'eth0' 'eth1'
 	;;
-*wandboard)
+*wandboard |\
+tx6u-8033)
 	ucidef_set_interface_wan 'eth0'
 	;;
 esac
diff --git a/target/linux/imx6/base-files/lib/imx6.sh b/target/linux/imx6/base-files/lib/imx6.sh
index 68caaff15f..c4b87d1c21 100755
--- a/target/linux/imx6/base-files/lib/imx6.sh
+++ b/target/linux/imx6/base-files/lib/imx6.sh
@@ -99,6 +99,10 @@ imx6_board_detect() {
 		name="wandboard"
 		;;
 
+	"Ka-Ro electronics TX6U-8033 Module on MB7 baseboard")
+		name="tx6u-8033"
+		;;
+
 	*)
 		name="generic"
 		;;
diff --git a/target/linux/imx6/base-files/lib/preinit/79_move_config b/target/linux/imx6/base-files/lib/preinit/79_move_config
index bdf397c4fc..de7196c7a1 100644
--- a/target/linux/imx6/base-files/lib/preinit/79_move_config
+++ b/target/linux/imx6/base-files/lib/preinit/79_move_config
@@ -15,6 +15,15 @@ move_config() {
 			umount /boot
 		fi
 		;;
+	tx6u-8033)
+		local bootpart=/dev/mmcblk2p1
+
+		if [ -b $bootpart ]; then
+			mkdir -p /boot
+			mount -t ext2 -o rw,noatime $bootpart /boot
+			[ -f /boot/sysupgrade.tgz ] && mv -f /boot/sysupgrade.tgz /
+		fi
+		;;
 	esac
 }
 
diff --git a/target/linux/imx6/base-files/lib/upgrade/platform.sh b/target/linux/imx6/base-files/lib/upgrade/platform.sh
index a090cc080b..9c9bed96fe 100755
--- a/target/linux/imx6/base-files/lib/upgrade/platform.sh
+++ b/target/linux/imx6/base-files/lib/upgrade/platform.sh
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2010-2015 OpenWrt.org
+# Copyright (C) 2010-2019 OpenWrt.org
 #
 
 . /lib/imx6.sh
@@ -30,6 +30,102 @@ apalis_do_upgrade() {
 	umount /boot
 }
 
+# (mostly) copied from brcm2708 platform.sh (which was copied from x86?)
+tx6u_8033_check_image() {
+	local diskdev partdev diff
+
+	[ "$#" -gt 1 ] && return 1
+
+	export_bootdevice && export_partdevice diskdev 0 || {
+		echo "Unable to determine upgrade device"
+		return 1
+	}
+
+	get_partitions "/dev/$diskdev" bootdisk
+
+	#extract the boot sector from the image
+	get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null
+
+	get_partitions /tmp/image.bs image
+
+	#compare tables
+	diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
+
+	rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
+
+	if [ -n "$diff" ]; then
+		echo "Partition layout has changed. Full image will be written."
+		ask_bool 0 "Abort" && exit 1
+		return 0
+	fi
+
+	return 0;
+}
+
+# (mostly) copied from brcm2708 platform.sh (which was copied from x86?)
+tx6u_8033_do_upgrade() {
+	local diskdev partdev diff
+
+	export_bootdevice && export_partdevice diskdev 0 || {
+		echo "Unable to determine upgrade device"
+		return 1
+	}
+
+	sync
+
+	if [ "$SAVE_PARTITIONS" = "1" ]; then
+		get_partitions "/dev/$diskdev" bootdisk
+
+		#extract the boot sector from the image
+		get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
+
+		get_partitions /tmp/image.bs image
+
+		#compare tables
+		diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
+	else
+		diff=1
+	fi
+
+	if [ -n "$diff" ]; then
+		get_image "$@" | dd of="/dev/$diskdev" bs=2M conv=fsync
+
+		# Separate removal and addtion is necessary; otherwise, partition 1
+		# will be missing if it overlaps with the old partition 2
+		partx -d - "/dev/$diskdev"
+		partx -a - "/dev/$diskdev"
+
+		return 0
+	fi
+
+	#iterate over each partition from the image and write it to the boot disk
+	while read part start size; do
+		if export_partdevice partdev $part; then
+			echo "Writing image to /dev/$partdev..."
+			get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
+		else
+			echo "Unable to find partition $part device, skipped."
+	fi
+	done < /tmp/partmap.image
+
+	#copy partition uuid
+	echo "Writing new UUID to /dev/$diskdev..."
+	get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
+}
+
+# (mostly) copied from brcm2708 platform.sh (which was copied from x86?)
+tx6u_8033_copy_config() {
+	local partdev
+
+	if export_partdevice partdev 1; then
+		mkdir -p /boot
+		[ -f /boot/vmlinuz.img ] || mount -t ext4 -o rw,noatime "/dev/$partdev" /boot
+		cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE"
+		sync
+		unmount /boot
+	fi
+}
+
 platform_check_image() {
 	local board=$(board_name)
 
@@ -41,6 +137,10 @@ platform_check_image() {
 		nand_do_platform_check $board $1
 		return $?;
 		;;
+	tx6u-8033)
+		tx6u_8033_check_image "$1"
+		return $?;
+		;;
 	esac
 
 	echo "Sysupgrade is not yet supported on $board."
@@ -57,6 +157,9 @@ platform_do_upgrade() {
 	*gw5*)
 		nand_do_upgrade "$1"
 		;;
+	tx6u-8033)
+		tx6u_8033_do_upgrade "$1"
+		;;
 	esac
 }
 
@@ -67,6 +170,9 @@ platform_copy_config() {
 	apalis*)
 		apalis_copy_config
 		;;
+	tx6u-8033)
+		tx6u_8033_copy_config
+		;;
 	esac
 }
 
diff --git a/target/linux/imx6/image/Makefile b/target/linux/imx6/image/Makefile
index d1e9e9034e..34fb4a2690 100644
--- a/target/linux/imx6/image/Makefile
+++ b/target/linux/imx6/image/Makefile
@@ -113,6 +113,24 @@ define Build/apalis-emmc
 	$(Build/imx6-combined-image-clean)
 endef
 
+define Build/karo-boot-img
+	$(RM) -rf $@.bootdir
+	mkdir $@.bootdir
+
+	$(CP) $(IMAGE_KERNEL) $@.bootdir/$(KERNEL_IMG)
+
+	genext2fs --block-size $(BLOCKSIZE:%k=%Ki) --size-in-blocks $$((1024 * 1024 * $(CONFIG_TARGET_KERNEL_PARTSIZE) / ($(subst k,* 1024,$(BLOCKSIZE))))) --root $@.bootdir $@.boot
+
+	# convert it to revision 1 - needed for u-boot ext2load
+	$(STAGING_DIR_HOST)/bin/tune2fs -O filetype $@.boot
+	$(STAGING_DIR_HOST)/bin/e2fsck -pDf $@.boot > /dev/null
+endef
+
+define Build/karo-sdcard-img
+	./gen_karo_sdcard_img.sh $@ $@.boot $(IMAGE_ROOTFS) $(CONFIG_TARGET_KERNEL_PARTSIZE) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
+endef
+
+
 #################################################
 # Devices
 #################################################
@@ -232,4 +250,20 @@ define Device/apalis
 endef
 TARGET_DEVICES += apalis
 
+define Device/tx6u-8033
+  DEVICE_TITLE := Ka-Ro electronics TX6U-8033 Module on MB7 baseboard
+  DEVICE_DTS := imx6dl-tx6u-8033
+  FILESYSTEMS := ext4
+  BLOCKSIZE := 4k
+  KERNEL_SUFFIX := -zImage
+  KERNEL_NAME := zImage
+  KERNEL := kernel-bin
+  KERNEL_IMG := vmlinuz
+  IMAGES := factory.img.gz sysupgrade.img.gz
+  IMAGE_SIZE := 3776m
+  IMAGE/sysupgrade.img.gz := karo-boot-img | karo-sdcard-img | check-size $$$$(IMAGE_SIZE) | gzip | append-metadata
+  IMAGE/factory.img.gz := karo-boot-img | karo-sdcard-img | check-size $$$$(IMAGE_SIZE) | gzip
+endef
+TARGET_DEVICES += tx6u-8033
+
 $(eval $(call BuildImage))
diff --git a/target/linux/imx6/image/gen_karo_sdcard_img.sh b/target/linux/imx6/image/gen_karo_sdcard_img.sh
new file mode 100755
index 0000000000..362ce5838b
--- /dev/null
+++ b/target/linux/imx6/image/gen_karo_sdcard_img.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+set -x
+[ $# -eq 5 ] || {
+    echo "SYNTAX: $0 <file> <bootfs image> <rootfs image> <bootfs size> <rootfs size>"
+    exit 1
+}
+
+OUTPUT="$1"
+BOOTFS="$2"
+ROOTFS="$3"
+BOOTFSSIZE="$4"
+ROOTFSSIZE="$5"
+
+head=4
+sect=63
+
+set `ptgen -o $OUTPUT -h $head -s $sect -l 4096 -t 83 -S 0x0cc66cc0 -p ${BOOTFSSIZE}M -t 83 -p ${ROOTFSSIZE}M`
+
+BOOTOFFSET="$(($1 / 512))"
+BOOTSIZE="$(($2 / 512))"
+ROOTFSOFFSET="$(($3 / 512))"
+ROOTFSSIZE="$(($4 / 512))"
+
+dd bs=512 if="$BOOTFS" of="$OUTPUT" seek="$BOOTOFFSET" conv=notrunc
+dd bs=512 if="$ROOTFS" of="$OUTPUT" seek="$ROOTFSOFFSET" conv=notrunc
diff --git a/target/linux/imx6/patches-4.14/100-bootargs.patch b/target/linux/imx6/patches-4.14/100-bootargs.patch
index 0954391203..6c025e15db 100644
--- a/target/linux/imx6/patches-4.14/100-bootargs.patch
+++ b/target/linux/imx6/patches-4.14/100-bootargs.patch
@@ -1,3 +1,16 @@
+--- a/arch/arm/boot/dts/imx6dl-tx6u-8033.dts
++++ b/arch/arm/boot/dts/imx6dl-tx6u-8033.dts
+@@ -51,6 +51,10 @@
+ 		display = &display;
+ 	};
+ 
++	chosen {
++		bootargs = "console=ttymxc0,115200";
++	};
++
+ 	backlight: backlight {
+ 		compatible = "pwm-backlight";
+ 		pwms = <&pwm2 0 500000 PWM_POLARITY_INVERTED>;
 --- a/arch/arm/boot/dts/imx6dl-wandboard.dts
 +++ b/arch/arm/boot/dts/imx6dl-wandboard.dts
 @@ -19,4 +19,8 @@
diff --git a/tools/Makefile b/tools/Makefile
index 2f57d25525..034e54c5d9 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -39,6 +39,7 @@ tools-$(BUILD_ISL) += isl
 tools-$(CONFIG_USE_SPARSE) += sparse
 tools-$(CONFIG_TARGET_apm821xx)$(CONFIG_TARGET_gemini) += genext2fs
 tools-$(CONFIG_TARGET_tegra) += cbootimage cbootimage-configs
+tools-$(CONFIG_TARGET_imx6) += genext2fs
 
 # builddir dependencies
 $(curdir)/bison/compile := $(curdir)/flex/compile
-- 
2.24.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list