meta-ampere: mtjade: Add more Host firmware support

Add support SCP firmware update with checking if the ampere_fru_upgrade
available to execute the update.
This commit also supports 2nd Host SPI-NOR update ability.

Tested:
1. Manually copy ampere_fru_upgrade to the /usr/sbin folder and run SCP
firmware update via Redfish.
2. Flash UEFI firmware update on the secondary Host SPI-NOR.

Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: Ic335ee2d21625239c3df1937ed5333708233845b
diff --git a/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh b/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh
index b7f4bc5..b13e4b5 100755
--- a/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh
@@ -15,10 +15,8 @@
 # limitations under the License.
 
 do_flash () {
-        OFFSET=$1
-
 	# Check the PNOR partition available
-	HOST_MTD=$(< /proc/mtd grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
+	HOST_MTD=$(< /proc/mtd grep "pnor-uefi" | sed -n 's/^\(.*\):.*/\1/p')
 	if [ -z "$HOST_MTD" ];
 	then
 		# If the PNOR partition is not available, then bind again driver
@@ -26,7 +24,7 @@
 		echo 1e630000.spi > /sys/bus/platform/drivers/aspeed-smc/bind
 		sleep 2
 
-		HOST_MTD=$(< /proc/mtd grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
+		HOST_MTD=$(< /proc/mtd grep "pnor-uefi" | sed -n 's/^\(.*\):.*/\1/p')
 		if [ -z "$HOST_MTD" ];
 		then
 			echo "Fail to probe Host SPI-NOR device"
@@ -34,8 +32,8 @@
 		fi
 	fi
 
-	echo "--- Flashing firmware to @/dev/$HOST_MTD offset=$OFFSET"
-	flashcp -v "$IMAGE" /dev/"$HOST_MTD" "$OFFSET"
+	echo "--- Flashing firmware to @/dev/$HOST_MTD"
+	flashcp -v "$IMAGE" /dev/"$HOST_MTD"
 }
 
 
@@ -50,6 +48,12 @@
 	exit 1
 fi
 
+if [ -z "$2" ]; then
+       DEV_SEL="1"    # by default, select primary device
+else
+       DEV_SEL="$2"
+fi
+
 # Turn off the Host if it is currently ON
 chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
 echo "--- Current Chassis State: $chassisstate"
@@ -74,8 +78,21 @@
 	exit 1
 fi
 
+# Switch the host SPI bus (between primary and secondary)
+# 227 is BMC_SPI0_BACKUP_SEL
+if [[ $DEV_SEL == 1 ]]; then
+	echo "Run update primary Host SPI-NOR"
+	gpioset 0 227=0       # Primary SPI
+elif [[ $DEV_SEL == 2 ]]; then
+	echo "Run update secondary Host SPI-NOR"
+	gpioset 0 227=1       # Second SPI
+else
+	echo "Please choose primary SPI (1) or second SPI (2)"
+	exit 0
+fi
+
 # Flash the firmware
-do_flash 0x400000
+do_flash
 
 # Switch the host SPI bus to HOST."
 echo "--- Switch the host SPI bus to HOST."