init: refactor first stage to not require fstab
In order to support dm-linear devices, we need an additional first-stage
step to ensure that required devices are created. This must happen before
setting up dm-verity or mounting any first-stage partitions.
This patch refactors FirstStageMount so that having a compatible fstab
is optional. This will let us use InitRequiredDevices on systems that
would not otherwise perform first-stage mounts.
Bug: 78914864
Test: non-AVB devices still boot
Change-Id: I11265375a9900d983da8cabcc77d32c503ded02e
diff --git a/init/init_first_stage.cpp b/init/init_first_stage.cpp
index 45d3d44..1b6e97e 100644
--- a/init/init_first_stage.cpp
+++ b/init/init_first_stage.cpp
@@ -118,14 +118,14 @@
// -----------------
FirstStageMount::FirstStageMount()
: need_dm_verity_(false), device_tree_fstab_(fs_mgr_read_fstab_dt(), fs_mgr_free_fstab) {
- if (!device_tree_fstab_) {
+ if (device_tree_fstab_) {
+ // Stores device_tree_fstab_->recs[] into mount_fstab_recs_ (vector<fstab_rec*>)
+ // for easier manipulation later, e.g., range-base for loop.
+ for (int i = 0; i < device_tree_fstab_->num_entries; i++) {
+ mount_fstab_recs_.push_back(&device_tree_fstab_->recs[i]);
+ }
+ } else {
LOG(INFO) << "Failed to read fstab from device tree";
- return;
- }
- // Stores device_tree_fstab_->recs[] into mount_fstab_recs_ (vector<fstab_rec*>)
- // for easier manipulation later, e.g., range-base for loop.
- for (int i = 0; i < device_tree_fstab_->num_entries; i++) {
- mount_fstab_recs_.push_back(&device_tree_fstab_->recs[i]);
}
}
@@ -138,8 +138,11 @@
}
bool FirstStageMount::DoFirstStageMount() {
- // Nothing to mount.
- if (mount_fstab_recs_.empty()) return true;
+ if (mount_fstab_recs_.empty()) {
+ // Nothing to mount.
+ LOG(INFO) << "First stage mount skipped (missing/incompatible/empty fstab in device tree)";
+ return true;
+ }
if (!InitDevices()) return false;
@@ -479,12 +482,6 @@
return true;
}
- // Firstly checks if device tree fstab entries are compatible.
- if (!is_android_dt_value_expected("fstab/compatible", "android,fstab")) {
- LOG(INFO) << "First stage mount skipped (missing/incompatible fstab in device tree)";
- return true;
- }
-
std::unique_ptr<FirstStageMount> handle = FirstStageMount::Create();
if (!handle) {
LOG(ERROR) << "Failed to create FirstStageMount";