u-boot: Reorder and update patches and bootenv fixes

Yocto does not apply patches by name, but instead it applies them
in the order that files are added to the SRC_URI variable.

Therefore move the common patch file to the top in the u-boot.inc file,
followed by the optional patches that are enabled via machine feature.
Update the patches so that they apply on that order.

Fix the loadaddr env variable to convert from an int.
Escape bootargs variables to keep the variable names and not have
them replaced during build time.

Change-Id: I28d469c643d66e4b11225f37c3331e471676aec5
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/common/recipes-bsp/u-boot/files/0001-config-ast-common-hack-bootopts.patch b/common/recipes-bsp/u-boot/files/0001-config-ast-common-hack-bootopts.patch
index d168769..f0895ce 100644
--- a/common/recipes-bsp/u-boot/files/0001-config-ast-common-hack-bootopts.patch
+++ b/common/recipes-bsp/u-boot/files/0001-config-ast-common-hack-bootopts.patch
@@ -9,7 +9,7 @@
  1 file changed, 6 insertions(+)
 
 diff --git a/include/configs/ast-common.h b/include/configs/ast-common.h
-index 110c780070..6f2a50b854 100644
+index 15e1db4..e7fa6ed 100644
 --- a/include/configs/ast-common.h
 +++ b/include/configs/ast-common.h
 @@ -84,7 +84,10 @@
@@ -23,9 +23,9 @@
  
  #define CONFIG_AST_SPI_NOR    /* AST SPI NOR Flash */
  #define CONFIG_FMC_CS			1
-@@ -96,11 +99,14 @@
- #define CONFIG_ENV_OFFSET		0x60000	/* environment starts here  */
- #define CONFIG_ENV_SIZE			0x20000	/* Total Size of Environment Sector */
+@@ -99,11 +102,14 @@
+ #define CONFIG_ENV_SIZE			0x10000	/* Total Size of Environment Sector */
+ #define CONFIG_ENV_SIZE_REDUND		0x10000
  
 +#if 0
  #define CONFIG_BOOTCOMMAND	\
@@ -39,5 +39,5 @@
  
  #define ASPEED_ENV_SETTINGS \
 -- 
-2.13.0
+1.8.2.2
 
diff --git a/common/recipes-bsp/u-boot/files/0004-config-ast-common-ubi-bootops.patch b/common/recipes-bsp/u-boot/files/0004-config-ast-common-ubi-bootops.patch
index d018565..4e465ce 100644
--- a/common/recipes-bsp/u-boot/files/0004-config-ast-common-ubi-bootops.patch
+++ b/common/recipes-bsp/u-boot/files/0004-config-ast-common-ubi-bootops.patch
@@ -9,7 +9,7 @@
  1 file changed, 18 insertions(+), 2 deletions(-)
 
 diff --git a/include/configs/ast-common.h b/include/configs/ast-common.h
-index b8b1f01..9c12f1f 100644
+index e7fa6ed..578de2c 100644
 --- a/include/configs/ast-common.h
 +++ b/include/configs/ast-common.h
 @@ -84,10 +84,16 @@
@@ -38,20 +38,21 @@
  
  #define CONFIG_ENV_OFFSET		0x60000	/* environment starts here  */
  #define CONFIG_ENV_OFFSET_REDUND	0x70000
-@@ -109,11 +116,20 @@
+@@ -109,12 +116,21 @@
  	"    bootm 20080000; else bootm 20080000 20300000; " \
  	"fi"
  #endif
 -#define CONFIG_BOOTCOMMAND                      "fdt addr 20080000; bootm 20080000"
 +#define CONFIG_BOOTCOMMAND		"run set_bootargs; run obmc_bootcmd"
  #define CONFIG_ENV_OVERWRITE
+ 
  #define ASPEED_ENV_SETTINGS \
 +	"ubiblock=0,1 \0" \
 +	"root=/dev/ubiblock0_1 \0" \
 +	"kernelname=kernel0 \0" \
 +	"kernelname=kernel0 \0" \
-+	"loadaddr=" CONFIG_LOADADDR "\0" \
-+	"set_bootargs=setenv bootargs " CONFIG_BOOTARGS " ubi.block=${ubiblock} root=${root} \0" \
++	"loadaddr=" __stringify(CONFIG_LOADADDR) "\0" \
++	"set_bootargs=setenv bootargs " CONFIG_BOOTARGS " ubi.block=\${ubiblock} root=\${root} \0" \
 +	"obmc_bootcmd=ubi part obmc-ubi; ubi read ${loadaddr} ${kernelname}; bootm ${loadaddr} \0" \
  	"verify=yes\0"	\
  	"spi_dma=yes\0" \
diff --git a/common/recipes-bsp/u-boot/u-boot.inc b/common/recipes-bsp/u-boot/u-boot.inc
index 5ccbea5..1089ec4 100644
--- a/common/recipes-bsp/u-boot/u-boot.inc
+++ b/common/recipes-bsp/u-boot/u-boot.inc
@@ -4,6 +4,8 @@
 UBRANCH = "v2016.07-aspeed-openbmc"
 SRC_URI = "git://git@github.com/openbmc/u-boot.git;branch=${UBRANCH};protocol=https"
 
+SRC_URI += "file://0001-configs-ast-Add-redundnant-env.patch"
+
 SRC_URI += "${@bb.utils.contains('MACHINE_FEATURES', 'obmc-ubi-fs', \
     'file://0001-config-ast-common-hack-bootopts.patch \
      file://0002-Add-MTD-support-to-Aspeed-Flash-driver.patch \
@@ -11,5 +13,3 @@
      file://0004-config-ast-common-ubi-bootops.patch', '', d)}"
 
 PV = "v2016.07+git${SRCPV}"
-
-SRC_URI += "file://0001-configs-ast-Add-redundnant-env.patch"