summaryrefslogtreecommitdiff
path: root/init/first_stage_init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'init/first_stage_init.cpp')
-rw-r--r--init/first_stage_init.cpp71
1 files changed, 12 insertions, 59 deletions
diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp
index d050ed783..78e5b60a1 100644
--- a/init/first_stage_init.cpp
+++ b/init/first_stage_init.cpp
@@ -27,7 +27,6 @@
#include <sys/utsname.h>
#include <unistd.h>
-#include <chrono>
#include <filesystem>
#include <string>
#include <vector>
@@ -108,39 +107,6 @@ bool ForceNormalBoot(const std::string& cmdline, const std::string& bootconfig)
cmdline.find("androidboot.force_normal_boot=1") != std::string::npos;
}
-static void Copy(const char* src, const char* dst) {
- if (link(src, dst) == 0) {
- LOG(INFO) << "hard linking " << src << " to " << dst << " succeeded";
- return;
- }
- PLOG(FATAL) << "hard linking " << src << " to " << dst << " failed";
-}
-
-// Move snapuserd before switching root, so that it is available at the same path
-// after switching root.
-void PrepareSwitchRoot() {
- constexpr const char* src = "/system/bin/snapuserd";
- constexpr const char* dst = "/first_stage_ramdisk/system/bin/snapuserd";
-
- if (access(dst, X_OK) == 0) {
- LOG(INFO) << dst << " already exists and it can be executed";
- return;
- }
-
- if (access(src, F_OK) != 0) {
- PLOG(INFO) << "Not moving " << src << " because it cannot be accessed";
- return;
- }
-
- auto dst_dir = android::base::Dirname(dst);
- std::error_code ec;
- if (access(dst_dir.c_str(), F_OK) != 0) {
- if (!fs::create_directories(dst_dir, ec)) {
- LOG(FATAL) << "Cannot create " << dst_dir << ": " << ec.message();
- }
- }
- Copy(src, dst);
-}
} // namespace
std::string GetModuleLoadList(bool recovery, const std::string& dir_path) {
@@ -157,7 +123,7 @@ std::string GetModuleLoadList(bool recovery, const std::string& dir_path) {
}
#define MODULE_BASE_DIR "/lib/modules"
-bool LoadKernelModules(bool recovery, bool want_console, bool want_parallel, int& modules_loaded) {
+bool LoadKernelModules(bool recovery, bool want_console, int& modules_loaded) {
struct utsname uts;
if (uname(&uts)) {
LOG(FATAL) << "Failed to get kernel version.";
@@ -206,8 +172,7 @@ bool LoadKernelModules(bool recovery, bool want_console, bool want_parallel, int
}
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(recovery, MODULE_BASE_DIR));
- bool retval = (want_parallel) ? m.LoadModulesParallel(std::thread::hardware_concurrency())
- : m.LoadListedModules(!want_console);
+ bool retval = m.LoadListedModules(!want_console);
modules_loaded = m.GetModuleCount();
if (modules_loaded > 0) {
return retval;
@@ -289,9 +254,6 @@ int FirstStageMain(int argc, char** argv) {
// stage init
CHECKCALL(mount("tmpfs", kSecondStageRes, "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV,
"mode=0755,uid=0,gid=0"))
-
- // First stage init stores Mainline sepolicy here.
- CHECKCALL(mkdir("/dev/selinux", 0744));
#undef CHECKCALL
SetStdioToDevNull(argv);
@@ -320,13 +282,11 @@ int FirstStageMain(int argc, char** argv) {
}
auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline, bootconfig) : 0;
- auto want_parallel =
- bootconfig.find("androidboot.load_modules_parallel = \"true\"") != std::string::npos;
boot_clock::time_point module_start_time = boot_clock::now();
int module_count = 0;
if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline, bootconfig), want_console,
- want_parallel, module_count)) {
+ module_count)) {
if (want_console != FirstStageConsoleParam::DISABLED) {
LOG(ERROR) << "Failed to load kernel modules, starting console";
} else {
@@ -341,11 +301,12 @@ int FirstStageMain(int argc, char** argv) {
<< module_elapse_time.count() << " ms";
}
+
bool created_devices = false;
if (want_console == FirstStageConsoleParam::CONSOLE_ON_FAILURE) {
if (!IsRecoveryMode()) {
created_devices = DoCreateDevices();
- if (!created_devices) {
+ if (!created_devices){
LOG(ERROR) << "Failed to create device nodes early";
}
}
@@ -369,30 +330,22 @@ int FirstStageMain(int argc, char** argv) {
// If "/force_debuggable" is present, the second-stage init will use a userdebug
// sepolicy and load adb_debug.prop to allow adb root, if the device is unlocked.
if (access("/force_debuggable", F_OK) == 0) {
- constexpr const char adb_debug_prop_src[] = "/adb_debug.prop";
- constexpr const char userdebug_plat_sepolicy_cil_src[] = "/userdebug_plat_sepolicy.cil";
std::error_code ec; // to invoke the overloaded copy_file() that won't throw.
- if (access(adb_debug_prop_src, F_OK) == 0 &&
- !fs::copy_file(adb_debug_prop_src, kDebugRamdiskProp, ec)) {
- LOG(WARNING) << "Can't copy " << adb_debug_prop_src << " to " << kDebugRamdiskProp
- << ": " << ec.message();
- }
- if (access(userdebug_plat_sepolicy_cil_src, F_OK) == 0 &&
- !fs::copy_file(userdebug_plat_sepolicy_cil_src, kDebugRamdiskSEPolicy, ec)) {
- LOG(WARNING) << "Can't copy " << userdebug_plat_sepolicy_cil_src << " to "
- << kDebugRamdiskSEPolicy << ": " << ec.message();
+ if (!fs::copy_file("/adb_debug.prop", kDebugRamdiskProp, ec) ||
+ !fs::copy_file("/userdebug_plat_sepolicy.cil", kDebugRamdiskSEPolicy, ec)) {
+ LOG(ERROR) << "Failed to setup debug ramdisk";
+ } else {
+ // setenv for second-stage init to read above kDebugRamdisk* files.
+ setenv("INIT_FORCE_DEBUGGABLE", "true", 1);
}
- // setenv for second-stage init to read above kDebugRamdisk* files.
- setenv("INIT_FORCE_DEBUGGABLE", "true", 1);
}
if (ForceNormalBoot(cmdline, bootconfig)) {
mkdir("/first_stage_ramdisk", 0755);
- PrepareSwitchRoot();
// SwitchRoot() must be called with a mount point as the target, so we bind mount the
// target directory to itself here.
if (mount("/first_stage_ramdisk", "/first_stage_ramdisk", nullptr, MS_BIND, nullptr) != 0) {
- PLOG(FATAL) << "Could not bind mount /first_stage_ramdisk to itself";
+ LOG(FATAL) << "Could not bind mount /first_stage_ramdisk to itself";
}
SwitchRoot("/first_stage_ramdisk");
}