From 2034cc3d05de963acc680835882a0c34d7e215cb Mon Sep 17 00:00:00 2001 From: Erfan Abdi Date: Tue, 14 Apr 2020 23:07:33 +0430 Subject: [PATCH] recovery: Map logical partitions before installation Change-Id: I785b49086a2baf462e97be831b495d7db72f7a42 --- recovery_main.cpp | 2 +- recovery_utils/include/recovery_utils/roots.h | 2 ++ recovery_utils/roots.cpp | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/recovery_main.cpp b/recovery_main.cpp index 6cca983c..dd26420e 100644 --- a/recovery_main.cpp +++ b/recovery_main.cpp @@ -583,7 +583,7 @@ int main(int argc, char** argv) { } case Device::ENTER_FASTBOOT: - if (android::fs_mgr::LogicalPartitionsMapped()) { + if (logical_partitions_mapped()) { ui->Print("Partitions may be mounted - rebooting to enter fastboot."); Reboot("fastboot"); } else { diff --git a/recovery_utils/include/recovery_utils/roots.h b/recovery_utils/include/recovery_utils/roots.h index d88fe564..2e08eea0 100644 --- a/recovery_utils/include/recovery_utils/roots.h +++ b/recovery_utils/include/recovery_utils/roots.h @@ -61,3 +61,5 @@ int setup_install_mounts(); // Returns true if there is /cache in the volumes. bool HasCache(); + +bool logical_partitions_mapped(); diff --git a/recovery_utils/roots.cpp b/recovery_utils/roots.cpp index ed4a2eaa..c107aeb6 100644 --- a/recovery_utils/roots.cpp +++ b/recovery_utils/roots.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "otautil/sysutil.h" @@ -371,6 +372,8 @@ int format_volume(const std::string& volume) { return format_volume(volume, "", ""); } +static bool logical_partitions_auto_mapped = false; + int setup_install_mounts() { if (fstab.empty()) { LOG(ERROR) << "can't set up install mounts: no fstab loaded"; @@ -394,6 +397,16 @@ int setup_install_mounts() { } } } + // Map logical partitions + if (android::base::GetBoolProperty("ro.boot.dynamic_partitions", false) && + !logical_partitions_mapped()) { + std::string super_name = fs_mgr_get_super_partition_name(); + if (!android::fs_mgr::CreateLogicalPartitions("/dev/block/by-name/" + super_name)) { + LOG(ERROR) << "Failed to map logical partitions"; + } else { + logical_partitions_auto_mapped = true; + } + } return 0; } @@ -402,3 +415,7 @@ bool HasCache() { static bool has_cache = volume_for_mount_point(CACHE_ROOT) != nullptr; return has_cache; } + +bool logical_partitions_mapped() { + return android::fs_mgr::LogicalPartitionsMapped() || logical_partitions_auto_mapped; +}