Skip to content

Commit 7905848

Browse files
init: handle more bootconfig parameters
As parameters are moved from kernel cmdline to bootconfig, first_stage_init needs to be updated to handle the new location. /proc/bootconfig should be checked first, if not present, then check /proc/cmdline. Test: launch_cvd Test: launch_cvd with 4.19 kernel artifacts that do not support bootconfig Test: Both of the above configurations with --num_instances 0 or 4 Test: Both configurations with androidboot.boot_devices or androidboot.boot_device set Bug: 173815685 Change-Id: I03743f922351d58375e8b9a903899b8bc54bd71e
1 parent fdac598 commit 7905848

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

init/first_stage_console.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,20 @@ void StartConsole(const std::string& cmdline) {
105105
_exit(127);
106106
}
107107

108-
int FirstStageConsole(const std::string& cmdline) {
109-
auto pos = cmdline.find("androidboot.first_stage_console=");
108+
int FirstStageConsole(const std::string& cmdline, const std::string& bootconfig) {
109+
auto pos = bootconfig.find("androidboot.first_stage_console =");
110+
if (pos != std::string::npos) {
111+
int val = 0;
112+
if (sscanf(bootconfig.c_str() + pos, "androidboot.first_stage_console = \"%d\"", &val) !=
113+
1) {
114+
return FirstStageConsoleParam::DISABLED;
115+
}
116+
if (val <= FirstStageConsoleParam::MAX_PARAM_VALUE && val >= 0) {
117+
return val;
118+
}
119+
}
120+
121+
pos = cmdline.find("androidboot.first_stage_console=");
110122
if (pos != std::string::npos) {
111123
int val = 0;
112124
if (sscanf(cmdline.c_str() + pos, "androidboot.first_stage_console=%d", &val) != 1) {

init/first_stage_console.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum FirstStageConsoleParam {
2929
};
3030

3131
void StartConsole(const std::string& cmdline);
32-
int FirstStageConsole(const std::string& cmdline);
32+
int FirstStageConsole(const std::string& cmdline, const std::string& bootconfig);
3333

3434
} // namespace init
3535
} // namespace android

init/first_stage_init.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ void FreeRamdisk(DIR* dir, dev_t dev) {
102102
}
103103
}
104104

105-
bool ForceNormalBoot(const std::string& cmdline) {
106-
return cmdline.find("androidboot.force_normal_boot=1") != std::string::npos;
105+
bool ForceNormalBoot(const std::string& cmdline, const std::string& bootconfig) {
106+
return bootconfig.find("androidboot.force_normal_boot = \"1\"") != std::string::npos ||
107+
cmdline.find("androidboot.force_normal_boot=1") != std::string::npos;
107108
}
108109

109110
} // namespace
@@ -211,6 +212,8 @@ int FirstStageMain(int argc, char** argv) {
211212
android::base::ReadFileToString("/proc/cmdline", &cmdline);
212213
// Don't expose the raw bootconfig to unprivileged processes.
213214
chmod("/proc/bootconfig", 0440);
215+
std::string bootconfig;
216+
android::base::ReadFileToString("/proc/bootconfig", &bootconfig);
214217
gid_t groups[] = {AID_READPROC};
215218
CHECKCALL(setgroups(arraysize(groups), groups));
216219
CHECKCALL(mount("sysfs", "/sys", "sysfs", 0, NULL));
@@ -278,11 +281,11 @@ int FirstStageMain(int argc, char** argv) {
278281
old_root_dir.reset();
279282
}
280283

281-
auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline) : 0;
284+
auto want_console = ALLOW_FIRST_STAGE_CONSOLE ? FirstStageConsole(cmdline, bootconfig) : 0;
282285

283286
boot_clock::time_point module_start_time = boot_clock::now();
284287
int module_count = 0;
285-
if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline), want_console,
288+
if (!LoadKernelModules(IsRecoveryMode() && !ForceNormalBoot(cmdline, bootconfig), want_console,
286289
module_count)) {
287290
if (want_console != FirstStageConsoleParam::DISABLED) {
288291
LOG(ERROR) << "Failed to load kernel modules, starting console";
@@ -324,7 +327,7 @@ int FirstStageMain(int argc, char** argv) {
324327
LOG(INFO) << "Copied ramdisk prop to " << dest;
325328
}
326329

327-
if (ForceNormalBoot(cmdline)) {
330+
if (ForceNormalBoot(cmdline, bootconfig)) {
328331
mkdir("/first_stage_ramdisk", 0755);
329332
// SwitchRoot() must be called with a mount point as the target, so we bind mount the
330333
// target directory to itself here.

0 commit comments

Comments
 (0)