From addbafdb0b545f93bfd4dea6aa5431341559132a Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 8 Dec 2020 20:28:41 +0000 Subject: [PATCH 1/4] Revert "Move e2fsck into /first_stage_ramdisk." This reverts commit 3337e782e6f8462c6a2954617e4c59c01ec502be. Reason for revert: e2fsck is moved into vendor ramdisk and installed to / or /first_stage_ramdisk depending on the device, so there is no need to move it. Bug: 173425293 Change-Id: I1eb431e6b2a1e0ba7d0da0278d076b6682a0156d Test: boots --- init/first_stage_init.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp index 83a32e746..0949fc522 100644 --- a/init/first_stage_init.cpp +++ b/init/first_stage_init.cpp @@ -99,34 +99,6 @@ bool ForceNormalBoot(const std::string& cmdline) { return cmdline.find("androidboot.force_normal_boot=1") != std::string::npos; } -// Move e2fsck before switching root, so that it is available at the same path -// after switching root. -void PrepareSwitchRoot() { - constexpr const char* src = "/system/bin/e2fsck"; - constexpr const char* dst = "/first_stage_ramdisk/system/bin/e2fsck"; - - if (access(dst, X_OK) == 0) { - LOG(INFO) << dst << " already exists and it can be executed"; - return; - } - - if (access(src, F_OK) != 0) { - PLOG(INFO) << "Not moving " << src << " because it cannot be accessed"; - return; - } - - auto dst_dir = android::base::Dirname(dst); - std::error_code ec; - if (!fs::create_directories(dst_dir, ec) && !!ec) { - LOG(FATAL) << "Cannot create " << dst_dir << ": " << ec.message(); - } - if (rename(src, dst) != 0) { - PLOG(FATAL) << "Cannot move " << src << " to " << dst - << ". Either install e2fsck.ramdisk so that it is at the correct place (" << dst - << "), or make ramdisk writable"; - } -} - } // namespace std::string GetModuleLoadList(bool recovery, const std::string& dir_path) { @@ -327,7 +299,6 @@ int FirstStageMain(int argc, char** argv) { if (ForceNormalBoot(cmdline)) { mkdir("/first_stage_ramdisk", 0755); - PrepareSwitchRoot(); // 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) { From 63be35649a2686a3b20db870826b70508f8fbb00 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 8 Dec 2020 12:29:59 -0800 Subject: [PATCH 2/4] Refactor the list of empty dirs in ramdisk in its own list. Test: build and manual inspect Bug: 173425293 Change-Id: I7805640af314b60801cc831f1d1f25820f0fb63b --- init/Android.mk | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/init/Android.mk b/init/Android.mk index ac31ef161..cf504edd4 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -75,13 +75,18 @@ LOCAL_REQUIRED_MODULES := \ adb_debug.prop \ # Set up the directories that first stage init mounts on. -LOCAL_POST_INSTALL_CMD := mkdir -p \ - $(TARGET_RAMDISK_OUT)/debug_ramdisk \ - $(TARGET_RAMDISK_OUT)/dev \ - $(TARGET_RAMDISK_OUT)/mnt \ - $(TARGET_RAMDISK_OUT)/proc \ - $(TARGET_RAMDISK_OUT)/second_stage_resources \ - $(TARGET_RAMDISK_OUT)/sys \ + +my_ramdisk_dirs := \ + debug_ramdisk \ + dev \ + mnt \ + proc \ + second_stage_resources \ + sys \ + +LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_RAMDISK_OUT)/,$(my_ramdisk_dirs)) + +my_ramdisk_dirs := LOCAL_STATIC_LIBRARIES := \ libc++fs \ From 55326187ab9163e5108cea7074cbb12d6738de60 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 8 Dec 2020 12:34:45 -0800 Subject: [PATCH 3/4] Also create dirs under /first_stage_ramdisk for GKI. If the device uses GKI and generic ramdisk, also create empty directories under /first_stage_ramdisk so that they won't have to be created at runtime. This allows generic ramdisk to be not writable. Test: boots Bug: 173425293 Change-Id: If987cb1d4af9f9ee94a43a4523f9e1465b01b16a --- init/Android.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/init/Android.mk b/init/Android.mk index cf504edd4..533642570 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -85,6 +85,9 @@ my_ramdisk_dirs := \ sys \ LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_RAMDISK_OUT)/,$(my_ramdisk_dirs)) +ifeq (true,$(BOARD_USES_GENERIC_KERNEL_IMAGE)) + LOCAL_POST_INSTALL_CMD += $(addprefix $(TARGET_RAMDISK_OUT)/first_stage_ramdisk/,$(my_ramdisk_dirs)) +endif my_ramdisk_dirs := From a3f83730438a8d623eb7b8c5866de8a81ecd8655 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 8 Dec 2020 12:39:58 -0800 Subject: [PATCH 4/4] Add /metadata to ramdisk. Now that GKI may not be writeable, also create /metadata at build time to avoid error log at boot time. Note that this also creates /first_stage_ramdisk/metadata in GKI. [ 1.891172] init: [libfs_mgr]check_fs(): mount(/dev/block/by-name/metadata,/metadata,ext4)=-1: No such file or directory Bug: 173425293 Test: boots Change-Id: I62d23c382ed1ad165c1d6598b3df41bd92206733 --- init/Android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/init/Android.mk b/init/Android.mk index 533642570..c881e2fd2 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -79,6 +79,7 @@ LOCAL_REQUIRED_MODULES := \ my_ramdisk_dirs := \ debug_ramdisk \ dev \ + metadata \ mnt \ proc \ second_stage_resources \