From bd512e368fb488c441ef4c81fd61c89459043f2c Mon Sep 17 00:00:00 2001 From: Tim Harvey Date: Fri, 12 Jan 2024 11:34:28 -0800 Subject: [PATCH] imx: add Gateworks Venice support Add support for Gateworks Venice imx8m family of boards: - required kernel modules for on-board devices - image generation - initial network config - sysupgrade support The resulting compressed disk image (bin/targets/imx/cortexa53/openwrt-imx-cortexa53-gateworks_venice-squashfs-img.gz) can be installed on a Gateworks venice board via U-Boot: u-boot=> tftpboot $loadaddr openwrt-imx-cortexa53-gateworks_venice-squashfs-img.gz && \ gzwrite mmc $dev $loadaddr $filesize WARNING: this will overwrite any boot firmware on the eMMC user hardware partition which if being used will brick your board requiring JTAG to re-program boot firmware and recover The compressed disk image contains the partition table and filesystems only and that it is expected that boot firmware is installed properly on the eMMC boot0 hardware partition. The easiest way to ensure this is to use the Gateworks JTAG adapter/process to install the latest boot firmware as follows from a Linux host: wget http://dev.gateworks.com/jtag/jtag_usbv4 chmod +x jtag_usbv4 wget http://dev.gateworks.com/venice/images/firmware-venice-imx8mm.bin sudo ./jtag_usbv4 -p firmware-venice-imx8mm.bin Signed-off-by: Tim Harvey --- .../base-files/etc/board.d/02_network | 27 ++++++++++ .../base-files/lib/preinit/79_move_config | 17 ++++++ .../base-files/lib/upgrade/platform.sh | 53 +++++++++++++++++++ target/linux/imx/cortexa53/config-default | 11 ++++ .../imx/image/bootscript-gateworks_venice | 41 ++++++++++++++ target/linux/imx/image/cortexa53.mk | 45 ++++++++++++++++ 6 files changed, 194 insertions(+) create mode 100644 target/linux/imx/cortexa53/base-files/etc/board.d/02_network create mode 100644 target/linux/imx/cortexa53/base-files/lib/preinit/79_move_config create mode 100755 target/linux/imx/cortexa53/base-files/lib/upgrade/platform.sh create mode 100644 target/linux/imx/image/bootscript-gateworks_venice diff --git a/target/linux/imx/cortexa53/base-files/etc/board.d/02_network b/target/linux/imx/cortexa53/base-files/etc/board.d/02_network new file mode 100644 index 0000000000..c6049824e0 --- /dev/null +++ b/target/linux/imx/cortexa53/base-files/etc/board.d/02_network @@ -0,0 +1,27 @@ +. /lib/functions/uci-defaults.sh + +board=$(board_name) + +board_config_update + +case "$board" in +gw,imx8mm-gw72xx-0x|\ +gw,imx8mp-gw72xx-2x|\ +gw,imx8mm-gw73xx-0x|\ +gw,imx8mp-gw73xx-2x|\ +gw,imx8mm-gw7902-0x) + ucidef_set_interfaces_lan_wan 'eth1' 'eth0' + ;; +gw,imx8mm-gw7901) + ucidef_set_interfaces_lan_wan 'lan2 lan3 lan4' 'lan1' + ;; +gateworks,imx8mp-gw74xx) + ucidef_set_network_device_path "eth0" "platform/soc@0/30800000.bus/30bf0000.ethernet" + ucidef_set_network_device_path "eth1" "platform/soc@0/30800000.bus/30be0000.ethernet" + ucidef_set_interfaces_lan_wan 'lan1 lan2 lan3 lan4' 'eth1' + ;; +esac + +board_config_flush + +exit 0 diff --git a/target/linux/imx/cortexa53/base-files/lib/preinit/79_move_config b/target/linux/imx/cortexa53/base-files/lib/preinit/79_move_config new file mode 100644 index 0000000000..a9b9a0f458 --- /dev/null +++ b/target/linux/imx/cortexa53/base-files/lib/preinit/79_move_config @@ -0,0 +1,17 @@ +. /lib/functions.sh +. /lib/upgrade/common.sh + +move_config() { + local board=$(board_name) + local partdev + + export_bootdevice && export_partdevice partdev 1 && { + mount -o rw,noatime "/dev/$partdev" /mnt + [ -f "/mnt/$BACKUP_FILE" ] && { + mv -f "/mnt/$BACKUP_FILE" / + } + umount /mnt + } +} + +boot_hook_add preinit_mount_root move_config diff --git a/target/linux/imx/cortexa53/base-files/lib/upgrade/platform.sh b/target/linux/imx/cortexa53/base-files/lib/upgrade/platform.sh new file mode 100755 index 0000000000..c59a69421a --- /dev/null +++ b/target/linux/imx/cortexa53/base-files/lib/upgrade/platform.sh @@ -0,0 +1,53 @@ + +enable_image_metadata_check() { + case "$(board_name)" in + gw,imx8m*) + REQUIRE_IMAGE_METADATA=1 + ;; + esac +} +enable_image_metadata_check + +platform_check_image() { + local board=$(board_name) + + case "$board" in + gw,imx8m*) + return 0 + ;; + esac + + echo "Sysupgrade is not yet supported on $board." + return 1 +} + +platform_do_upgrade() { + local board=$(board_name) + + case "$board" in + gw,imx8m*) + export_bootdevice && export_partdevice diskdev 0 || { + echo "Unable to find root device." + return 1 + } + v "Updating /dev/$diskdev..." + get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync + ;; + esac +} + +platform_copy_config() { + local board=$(board_name) + local partdev + + case "$board" in + gw,imx8m*) + export_partdevice partdev 1 && { + v "Storing $UPGRADE_BACKUP on /dev/$partdev..." + mount -o rw,noatime "/dev/$partdev" /mnt + cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE" + umount /mnt + } + ;; + esac +} diff --git a/target/linux/imx/cortexa53/config-default b/target/linux/imx/cortexa53/config-default index 2076395ee8..026ddf6708 100644 --- a/target/linux/imx/cortexa53/config-default +++ b/target/linux/imx/cortexa53/config-default @@ -45,6 +45,7 @@ CONFIG_CMA_AREAS=7 # CONFIG_CMA_DEBUG is not set # CONFIG_CMA_DEBUGFS is not set # CONFIG_CMA_SYSFS is not set +# CONFIG_COMMON_CLK_BD718XX is not set CONFIG_CONSOLE_TRANSLATIONS=y CONFIG_CONTIG_ALLOC=y CONFIG_CRYPTO_AES_ARM64=y @@ -96,9 +97,16 @@ CONFIG_INTERCONNECT_IMX8MN=y CONFIG_INTERCONNECT_IMX8MP=y CONFIG_INTERCONNECT_IMX8MQ=y CONFIG_MEMORY_ISOLATION=y +CONFIG_MFD_CORE=y +CONFIG_MFD_ROHM_BD718XX=y # CONFIG_MMC_SDHCI_PCI is not set CONFIG_MODULES_USE_ELF_RELA=y CONFIG_NEED_SG_DMA_LENGTH=y +# CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI is not set +CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C=y +CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON=y +# CONFIG_NET_DSA_MICROCHIP_KSZ_SPI is not set +CONFIG_NET_DSA_TAG_KSZ=y CONFIG_NOP_USB_XCEIV=y CONFIG_PARTITION_PERCPU=y CONFIG_PCI=y @@ -133,8 +141,11 @@ CONFIG_POWER_RESET=y CONFIG_POWER_SUPPLY=y CONFIG_QUEUED_RWLOCKS=y CONFIG_QUEUED_SPINLOCKS=y +CONFIG_REGMAP_IRQ=y +CONFIG_REGULATOR_BD718XX=y CONFIG_REGULATOR_MP5416=y CONFIG_REGULATOR_PCA9450=y +CONFIG_REGULATOR_ROHM=y CONFIG_RESET_IMX7=y CONFIG_RODATA_FULL_DEFAULT_ENABLED=y CONFIG_SOC_IMX8M=y diff --git a/target/linux/imx/image/bootscript-gateworks_venice b/target/linux/imx/image/bootscript-gateworks_venice new file mode 100644 index 0000000000..062947f27b --- /dev/null +++ b/target/linux/imx/image/bootscript-gateworks_venice @@ -0,0 +1,41 @@ +# distro-config bootscript +# - use only well-known variable names provided by U-Boot Distro boot +# - devtype - device type script run from (mmc|usb|scsi) +# - devnum - device number script run from (0 based int) +# - distro_bootpart - partition script run from (0 based int) +# - prefix - directory boot script was found in +# - kernel_addr_r - address to load kernel image to +# - fdt_addr_r - address to load dtb to +# - ftdcontroladdr - address dtb is at +# - fdt_file{1,2,3,4,5} name of fdt to load +# - fdt_overlays - list of fdt overlay files to load and apply +echo "Gateworks Venice OpenWrt Boot script v1.0" + +# determine root device using PARTUUID: +# - this avoids any difference beteween uboot's device names/numbers +# not matching Linux as device enumeration is not a set API. +# - PARTUUID is disk UUID concatenated with partition number +# - for MBR disk UUID is unique disk id at offset 440 +# - for GPT disk UUID is GPT UUID +# - for OpenWrt the squasfs rootfs is not readable by U-Boot so we have +# a 'boot' partition containing bootscript kernel dtbs followed by the rootfs +# partition, therefore we add 1 to the current partition +setexpr rootpart ${distro_bootpart} + 1 # root on 'next' partition +part uuid ${devtype} ${devnum}:${rootpart} uuid +setenv bootargs ${bootargs} console=${console} root=PARTUUID=${uuid} rootfstype=squashfs,ext4,f2fs rootwait + +# load dtb (we try fdt_file and then fdt_file{1,2,3,4,5}) +echo "loading DTB..." +setenv fdt_addr +setenv fdt_list $fdt_file $fdt_file1 $fdt_file2 $fdt_file3 $fdt_file4 $fdt_file5 +setenv load_fdt 'echo Loading $fdt...; load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${fdt} && setenv fdt_addr ${fdt_addr_r}' +setenv apply_overlays 'fdt addr $fdt_addr_r && fdt resize && for fdt in "$fdt_overlays"; do load ${devtype} ${devnum}:${distro_bootpart} $loadaddr $prefix/$fdt && fdt apply $loadaddr && echo applied $prefix/$fdt; done' +for fdt in ${fdt_list}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${fdt}; then run load_fdt; fi; done +if test -z "$fdt_addr"; then echo "Warning: Using bootloader DTB"; setenv fdt_addr $fdtcontroladdr; fi +if test -n "$fdt_overlays"; then echo "Applying overlays"; run apply_overlays; fi +if test -n "$fixfdt"; then echo "Adjusting FDT"; run fixfdt; fi + +# load and boot kernel +echo "loading kernel..." +load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} ${prefix}Image && +booti ${kernel_addr_r} - ${fdt_addr} diff --git a/target/linux/imx/image/cortexa53.mk b/target/linux/imx/image/cortexa53.mk index d8bf33407b..7458162da3 100644 --- a/target/linux/imx/image/cortexa53.mk +++ b/target/linux/imx/image/cortexa53.mk @@ -1,3 +1,30 @@ +define Build/boot-scr + rm -f $@-boot.scr + mkimage -A arm64 -O linux -T script -C none -a 0 -e 0 \ + -d bootscript-$(BOOT_SCRIPT) $@-boot.scr +endef + +define Build/boot-img-ext4 + rm -fR $@.boot + mkdir -p $@.boot + $(foreach dts,$(DEVICE_DTS), $(CP) $(KDIR)/image-$(dts).dtb $@.boot/$(dts).dtb;) + $(CP) $(IMAGE_KERNEL) $@.boot/$(KERNEL_NAME) + -$(CP) $@-boot.scr $@.boot/boot.scr + make_ext4fs -J -L kernel -l $(CONFIG_TARGET_KERNEL_PARTSIZE)M \ + $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \ + $@.bootimg $@.boot +endef + +define Build/sdcard-img-ext4 + SIGNATURE="$(IMG_PART_SIGNATURE)" \ + PARTOFFSET="$(PARTITION_OFFSET)" PADDING=1 \ + $(if $(filter $(1),efi),GUID="$(IMG_PART_DISKGUID)") $(SCRIPT_DIR)/gen_image_generic.sh \ + $@ \ + $(CONFIG_TARGET_KERNEL_PARTSIZE) $@.boot \ + $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS) \ + 256 +endef + define Device/Default PROFILES := Default FILESYSTEMS := squashfs ubifs ext4 @@ -13,3 +40,21 @@ define Device/imx8m DEVICE_DTS := $(basename $(notdir $(wildcard $(DTS_DIR)/freescale/imx8m*.dts))) endef TARGET_DEVICES += imx8m + +define Device/gateworks_venice + $(call Device/Default) + FILESYSTEMS := squashfs ext4 + DEVICE_VENDOR := Gateworks + DEVICE_MODEL := i.MX8M Venice + BOOT_SCRIPT := gateworks_venice + PARTITION_OFFSET := 16M + DEVICE_DTS := $(basename $(notdir $(wildcard $(DTS_DIR)/freescale/imx8m*-venice*.dts))) + DEVICE_PACKAGES := \ + kmod-hwmon-gsc kmod-rtc-ds1672 kmod-eeprom-at24 \ + kmod-gpio-button-hotplug kmod-leds-gpio kmod-pps-gpio \ + kmod-lan743x kmod-sky2 kmod-iio-st_accel-i2c \ + kmod-can kmod-can-flexcan kmod-can-mcp251x + IMAGES := img.gz + IMAGE/img.gz := boot-scr | boot-img-ext4 | sdcard-img-ext4 | gzip | append-metadata +endef +TARGET_DEVICES += gateworks_venice