ANDROID: Put system-as-root behind a compile-time flag.

For DAP devices (such as cuttlefish), we:
 - Do not specify "skip_initramfs" on the kernel command-line. We must
   always boot to the ramdisk.
 - Do not assume ramdisk boots to recovery. Instead, boot to the
   recovery partition for recovery mode.

Bug: 141272741
Test: cuttlefish boots

Change-Id: Ie1c23b4e1c998e8035a1df672fd3b5bad912bc4e
Signed-off-by: David Anderson <dvander@google.com>

Link: https://android-review.googlesource.com/c/platform/external/u-boot/+/1126445/7
Bug: https://baylibre.atlassian.net/browse/RITA-97
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
diff --git a/common/android_bootloader.c b/common/android_bootloader.c
index 00af3f7..0cb5cf0 100644
--- a/common/android_bootloader.c
+++ b/common/android_bootloader.c
@@ -12,6 +12,7 @@
 #include <malloc.h>
 
 #define ANDROID_PARTITION_BOOT "boot"
+#define ANDROID_PARTITION_RECOVERY "recovery"
 #define ANDROID_PARTITION_SYSTEM "system"
 
 #define ANDROID_ARG_SLOT_SUFFIX "androidboot.slot_suffix="
@@ -267,12 +268,16 @@
 {
 	enum android_boot_mode mode;
 	disk_partition_t boot_part_info;
-	disk_partition_t system_part_info;
-	int boot_part_num, system_part_num;
+	int boot_part_num;
 	int ret;
 	char *command_line;
 	char slot_suffix[3];
 	const char *mode_cmdline = NULL;
+	const char *boot_partition = ANDROID_PARTITION_BOOT;
+#ifdef CONFIG_ANDROID_SYSTEM_AS_ROOT
+	int system_part_num
+	disk_partition_t system_part_info;
+#endif
 
 	/* Determine the boot mode and clear its value for the next boot if
 	 * needed.
@@ -282,16 +287,22 @@
 
 	switch (mode) {
 	case ANDROID_BOOT_MODE_NORMAL:
+#ifdef CONFIG_ANDROID_SYSTEM_AS_ROOT
 		/* In normal mode, we load the kernel from "boot" but append
 		 * "skip_initramfs" to the cmdline to make it ignore the
 		 * recovery initramfs in the boot partition.
 		 */
 		mode_cmdline = "skip_initramfs";
+#endif
 		break;
 	case ANDROID_BOOT_MODE_RECOVERY:
+#ifdef CONFIG_ANDROID_SYSTEM_AS_ROOT
 		/* In recovery mode we still boot the kernel from "boot" but
 		 * don't skip the initramfs so it boots to recovery.
 		 */
+#else
+		boot_partition = ANDROID_PARTITION_RECOVERY;
+#endif
 		break;
 	case ANDROID_BOOT_MODE_BOOTLOADER:
 		/* Bootloader mode enters fastboot. If this operation fails we
@@ -310,14 +321,14 @@
 
 	/* Load the kernel from the desired "boot" partition. */
 	boot_part_num =
-	    android_part_get_info_by_name_suffix(dev_desc,
-						 ANDROID_PARTITION_BOOT,
+	    android_part_get_info_by_name_suffix(dev_desc, boot_partition,
 						 slot_suffix, &boot_part_info);
 	if (boot_part_num < 0)
 		return -1;
 	debug("ANDROID: Loading kernel from \"%s\", partition %d.\n",
 	      boot_part_info.name, boot_part_num);
 
+#ifdef CONFIG_ANDROID_SYSTEM_AS_ROOT
 	system_part_num =
 	    android_part_get_info_by_name_suffix(dev_desc,
 						 ANDROID_PARTITION_SYSTEM,
@@ -327,15 +338,18 @@
 		return -1;
 	debug("ANDROID: Using system image from \"%s\", partition %d.\n",
 	      system_part_info.name, system_part_num);
+#endif
 
 	ret = android_image_load(dev_desc, &boot_part_info, kernel_address,
 				 -1UL);
 	if (ret < 0)
 		return ret;
 
+#ifdef CONFIG_ANDROID_SYSTEM_AS_ROOT
 	/* Set Android root variables. */
 	env_set_ulong("android_root_devnum", dev_desc->devnum);
 	env_set_ulong("android_root_partnum", system_part_num);
+#endif
 	env_set("android_slotsufix", slot_suffix);
 
 	/* Assemble the command line */