twrp.cpp: Fix up loading modules

 * kernel modules such as msm_drm must be load at early stage before graphics loading.

 * Fix booting devices having separate drm gki module

Change-Id: Iba648d08760d7970c08cbaee1a5ca26cac29fce3
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 8aede55..b7e4eec 100755
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -3584,12 +3584,7 @@
 }
 
 bool TWPartitionManager::Get_Super_Status() {
-	std::string fastboot_mode = android::base::GetProperty("sys.usb.config", "");
-	if (fastboot_mode == "fastboot") {
-		return false;
-	}
-	else
-		return access(Get_Super_Partition().c_str(), F_OK) == 0;
+	return access(Get_Super_Partition().c_str(), F_OK) == 0;
 }
 
 bool TWPartitionManager::Recreate_Logs_Dir() {
diff --git a/twrp.cpp b/twrp.cpp
index 8ed0a8a..7a47c5c 100644
--- a/twrp.cpp
+++ b/twrp.cpp
@@ -110,21 +110,6 @@
 		LOGINFO("starting fastboot\n");
 
 #ifdef TW_LOAD_VENDOR_MODULES
-		printf("=> Linking mtab\n");
-		symlink("/proc/mounts", "/etc/mtab");
-		std::string fstab_filename = "/etc/twrp.fstab";
-		if (!TWFunc::Path_Exists(fstab_filename)) {
-			fstab_filename = "/etc/recovery.fstab";
-		}
-		printf("=> Processing %s\n", fstab_filename.c_str());
-		if (!PartitionManager.Process_Fstab(fstab_filename, 1, false)) {
-			LOGERR("Failing out of recovery due to problem with fstab.\n");
-			return;
-		}
-		TWPartition* ven = PartitionManager.Find_Partition_By_Path("/vendor");
-		PartitionManager.Setup_Super_Devices();
-		PartitionManager.Prepare_Super_Volume(ven);
-		KernelModuleLoader::Load_Vendor_Modules();
 		if (android::base::GetBoolProperty("ro.virtual_ab.enabled", false)) {
 			PartitionManager.Unmap_Super_Devices();
 		}
@@ -142,10 +127,6 @@
 static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decryption) {
 	char crash_prop_val[PROPERTY_VALUE_MAX];
 	int crash_counter;
-	std::string cmdline;
-	if (TWFunc::read_file("/proc/cmdline", cmdline) != 0) {
-		LOGINFO("Unable to read cmdline for fastboot mode\n");
-	}
 
 	property_get("twrp.crash_counter", crash_prop_val, "-1");
 	crash_counter = atoi(crash_prop_val) + 1;
@@ -159,26 +140,6 @@
 		printf("twrp.crash_counter=%d\n", crash_counter);
 	}
 
-	printf("=> Linking mtab\n");
-	symlink("/proc/mounts", "/etc/mtab");
-	std::string fstab_filename = "/etc/twrp.fstab";
-	if (!TWFunc::Path_Exists(fstab_filename)) {
-		fstab_filename = "/etc/recovery.fstab";
-	}
-	printf("=> Processing %s\n", fstab_filename.c_str());
-	if (!PartitionManager.Process_Fstab(fstab_filename, 1, true)) {
-		LOGERR("Failing out of recovery due to problem with fstab.\n");
-		return;
-	}
-
-#ifdef TW_LOAD_VENDOR_MODULES
-	bool fastboot_mode = cmdline.find("twrpfastboot=1") != std::string::npos;
-	if (fastboot_mode)
-		KernelModuleLoader::Load_Vendor_Modules();
-	else
-		KernelModuleLoader::Load_Vendor_Modules();
-#endif
-
 // We are doing this here to allow super partition to be set up prior to overriding properties
 #if defined(TW_INCLUDE_LIBRESETPROP) && defined(TW_OVERRIDE_SYSTEM_PROPS)
 	stringstream override_props(EXPAND(TW_OVERRIDE_SYSTEM_PROPS));
@@ -417,14 +378,32 @@
 
 	// Load default values to set DataManager constants and handle ifdefs
 	DataManager::SetDefaultValues();
+	startupArgs startup;
+	startup.parse(&argc, &argv);
+	printf("=> Linking mtab\n");
+	symlink("/proc/mounts", "/etc/mtab");
+	std::string fstab_filename = "/etc/twrp.fstab";
+	if (!TWFunc::Path_Exists(fstab_filename)) {
+		fstab_filename = "/etc/recovery.fstab";
+	}
+	printf("=> Processing %s\n", fstab_filename.c_str());
+	if (!PartitionManager.Process_Fstab(fstab_filename, 1, !startup.Get_Fastboot_Mode())) {
+		LOGERR("Failing out of recovery due to problem with fstab.\n");
+		return -1;
+	}
+
+#ifdef TW_LOAD_VENDOR_MODULES
+	if (startup.Get_Fastboot_Mode())
+		PartitionManager.Prepare_Super_Volume(PartitionManager.Find_Partition_By_Path("/vendor"));
+	KernelModuleLoader::Load_Vendor_Modules();
+#endif
+
 	printf("Starting the UI...\n");
 	gui_init();
 
 	// Load up all the resources
 	gui_loadResources();
 
-	startupArgs startup;
-	startup.parse(&argc, &argv);
 	twrpAdbBuFifo *adb_bu_fifo = new twrpAdbBuFifo();
 	TWFunc::Clear_Bootloader_Message();