meta-nuvoton: npcm8xx-bootloader: initial recipe

Add new recipe npcm8xx-bootloader to replace npcm8xx-igps-native, and
also remove relative merge/sign functions and settings.

Tested:
TIP/No TIP/SA boot OK.
Settings replace function work, hardening replace work.

Change-Id: I1db20b483cf1de72ce05ca2a14df0a75fdb37d36
Signed-off-by: Brian Ma <chma0@nuvoton.com>
diff --git a/meta-nuvoton/recipes-bsp/images/npcm8xx-bootloader/settings.json b/meta-nuvoton/recipes-bsp/images/npcm8xx-bootloader/settings.json
new file mode 100644
index 0000000..8a741dc
--- /dev/null
+++ b/meta-nuvoton/recipes-bsp/images/npcm8xx-bootloader/settings.json
@@ -0,0 +1,13 @@
+{
+    "BootBlockAndHeader.xml":
+    {
+        "MC_CONFIG": "0x04"
+    },
+    "key_setting_edit_me.py":
+    {
+        "COMBO1_OFFSET": "2048*1024"
+    },
+    "BootBlockAndHeader_no_tip.xml":
+    {
+    }
+}
diff --git a/meta-nuvoton/recipes-bsp/images/npcm8xx-bootloader_0.1.0.bb b/meta-nuvoton/recipes-bsp/images/npcm8xx-bootloader_0.1.0.bb
new file mode 100644
index 0000000..69ceeae
--- /dev/null
+++ b/meta-nuvoton/recipes-bsp/images/npcm8xx-bootloader_0.1.0.bb
@@ -0,0 +1,92 @@
+SUMMARY = "Nuvoton NPCM8XX bootloader"
+DESCRIPTION = "This is front end recipe for NPCM8XX IGPS. It replace \
+original IGPS recipe which need implement many redundant function in \
+recipe or class. After we add some hook in IGPS, now we can generate \
+full bootbloader by IGPS script. We only need collect all built images \
+from deploy folder, put them to IGPS input folder, and run script."
+HOMEPAGE = "https://github.com/Nuvoton-Israel/igps-npcm8xx"
+LICENSE = "GPL-2.0-only"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=b234ee4d69f5fce4486a80fdaf4a4263"
+
+IGPS_BRANCH ?= "main"
+SRC_URI = " \
+    git://github.com/Nuvoton-Israel/igps-npcm8xx;branch=${IGPS_BRANCH};protocol=https \
+"
+SRCREV = "518d3f58f4f157373a5b1aaebaf22f80bb13d0d9"
+
+S = "${WORKDIR}/git"
+
+DEPENDS = " \
+    npcm8xx-tip-fw npcm8xx-bootblock trusted-firmware-a optee-os \
+    u-boot-nuvoton npcm7xx-bingo-native openssl-native \
+"
+inherit obmc-phosphor-utils
+inherit python3native deploy
+FILE_FMT = "file://{}"
+
+# Sign keys, replace them for production
+IGPS_KEYS = ""
+# Configuration files, clean them if no need
+IGPS_CSVS = ""
+IGPS_SETTINGS = "settings.json"
+IGPS_CONFS = "${IGPS_KEYS} ${IGPS_CSVS} ${IGPS_SETTINGS}"
+SRC_URI += "${@compose_list(d, 'FILE_FMT', 'IGPS_CONFS')}"
+
+IGPS_SCRIPT_BASE = "${S}/py_scripts/ImageGeneration"
+BB_BIN = "arbel_a35_bootblock"
+BB_BIN .= "${@'_no_tip.bin' if d.getVar("TIP_IMAGE") != 'True' else '.bin'}"
+
+do_configure[dirs] = "${WORKDIR}"
+do_configure() {
+    KEY_FOLDER=${IGPS_SCRIPT_BASE}/keys/openssl
+    CSV_FOLDER=${IGPS_SCRIPT_BASE}/inputs/registers
+    # keys
+    install -d ${KEY_FOLDER}
+    if [ -n "${IGPS_KEYS}" ];then
+        cp -v ${IGPS_KEYS} ${KEY_FOLDER}
+    fi
+
+    # csv files
+    install -d ${CSV_FOLDER}
+    if [ -n "${IGPS_CSVS}" ];then
+        cp -v ${IGPS_CSVS} ${CSV_FOLDER}
+    fi
+
+    # change customized settings for XML and key setting
+    if [ -n "${IGPS_SETTINGS}" ];then
+        cd ${S}
+        python3 ${IGPS_SCRIPT_BASE}/config_replacer.py ${WORKDIR}/${IGPS_SETTINGS}
+    fi
+}
+
+do_compile() {
+    # copy Openbmc built images
+    cd ${DEPLOY_DIR_IMAGE}
+    cp -v ${BB_BIN} bl31.bin tee.bin u-boot.bin ${IGPS_SCRIPT_BASE}/inputs
+
+    cd ${IGPS_SCRIPT_BASE}
+    install -d output_binaries/tmp
+    install -d inputs/key_input
+    if [ "${TIP_IMAGE}" = "True" ] || [ "${SA_TIP_IMAGE}" = "True" ];then
+      # Do not sign combo0 image again
+      python3 ${S}/py_scripts/GenerateAll.py openssl ${DEPLOY_DIR_IMAGE}
+    else
+      # for No TIP, we can run IGPS script directly
+      python3 ${S}/py_scripts/GenerateAll.py openssl
+    fi
+}
+
+do_deploy() {
+    OUT=${IGPS_SCRIPT_BASE}/output_binaries
+    BOOTLOADER=u-boot.bin.merged
+    install -d ${DEPLOYDIR}
+    if [ "${SA_TIP_IMAGE}" = "True" ];then
+        install -m 644 ${OUT}/Secure/image_no_tip_SA.bin ${DEPLOYDIR}/${BOOTLOADER}
+    elif [ "${TIP_IMAGE}" = "True" ];then
+        install -m 644 ${OUT}/Secure/Kmt_TipFwL0_Skmt_TipFwL1_BootBlock_BL31_Tee_uboot.bin ${DEPLOYDIR}/${BOOTLOADER}
+    else
+        install -m 644 ${OUT}/Basic/image_no_tip.bin ${DEPLOYDIR}/${BOOTLOADER}
+    fi
+}
+addtask deploy before do_build after do_compile
+PACKAGE_ARCH = "${MACHINE_ARCH}"
diff --git a/meta-nuvoton/recipes-bsp/images/npcm8xx-igps-native_04.01.03.bb b/meta-nuvoton/recipes-bsp/images/npcm8xx-igps-native_04.01.03.bb
deleted file mode 100644
index 78210af..0000000
--- a/meta-nuvoton/recipes-bsp/images/npcm8xx-igps-native_04.01.03.bb
+++ /dev/null
@@ -1,4 +0,0 @@
-# tag IGPS_04.01.03
-SRCREV = "ae5ddb6c8ff350835d411b9e3bfb4443db596067"
-
-require npcm8xx-igps.inc
diff --git a/meta-nuvoton/recipes-bsp/images/npcm8xx-igps.inc b/meta-nuvoton/recipes-bsp/images/npcm8xx-igps.inc
deleted file mode 100644
index 7c043f8..0000000
--- a/meta-nuvoton/recipes-bsp/images/npcm8xx-igps.inc
+++ /dev/null
@@ -1,46 +0,0 @@
-SUMMARY = "Image Generation and Programming Scripts for NPCM8XX (Arbel) devices"
-DESCRIPTION = "Image Generation and Programming Scripts for NPCM8XX (Arbel) devices"
-HOMEPAGE = "https://github.com/Nuvoton-Israel/igps-npcm8xx"
-LICENSE = "GPLv2"
-LIC_FILES_CHKSUM = "file://LICENSE;md5=b234ee4d69f5fce4486a80fdaf4a4263"
-
-IGPS_BRANCH ?= "main"
-SRC_URI = " \
-    git://github.com/Nuvoton-Israel/igps-npcm8xx;branch=${IGPS_BRANCH};protocol=https \
-"
-
-S = "${WORKDIR}/git"
-
-DEST = "${D}${datadir}/${BPN}"
-
-# Adjust paths for use with bitbake
-do_patch() {
-	sed -i -e 's,output_binaries/tmp/,,g' ${S}/py_scripts/ImageGeneration/references/*.xml \
-		${S}/py_scripts/ImageGeneration/inputs/*.xml
-}
-
-do_install() {
-	install -d ${DEST}
-    if [ "${TIP_IMAGE}" = "True" ] ; then
-        install py_scripts/ImageGeneration/references/BootBlockAndHeader_${DEVICE_GEN}_${IGPS_MACHINE}.xml ${DEST}
-	else
-        install py_scripts/ImageGeneration/references/BootBlockAndHeader_${DEVICE_GEN}_${IGPS_MACHINE}_NoTip.xml ${DEST}
-    fi
-	install py_scripts/ImageGeneration/references/UbootHeader_${DEVICE_GEN}.xml ${DEST}
-	install py_scripts/ImageGeneration/inputs/BL31_AndHeader.xml ${DEST}
-	install py_scripts/ImageGeneration/inputs/OpTeeAndHeader.xml ${DEST}
-	install py_scripts/ImageGeneration/asn1.py ${DEST}
-	install py_scripts/ImageGeneration/BinarySignatureGenerator.py ${DEST}
-}
-
-inherit deploy
-
-do_deploy () {
-	# copy default keys to deploy folder
-	install -d ${DEPLOYDIR}
-	cp -vur py_scripts/ImageGeneration/keys/${SIGN_TYPE} ${DEPLOYDIR}/
-}
-
-inherit native
-
-addtask deploy before do_build after do_compile