[PATCH] imx: add imx8mplus platform support

Piotr Dymacz pepe2k at gmail.com
Tue Aug 16 04:16:23 PDT 2022


Hi Andy,

Sorry for late reply. Please, see my comments inline below.

Rafał, Petr, it would be great if you could give your thoughts regarding 
my concerns about the 'firmware-imx' package.

On 04.07.2022 09:24, Yuantian Tang wrote:
> Imx8mplus_evk device is built to meet the needs of Smart Home,
> Building, City and Industry 4.0, 5G gateway and router  applications.
> 
> Hardware specifications:
> CPU: 4x or 2x Cortex-A53 up to 1.8 GHz
> DRAM: 32-bit DDR4 & LPDDR4 up to 4.0GT/s
> Board: imx8mp_evk
> SoC: imx8mplus
> On-board WiFi/Bluetooth chip: NXP 88W8997
> Ethernet: 2x Gigabit Ethernet with AVB, IEEE 1588, EEE and 1x w/ TSN
> 
> Signed-off-by: Yuantian Tang <andy.tang at nxp.com>
> ---
>   package/boot/atf-imx/Makefile                 |   51 +
>   package/boot/uboot-imx/Makefile               |   48 +-
>   .../uboot-imx/files/imx8mp-sdboot-uEnv.txt    |   12 +
>   package/firmware/imx/Makefile                 |   47 +
>   package/utils/imx-mkimage/Makefile            |   38 +
>   target/linux/imx/Makefile                     |    5 +-
>   target/linux/imx/config-5.15                  |  443 ---
>   target/linux/imx/cortexa7/config-default      |  441 +++
>   target/linux/imx/cortexa7/target.mk           |    2 +
>   target/linux/imx/cortexa9/config-default      |  441 +++
>   target/linux/imx/cortexa9/target.mk           |    2 +
>   target/linux/imx/image/gen_sdcard_head_img.sh |   21 +
>   target/linux/imx/image/imx8.mk                |   98 +
>   .../linux/imx/image/mkits-multiple-config.sh  |  600 ++++
>   target/linux/imx/imx8/config-5.15             | 2661 +++++++++++++++++
>   target/linux/imx/imx8/target.mk               |   11 +
>   .../0001-fix-the-compiling-error.patch        |   39 +
>   17 files changed, 4508 insertions(+), 452 deletions(-)
>   create mode 100644 package/boot/atf-imx/Makefile
>   create mode 100644 package/boot/uboot-imx/files/imx8mp-sdboot-uEnv.txt
>   create mode 100644 package/firmware/imx/Makefile
>   create mode 100644 package/utils/imx-mkimage/Makefile
>   delete mode 100644 target/linux/imx/config-5.15
>   create mode 100755 target/linux/imx/image/gen_sdcard_head_img.sh
>   create mode 100644 target/linux/imx/image/imx8.mk
>   create mode 100755 target/linux/imx/image/mkits-multiple-config.sh
>   create mode 100644 target/linux/imx/imx8/config-5.15
>   create mode 100644 target/linux/imx/imx8/target.mk
>   create mode 100644 target/linux/imx/patches-5.15/0001-fix-the-compiling-error.patch
> 
> diff --git a/package/boot/atf-imx/Makefile b/package/boot/atf-imx/Makefile
> new file mode 100644
> index 0000000000..e76393d1e9
> --- /dev/null
> +++ b/package/boot/atf-imx/Makefile

We already have bunch of arm-trusted-firmware-* packages for other 
targets and also 'include/trusted-firmware-a.mk' template.

Is there any reason to use custom approach here?

[snip]

> diff --git a/package/boot/uboot-imx/Makefile b/package/boot/uboot-imx/Makefile
> index 305d127557..f323f92dce 100644
> --- a/package/boot/uboot-imx/Makefile
> +++ b/package/boot/uboot-imx/Makefile
> @@ -7,10 +7,14 @@
>   
>   include $(TOPDIR)/rules.mk
>   
> -PKG_VERSION:=2022.01
> +PKG_NAME:=uboot-imx
> +PKG_VERSION:=lf-5.15.5-1.0.0
>  PKG_RELEASE:=$(AUTORELEASE)
>   
> -PKG_HASH:=81b4543227db228c03f8a1bf5ddbc813b0bb8f6555ce46064ef721a6fc680413
> +PKG_SOURCE_PROTO:=git
> +PKG_SOURCE_URL:=https://source.codeaurora.org/external/imx/uboot-imx

Please, use the upstream U-Boot. The 'imx8mp_evk' is supported since 
U-Boot ~2020.01 if I'm right.

Are there any specific changes in your U-Boot fork required by this 
board/platform?

[snip]

> diff --git a/package/firmware/imx/Makefile b/package/firmware/imx/Makefile
> new file mode 100644
> index 0000000000..880a882aa2
> --- /dev/null
> +++ b/package/firmware/imx/Makefile
> @@ -0,0 +1,47 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +# Copyright 2022 NXP
> +#
> +
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=firmware-imx
> +PKG_VERSION:=8.15
> +PKG_RELEASE:=1
> +
> +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).bin
> +PKG_SOURCE_URL:=https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/
> +PKG_HASH:=ef91390da6c8a6a48c8121a5dd667de8

OK, so a 'firmware-imx-8.15.bin' file, hosted somewhere on NXP servers 
which seems to be a self-extracting package with bunch of proprietary 
binary blobs and almost 700 lines license. And it asks for EULA 
acceptance when extracting:

"Welcome to NXP firmware-imx-8.15.bin

You need to read and accept the EULA before you can continue.

LA_OPT_NXP_Software_License v34 February 2022
[...]
"
I don't think we can accept this (Rafał, Petr, any opinions?). Looking 
at other open source projects, e.g. Barebox requires users to manually 
obtain and extract the firmware [1]. U-Boot documentation for this board 
mentions only the DDR training and ATF firmware [2].

Are all the blobs really required by this platform? Is there any other, 
more open source friendly way to get these binary blobs?

> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/firmware-imx
> +  SECTION:=firmware
> +  CATEGORY:=Firmware
> +  TITLE:=NXP firmware for imx soc
> +  MKIMG_DIR:=`find $(STAGING_DIR_IMAGE) -name imx-mkimage*  | xargs basename`/iMX8M
> +  BUILD_TARGET:=imx
> +  BUILD_SUBTARGET:=imx8
> +  DEPENDS:=+imx-mkimage
> +endef
> +
> +define Package/firmware-imx/install
> +endef
> +
> +define Build/Compile
> +endef
> +
> +define Build/Install
> +endef
> +
> +UNPACK_CMD:=
> +define Build/InstallDev
> +	$(PKG_UNPACK)
> +	$(CP) $(DL_DIR)/$(PKG_SOURCE) $(PKG_BUILD_DIR)
> +	chmod a+x $(PKG_BUILD_DIR)/$(PKG_SOURCE)
> +	cd $(PKG_BUILD_DIR) && ./$(PKG_SOURCE) --auto-accept

Ach, the '--auto-accept' deals with the EULA acceptance...

> +	$(CP) $(PKG_BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)/firmware/ddr/synopsys/* \
> +		$(STAGING_DIR_IMAGE)/$(MKIMG_DIR)
> +endef
> +
> +$(eval $(call BuildPackage,firmware-imx))
> diff --git a/package/utils/imx-mkimage/Makefile b/package/utils/imx-mkimage/Makefile
> new file mode 100644
> index 0000000000..4ad1b18773
> --- /dev/null
> +++ b/package/utils/imx-mkimage/Makefile
> @@ -0,0 +1,38 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +# Copyright 2022 NXP
> +#
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=imx-mkimage
> +PKG_VERSION:=lf-5.15.5-1.0.0
> +PKG_RELEASE:=$(AUTORELEASE)
> +
> +PKG_SOURCE_PROTO:=git
> +PKG_SOURCE_URL:=https://source.codeaurora.org/external/imx/imx-mkimage.git
> +PKG_SOURCE_VERSION:=lf-5.15.5-1.0.0
> +PKG_MIRROR_HASH:=fdb2086a1182b2c96e8c8dcfb795f004

Another fork? Any good reason to use this instead of tools/mkimage (we 
use version from U-Boot 2022.07 at the moment)? Is there anything 
missing in the upstream so that we can't use it?

[snip]

> diff --git a/target/linux/imx/Makefile b/target/linux/imx/Makefile
> index 5fb7a4d339..351873beaa 100644
> --- a/target/linux/imx/Makefile
> +++ b/target/linux/imx/Makefile
> @@ -4,18 +4,15 @@
>   
>   include $(TOPDIR)/rules.mk
>   
> -ARCH:=arm
>   BOARD:=imx
>   BOARDNAME:=NXP i.MX
>   FEATURES:=audio display fpu gpio pcie rtc usb usbgadget squashfs targz nand ubifs boot-part rootfs-part
> -SUBTARGETS:=cortexa7 cortexa9
> +SUBTARGETS:=cortexa7 cortexa9 imx8

Please, follow the pattern here and use 'cortexa53' instead of 'imx8'.

>   
>   KERNEL_PATCHVER:=5.15
>   
>   include $(INCLUDE_DIR)/target.mk
>   
> -KERNELNAME:=zImage dtbs
> -
>   DEFAULT_PACKAGES += uboot-envtools mkf2fs e2fsprogs blkid
>   
>   $(eval $(call BuildTarget))
> diff --git a/target/linux/imx/config-5.15 b/target/linux/imx/config-5.15
> deleted file mode 100644
> index 1a3c83274c..0000000000
> --- a/target/linux/imx/config-5.15
> +++ /dev/null

Any reason you don't want to keep common config for the whole target?
Have a look at sunxi and mvebu targets.

> @@ -1,443 +0,0 @@

[snip]

> diff --git a/target/linux/imx/cortexa7/config-default b/target/linux/imx/cortexa7/config-default
> index 480e98867f..20c77cbcbd 100644
> --- a/target/linux/imx/cortexa7/config-default
> +++ b/target/linux/imx/cortexa7/config-default
> @@ -26,3 +26,444 @@ CONFIG_SPI_FSL_QUADSPI=y
>   CONFIG_SPI_MEM=y
>   CONFIG_USB_CHIPIDEA_IMX=y
>   CONFIG_USB_EHCI_MXC=y

[snip]

> diff --git a/target/linux/imx/cortexa7/target.mk b/target/linux/imx/cortexa7/target.mk
> index 11de87507d..1fec64b00c 100644
> --- a/target/linux/imx/cortexa7/target.mk
> +++ b/target/linux/imx/cortexa7/target.mk
> @@ -1,6 +1,8 @@
> +ARCH:=arm
>   BOARDNAME:=NXP i.MX with Cortex-A7
>   CPU_TYPE:=cortex-a7
>   CPU_SUBTYPE:=neon-vfpv4
> +KERNELNAME:=zImage dtbs
>   
>   define Target/Description
>   	Build firmware images for NXP i.MX (Cortex-A7) based boards.
> diff --git a/target/linux/imx/cortexa9/config-default b/target/linux/imx/cortexa9/config-default
> index d829bc7741..42ca6ce8b5 100644
> --- a/target/linux/imx/cortexa9/config-default
> +++ b/target/linux/imx/cortexa9/config-default
> @@ -56,3 +56,444 @@ CONFIG_SOC_IMX6=y
>   CONFIG_SOC_IMX6Q=y
>   CONFIG_SOC_IMX6SL=y
>   CONFIG_SOC_IMX6SX=y

[snip]

> diff --git a/target/linux/imx/cortexa9/target.mk b/target/linux/imx/cortexa9/target.mk
> index 9bd63c7be1..cc48a8dbd0 100644
> --- a/target/linux/imx/cortexa9/target.mk
> +++ b/target/linux/imx/cortexa9/target.mk
> @@ -1,6 +1,8 @@
> +ARCH:=arm
>   BOARDNAME:=NXP i.MX with Cortex-A9
>   CPU_TYPE:=cortex-a9
>   CPU_SUBTYPE:=neon
> +KERNELNAME:=zImage dtbs >
>   define Target/Description
>   	Build firmware images for NXP i.MX (Cortex-A9) based boards.
> diff --git a/target/linux/imx/image/gen_sdcard_head_img.sh b/target/linux/imx/image/gen_sdcard_head_img.sh
> new file mode 100755
> index 0000000000..583ec1bd95
> --- /dev/null
> +++ b/target/linux/imx/image/gen_sdcard_head_img.sh
> @@ -0,0 +1,21 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +# Copyright 2022 NXP
> +
> +set -x
> +[ $# -eq 5 ] || {
> +    echo "SYNTAX: $0 <file> <kernel part offset> <kernel size> <rootfs part offset> <rootfs size>"
> +    exit 1
> +}
> +
> +OUTPUT="$1"
> +KERNELOFFSET="$(($2 * 1024))"
> +KERNELSIZE="$3"
> +ROOTFSOFFSET="$(($4 * 1024))"
> +ROOTFSSIZE="$5"
> +
> +head=4
> +sect=63
> +
> +set $(ptgen -o $OUTPUT -h $head -s $sect -t 83 -p ${KERNELSIZE}M@${KERNELOFFSET} -p ${ROOTFSSIZE}M@${ROOTFSOFFSET})
> diff --git a/target/linux/imx/image/imx8.mk b/target/linux/imx/image/imx8.mk
> new file mode 100644
> index 0000000000..0695389607
> --- /dev/null
> +++ b/target/linux/imx/image/imx8.mk
> @@ -0,0 +1,98 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +# Copyright 2022 NXP
> +
> +# 16MB bootloader + 40MB kernel
> +IMX_SD_KERNELPART_SIZE = 40
> +IMX_SD_KERNELPART_OFFSET = 16
> +IMX_SD_ROOTFSPART_OFFSET = 64
> +IMX_SD_IMAGE_SIZE = $(shell echo $$((($(IMX_SD_ROOTFSPART_OFFSET) + \
> +	$(CONFIG_TARGET_ROOTFS_PARTSIZE)))))
> +
> +define Build/imx-clean
> +	# Clean the target
> +	rm -f $@
> +endef
> +
> +define Build/imx-compile-dtb
> +	# Compile dts file to dtb
> +	$(call Image/BuildDTB,$(DTS_DIR)/$(DEVICE_DTS).dts,$(DTS_DIR)/$(DEVICE_DTS).dtb)
> +endef
> +
> +define Build/imx-create-flash
> +	# Combile firmware + bl31 + uboot to flash.bin
> +	cd $(STAGING_DIR_IMAGE)/$(MKIMG_DIR) && $(MAKE) SOC=$(PLAT) $(DEVICE_TYPE)
> +endef
> +
> +define Build/imx-append
> +	# append binary
> +	dd if=$(STAGING_DIR_IMAGE)/$(1) >> $@
> +endef
> +
> +define Build/imx-append-boot
> +	# Append the uboot, firmware etc.
> +	dd if=$(STAGING_DIR_IMAGE)/$(MKIMG_DIR)/$(SOC_TYPE)/flash.bin >> $@
> +endef
> +
> +define Build/imx-append-dtb
> +	# Append the dtb file
> +	dd if=$(DTS_DIR)/$(1).dtb >> $@
> +endef
> +
> +define Build/imx-append-kernel
> +	# append the kernel
> +	mkdir -p $@.tmp && \
> +	cp $(IMAGE_KERNEL) $@.tmp && \
> +	cp $(DTS_DIR)/$(DEVICE_DTS).dtb $@.tmp && \
> +	make_ext4fs -J -L kernel -l "$(IMX_SD_KERNELPART_SIZE)M" "$@.kernel.part" "$@.tmp" && \
> +	dd if=$@.kernel.part >> $@ && \
> +	rm -rf $@.tmp && \
> +	rm -f $@.kernel.part
> +endef
> +
> +define Build/imx-append-sdhead
> +	# Create the sd file table
> +	./gen_sdcard_head_img.sh $(STAGING_DIR_IMAGE)/$(1)-sdcard-head.img \
> +		$(IMX_SD_KERNELPART_OFFSET) $(IMX_SD_KERNELPART_SIZE) \
> +		$(IMX_SD_ROOTFSPART_OFFSET) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
> +	dd if=$(STAGING_DIR_IMAGE)/$(1)-sdcard-head.img >> $@
> +endef
> +
> +define Device/Default
> +  PROFILES := Default
> +  FILESYSTEMS := squashfs
> +  KERNEL_INITRAMFS = kernel-bin
> +  KERNEL_LOADADDR := 0x80080000
> +  KERNEL_ENTRY_POINT := 0x80080000
> +  IMAGE_SIZE := 64m
> +  KERNEL = kernel-bin
> +  IMAGES := sdcard.img sysupgrade.bin
> +  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
> +endef
> +
> +define Device/imx8mplus
> +  DEVICE_VENDOR := NXP
> +  DEVICE_MODEL := IMX8MPLUS
> +  DEVICE_VARIANT := SD Card Boot
> +  PLAT := iMX8MP

Any better and more self-explaining name than 'PLAT'?

> +  SOC_TYPE := iMX8M
> +  DEVICE_TYPE := flash_evk

This looks wrong, have a look at 'DEVICE_TYPE' in include/target.mk.

> +  ENV_NAME:=imx8mp-sdboot
> +  MKIMG_DIR:= `find $(STAGING_DIR_IMAGE) -name imx-mkimage* | xargs basename`
> +  DEVICE_PACKAGES += \
> +	atf-imx8mp \
> +	firmware-imx \
> +	imx-mkimage \
> +	u-boot-imx8mp
> +  DEVICE_DTS := freescale/imx8mp-evk
> +  IMAGE/sdcard.img := \
> +	imx-compile-dtb | \
> +	imx-create-flash | \
> +	imx-clean | \
> +	imx-append-sdhead $(1) | pad-to 32K | \
> +	imx-append-boot | pad-to 4M | \
> +	imx-append $$(ENV_NAME)-uboot-env.bin | pad-to $(IMX_SD_KERNELPART_OFFSET)M | \
> +	imx-append-kernel | pad-to $(IMX_SD_ROOTFSPART_OFFSET)M | \
> +	append-rootfs | pad-to $(IMX_SD_IMAGE_SIZE)M

I'm pretty sure all of that custom image receipts could be re-worked and 
in case of some of them a generic ones might be use but we can deal with 
that later, when other things are resolved.

> +endef
> +TARGET_DEVICES += imx8mplus
> diff --git a/target/linux/imx/image/mkits-multiple-config.sh b/target/linux/imx/image/mkits-multiple-config.sh
> new file mode 100755
> index 0000000000..0d83f9e34d
> --- /dev/null
> +++ b/target/linux/imx/image/mkits-multiple-config.sh

[snip]

Maybe instead of introducing another copy of the same script (see the 
'layerscape' target) you could reuse existing one and make some generic 
image commands out of it?

> diff --git a/target/linux/imx/imx8/config-5.15 b/target/linux/imx/imx8/config-5.15
> new file mode 100644
> index 0000000000..2b6ab299a0
> --- /dev/null
> +++ b/target/linux/imx/imx8/config-5.15
> @@ -0,0 +1,2661 @@

[snip]

> diff --git a/target/linux/imx/imx8/target.mk b/target/linux/imx/imx8/target.mk
> new file mode 100644
> index 0000000000..f990298d80
> --- /dev/null
> +++ b/target/linux/imx/imx8/target.mk
> @@ -0,0 +1,11 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +#
> +# Copyright 2022 NXP
> +
> +ARCH:=aarch64
> +BOARDNAME:=NXP i.MX8 boards
> +KERNELNAME:=Image
> +
> +define Target/Description
> +	Build firmware images for NXP imx8 boards.
> +endef
> diff --git a/target/linux/imx/patches-5.15/0001-fix-the-compiling-error.patch b/target/linux/imx/patches-5.15/0001-fix-the-compiling-error.patch
> new file mode 100644
> index 0000000000..bd2cd68be8
> --- /dev/null
> +++ b/target/linux/imx/patches-5.15/0001-fix-the-compiling-error.patch
> @@ -0,0 +1,39 @@
> +From b671acdd69098b12ff7f567b1b6211ab4f38bf20 Mon Sep 17 00:00:00 2001
> +From: Yuantian Tang <andy.tang at nxp.com>
> +Date: Tue, 28 Jun 2022 14:26:12 +0800
> +Subject: [PATCH] fix the compiling error

Please, be more specific.

> +
> +Signed-off-by: Andy Tang <andy.tang at nxp.com>
> +---
> + arch/arm64/kvm/hyp/nvhe/gen-hyprel.c | 1 +
> + scripts/Makefile                     | 2 +-
> + 2 files changed, 2 insertions(+), 1 deletion(-)
> +
> +diff --git a/arch/arm64/kvm/hyp/nvhe/gen-hyprel.c b/arch/arm64/kvm/hyp/nvhe/gen-hyprel.c
> +index 6bc88a756cb7..99506facd30e 100644
> +--- a/arch/arm64/kvm/hyp/nvhe/gen-hyprel.c
> ++++ b/arch/arm64/kvm/hyp/nvhe/gen-hyprel.c
> +@@ -36,6 +36,7 @@
> + #include <sys/types.h>
> + #include <sys/stat.h>
> + #include <unistd.h>
> ++#include <uapi/linux/elf-em.h>
> +
> + #include <generated/autoconf.h>
> +
> +diff --git a/scripts/Makefile b/scripts/Makefile
> +index 9adb6d247818..7013da949282 100644
> +--- a/scripts/Makefile
> ++++ b/scripts/Makefile
> +@@ -21,7 +21,7 @@ HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
> + HOSTCFLAGS_sign-file.o = $(CRYPTO_CFLAGS)
> + HOSTLDLIBS_sign-file = $(CRYPTO_LIBS)
> + HOSTCFLAGS_extract-cert.o = $(CRYPTO_CFLAGS)
> +-HOSTLDLIBS_extract-cert = $(CRYPTO_LIBS)
> ++HOSTLDLIBS_extract-cert = $(CRYPTO_LIBS) -lpthread
> +
> + ifdef CONFIG_UNWINDER_ORC
> + ifeq ($(ARCH),x86_64)
> +--
> +2.25.1
> +

[1] https://barebox.org/doc/latest/boards/imx/nxp-imx8mq-evk.html
[2] 
https://github.com/u-boot/u-boot/blob/master/doc/board/nxp/imx8mp_evk.rst

-- 
Cheers,
Piotr



More information about the openwrt-devel mailing list