Skip to content

Commit d96d0f7

Browse files
author
Elliot Berman
committed
first_stage_mount: Create snapshot devices before launching first_stage_console
During device bringup, dynamic partitions may not be properly configured by some sort of build or load misconfiguration. Diagnosing such issues can be difficult without being able to see which partitions are available and what they contain. Aditionally, making logical partitions available to first stage console permits early mounting of vendor partition and allows primitive validation of vendor scripts without requiring full Android environment. For instance, vendor_dlkm partition and modules can be probed needing to have a full Android bootup. Creation of logical partitions is done only when first_stage_console is requested in order to have minimal impact on normal boot. Thus, only a small refactor is required to split CreateLogicalPartitions out of MountPartitions. Bug: 174685384 Bug: 173732805 Change-Id: I828ce999be6d786bf46dd5655dfda81d046906ab Signed-off-by: Elliot Berman <[email protected]>
1 parent 003bf06 commit d96d0f7

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

init/first_stage_init.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,15 @@ int FirstStageMain(int argc, char** argv) {
286286
}
287287
}
288288

289+
290+
bool created_devices = false;
289291
if (want_console == FirstStageConsoleParam::CONSOLE_ON_FAILURE) {
292+
if (!IsRecoveryMode()) {
293+
created_devices = DoCreateDevices();
294+
if (!created_devices){
295+
LOG(ERROR) << "Failed to create device nodes early";
296+
}
297+
}
290298
StartConsole(cmdline);
291299
}
292300

@@ -327,7 +335,7 @@ int FirstStageMain(int argc, char** argv) {
327335
}
328336
}
329337

330-
if (!DoFirstStageMount()) {
338+
if (!DoFirstStageMount(!created_devices)) {
331339
LOG(FATAL) << "Failed to mount required partitions early ...";
332340
}
333341

init/first_stage_mount.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class FirstStageMount {
8282
// The factory method to create either FirstStageMountVBootV1 or FirstStageMountVBootV2
8383
// based on device tree configurations.
8484
static std::unique_ptr<FirstStageMount> Create();
85+
bool DoCreateDevices(); // Creates devices and logical partitions from storage devices
8586
bool DoFirstStageMount(); // Mounts fstab entries read from device tree.
8687
bool InitDevices();
8788

@@ -244,13 +245,7 @@ std::unique_ptr<FirstStageMount> FirstStageMount::Create() {
244245
}
245246
}
246247

247-
bool FirstStageMount::DoFirstStageMount() {
248-
if (!IsDmLinearEnabled() && fstab_.empty()) {
249-
// Nothing to mount.
250-
LOG(INFO) << "First stage mount skipped (missing/incompatible/empty fstab in device tree)";
251-
return true;
252-
}
253-
248+
bool FirstStageMount::DoCreateDevices() {
254249
if (!InitDevices()) return false;
255250

256251
// Mount /metadata before creating logical partitions, since we need to
@@ -269,6 +264,16 @@ bool FirstStageMount::DoFirstStageMount() {
269264

270265
if (!CreateLogicalPartitions()) return false;
271266

267+
return true;
268+
}
269+
270+
bool FirstStageMount::DoFirstStageMount() {
271+
if (!IsDmLinearEnabled() && fstab_.empty()) {
272+
// Nothing to mount.
273+
LOG(INFO) << "First stage mount skipped (missing/incompatible/empty fstab in device tree)";
274+
return true;
275+
}
276+
272277
if (!MountPartitions()) return false;
273278

274279
return true;
@@ -829,8 +834,18 @@ bool FirstStageMountVBootV2::InitAvbHandle() {
829834

830835
// Public functions
831836
// ----------------
837+
// Creates devices and logical partitions from storage devices
838+
bool DoCreateDevices() {
839+
std::unique_ptr<FirstStageMount> handle = FirstStageMount::Create();
840+
if (!handle) {
841+
LOG(ERROR) << "Failed to create FirstStageMount";
842+
return false;
843+
}
844+
return handle->DoCreateDevices();
845+
}
846+
832847
// Mounts partitions specified by fstab in device tree.
833-
bool DoFirstStageMount() {
848+
bool DoFirstStageMount(bool create_devices) {
834849
// Skips first stage mount if we're in recovery mode.
835850
if (IsRecoveryMode()) {
836851
LOG(INFO) << "First stage mount skipped (recovery mode)";
@@ -842,6 +857,11 @@ bool DoFirstStageMount() {
842857
LOG(ERROR) << "Failed to create FirstStageMount";
843858
return false;
844859
}
860+
861+
if (create_devices) {
862+
if (!handle->DoCreateDevices()) return false;
863+
}
864+
845865
return handle->DoFirstStageMount();
846866
}
847867

init/first_stage_mount.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
namespace android {
2020
namespace init {
2121

22-
bool DoFirstStageMount();
22+
bool DoCreateDevices();
23+
bool DoFirstStageMount(bool create_devices);
2324
void SetInitAvbVersionInRecovery();
2425

2526
} // namespace init

0 commit comments

Comments
 (0)