meta-aspeed: otptool: Multiple configurations

Enable generating multiple OTP binaries by specifying multiple OTP
configuration files.

Change-Id: I1ce81cd2c1d0f501578b927eb31cce5a37cdcf1f
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/meta-aspeed/classes/otptool.bbclass b/meta-aspeed/classes/otptool.bbclass
index 5262519..7da3e6e 100644
--- a/meta-aspeed/classes/otptool.bbclass
+++ b/meta-aspeed/classes/otptool.bbclass
@@ -2,43 +2,54 @@
 # to create OTP image
 # The variables below carry default values to the create_otp()
 # function below.
-OTPTOOL_CONFIG ?= ""
+OTPTOOL_CONFIGS ?= ""
 OTPTOOL_KEY_DIR ?= ""
 OTPTOOL_EXTRA_OPTS ?= ""
 OTPTOOL_EXTRA_DEPENDS ?= " socsec-native"
 DEPENDS += '${@oe.utils.conditional("SOCSEC_SIGN_ENABLE", "1", "${OTPTOOL_EXTRA_DEPENDS}", "", d)}'
 
+do_otptool() {
+    local otptool_config=$1
+    otptool_config_slug="$(basename ${otptool_config} .json)"
+    otptool_config_outdir="${B}"/"${CONFIG_B_PATH}"/"${otptool_config_slug}"
+    mkdir -p "${otptool_config_outdir}"
+    otptool make_otp_image \
+        --key_folder ${OTPTOOL_KEY_DIR} \
+        --output_folder "${otptool_config_outdir}" \
+        ${otptool_config} \
+        ${OTPTOOL_EXTRA_OPTS}
+
+    if [ $? -ne 0 ]; then
+        bbfatal "Generated OTP image failed."
+    fi
+
+    otptool print "${otptool_config_outdir}"/otp-all.image
+
+    if [ $? -ne 0 ]; then
+        bbfatal "Printed OTP image failed."
+    fi
+
+    install -m 0644 -T \
+        "${otptool_config_outdir}"/otp-all.image \
+        ${DEPLOYDIR}/"${otptool_config_slug}"-otp-all.image
+}
+
 # Creates the OTP image
 create_otp_helper() {
     if [ "${SOC_FAMILY}" != "aspeed-g6" ] ; then
         bbwarn "OTP creation is only supported on AST2600 boards"
-    elif [ ! -e "${OTPTOOL_CONFIG}" ] ; then
-        bbfatal "Invalid otptool config: ${OTPTOOL_CONFIG}"
+    elif [ -z "${OTPTOOL_CONFIGS}" ] ; then
+        bbfatal "OTPTOOL_CONFIGS is empty, no otptool configurations available"
     elif [ ! -d "${OTPTOOL_KEY_DIR}" ] ; then
         bbfatal "Invalid otptool signing key directory: ${OTPTOOL_KEY_DIR}"
     else
-        otptool_config_slug="$(basename ${OTPTOOL_CONFIG} .json)"
-        otptool_config_outdir="${B}"/"${CONFIG_B_PATH}"/"${otptool_config_slug}"
-        mkdir -p "${otptool_config_outdir}"
-        otptool make_otp_image \
-            --key_folder ${OTPTOOL_KEY_DIR} \
-            --output_folder "${otptool_config_outdir}" \
-            ${OTPTOOL_CONFIG} \
-            ${OTPTOOL_EXTRA_OPTS}
+        for otptool_config in ${OTPTOOL_CONFIGS} ; do
+            if [ ! -e ${otptool_config} ] ; then
+                bbfatal "Invalid otptool config: ${otptool_config}"
+            fi
 
-        if [ $? -ne 0 ]; then
-            bbfatal "Generated OTP image failed."
-        fi
-
-        otptool print "${otptool_config_outdir}"/otp-all.image
-
-        if [ $? -ne 0 ]; then
-            bbfatal "Printed OTP image failed."
-        fi
-
-        install -m 0644 -T \
-            "${otptool_config_outdir}"/otp-all.image \
-            ${DEPLOYDIR}/"${otptool_config_slug}"-otp-all.image
+            do_otptool $otptool_config
+        done
     fi
 }