phosphor: u-boot: Switch sides on failure to boot

This is an incomplete effort to prevent a hang in u-boot due to a
failed `boot` command. This will not take affect by updating via the
ubi.mtd.tar method, as it does not allow arbitrary updates to the u-boot
environment. Resolving that issue will take at least one more change and
force a double reboot to complete the upgrade, or writing the full flash
image and take the hit of the associated loss of system-specific
settings (such as network configuration).

Tested: Instrumented which chip the system was currently booted from,
	configured u-boot with a broken kernelname environment variable,
	attempted to boot, confirmed a system reset occurred and the
 	chip used by the reboot was different.

Change-Id: I825728caff6b5d4bb4d527bfe86488d5f5487f14
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/meta-phosphor/common/recipes-bsp/u-boot/files/0005-config-ast-common-Fall-back-to-secondary-flash-on-fa.patch b/meta-phosphor/common/recipes-bsp/u-boot/files/0005-config-ast-common-Fall-back-to-secondary-flash-on-fa.patch
new file mode 100644
index 0000000..c54b734
--- /dev/null
+++ b/meta-phosphor/common/recipes-bsp/u-boot/files/0005-config-ast-common-Fall-back-to-secondary-flash-on-fa.patch
@@ -0,0 +1,34 @@
+From 345b1ade63576f5a8a1c3a4a1b75aab41d84b714 Mon Sep 17 00:00:00 2001
+From: Andrew Jeffery <andrew@aj.id.au>
+Date: Fri, 20 Apr 2018 13:29:58 +0930
+Subject: [PATCH] config/ast-common: Fall-back to secondary flash on failed
+ bootm
+
+Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
+---
+ include/configs/ast-common.h | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/include/configs/ast-common.h b/include/configs/ast-common.h
+index ad08016ec110..10ef6a1955b7 100644
+--- a/include/configs/ast-common.h
++++ b/include/configs/ast-common.h
+@@ -127,12 +127,14 @@
+ #define CONFIG_ENV_OVERWRITE
+ 
+ #define ASPEED_ENV_SETTINGS \
++	"wdt2bite=mw.l 0x1e785024 0xa 1; mw.b 0x1e78502c 0xb3 1 \0" \
++	"bootalt=run wdt2bite \0" \
+ 	"ubiblock=0,1 \0" \
+ 	"root=/dev/ubiblock0_1 \0" \
+ 	"kernelname=kernel-0 \0" \
+ 	"loadaddr=" __stringify(CONFIG_LOADADDR) "\0" \
+ 	"set_bootargs=setenv bootargs " CONFIG_BOOTARGS " ubi.block=\${ubiblock} root=\${root} \0" \
+-	"obmc_bootcmd=ubi part obmc-ubi; run do_rwreset; ubi read ${loadaddr} ${kernelname}; bootm ${loadaddr} \0" \
++	"obmc_bootcmd=ubi part obmc-ubi; run do_rwreset; ubi read ${loadaddr} ${kernelname}; bootm ${loadaddr} || run bootalt \0" \
+ 	"verify=yes\0"	\
+ 	"spi_dma=yes\0" \
+ 	"mtdids=" MTDIDS_DEFAULT "\0" \
+-- 
+2.14.1
+
diff --git a/meta-phosphor/common/recipes-bsp/u-boot/u-boot-aspeed.inc b/meta-phosphor/common/recipes-bsp/u-boot/u-boot-aspeed.inc
index 6ec91b4..5286c1b 100644
--- a/meta-phosphor/common/recipes-bsp/u-boot/u-boot-aspeed.inc
+++ b/meta-phosphor/common/recipes-bsp/u-boot/u-boot-aspeed.inc
@@ -6,6 +6,7 @@
     file://0002-config-ast-common-hack-bootopts.patch \
     file://0003-config-ast-common-Add-bootopts-to-support-ubi-and-mt.patch \
     file://0004-config-ast-common-Add-conditional-factory-reset-comm.patch \
+    file://0005-config-ast-common-Fall-back-to-secondary-flash-on-fa.patch \
     "
 
 do_patch[depends] += "os-release:do_populate_sysroot"