From 990d957b69d62ede3a13157d83a8901bb6d07ce6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20H=C3=B6ppner?= <jonas.hoeppner@garz-fricke.com>
Date: Thu, 25 Nov 2021 16:19:29 +0100
Subject: [PATCH] imx8mpguf:Add new machine for imx8m plus variant

Add machine conf.
Adapt u-boot branch for new machine.
Adapt imxmkimage branch for new machine.
Adapt kernel receipe.
---
 conf/machine/imx8mguf.conf                    | 99 ++-----------------
 conf/machine/imx8mpguf.conf                   | 30 ++++++
 conf/machine/include/imx8guf.inc              | 85 ++++++++++++++++
 .../imx-mkimage/imx-boot_%.bbappend           | 10 ++
 .../imx-mkimage/imx-mkimage_kuk.inc           |  8 +-
 .../recipes-bsp/u-boot/u-boot-imx_%.bbappend  | 22 +++--
 .../{imx8mguf => mx8m}/defconfig              |  0
 recipes-kernel/linux/linux-imx-kuk_5.10.bb    |  2 +-
 8 files changed, 153 insertions(+), 103 deletions(-)
 create mode 100644 conf/machine/imx8mpguf.conf
 create mode 100644 conf/machine/include/imx8guf.inc
 rename recipes-kernel/linux/linux-guf-5.10/{imx8mguf => mx8m}/defconfig (100%)

diff --git a/conf/machine/imx8mguf.conf b/conf/machine/imx8mguf.conf
index cd037fc0..6b5f33e9 100644
--- a/conf/machine/imx8mguf.conf
+++ b/conf/machine/imx8mguf.conf
@@ -1,107 +1,27 @@
 #@TYPE: Machine
-#@NAME: Garz & Fricke i.MX8M Mini/Nano
-#@SOC: i.MX8M Mini/Nano
-#@DESCRIPTION: Machine configuration for Garz & Fricke i.MX8M platforms
+#@NAME: Garz & Fricke i.MX8M Mini
+#@SOC: i.MX8M Mini
+#@DESCRIPTION: Machine configuration for Garz & Fricke i.MX8MM platforms
 
 
-# Default is set to mainline, which then triggers MACHINEOVERRIDES
-# automatism, that changes the MACHINEOVERRIDES in a way not working
-# for me out of the box, 'guf' does not mean anything here
-IMX_DEFAULT_BSP = "nxp"
-# Guf does only lead to missing imx-alsa-plugins and imx-kernel-headers 
-#IMX_DEFAULT_BSP = "guf" 
-MACHINE_USES_VIVANTE_KERNEL_DRIVER_MODULE="1"
-
-require conf/machine/include/imx-base.inc 
-
-# imx-base adds wic image types, but then
-# the build fails because of imx-boot
-# so we reset the image type here
-SOC_DEFAULT_IMAGE_FSTYPES = "tar.gz" 
-
-require include/guf.inc
-
-# DEFAULTTUNE is set to cortexa53-crypto in imx-base, 
-# which does not work (yet?)
-require conf/machine/include/tune-cortexa53.inc
-
-# should we use arch-arm64 or better tune-cortexa53 ?
-# in meta-freescale cortexa53 is used, so I go with them for now
-# require conf/machine/include/arm/arch-arm64.inc
-
-
-EXTRA_IMAGEDEPENDS_append = " \
-	imx-boot \
-"
-
-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS_remove = " \
-	kernel-module-gfplatdetect \
-"
-
-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS_append = " \
-	kernel-module-8723ds \
-	linux-firmware-imx-sdma-imx7d \
-	linux-firmware-imx-vpu \
-	rtl8723ds \
-	rtl8723ds-bt-uart-driver \
-"
-
-# Spreadspectrum is a python script and we don't want python in fngsystem
-# TODO: Create alternative, maybe sh?
-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS_append_guf = " \
-	spreadspectrum \
-"
+require include/imx8guf.inc
 
 # Support mx8mn here, as well, or is separate machine-config required for Nano ?
 SOC_FAMILY = "mx8:mx8m:mx8mm"
-
-PREFERRED_PROVIDER_virtual/kernel = "linux-imx-kuk"
-PREFERRED_VERSION_linux-guf = "5.10.9"
-
-PREFERRED_PROVIDER_u-boot = "u-boot-imx"
-PREFERRED_PROVIDER_virtual/bootloader = "u-boot-imx"
-PREFERRED_VERSION_u-boot = "2019.04"
-
-PREFERRED_VERSION_gstreamer1.0 = "1.16.imx"
-PREFERRED_VERSION_gstreamer1.0-plugins-base = "1.16.imx"
-PREFERRED_VERSION_gstreamer1.0-plugins-good = "1.16.imx"
-PREFERRED_VERSION_gstreamer1.0-plugins-bad = "1.16.imx"
-
-# uImage and zImage build targets not supported for arm64.
-# If compressed kernel images are to be used, bootloader must unpack them
-KERNEL_IMAGETYPE = "Image"
-
-# Seems not to get set for i.MX8. So far, no idea how this is going to work... PIC?
-LOADADDR = ""
+ATF_PLATFORM = "imx8mm"
 
 # Not sure, if UBOOT_MACHINE or UBOOT_CONFIG should be set to select the proper platform
 # both at once is not possible
-# UBOOT_MACHINE = "tanaro_v1r1_1gb_config"
-UBOOT_CONFIG ??= "sd"
 UBOOT_CONFIG[sd] = "tanaro_v1r1_1gb_defconfig,sdcard"
 
 # so far it seems that TANARO needs the trizeps8mini DTB for U-Boot
 UBOOT_DTB_NAME = "kuk-trizeps8mini.dtb"
-
-# Do we need to set these variables?
-UBOOT_SUFFIX = "bin"
-UBOOT_MAKE_TARGET = ""
-SPL_BINARY = "spl/u-boot-spl.bin"
-BOOT_SPACE = "65536"
-
 # Set imx-mkimage boot target
 IMXBOOT_TARGETS = "flash_trizeps8mini"
 
-# i.MX8 documentation suggests, we need a seek of 32, NXP and KuK seem to use 33, though
+# i.MX8MM needs a seek of 33 (used for wic image only)
 IMX_BOOT_SEEK = "33"
 
-# Set DDR FIRMWARE: TANARO uses LPDDR4
-# Firmware is provided by imx-mkimage-kuk repo, so no need to specify here additionally
-# DDR_FIRMWARE_NAME = "lpddr4_pmu_train_1d_imem.bin \
-#                      lpddr4_pmu_train_1d_dmem.bin \
-#                      lpddr4_pmu_train_2d_imem.bin \
-#                      lpddr4_pmu_train_2d_dmem.bin"
-
 OPTEE_BIN_EXT = "8m"
 
 KERNEL_DEVICETREE ?= " \
@@ -112,10 +32,3 @@ KERNEL_DEVICETREE ?= " \
     keithkoep/kuk-trizeps8mini-pconxs-edt7cap.dtb \
 "
 
-SERIAL_CONSOLES = "115200;ttymxc0"
-
-# build WIC image for IMX8M
-IMAGE_FSTYPES_append_guf = " wic "
-WKS_FILE = "guf-imx-boot-bootpart.wks.in"
-
-
diff --git a/conf/machine/imx8mpguf.conf b/conf/machine/imx8mpguf.conf
new file mode 100644
index 00000000..24f5282a
--- /dev/null
+++ b/conf/machine/imx8mpguf.conf
@@ -0,0 +1,30 @@
+#@TYPE: Machine
+#@NAME: Garz & Fricke i.MX8M Plus
+#@SOC: i.MX8M Plus
+#@DESCRIPTION: Machine configuration for Garz & Fricke i.MX8MP platforms
+
+
+require include/imx8guf.inc
+
+# Support mx8mn here, as well, or is separate machine-config required for Nano ?
+SOC_FAMILY = "mx8:mx8m:mx8mp"
+ATF_PLATFORM = "imx8mp"
+
+# Not sure, if UBOOT_MACHINE or UBOOT_CONFIG should be set to select the proper platform
+# both at once is not possible
+UBOOT_CONFIG[sd] = "trizeps8plus_defconfig,sdcard"
+
+# so far it seems that TANARO needs the trizeps8mini DTB for U-Boot
+UBOOT_DTB_NAME = "kuk-trizeps8plus.dtb"
+# Set imx-mkimage boot target
+IMXBOOT_TARGETS = "flash_trizeps8plus"
+
+# i.MX8MM needs a seek of 32 (used for wic image only)
+IMX_BOOT_SEEK = "32"
+
+OPTEE_BIN_EXT = "8m"
+
+KERNEL_DEVICETREE ?= " \
+    keithkoep/kuk-trizeps8plus-pconxs_v3-atm0700.dtb \
+"
+
diff --git a/conf/machine/include/imx8guf.inc b/conf/machine/include/imx8guf.inc
new file mode 100644
index 00000000..f47dd1ae
--- /dev/null
+++ b/conf/machine/include/imx8guf.inc
@@ -0,0 +1,85 @@
+# Default is set to mainline, which then triggers MACHINEOVERRIDES
+# automatism, that changes the MACHINEOVERRIDES in a way not working
+# for me out of the box, 'guf' does not mean anything here
+IMX_DEFAULT_BSP = "nxp"
+# Guf does only lead to missing imx-alsa-plugins and imx-kernel-headers 
+#IMX_DEFAULT_BSP = "guf" 
+MACHINE_USES_VIVANTE_KERNEL_DRIVER_MODULE="1"
+
+require conf/machine/include/imx-base.inc 
+
+# imx-base adds wic image types, but then
+# the build fails because of imx-boot
+# so we reset the image type here
+SOC_DEFAULT_IMAGE_FSTYPES = "tar.gz" 
+
+require guf.inc
+
+# DEFAULTTUNE is set to cortexa53-crypto in imx-base, 
+# which does not work (yet?)
+require conf/machine/include/tune-cortexa53.inc
+
+# should we use arch-arm64 or better tune-cortexa53 ?
+# in meta-freescale cortexa53 is used, so I go with them for now
+# require conf/machine/include/arm/arch-arm64.inc
+
+
+EXTRA_IMAGEDEPENDS_append = " \
+	imx-boot \
+"
+
+MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS_remove = " \
+	kernel-module-gfplatdetect \
+"
+
+MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS_append = " \
+	kernel-module-8723ds \
+	linux-firmware-imx-sdma-imx7d \
+	linux-firmware-imx-vpu \
+	rtl8723ds \
+	rtl8723ds-bt-uart-driver \
+"
+
+# Spreadspectrum is a python script and we don't want python in fngsystem
+# TODO: Create alternative, maybe sh?
+MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS_append_guf = " \
+	spreadspectrum \
+"
+
+# Do we need to set these variables?
+UBOOT_SUFFIX = "bin"
+UBOOT_MAKE_TARGET = ""
+SPL_BINARY = "spl/u-boot-spl.bin"
+BOOT_SPACE = "65536"
+UBOOT_CONFIG ??= "sd"
+
+# Set DDR FIRMWARE: TANARO uses LPDDR4
+# Firmware is provided by imx-mkimage-kuk repo, so no need to specify here additionally
+# DDR_FIRMWARE_NAME = "lpddr4_pmu_train_1d_imem.bin \
+#                      lpddr4_pmu_train_1d_dmem.bin \
+#                      lpddr4_pmu_train_2d_imem.bin \
+#                      lpddr4_pmu_train_2d_dmem.bin"
+
+PREFERRED_PROVIDER_virtual/kernel = "linux-imx-kuk"
+PREFERRED_VERSION_linux-guf = "5.10.9"
+
+PREFERRED_PROVIDER_u-boot = "u-boot-imx"
+PREFERRED_PROVIDER_virtual/bootloader = "u-boot-imx"
+PREFERRED_VERSION_u-boot = "2019.04"
+
+PREFERRED_VERSION_gstreamer1.0 = "1.16.imx"
+PREFERRED_VERSION_gstreamer1.0-plugins-base = "1.16.imx"
+PREFERRED_VERSION_gstreamer1.0-plugins-good = "1.16.imx"
+PREFERRED_VERSION_gstreamer1.0-plugins-bad = "1.16.imx"
+
+# uImage and zImage build targets not supported for arm64.
+# If compressed kernel images are to be used, bootloader must unpack them
+KERNEL_IMAGETYPE = "Image"
+
+# Seems not to get set for i.MX8. So far, no idea how this is going to work... PIC?
+LOADADDR = ""
+
+
+# build WIC image for IMX8
+IMAGE_FSTYPES_append_guf = " wic "
+WKS_FILE = "guf-imx-boot-bootpart.wks.in"
diff --git a/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-boot_%.bbappend b/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-boot_%.bbappend
index 9587d1c8..dd795cae 100644
--- a/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-boot_%.bbappend
+++ b/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-boot_%.bbappend
@@ -3,9 +3,16 @@ require imx-mkimage_kuk.inc
 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
 
 SOC_TARGET_imx8mguf = "iMX8MM"
+SOC_TARGET_imx8mpguf = "iMX8MP"
 SOC_FAMILY_imx8mguf = "mx8m"
+SOC_FAMILY_imx8mpguf = "mx8m"
 ATF_MACHINE_NAME_imx8mguf = "bl31-imx8mm.bin"
+ATF_MACHINE_NAME_imx8mpguf = "bl31-imx8mp.bin"
 BOOT_STAGING_imx8mguf = "${S}/iMX8M"
+BOOT_STAGING_imx8mpguf = "${S}/iMX8M"
+
+# Using prepuilt bl31 for now
+DEPENDS_remove = "imx-atf"
 
 # Remove some copy operations from the original compile_mx8m, because we already
 # have some of the files fscl wants to copy there checked out
@@ -18,6 +25,9 @@ compile_mx8m() {
     cp ${DEPLOY_DIR_IMAGE}/${BOOT_TOOLS}/u-boot-nodtb.bin-${MACHINE}-${UBOOT_CONFIG} \
                                                              ${BOOT_STAGING}/u-boot-nodtb.bin
     cp ${STAGING_DIR_NATIVE}/${bindir}/mkimage               ${BOOT_STAGING}/mkimage_uboot
+    
+    # bl31 is already part of the mkimage repo
+    #cp ${DEPLOY_DIR_IMAGE}/${BOOT_TOOLS}/${ATF_MACHINE_NAME} ${BOOT_STAGING}/bl31.bin
     cp ${BOOT_STAGING}/${ATF_MACHINE_NAME}                   ${BOOT_STAGING}/bl31.bin
     cp ${DEPLOY_DIR_IMAGE}/${UBOOT_NAME}                     ${BOOT_STAGING}/u-boot.bin
 }
diff --git a/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-mkimage_kuk.inc b/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-mkimage_kuk.inc
index b7351598..df700ad4 100644
--- a/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-mkimage_kuk.inc
+++ b/dynamic-layers/freescale-layer/recipes-bsp/imx-mkimage/imx-mkimage_kuk.inc
@@ -1,3 +1,7 @@
-SRCBRANCH = "kuk_imx_4.14.98_2.0.0_ga"
 SRC_URI = "git://git@gitlab.com/garz-fricke/3rd-party/kuk/imx-mkimage-kuk.git;protocol=ssh;branch=${SRCBRANCH}"
-SRCREV = "578867c831879c4c9087292fb93ed2ee7ccd3505"
+
+SRCBRANCH_imx8mguf = "kuk_imx_4.14.98_2.0.0_ga"
+SRCREV_imx8mguf = "578867c831879c4c9087292fb93ed2ee7ccd3505"
+
+SRCBRANCH_imx8mpguf = "kuk_lf-5.10.52_2.1.0"
+SRCREV_imx8mpguf = "3748257787e25fea042c8e05cfe83cb6938a3f34"
diff --git a/dynamic-layers/freescale-layer/recipes-bsp/u-boot/u-boot-imx_%.bbappend b/dynamic-layers/freescale-layer/recipes-bsp/u-boot/u-boot-imx_%.bbappend
index 3db9138c..342aa0b1 100644
--- a/dynamic-layers/freescale-layer/recipes-bsp/u-boot/u-boot-imx_%.bbappend
+++ b/dynamic-layers/freescale-layer/recipes-bsp/u-boot/u-boot-imx_%.bbappend
@@ -3,14 +3,22 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
 # Get include file from poky layer
 FILESEXTRAPATHS_append := "${BSPDIR}/sources/poky/meta/recipes-bsp/u-boot/files:"
 
-COMPATIBLE_MACHINE = "(imx8mguf)"
+COMPATIBLE_MACHINE = "(imx8mguf|imx8mpguf)"
 
-PV = "2019.04"
-
-# Keith und Koep u-boot for imx8
-SRCBRANCH = "guf_imx_v2019.04_5.4.3_2021-11-29"
-SRCREV = "${AUTOREV}"
 SRC_URI = "git://git@gitlab.com/garz-fricke/3rd-party/kuk/uboot-imx-kuk.git;protocol=ssh;branch=${SRCBRANCH};nobranch=1 \
            file://add-u-boot-initial-env-target-to-Makefile.patch \
-           file://remove-redundant-yyloc-global.patch \
 "
+SRCREV = "${AUTOREV}"
+
+## Keith und Koep u-boot for imx8
+
+# imx8mm
+PV_imx8mguf = "2019.04"
+SRCBRANCH_imx8mguf = "guf_imx_v2019.04_5.4.3_2021-11-29"
+SRC_URI_append_imx8mguf = " \
+           file://remove-redundant-yyloc-global.patch \
+           "
+
+# imx8mp
+PV_imx8mpguf = "2020.04"
+SRCBRANCH_imx8mpguf = "kuk_imx_v2020.04-tr8plus"
diff --git a/recipes-kernel/linux/linux-guf-5.10/imx8mguf/defconfig b/recipes-kernel/linux/linux-guf-5.10/mx8m/defconfig
similarity index 100%
rename from recipes-kernel/linux/linux-guf-5.10/imx8mguf/defconfig
rename to recipes-kernel/linux/linux-guf-5.10/mx8m/defconfig
diff --git a/recipes-kernel/linux/linux-imx-kuk_5.10.bb b/recipes-kernel/linux/linux-imx-kuk_5.10.bb
index 6938237d..585a0036 100644
--- a/recipes-kernel/linux/linux-imx-kuk_5.10.bb
+++ b/recipes-kernel/linux/linux-imx-kuk_5.10.bb
@@ -2,7 +2,7 @@ require linux-guf.inc
 
 KERNEL_CONFIG_COMMAND = "oe_runmake_call -C ${S} CC="${KERNEL_CC}" O=${B} olddefconfig"
 
-COMPATIBLE_MACHINE = "(imx8mguf)"
+COMPATIBLE_MACHINE = "(imx8mguf|imx8mpguf)"
 
 LINUX_VERSION = "5.10"
 LINUX_VERSION_EXTENSION = "-guf"
-- 
GitLab