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.cpp87
1 files changed, 18 insertions, 69 deletions
diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp
index 78e5b60a1..021557697 100644
--- a/init/first_stage_init.cpp
+++ b/init/first_stage_init.cpp
@@ -41,8 +41,6 @@
#include "first_stage_console.h"
#include "first_stage_mount.h"
#include "reboot_utils.h"
-#include "second_stage_resources.h"
-#include "snapuserd_transition.h"
#include "switch_root.h"
#include "util.h"
@@ -91,20 +89,13 @@ void FreeRamdisk(DIR* dir, dev_t dev) {
}
}
}
- } else if (de->d_type == DT_REG) {
- // Do not free snapuserd if we will need the ramdisk copy during the
- // selinux transition.
- if (de->d_name == "snapuserd"s && IsFirstStageSnapuserdRunning()) {
- continue;
- }
}
unlinkat(dfd, de->d_name, is_dir ? AT_REMOVEDIR : 0);
}
}
-bool ForceNormalBoot(const std::string& cmdline, const std::string& bootconfig) {
- return bootconfig.find("androidboot.force_normal_boot = \"1\"") != std::string::npos ||
- cmdline.find("androidboot.force_normal_boot=1") != std::string::npos;
+bool ForceNormalBoot(const std::string& cmdline) {
+ return cmdline.find("androidboot.force_normal_boot=1") != std::string::npos;
}
} // namespace
@@ -123,7 +114,7 @@ std::string GetModuleLoadList(bool recovery, const std::string& dir_path) {
}
#define MODULE_BASE_DIR "/lib/modules"
-bool LoadKernelModules(bool recovery, bool want_console, int& modules_loaded) {
+bool LoadKernelModules(bool recovery, bool want_console) {
struct utsname uts;
if (uname(&uts)) {
LOG(FATAL) << "Failed to get kernel version.";
@@ -165,7 +156,7 @@ bool LoadKernelModules(bool recovery, bool want_console, int& modules_loaded) {
dir_path.append(module_dir);
Modprobe m({dir_path}, GetModuleLoadList(recovery, dir_path));
bool retval = m.LoadListedModules(!want_console);
- modules_loaded = m.GetModuleCount();
+ int modules_loaded = m.GetModuleCount();
if (modules_loaded > 0) {
return retval;
}
@@ -173,7 +164,7 @@ bool LoadKernelModules(bool recovery, bool want_console, int& modules_loaded) {
Modprobe m({MODULE_BASE_DIR}, GetModuleLoadList(recovery, MODULE_BASE_DIR));
bool retval = m.LoadListedModules(!want_console);
- modules_loaded = m.GetModuleCount();
+ int modules_loaded = m.GetModuleCount();
if (modules_loaded > 0) {
return retval;
}
@@ -201,7 +192,6 @@ int FirstStageMain(int argc, char** argv) {
CHECKCALL(mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755"));
CHECKCALL(mkdir("/dev/pts", 0755));
CHECKCALL(mkdir("/dev/socket", 0755));
- CHECKCALL(mkdir("/dev/dm-user", 0755));
CHECKCALL(mount("devpts", "/dev/pts", "devpts", 0, NULL));
#define MAKE_STR(x) __STRING(x)
CHECKCALL(mount("proc", "/proc", "proc", 0, "hidepid=2,gid=" MAKE_STR(AID_READPROC)));
@@ -210,10 +200,6 @@ int FirstStageMain(int argc, char** argv) {
CHECKCALL(chmod("/proc/cmdline", 0440));
std::string cmdline;
android::base::ReadFileToString("/proc/cmdline", &cmdline);
- // Don't expose the raw bootconfig to unprivileged processes.
- chmod("/proc/bootconfig", 0440);
- std::string bootconfig;
- android::base::ReadFileToString("/proc/bootconfig", &bootconfig);
gid_t groups[] = {AID_READPROC};
CHECKCALL(setgroups(arraysize(groups), groups));
CHECKCALL(mount("sysfs", "/sys", "sysfs", 0, NULL));
@@ -249,11 +235,6 @@ int FirstStageMain(int argc, char** argv) {
// /debug_ramdisk is used to preserve additional files from the debug ramdisk
CHECKCALL(mount("tmpfs", "/debug_ramdisk", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV,
"mode=0755,uid=0,gid=0"));
-
- // /second_stage_resources is used to preserve files from first to second
- // stage init
- CHECKCALL(mount("tmpfs", kSecondStageRes, "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV,
- "mode=0755,uid=0,gid=0"))
#undef CHECKCALL
SetStdioToDevNull(argv);
@@ -281,54 +262,32 @@ int FirstStageMain(int argc, char** argv) {
old_root_dir.reset();
}
- auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline, bootconfig) : 0;
+ auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline) : 0;
- boot_clock::time_point module_start_time = boot_clock::now();
- int module_count = 0;
- if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline, bootconfig), want_console,
- module_count)) {
+ if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline), want_console)) {
if (want_console != FirstStageConsoleParam::DISABLED) {
LOG(ERROR) << "Failed to load kernel modules, starting console";
} else {
LOG(FATAL) << "Failed to load kernel modules";
}
}
- if (module_count > 0) {
- auto module_elapse_time = std::chrono::duration_cast<std::chrono::milliseconds>(
- boot_clock::now() - module_start_time);
- setenv(kEnvInitModuleDurationMs, std::to_string(module_elapse_time.count()).c_str(), 1);
- LOG(INFO) << "Loaded " << module_count << " kernel modules took "
- << module_elapse_time.count() << " ms";
- }
-
- bool created_devices = false;
if (want_console == FirstStageConsoleParam::CONSOLE_ON_FAILURE) {
- if (!IsRecoveryMode()) {
- created_devices = DoCreateDevices();
- if (!created_devices){
- LOG(ERROR) << "Failed to create device nodes early";
- }
- }
- StartConsole(cmdline);
+ StartConsole();
}
- if (access(kBootImageRamdiskProp, F_OK) == 0) {
- std::string dest = GetRamdiskPropForSecondStage();
- std::string dir = android::base::Dirname(dest);
- std::error_code ec;
- if (!fs::create_directories(dir, ec) && !!ec) {
- LOG(FATAL) << "Can't mkdir " << dir << ": " << ec.message();
- }
- if (!fs::copy_file(kBootImageRamdiskProp, dest, ec)) {
- LOG(FATAL) << "Can't copy " << kBootImageRamdiskProp << " to " << dest << ": "
- << ec.message();
+ if (ForceNormalBoot(cmdline)) {
+ mkdir("/first_stage_ramdisk", 0755);
+ // 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) {
+ LOG(FATAL) << "Could not bind mount /first_stage_ramdisk to itself";
}
- LOG(INFO) << "Copied ramdisk prop to " << dest;
+ SwitchRoot("/first_stage_ramdisk");
}
- // 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 this file 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) {
std::error_code ec; // to invoke the overloaded copy_file() that won't throw.
if (!fs::copy_file("/adb_debug.prop", kDebugRamdiskProp, ec) ||
@@ -340,17 +299,7 @@ int FirstStageMain(int argc, char** argv) {
}
}
- if (ForceNormalBoot(cmdline, bootconfig)) {
- mkdir("/first_stage_ramdisk", 0755);
- // 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) {
- LOG(FATAL) << "Could not bind mount /first_stage_ramdisk to itself";
- }
- SwitchRoot("/first_stage_ramdisk");
- }
-
- if (!DoFirstStageMount(!created_devices)) {
+ if (!DoFirstStageMount()) {
LOG(FATAL) << "Failed to mount required partitions early ...";
}