Skip to content

Instantly share code, notes, and snippets.

@HemanthJabalpuri
Last active December 23, 2023 06:20
Show Gist options
  • Save HemanthJabalpuri/5acb866f9fe11b34e5b469b4500e0769 to your computer and use it in GitHub Desktop.
Save HemanthJabalpuri/5acb866f9fe11b34e5b469b4500e0769 to your computer and use it in GitHub Desktop.
From beaa41efdc24b53b642a31cb3f4fe11313237b8f Mon Sep 17 00:00:00 2001
From: der_akinator <[email protected]>
Date: Thu, 23 Nov 2023 05:45:16 +0000
Subject: [PATCH] load modules from vendor_boot ramdisk in TWRP instead of depending on init
Use 'TW_LOAD_VENDOR_BOOT_MODULES := true'
to use TWRP module loader code for vendor_boot module loading.
Some devices need this for successful kernel module loading.
* See
https://twrp.zulipchat.com/#narrow/stream/290975-development-device/topic/Moto.20G52.20.28rhode.29/near/403681268
Change-Id: Ic772b59f612ceec836cf0ca38369a40936932307
---
diff --git a/Android.mk b/Android.mk
index a939c87..a2088d7 100644
--- a/Android.mk
+++ b/Android.mk
@@ -317,6 +317,9 @@
ifeq ($(TW_LOAD_VENDOR_MODULES_EXCLUDE_GKI),true)
LOCAL_CFLAGS += -DTW_LOAD_VENDOR_MODULES_EXCLUDE_GKI
endif
+ ifeq ($(TW_LOAD_VENDOR_BOOT_MODULES),true)
+ LOCAL_CFLAGS += -DTW_LOAD_VENDOR_BOOT_MODULES
+ endif
endif
ifeq ($(TW_INCLUDE_CRYPTO), true)
LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO -DUSE_FSCRYPT -Wno-macro-redefined
diff --git a/kernel_module_loader.cpp b/kernel_module_loader.cpp
index 292d18f..47ca4a3 100644
--- a/kernel_module_loader.cpp
+++ b/kernel_module_loader.cpp
@@ -73,6 +73,12 @@
case FASTBOOTD_MODE:
case RECOVERY_IN_BOOT_MODE:
+#ifdef TW_LOAD_VENDOR_BOOT_MODULES
+ for (auto&& module_dir:module_dirs) {
+ modules_loaded += Try_And_Load_Modules(module_dir, false);
+ if (modules_loaded >= expected_module_count) goto exit;
+ }
+#endif
/* In both mode vendor_boot or vendor modules are used
* Because Ramdisk is flashed in both.
*/
From bbd81a6be39021c77501aaa06e2dcddd15df6cea Mon Sep 17 00:00:00 2001
From: Fernando Oliveira <[email protected]>
Date: Sun, 22 Oct 2023 12:09:06 -0300
Subject: [PATCH] set data/recovery on devices where the TW_INCLUDE_CRYPTO flag has not been set
On some devices where the cryptography is broken, the maintainers do not set the flag and the data/recovery is not being created, so that at each boot the settings are not saved.
Change-Id: I4b308d17aea18bdda215b1f11393e40f2d4647b9
Signed-off-by: Fernando Oliveira <[email protected]>
---
diff --git a/data.cpp b/data.cpp
index c19fe4c..db04741 100644
--- a/data.cpp
+++ b/data.cpp
@@ -1140,5 +1140,5 @@
void DataManager::LoadTWRPFolderInfo(void)
{
SetValue(TW_RECOVERY_FOLDER_VAR, TWFunc::Check_For_TwrpFolder());
- mBackingFile = GetSettingsStoragePath() + GetStrValue(TW_RECOVERY_NAME) + '/' + TW_SETTINGS_FILE;
+ mBackingFile = GetSettingsStoragePath() + GetStrValue(TW_RECOVERY_NAME) + TW_SETTINGS_FILE;
}
diff --git a/partition.cpp b/partition.cpp
index 18528f1..351e26b 100755
--- a/partition.cpp
+++ b/partition.cpp
@@ -1275,6 +1275,8 @@
Storage_Path = Mount_Point + "/media/0";
Symlink_Path = Storage_Path;
DataManager::SetValue(TW_INTERNAL_PATH, Mount_Point + "/media/0");
+ //Devices without encryption do not run the Post_Decrypt function so the "data/recovery" folder was not being created on these devices
+ DataManager::SetValue("tw_settings_path", TW_STORAGE_PATH);
UnMount(true);
}
DataManager::SetValue("tw_has_internal", 1);
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index ca7e232..f25552b 100755
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -3169,8 +3169,6 @@
}
}
- //Devices without encryption do not run the Post_Decrypt function so the "data/recovery" folder was not being created on these devices
- DataManager::SetValue("tw_settings_path", TW_STORAGE_PATH);
LOGINFO("Decrypt adopted storage starting\n");
char* xmlFile = PageManager::LoadFileToBuffer(path, NULL);
xml_document<> *doc = NULL;
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 6be85be..7f4921e 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -1452,9 +1452,12 @@
if (oldFolder == "" && customTWRPFolders.empty()) {
LOGINFO("No recovery folder found. Using default folder.\n");
+ TWPartition* SDCard = PartitionManager.Find_Partition_By_Path(DataManager::GetCurrentStoragePath());
//Creates the TWRP folder if it does not exist on the device and if the folder has not been changed to a new name
- mainPath += TW_DEFAULT_RECOVERY_FOLDER;
- mkdir(mainPath.c_str(), 0777);
+ if (SDCard->Mount(true)) {
+ mainPath += TW_DEFAULT_RECOVERY_FOLDER;
+ mkdir(mainPath.c_str(), 0777);
+ }
goto exit;
} else if (customTWRPFolders.empty()) {
LOGINFO("No custom recovery folder found. Using TWRP as default.\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment