bigbiff | 22851b9 | 2021-09-01 16:46:57 -0400 | [diff] [blame] | 1 | #ifndef _KERNELMODULELOADER_HPP |
| 2 | #define _KERNELMODULELOADER_HPP |
| 3 | |
| 4 | #include <dirent.h> |
| 5 | #include <string> |
| 6 | #include <vector> |
Mohd Faraz | fe8bcd4 | 2023-08-26 20:50:26 +0530 | [diff] [blame] | 7 | #include <android-base/file.h> |
bigbiff | 22851b9 | 2021-09-01 16:46:57 -0400 | [diff] [blame] | 8 | #include <android-base/strings.h> |
| 9 | #include <modprobe/modprobe.h> |
bigbiff | 850fa28 | 2021-10-09 12:37:29 -0400 | [diff] [blame] | 10 | #include <sys/mount.h> |
bigbiff | 22851b9 | 2021-09-01 16:46:57 -0400 | [diff] [blame] | 11 | #include <sys/utsname.h> |
| 12 | |
| 13 | #include "twcommon.h" |
| 14 | #include "twrp-functions.hpp" |
| 15 | |
bigbiff | 8c52c87 | 2022-04-10 17:34:46 -0400 | [diff] [blame] | 16 | #define VENDOR_MODULE_DIR "/vendor/lib/modules" // Base path for vendor kernel modules to check by TWRP |
| 17 | #define VENDOR_BOOT_MODULE_DIR "/lib/modules" // vendor_boot ramdisk GKI modules to check by TWRP |
| 18 | #define VENDOR_DLKM_MODULE_DIR "/vendor_dlkm/lib/modules" // vendor_dlkm placed modules to check by TWRP |
bigbiff | 22851b9 | 2021-09-01 16:46:57 -0400 | [diff] [blame] | 19 | typedef enum { |
| 20 | RECOVERY_FASTBOOT_MODE = 0, |
| 21 | RECOVERY_IN_BOOT_MODE, |
| 22 | FASTBOOTD_MODE |
| 23 | } BOOT_MODE; |
| 24 | |
| 25 | class KernelModuleLoader |
| 26 | { |
| 27 | public: |
Mohd Faraz | fe8bcd4 | 2023-08-26 20:50:26 +0530 | [diff] [blame] | 28 | static bool Load_Vendor_Modules(); // Load specific maintainer defined kernel modules in TWRP |
bigbiff | 22851b9 | 2021-09-01 16:46:57 -0400 | [diff] [blame] | 29 | |
| 30 | private: |
bigbiff | 850fa28 | 2021-10-09 12:37:29 -0400 | [diff] [blame] | 31 | static int Try_And_Load_Modules(std::string module_dir, bool vendor_is_mounted); // Use libmodprobe to attempt loading kernel modules |
bigbiff | 22851b9 | 2021-09-01 16:46:57 -0400 | [diff] [blame] | 32 | static bool Write_Module_List(std::string module_dir); // Write list of modules to load from TW_LOAD_VENDOR_MODULES |
Mohd Faraz | fe8bcd4 | 2023-08-26 20:50:26 +0530 | [diff] [blame] | 33 | static bool Copy_Modules_To_Tmpfs(std::string module_dir); // Copy modules to ramdisk for loading |
bigbiff | 850fa28 | 2021-10-09 12:37:29 -0400 | [diff] [blame] | 34 | static std::vector<string> Skip_Loaded_Kernel_Modules(); // return list of loaded kernel modules already done by init |
Mohd Faraz | fe8bcd4 | 2023-08-26 20:50:26 +0530 | [diff] [blame] | 35 | static BOOT_MODE Get_Boot_Mode(); // For getting the current boot mode |
bigbiff | 22851b9 | 2021-09-01 16:46:57 -0400 | [diff] [blame] | 36 | }; |
| 37 | |
Mohd Faraz | fe8bcd4 | 2023-08-26 20:50:26 +0530 | [diff] [blame] | 38 | #endif // _KERNELMODULELOADER_HPP |