Loading init/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -61,6 +61,7 @@ cc_defaults { static_libs: [ static_libs: [ "libseccomp_policy", "libseccomp_policy", "libavb", "libavb", "libc++fs", "libcgrouprc_format", "libcgrouprc_format", "libprotobuf-cpp-lite", "libprotobuf-cpp-lite", "libpropertyinfoserializer", "libpropertyinfoserializer", Loading init/Android.mk +2 −0 Original line number Original line Diff line number Diff line Loading @@ -68,12 +68,14 @@ LOCAL_UNSTRIPPED_PATH := $(TARGET_RAMDISK_OUT_UNSTRIPPED) # Set up the same mount points on the ramdisk that system-as-root contains. # Set up the same mount points on the ramdisk that system-as-root contains. LOCAL_POST_INSTALL_CMD := mkdir -p \ LOCAL_POST_INSTALL_CMD := mkdir -p \ $(TARGET_RAMDISK_OUT)/apex \ $(TARGET_RAMDISK_OUT)/apex \ $(TARGET_RAMDISK_OUT)/debug_ramdisk \ $(TARGET_RAMDISK_OUT)/dev \ $(TARGET_RAMDISK_OUT)/dev \ $(TARGET_RAMDISK_OUT)/mnt \ $(TARGET_RAMDISK_OUT)/mnt \ $(TARGET_RAMDISK_OUT)/proc \ $(TARGET_RAMDISK_OUT)/proc \ $(TARGET_RAMDISK_OUT)/sys \ $(TARGET_RAMDISK_OUT)/sys \ LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libc++fs \ libfs_avb \ libfs_avb \ libfs_mgr \ libfs_mgr \ libfec \ libfec \ Loading init/debug_ramdisk.h 0 → 100644 +26 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once namespace android { namespace init { constexpr const char kDebugRamdiskProp[] = "/debug_ramdisk/adb_debug.prop"; constexpr const char kDebugRamdiskSEPolicy[] = "/debug_ramdisk/userdebug_plat_sepolicy.cil"; } // namespace init } // namespace android init/first_stage_init.cpp +15 −1 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <sys/types.h> #include <sys/types.h> #include <unistd.h> #include <unistd.h> #include <filesystem> #include <string> #include <string> #include <vector> #include <vector> Loading @@ -35,6 +36,7 @@ #include <cutils/android_reboot.h> #include <cutils/android_reboot.h> #include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h> #include "debug_ramdisk.h" #include "first_stage_mount.h" #include "first_stage_mount.h" #include "reboot_utils.h" #include "reboot_utils.h" #include "switch_root.h" #include "switch_root.h" Loading @@ -44,6 +46,8 @@ using android::base::boot_clock; using namespace std::literals; using namespace std::literals; namespace fs = std::filesystem; namespace android { namespace android { namespace init { namespace init { Loading Loading @@ -159,6 +163,9 @@ int FirstStageMain(int argc, char** argv) { CHECKCALL(mount("tmpfs", "/apex", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, CHECKCALL(mount("tmpfs", "/apex", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, "mode=0755,uid=0,gid=0")); "mode=0755,uid=0,gid=0")); // /debug_ramdisk is used to preserve additional files from the debug ramdisk CHECKCALL(mount("tmpfs", "/debug_ramdisk", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, "mode=0755,uid=0,gid=0")); #undef CHECKCALL #undef CHECKCALL // Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually // Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually Loading Loading @@ -202,8 +209,15 @@ int FirstStageMain(int argc, char** argv) { // If this file is present, the second-stage init will use a userdebug sepolicy // 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. // and load adb_debug.prop to allow adb root, if the device is unlocked. if (access("/force_debuggable", F_OK) == 0) { if (access("/force_debuggable", F_OK) == 0) { std::error_code ec; // to invoke the overloaded copy_file() that won't throw. if (!fs::copy_file("/adb_debug.prop", kDebugRamdiskProp, ec) || !fs::copy_file("/userdebug_plat_sepolicy.cil", kDebugRamdiskSEPolicy, ec)) { LOG(ERROR) << "Failed to setup debug ramdisk"; } else { // setenv for second-stage init to read above kDebugRamdisk* files. setenv("INIT_FORCE_DEBUGGABLE", "true", 1); setenv("INIT_FORCE_DEBUGGABLE", "true", 1); } } } if (!DoFirstStageMount()) { if (!DoFirstStageMount()) { LOG(FATAL) << "Failed to mount required partitions early ..."; LOG(FATAL) << "Failed to mount required partitions early ..."; Loading init/init.cpp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -621,6 +621,12 @@ static void GlobalSeccomp() { }); }); } } static void UmountDebugRamdisk() { if (umount("/debug_ramdisk") != 0) { LOG(ERROR) << "Failed to umount /debug_ramdisk"; } } int SecondStageMain(int argc, char** argv) { int SecondStageMain(int argc, char** argv) { if (REBOOT_BOOTLOADER_ON_PANIC) { if (REBOOT_BOOTLOADER_ON_PANIC) { InstallRebootSignalHandlers(); InstallRebootSignalHandlers(); Loading Loading @@ -690,6 +696,7 @@ int SecondStageMain(int argc, char** argv) { InstallSignalFdHandler(&epoll); InstallSignalFdHandler(&epoll); property_load_boot_defaults(load_debug_prop); property_load_boot_defaults(load_debug_prop); UmountDebugRamdisk(); fs_mgr_vendor_overlay_mount_all(); fs_mgr_vendor_overlay_mount_all(); export_oem_lock_status(); export_oem_lock_status(); StartPropertyService(&epoll); StartPropertyService(&epoll); Loading Loading
init/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -61,6 +61,7 @@ cc_defaults { static_libs: [ static_libs: [ "libseccomp_policy", "libseccomp_policy", "libavb", "libavb", "libc++fs", "libcgrouprc_format", "libcgrouprc_format", "libprotobuf-cpp-lite", "libprotobuf-cpp-lite", "libpropertyinfoserializer", "libpropertyinfoserializer", Loading
init/Android.mk +2 −0 Original line number Original line Diff line number Diff line Loading @@ -68,12 +68,14 @@ LOCAL_UNSTRIPPED_PATH := $(TARGET_RAMDISK_OUT_UNSTRIPPED) # Set up the same mount points on the ramdisk that system-as-root contains. # Set up the same mount points on the ramdisk that system-as-root contains. LOCAL_POST_INSTALL_CMD := mkdir -p \ LOCAL_POST_INSTALL_CMD := mkdir -p \ $(TARGET_RAMDISK_OUT)/apex \ $(TARGET_RAMDISK_OUT)/apex \ $(TARGET_RAMDISK_OUT)/debug_ramdisk \ $(TARGET_RAMDISK_OUT)/dev \ $(TARGET_RAMDISK_OUT)/dev \ $(TARGET_RAMDISK_OUT)/mnt \ $(TARGET_RAMDISK_OUT)/mnt \ $(TARGET_RAMDISK_OUT)/proc \ $(TARGET_RAMDISK_OUT)/proc \ $(TARGET_RAMDISK_OUT)/sys \ $(TARGET_RAMDISK_OUT)/sys \ LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libc++fs \ libfs_avb \ libfs_avb \ libfs_mgr \ libfs_mgr \ libfec \ libfec \ Loading
init/debug_ramdisk.h 0 → 100644 +26 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once namespace android { namespace init { constexpr const char kDebugRamdiskProp[] = "/debug_ramdisk/adb_debug.prop"; constexpr const char kDebugRamdiskSEPolicy[] = "/debug_ramdisk/userdebug_plat_sepolicy.cil"; } // namespace init } // namespace android
init/first_stage_init.cpp +15 −1 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <sys/types.h> #include <sys/types.h> #include <unistd.h> #include <unistd.h> #include <filesystem> #include <string> #include <string> #include <vector> #include <vector> Loading @@ -35,6 +36,7 @@ #include <cutils/android_reboot.h> #include <cutils/android_reboot.h> #include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h> #include "debug_ramdisk.h" #include "first_stage_mount.h" #include "first_stage_mount.h" #include "reboot_utils.h" #include "reboot_utils.h" #include "switch_root.h" #include "switch_root.h" Loading @@ -44,6 +46,8 @@ using android::base::boot_clock; using namespace std::literals; using namespace std::literals; namespace fs = std::filesystem; namespace android { namespace android { namespace init { namespace init { Loading Loading @@ -159,6 +163,9 @@ int FirstStageMain(int argc, char** argv) { CHECKCALL(mount("tmpfs", "/apex", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, CHECKCALL(mount("tmpfs", "/apex", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, "mode=0755,uid=0,gid=0")); "mode=0755,uid=0,gid=0")); // /debug_ramdisk is used to preserve additional files from the debug ramdisk CHECKCALL(mount("tmpfs", "/debug_ramdisk", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, "mode=0755,uid=0,gid=0")); #undef CHECKCALL #undef CHECKCALL // Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually // Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually Loading Loading @@ -202,8 +209,15 @@ int FirstStageMain(int argc, char** argv) { // If this file is present, the second-stage init will use a userdebug sepolicy // 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. // and load adb_debug.prop to allow adb root, if the device is unlocked. if (access("/force_debuggable", F_OK) == 0) { if (access("/force_debuggable", F_OK) == 0) { std::error_code ec; // to invoke the overloaded copy_file() that won't throw. if (!fs::copy_file("/adb_debug.prop", kDebugRamdiskProp, ec) || !fs::copy_file("/userdebug_plat_sepolicy.cil", kDebugRamdiskSEPolicy, ec)) { LOG(ERROR) << "Failed to setup debug ramdisk"; } else { // setenv for second-stage init to read above kDebugRamdisk* files. setenv("INIT_FORCE_DEBUGGABLE", "true", 1); setenv("INIT_FORCE_DEBUGGABLE", "true", 1); } } } if (!DoFirstStageMount()) { if (!DoFirstStageMount()) { LOG(FATAL) << "Failed to mount required partitions early ..."; LOG(FATAL) << "Failed to mount required partitions early ..."; Loading
init/init.cpp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -621,6 +621,12 @@ static void GlobalSeccomp() { }); }); } } static void UmountDebugRamdisk() { if (umount("/debug_ramdisk") != 0) { LOG(ERROR) << "Failed to umount /debug_ramdisk"; } } int SecondStageMain(int argc, char** argv) { int SecondStageMain(int argc, char** argv) { if (REBOOT_BOOTLOADER_ON_PANIC) { if (REBOOT_BOOTLOADER_ON_PANIC) { InstallRebootSignalHandlers(); InstallRebootSignalHandlers(); Loading Loading @@ -690,6 +696,7 @@ int SecondStageMain(int argc, char** argv) { InstallSignalFdHandler(&epoll); InstallSignalFdHandler(&epoll); property_load_boot_defaults(load_debug_prop); property_load_boot_defaults(load_debug_prop); UmountDebugRamdisk(); fs_mgr_vendor_overlay_mount_all(); fs_mgr_vendor_overlay_mount_all(); export_oem_lock_status(); export_oem_lock_status(); StartPropertyService(&epoll); StartPropertyService(&epoll); Loading