Added dual-boot capable kernel and fs loading cmds.

Similar to how bootcmd is conditional, the loading commands are now as
well.  This makes it so that 'lk' and 'lf' change depending on whether
ACTIVATED_KERNEL_NAME is 'kernel1' or not.

The change is specifically where to install the kernel and fs, as well
as some macro cleanup for easier readability.

Change-Id: I2e0af3c87a7dd5bf2d3df316a5aa5d9618f9baa3
diff --git a/include/configs/board953x.h b/include/configs/board953x.h
index d0fe913..dbc7ed7 100755
--- a/include/configs/board953x.h
+++ b/include/configs/board953x.h
@@ -121,10 +121,39 @@
 
 #undef CONFIG_BOOTARGS
 
-#define __gen_cmd(n, a, f, ec, cc, el)		\
-	#n "=tftp 0x80060000 ${dir}" #f "&&"	\
+/* __gen_cmd with no null-terminator, and no "#n=" prefix */
+#define __gen_cmd_nn(n, a, f, ec, cc, el) \
+	"tftp 0x80060000 ${dir}" #f "&&"	\
 	#ec " " #a " " #el "&&"			\
-	#cc " $fileaddr " #a " $filesize\0"
+	#cc " $fileaddr " #a " $filesize"
+
+#define __gen_cmd(n, a, f, ec, cc, el) \
+        #n "=" __gen_cmd_nn(n, a, f, ec, cc, el) "\0"
+
+/* Macros for partition selection logic (for readability more than anything) */
+#define __if_booting_to_partition_2 \
+    "if test \"${ACTIVATED_KERNEL_NAME}\" = \"kernel1\"; then " \
+
+#define __else " else "
+
+#define __endif " fi "
+
+/*
+ * Configures two different potential address installation locations: a1 and a2.
+ */
+#define __gen_dualboot_cmd(n, a1, a2, f, ec1, ec2, cc1, cc2, el) \
+        #n "=" \
+        __if_booting_to_partition_2 \
+            __gen_cmd_nn(n, a2, f, ec2, cc2, el) ";" \
+        __else \
+            __gen_cmd_nn(n, a1, f, ec1, cc1, +el) ";" \
+        __endif "\0"
+
+#define gen_dualboot_cmd_el(n, a1, a2, f, el) \
+        __gen_dualboot_cmd(n, a1, a2, f, erase, erase_ext, cp.b, write_ext, el)
+
+#define gen_dualboot_cmd(n, a1, a2, f) \
+        gen_dualboot_cmd_el(n, a1, a2, f, $filesize)
 
 #define gen_cmd(n, a, f)			\
 	__gen_cmd(n, a, f, erase, cp.b, +$filesize)
@@ -145,7 +174,6 @@
 #	define ATH_U_FILE	u-boot.bin
 #endif
 
-
 #ifdef CONFIG_ATH_NAND_SUPPORT
 #	ifdef CONFIG_ATH_NAND_BR	// nand boot rom
 #		if defined(COMPRESSED_UBOOT)
@@ -195,8 +223,10 @@
 #	if (FLASH_SIZE == 32)
 #		define ATH_F_LEN		0xd90000
 #		define ATH_K_ADDR		0x9fe70000
+#		define ATH_K_ADDR_2		0x1d90000
 #		define MTDPARTS_DEFAULT		"mtdparts=ath-nor0:320k(loader),64k(env),256k(sysvar1),256k(sysvar2),13888k(rootfs0),1408k(kernel0),64k(mib0),64k(ART),64k(test),13888k(rootfs1),1408k(kernel1),1088k(config)"
 #		define ATH_F_ADDR               0x9f0e0000
+#		define ATH_F_ADDR_2             0x1000000
 #	elif (FLASH_SIZE == 16)
 #		define ATH_F_LEN		0xE30000
 #		define ATH_K_ADDR		0x9fE80000
@@ -229,11 +259,11 @@
 #endif
 
 #ifndef ATH_F_CMD
-#	define ATH_F_CMD	gen_cmd_el(lf, ATH_F_ADDR, ATH_F_FILE, ATH_F_LEN)
+#	define ATH_F_CMD	gen_dualboot_cmd_el(lf, ATH_F_ADDR, ATH_F_ADDR_2, ATH_F_FILE, ATH_F_LEN)
 #endif
 
 #ifndef ATH_K_CMD
-#	define ATH_K_CMD	gen_cmd(lk, ATH_K_ADDR, ATH_K_FILE)
+#	define ATH_K_CMD	gen_dualboot_cmd(lk, ATH_K_ADDR, ATH_K_ADDR_2, ATH_K_FILE)
 #endif
 
 #define CONFIG_EXTRA_ENV_SETTINGS	\
@@ -282,20 +312,16 @@
 1408k(kernel1),\
 1088k(config)"
 
+#			define __WC_READ_EXT " read_ext 0x82060000 0x1d90000 0x160000 "
 #			define CONFIG_BOOTCOMMAND	\
-\
-"if test \"${ACTIVATED_KERNEL_NAME}\" = \"kernel1\"; then \
-\
-setenv bootargs " __WC_BOOTARGS_CONSOLE " root=31:09 " __WC_BOOTARGS_PART_DEFS \
-       "&& read_ext 0x82060000 0x1d90000 0x160000 \
-       && bootm 0x82060000; \
-\
-else \
-\
-setenv bootargs " __WC_BOOTARGS_CONSOLE " root=31:04 " __WC_BOOTARGS_PART_DEFS \
-       "&& bootm 0x9fe70000; \
-\
-fi"
+__if_booting_to_partition_2 \
+    "setenv bootargs " __WC_BOOTARGS_CONSOLE " root=31:09 " __WC_BOOTARGS_PART_DEFS \
+       "&&" __WC_READ_EXT \
+       "&& bootm 0x82060000;" \
+__else \
+    "setenv bootargs " __WC_BOOTARGS_CONSOLE " root=31:04 " __WC_BOOTARGS_PART_DEFS \
+       "&& bootm 0x9fe70000;" \
+__endif
 
 #		elif (FLASH_SIZE == 16)
 #			define CONFIG_BOOTCOMMAND	"bootm 0x9fE80000"