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

Commit c4a1a32e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "debug_ramdisk_path"

* changes:
  init: adding fallback paths for debug ramdisk
  init: loading debug resources before chroot into first_stage_ramdisk
parents 3b0ec907 6cb4311f
Loading
Loading
Loading
Loading
+21 −17
Original line number Original line Diff line number Diff line
@@ -327,28 +327,22 @@ int FirstStageMain(int argc, char** argv) {
        LOG(INFO) << "Copied ramdisk prop to " << dest;
        LOG(INFO) << "Copied ramdisk prop to " << dest;
    }
    }


    if (ForceNormalBoot(cmdline, bootconfig)) {
    // If "/force_debuggable" is present, the second-stage init will use a userdebug
        mkdir("/first_stage_ramdisk", 0755);
    // sepolicy and load adb_debug.prop to allow adb root, if the device is unlocked.
        // SwitchRoot() must be called with a mount point as the target, so we bind mount the
    bool found_debuggable = false;
        // 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");
    }

    std::string force_debuggable("/force_debuggable");
    std::string adb_debug_prop("/adb_debug.prop");
    std::string adb_debug_prop("/adb_debug.prop");
    std::string userdebug_sepolicy("/userdebug_plat_sepolicy.cil");
    std::string userdebug_sepolicy("/userdebug_plat_sepolicy.cil");
    if (IsRecoveryMode()) {
    if (access("/force_debuggable", F_OK) == 0) {
        // Update these file paths since we didn't switch root
        found_debuggable = true;
        force_debuggable.insert(0, "/first_stage_ramdisk");
    } else if (access("/first_stage_ramdisk/force_debuggable", F_OK) == 0) {
        // Fallback to legacy debug resource paths.
        // TODO(b/186485355): removes the fallback path once it is not needed.
        found_debuggable = true;
        adb_debug_prop.insert(0, "/first_stage_ramdisk");
        adb_debug_prop.insert(0, "/first_stage_ramdisk");
        userdebug_sepolicy.insert(0, "/first_stage_ramdisk");
        userdebug_sepolicy.insert(0, "/first_stage_ramdisk");
    }
    }
    // 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 (found_debuggable) {
    if (access(force_debuggable.c_str(), F_OK) == 0) {
        std::error_code ec;  // to invoke the overloaded copy_file() that won't throw.
        std::error_code ec;  // to invoke the overloaded copy_file() that won't throw.
        if (!fs::copy_file(adb_debug_prop, kDebugRamdiskProp, ec) ||
        if (!fs::copy_file(adb_debug_prop, kDebugRamdiskProp, ec) ||
            !fs::copy_file(userdebug_sepolicy, kDebugRamdiskSEPolicy, ec)) {
            !fs::copy_file(userdebug_sepolicy, kDebugRamdiskSEPolicy, ec)) {
@@ -359,6 +353,16 @@ 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(!created_devices)) {
        LOG(FATAL) << "Failed to mount required partitions early ...";
        LOG(FATAL) << "Failed to mount required partitions early ...";
    }
    }