Merge "init: clean up DelayService()" into main
diff --git a/fs_mgr/libfs_avb/avb_ops.cpp b/fs_mgr/libfs_avb/avb_ops.cpp
index a119bfc..cc19776 100644
--- a/fs_mgr/libfs_avb/avb_ops.cpp
+++ b/fs_mgr/libfs_avb/avb_ops.cpp
@@ -108,8 +108,8 @@
// Converts a partition name (with ab_suffix) to the corresponding mount point.
// e.g., "system_a" => "/system",
// e.g., "vendor_a" => "/vendor",
-static std::string DeriveMountPoint(const std::string& partition_name) {
- const std::string ab_suffix = fs_mgr_get_slot_suffix();
+static std::string DeriveMountPoint(const std::string& partition_name,
+ const std::string& ab_suffix) {
std::string mount_point(partition_name);
auto found = partition_name.rfind(ab_suffix);
if (found != std::string::npos) {
@@ -119,7 +119,7 @@
return "/" + mount_point;
}
-FsManagerAvbOps::FsManagerAvbOps() {
+FsManagerAvbOps::FsManagerAvbOps(const std::string& slot_suffix) {
// We only need to provide the implementation of read_from_partition()
// operation since that's all what is being used by the avb_slot_verify().
// Other I/O operations are only required in bootloader but not in
@@ -135,6 +135,11 @@
// Sets user_data for GetInstanceFromAvbOps() to convert it back to FsManagerAvbOps.
avb_ops_.user_data = this;
+
+ slot_suffix_ = slot_suffix;
+ if (slot_suffix_.empty()) {
+ slot_suffix_ = fs_mgr_get_slot_suffix();
+ }
}
// Given a partition name (with ab_suffix), e.g., system_a, returns the corresponding
@@ -149,7 +154,7 @@
return "";
}
- const auto mount_point = DeriveMountPoint(partition_name);
+ const auto mount_point = DeriveMountPoint(partition_name, slot_suffix_);
if (mount_point.empty()) return "";
auto fstab_entry = GetEntryForMountPoint(&fstab_, mount_point);
diff --git a/fs_mgr/libfs_avb/avb_ops.h b/fs_mgr/libfs_avb/avb_ops.h
index 12686a6..709091e 100644
--- a/fs_mgr/libfs_avb/avb_ops.h
+++ b/fs_mgr/libfs_avb/avb_ops.h
@@ -48,7 +48,7 @@
//
class FsManagerAvbOps {
public:
- FsManagerAvbOps();
+ explicit FsManagerAvbOps(const std::string& slot_suffix = {});
static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) {
return reinterpret_cast<FsManagerAvbOps*>(ops->user_data);
@@ -66,6 +66,7 @@
std::string GetPartitionPath(const char* partition_name);
AvbOps avb_ops_;
Fstab fstab_;
+ std::string slot_suffix_;
};
} // namespace fs_mgr
diff --git a/fs_mgr/libfs_avb/fs_avb.cpp b/fs_mgr/libfs_avb/fs_avb.cpp
index a288876..fb22423 100644
--- a/fs_mgr/libfs_avb/fs_avb.cpp
+++ b/fs_mgr/libfs_avb/fs_avb.cpp
@@ -182,6 +182,11 @@
// class AvbHandle
// ---------------
+AvbHandle::AvbHandle() : status_(AvbHandleStatus::kUninitialized) {
+ slot_suffix_ = fs_mgr_get_slot_suffix();
+ other_slot_suffix_ = fs_mgr_get_other_slot_suffix();
+}
+
AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(
const std::string& partition_name, const std::string& ab_suffix,
const std::string& ab_other_suffix, const std::string& expected_public_key_path,
@@ -194,6 +199,9 @@
return nullptr;
}
+ avb_handle->slot_suffix_ = ab_suffix;
+ avb_handle->other_slot_suffix_ = ab_other_suffix;
+
std::string expected_key_blob;
if (!expected_public_key_path.empty()) {
if (access(expected_public_key_path.c_str(), F_OK) != 0) {
@@ -373,9 +381,14 @@
return avb_handle;
}
-AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta() {
+AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(const std::string& slot_suffix) {
// Loads inline vbmeta images, starting from /vbmeta.
- return LoadAndVerifyVbmeta("vbmeta", fs_mgr_get_slot_suffix(), fs_mgr_get_other_slot_suffix(),
+ auto suffix = slot_suffix;
+ if (suffix.empty()) {
+ suffix = fs_mgr_get_slot_suffix();
+ }
+ auto other_suffix = android::fs_mgr::OtherSlotSuffix(suffix);
+ return LoadAndVerifyVbmeta("vbmeta", suffix, other_suffix,
{} /* expected_public_key, already checked by bootloader */,
HashAlgorithm::kSHA256,
IsAvbPermissive(), /* allow_verification_error */
@@ -399,7 +412,7 @@
? AVB_SLOT_VERIFY_FLAGS_ALLOW_VERIFICATION_ERROR
: AVB_SLOT_VERIFY_FLAGS_NONE;
AvbSlotVerifyResult verify_result =
- avb_ops.AvbSlotVerify(fs_mgr_get_slot_suffix(), flags, &avb_handle->vbmeta_images_);
+ avb_ops.AvbSlotVerify(avb_handle->slot_suffix_, flags, &avb_handle->vbmeta_images_);
// Only allow the following verify results:
// - AVB_SLOT_VERIFY_RESULT_OK.
@@ -492,7 +505,7 @@
}
if (!LoadAvbHashtreeToEnableVerity(fstab_entry, wait_for_verity_dev, vbmeta_images_,
- fs_mgr_get_slot_suffix(), fs_mgr_get_other_slot_suffix())) {
+ slot_suffix_, other_slot_suffix_)) {
return AvbHashtreeResult::kFail;
}
@@ -526,8 +539,8 @@
if (vbmeta_images_.size() < 1) {
return "";
}
- std::string avb_partition_name = DeriveAvbPartitionName(fstab_entry, fs_mgr_get_slot_suffix(),
- fs_mgr_get_other_slot_suffix());
+ std::string avb_partition_name =
+ DeriveAvbPartitionName(fstab_entry, slot_suffix_, other_slot_suffix_);
auto avb_prop_name = "com.android.build." + avb_partition_name + ".security_patch";
return GetAvbPropertyDescriptor(avb_prop_name, vbmeta_images_);
}
diff --git a/fs_mgr/libfs_avb/include/fs_avb/fs_avb.h b/fs_mgr/libfs_avb/include/fs_avb/fs_avb.h
index 4702e68..924ab24 100644
--- a/fs_mgr/libfs_avb/include/fs_avb/fs_avb.h
+++ b/fs_mgr/libfs_avb/include/fs_avb/fs_avb.h
@@ -83,8 +83,8 @@
// is verified and can be trusted.
//
// TODO(bowgotsai): remove Open() and switch to LoadAndVerifyVbmeta().
- static AvbUniquePtr Open(); // loads inline vbmeta, via libavb.
- static AvbUniquePtr LoadAndVerifyVbmeta(); // loads inline vbmeta.
+ static AvbUniquePtr Open(); // loads inline vbmeta, via libavb.
+ static AvbUniquePtr LoadAndVerifyVbmeta(const std::string& slot_suffix = {});
// The caller can specify optional preload_avb_key_blobs for public key matching.
// This is mostly for init to preload AVB keys before chroot into /system.
@@ -137,12 +137,14 @@
AvbHandle& operator=(AvbHandle&&) noexcept = delete; // no move assignment
private:
- AvbHandle() : status_(AvbHandleStatus::kUninitialized) {}
+ AvbHandle();
std::vector<VBMetaData> vbmeta_images_;
VBMetaInfo vbmeta_info_; // A summary info for vbmeta_images_.
AvbHandleStatus status_;
std::string avb_version_;
+ std::string slot_suffix_;
+ std::string other_slot_suffix_;
};
} // namespace fs_mgr
diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h
index 150a47d..09471f0 100644
--- a/fs_mgr/libfstab/include/fstab/fstab.h
+++ b/fs_mgr/libfstab/include/fstab/fstab.h
@@ -145,5 +145,8 @@
// Otherwise returns false and |*out| is not modified.
bool GetKernelCmdline(const std::string& key, std::string* out);
+// Return the "other" slot for the given slot suffix.
+std::string OtherSlotSuffix(const std::string& suffix);
+
} // namespace fs_mgr
} // namespace android
diff --git a/fs_mgr/libfstab/slotselect.cpp b/fs_mgr/libfstab/slotselect.cpp
index 97b2ba1..db3f8da 100644
--- a/fs_mgr/libfstab/slotselect.cpp
+++ b/fs_mgr/libfstab/slotselect.cpp
@@ -74,3 +74,13 @@
}
return true;
}
+
+namespace android {
+namespace fs_mgr {
+
+std::string OtherSlotSuffix(const std::string& suffix) {
+ return other_suffix(suffix);
+}
+
+} // namespace fs_mgr
+} // namespace android
diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp
index 88300cb..3239eb7 100644
--- a/init/first_stage_init.cpp
+++ b/init/first_stage_init.cpp
@@ -35,6 +35,7 @@
#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
#include <modprobe/modprobe.h>
#include <private/android_filesystem_config.h>
@@ -153,6 +154,15 @@
Copy(snapuserd, dst);
}
}
+
+std::string GetPageSizeSuffix() {
+ static const size_t page_size = sysconf(_SC_PAGE_SIZE);
+ if (page_size <= 4096) {
+ return "";
+ }
+ return android::base::StringPrintf("_%zuk", page_size / 1024);
+}
+
} // namespace
std::string GetModuleLoadList(BootMode boot_mode, const std::string& dir_path) {
@@ -201,10 +211,18 @@
}
dirent* entry = nullptr;
std::vector<std::string> module_dirs;
+ const std::string release_specific_module_dir = uts.release + GetPageSizeSuffix();
while ((entry = readdir(base_dir.get()))) {
if (entry->d_type != DT_DIR) {
continue;
}
+ if (entry->d_name == release_specific_module_dir) {
+ LOG(INFO) << "Release specific kernel module dir " << release_specific_module_dir
+ << " found, loading modules from here with no fallbacks.";
+ module_dirs.clear();
+ module_dirs.emplace_back(entry->d_name);
+ break;
+ }
int dir_major = 0, dir_minor = 0;
if (sscanf(entry->d_name, "%d.%d", &dir_major, &dir_minor) != 2 || dir_major != major ||
dir_minor != minor) {
@@ -228,6 +246,7 @@
bool retval = m.LoadListedModules(!want_console);
modules_loaded = m.GetModuleCount();
if (modules_loaded > 0) {
+ LOG(INFO) << "Loaded " << modules_loaded << " modules from " << dir_path;
return retval;
}
}
@@ -237,6 +256,7 @@
: m.LoadListedModules(!want_console);
modules_loaded = m.GetModuleCount();
if (modules_loaded > 0) {
+ LOG(INFO) << "Loaded " << modules_loaded << " modules from " << MODULE_BASE_DIR;
return retval;
}
return true;