Make it possible to disable SYSTEM_ROOT_IMAGE feature

In newer platform versions, the system-as-root image feature is
deprecated, eliminating the need to pass the Android fstab through
device-tree. As cuttlefish only uses the device-tree for the Android
fstab, we can stop using it altogether.

For maximum backwards compatibility, this change does not actually
remove the build/install of the initrd-root.dtb file, but the file is
not required any more. An fstab.vsoc file is installed in the root of
the initramfs which describes all of the mount points.

This change can be enabled with TARGET_BUILD_SYSTEM_ROOT_IMAGE=false
on the build command line.

This change also makes it possible to boot newer platform versions on
hypervisors that do not support device-tree.

Bug: 120163151
Test: m -j128 TARGET_BUILD_SYSTEM_ROOT_IMAGE=false dist && launch_cvd
Change-Id: I507b7baa7b65908dd0e877ccc086c61b4026028a
diff --git a/shared/BoardConfig.mk b/shared/BoardConfig.mk
index ab4524f..d77be50 100644
--- a/shared/BoardConfig.mk
+++ b/shared/BoardConfig.mk
@@ -25,7 +25,7 @@
 TARGET_COPY_OUT_VENDOR := vendor
 
 TARGET_NO_RECOVERY := true
-ifneq (,$(CUTTLEFISH_SYSTEM_AS_ROOT))
+ifeq ($(TARGET_BUILD_SYSTEM_ROOT_IMAGE),true)
 BOARD_BUILD_SYSTEM_ROOT_IMAGE := true
 endif
 BOARD_USES_GENERIC_AUDIO := false
diff --git a/shared/config/Android.mk b/shared/config/Android.mk
index 9a75f3f..cfbce97 100644
--- a/shared/config/Android.mk
+++ b/shared/config/Android.mk
@@ -38,6 +38,10 @@
 
 include $(CLEAR_VARS)
 
+# This file is deprecated and is kept round for host tools compatibility with
+# older target filesystem images. It is not necessary to pass a .dtb blob
+# through to QEMU any more.
+
 LOCAL_MODULE := initrd_root_dtb
 LOCAL_MODULE_CLASS := ETC
 LOCAL_MODULE_PATH := $(HOST_OUT)/config
diff --git a/shared/config/fstab.vsoc b/shared/config/fstab.dtb
similarity index 100%
rename from shared/config/fstab.vsoc
rename to shared/config/fstab.dtb
diff --git a/shared/config/fstab.initrd b/shared/config/fstab.initrd
new file mode 100644
index 0000000..0ea6f8e0
--- /dev/null
+++ b/shared/config/fstab.initrd
@@ -0,0 +1,5 @@
+/dev/block/vda /system ext4 noatime,ro,errors=panic wait
+/dev/block/vdb /data ext4 nodev,noatime,nosuid,errors=panic wait
+/dev/block/vdc /cache ext4 nodev,noatime,nosuid,errors=panic wait
+/dev/block/vdd /vendor ext4 noatime,ro,errors=panic wait
+/dev/block/zram0 none swap defaults zramsize=75%
diff --git a/shared/device.mk b/shared/device.mk
index 5f77625..7e5e4f7 100644
--- a/shared/device.mk
+++ b/shared/device.mk
@@ -129,7 +129,6 @@
     device/google/cuttlefish/shared/config/media_codecs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs.xml \
     device/google/cuttlefish/shared/config/media_codecs_performance.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_performance.xml \
     device/google/cuttlefish/shared/config/media_profiles.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_profiles_V1_0.xml \
-    device/google/cuttlefish/shared/config/fstab.vsoc:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.vsoc \
     frameworks/av/media/libeffects/data/audio_effects.conf:system/etc/audio_effects.conf \
     frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_audio.xml \
     frameworks/av/media/libstagefright/data/media_codecs_google_telephony.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_google_telephony.xml \
@@ -159,6 +158,26 @@
 
 
 #
+# The fstab requires special handling. For system-as-root builds, we *must*
+# retrieve the vendor partition mount options from DTB, as system must be
+# "pristine" to support GSI. For builds with an initrd, we prefer not to
+# rely on DTB, and *must* retrieve the partition mount options from an fstab
+# in the initrd instead. (In either case, the fstab *must also* be installed to
+# /vendor/etc)
+#
+ifeq ($(TARGET_BUILD_SYSTEM_ROOT_IMAGE),true)
+PRODUCT_COPY_FILES += \
+    device/google/cuttlefish/shared/config/fstab.dtb:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.vsoc \
+
+else
+PRODUCT_COPY_FILES += \
+    device/google/cuttlefish/shared/config/fstab.initrd:$(TARGET_COPY_OUT_RAMDISK)/fstab.vsoc \
+    device/google/cuttlefish/shared/config/fstab.initrd:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.vsoc \
+
+endif
+
+
+#
 # USB Specific
 #
 PRODUCT_COPY_FILES += \
diff --git a/shared/gsi/device.mk b/shared/gsi/device.mk
index e00222d..a25ab83 100644
--- a/shared/gsi/device.mk
+++ b/shared/gsi/device.mk
@@ -23,7 +23,7 @@
 include device/google/cuttlefish/shared/device.mk
 PRODUCT_SHIPPING_API_LEVEL := 27
 
-CUTTLEFISH_SYSTEM_AS_ROOT := true
+TARGET_BUILD_SYSTEM_ROOT_IMAGE ?= true
 
 PRODUCT_CHARACTERISTICS := nosdcard
 
diff --git a/shared/phone/device.mk b/shared/phone/device.mk
index a4c4813..0528e22 100644
--- a/shared/phone/device.mk
+++ b/shared/phone/device.mk
@@ -20,7 +20,7 @@
 $(call inherit-product, frameworks/native/build/phone-xhdpi-2048-dalvik-heap.mk)
 $(call inherit-product, device/google/cuttlefish/shared/device.mk)
 
-CUTTLEFISH_SYSTEM_AS_ROOT := true
+TARGET_BUILD_SYSTEM_ROOT_IMAGE ?= true
 
 PRODUCT_CHARACTERISTICS := nosdcard