Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29954f60 authored by David Anderson's avatar David Anderson
Browse files

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
parent 78393951
Loading
Loading
Loading
Loading
+12 −15
Original line number Original line Diff line number Diff line
@@ -118,15 +118,15 @@ static bool inline IsRecoveryMode() {
// -----------------
// -----------------
FirstStageMount::FirstStageMount()
FirstStageMount::FirstStageMount()
    : need_dm_verity_(false), device_tree_fstab_(fs_mgr_read_fstab_dt(), fs_mgr_free_fstab) {
    : need_dm_verity_(false), device_tree_fstab_(fs_mgr_read_fstab_dt(), fs_mgr_free_fstab) {
    if (!device_tree_fstab_) {
    if (device_tree_fstab_) {
        LOG(INFO) << "Failed to read fstab from device tree";
        return;
    }
        // Stores device_tree_fstab_->recs[] into mount_fstab_recs_ (vector<fstab_rec*>)
        // Stores device_tree_fstab_->recs[] into mount_fstab_recs_ (vector<fstab_rec*>)
        // for easier manipulation later, e.g., range-base for loop.
        // for easier manipulation later, e.g., range-base for loop.
        for (int i = 0; i < device_tree_fstab_->num_entries; i++) {
        for (int i = 0; i < device_tree_fstab_->num_entries; i++) {
            mount_fstab_recs_.push_back(&device_tree_fstab_->recs[i]);
            mount_fstab_recs_.push_back(&device_tree_fstab_->recs[i]);
        }
        }
    } else {
        LOG(INFO) << "Failed to read fstab from device tree";
    }
}
}


std::unique_ptr<FirstStageMount> FirstStageMount::Create() {
std::unique_ptr<FirstStageMount> FirstStageMount::Create() {
@@ -138,8 +138,11 @@ std::unique_ptr<FirstStageMount> FirstStageMount::Create() {
}
}


bool FirstStageMount::DoFirstStageMount() {
bool FirstStageMount::DoFirstStageMount() {
    if (mount_fstab_recs_.empty()) {
        // Nothing to mount.
        // Nothing to mount.
    if (mount_fstab_recs_.empty()) return true;
        LOG(INFO) << "First stage mount skipped (missing/incompatible/empty fstab in device tree)";
        return true;
    }


    if (!InitDevices()) return false;
    if (!InitDevices()) return false;


@@ -479,12 +482,6 @@ bool DoFirstStageMount() {
        return true;
        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();
    std::unique_ptr<FirstStageMount> handle = FirstStageMount::Create();
    if (!handle) {
    if (!handle) {
        LOG(ERROR) << "Failed to create FirstStageMount";
        LOG(ERROR) << "Failed to create FirstStageMount";