Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2018 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/aosp/dynamic_partition_control_android.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 18 | |
Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 19 | #include <algorithm> |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 20 | #include <chrono> // NOLINT(build/c++11) - using libsnapshot / liblp API |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 21 | #include <cstdint> |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 22 | #include <map> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 23 | #include <memory> |
| 24 | #include <set> |
| 25 | #include <string> |
Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 26 | #include <string_view> |
| 27 | #include <utility> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 28 | #include <vector> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 29 | |
| 30 | #include <android-base/properties.h> |
| 31 | #include <android-base/strings.h> |
| 32 | #include <base/files/file_util.h> |
| 33 | #include <base/logging.h> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 34 | #include <base/strings/string_util.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 35 | #include <bootloader_message/bootloader_message.h> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 36 | #include <fs_mgr.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 37 | #include <fs_mgr_dm_linear.h> |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 38 | #include <fs_mgr_overlayfs.h> |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 39 | #include <libavb/libavb.h> |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 40 | #include <libdm/dm.h> |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 41 | #include <liblp/liblp.h> |
| 42 | #include <libsnapshot/cow_writer.h> |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 43 | #include <libsnapshot/snapshot.h> |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 44 | #include <libsnapshot/snapshot_stub.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 45 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 46 | #include "update_engine/aosp/cleanup_previous_update_action.h" |
| 47 | #include "update_engine/aosp/dynamic_partition_utils.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 48 | #include "update_engine/common/boot_control_interface.h" |
Kelvin Zhang | b9a5f61 | 2021-01-22 14:34:05 -0500 | [diff] [blame] | 49 | #include "update_engine/common/dynamic_partition_control_interface.h" |
| 50 | #include "update_engine/common/platform_constants.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 51 | #include "update_engine/common/utils.h" |
Yifan Hong | 6a6d0f1 | 2020-03-11 13:20:52 -0700 | [diff] [blame] | 52 | #include "update_engine/payload_consumer/delta_performer.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 53 | |
| 54 | using android::base::GetBoolProperty; |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 55 | using android::base::GetProperty; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 56 | using android::base::Join; |
| 57 | using android::dm::DeviceMapper; |
| 58 | using android::dm::DmDeviceState; |
| 59 | using android::fs_mgr::CreateLogicalPartition; |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 60 | using android::fs_mgr::CreateLogicalPartitionParams; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 61 | using android::fs_mgr::DestroyLogicalPartition; |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 62 | using android::fs_mgr::Fstab; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 63 | using android::fs_mgr::MetadataBuilder; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 64 | using android::fs_mgr::Partition; |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 65 | using android::fs_mgr::PartitionOpener; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 66 | using android::fs_mgr::SlotSuffixForSlotNumber; |
Yifan Hong | f526156 | 2020-03-10 10:28:10 -0700 | [diff] [blame] | 67 | using android::snapshot::OptimizeSourceCopyOperation; |
Yifan Hong | 0850bca | 2020-01-16 15:14:07 -0800 | [diff] [blame] | 68 | using android::snapshot::Return; |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 69 | using android::snapshot::SnapshotManager; |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 70 | using android::snapshot::SnapshotManagerStub; |
Yifan Hong | 2257ee1 | 2020-01-13 18:33:00 -0800 | [diff] [blame] | 71 | using android::snapshot::UpdateState; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 72 | |
| 73 | namespace chromeos_update_engine { |
| 74 | |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 75 | constexpr char kUseDynamicPartitions[] = "ro.boot.dynamic_partitions"; |
| 76 | constexpr char kRetrfoitDynamicPartitions[] = |
| 77 | "ro.boot.dynamic_partitions_retrofit"; |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 78 | constexpr char kVirtualAbEnabled[] = "ro.virtual_ab.enabled"; |
| 79 | constexpr char kVirtualAbRetrofit[] = "ro.virtual_ab.retrofit"; |
Kelvin Zhang | da1b314 | 2020-09-24 17:09:02 -0400 | [diff] [blame] | 80 | constexpr char kVirtualAbCompressionEnabled[] = |
| 81 | "ro.virtual_ab.compression.enabled"; |
| 82 | |
| 83 | // Currently, android doesn't have a retrofit prop for VAB Compression. However, |
| 84 | // struct FeatureFlag forces us to determine if a feature is 'retrofit'. So this |
| 85 | // is here just to simplify code. Replace it with real retrofit prop name once |
| 86 | // there is one. |
| 87 | constexpr char kVirtualAbCompressionRetrofit[] = ""; |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 88 | constexpr char kPostinstallFstabPrefix[] = "ro.postinstall.fstab.prefix"; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 89 | // Map timeout for dynamic partitions. |
| 90 | constexpr std::chrono::milliseconds kMapTimeout{1000}; |
| 91 | // Map timeout for dynamic partitions with snapshots. Since several devices |
| 92 | // needs to be mapped, this timeout is longer than |kMapTimeout|. |
| 93 | constexpr std::chrono::milliseconds kMapSnapshotTimeout{5000}; |
| 94 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 95 | DynamicPartitionControlAndroid::~DynamicPartitionControlAndroid() { |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 96 | Cleanup(); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 99 | static FeatureFlag GetFeatureFlag(const char* enable_prop, |
| 100 | const char* retrofit_prop) { |
Kelvin Zhang | da1b314 | 2020-09-24 17:09:02 -0400 | [diff] [blame] | 101 | // Default retrofit to false if retrofit_prop is empty. |
| 102 | bool retrofit = retrofit_prop && retrofit_prop[0] != '\0' && |
| 103 | GetBoolProperty(retrofit_prop, false); |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 104 | bool enabled = GetBoolProperty(enable_prop, false); |
| 105 | if (retrofit && !enabled) { |
| 106 | LOG(ERROR) << retrofit_prop << " is true but " << enable_prop |
| 107 | << " is not. These sysprops are inconsistent. Assume that " |
| 108 | << enable_prop << " is true from now on."; |
| 109 | } |
| 110 | if (retrofit) { |
| 111 | return FeatureFlag(FeatureFlag::Value::RETROFIT); |
| 112 | } |
| 113 | if (enabled) { |
| 114 | return FeatureFlag(FeatureFlag::Value::LAUNCH); |
| 115 | } |
| 116 | return FeatureFlag(FeatureFlag::Value::NONE); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 119 | DynamicPartitionControlAndroid::DynamicPartitionControlAndroid( |
| 120 | uint32_t source_slot) |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 121 | : dynamic_partitions_( |
| 122 | GetFeatureFlag(kUseDynamicPartitions, kRetrfoitDynamicPartitions)), |
Kelvin Zhang | da1b314 | 2020-09-24 17:09:02 -0400 | [diff] [blame] | 123 | virtual_ab_(GetFeatureFlag(kVirtualAbEnabled, kVirtualAbRetrofit)), |
| 124 | virtual_ab_compression_(GetFeatureFlag(kVirtualAbCompressionEnabled, |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 125 | kVirtualAbCompressionRetrofit)), |
| 126 | source_slot_(source_slot) { |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 127 | if (GetVirtualAbFeatureFlag().IsEnabled()) { |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 128 | snapshot_ = SnapshotManager::New(); |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 129 | } else { |
| 130 | snapshot_ = SnapshotManagerStub::New(); |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 131 | } |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 132 | CHECK(snapshot_ != nullptr) << "Cannot initialize SnapshotManager."; |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 135 | FeatureFlag DynamicPartitionControlAndroid::GetDynamicPartitionsFeatureFlag() { |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 136 | return dynamic_partitions_; |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 139 | FeatureFlag DynamicPartitionControlAndroid::GetVirtualAbFeatureFlag() { |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 140 | return virtual_ab_; |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Kelvin Zhang | da1b314 | 2020-09-24 17:09:02 -0400 | [diff] [blame] | 143 | FeatureFlag |
| 144 | DynamicPartitionControlAndroid::GetVirtualAbCompressionFeatureFlag() { |
Kelvin Zhang | b9a5f61 | 2021-01-22 14:34:05 -0500 | [diff] [blame] | 145 | if constexpr (constants::kIsRecovery) { |
| 146 | // Don't attempt VABC in recovery |
| 147 | return FeatureFlag(FeatureFlag::Value::NONE); |
| 148 | } |
Kelvin Zhang | da1b314 | 2020-09-24 17:09:02 -0400 | [diff] [blame] | 149 | return virtual_ab_compression_; |
| 150 | } |
| 151 | |
Yifan Hong | f526156 | 2020-03-10 10:28:10 -0700 | [diff] [blame] | 152 | bool DynamicPartitionControlAndroid::OptimizeOperation( |
| 153 | const std::string& partition_name, |
| 154 | const InstallOperation& operation, |
| 155 | InstallOperation* optimized) { |
Alessio Balsini | 2a3b4a2 | 2019-11-25 16:46:51 +0000 | [diff] [blame] | 156 | switch (operation.type()) { |
| 157 | case InstallOperation::SOURCE_COPY: |
| 158 | return target_supports_snapshot_ && |
| 159 | GetVirtualAbFeatureFlag().IsEnabled() && |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 160 | mapped_devices_.count(partition_name + |
| 161 | SlotSuffixForSlotNumber(target_slot_)) > 0 && |
Yifan Hong | f526156 | 2020-03-10 10:28:10 -0700 | [diff] [blame] | 162 | OptimizeSourceCopyOperation(operation, optimized); |
Alessio Balsini | 2a3b4a2 | 2019-11-25 16:46:51 +0000 | [diff] [blame] | 163 | break; |
| 164 | default: |
| 165 | break; |
| 166 | } |
Alessio Balsini | 14980e2 | 2019-11-26 11:46:06 +0000 | [diff] [blame] | 167 | return false; |
| 168 | } |
| 169 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 170 | bool DynamicPartitionControlAndroid::MapPartitionInternal( |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 171 | const std::string& super_device, |
| 172 | const std::string& target_partition_name, |
| 173 | uint32_t slot, |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 174 | bool force_writable, |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 175 | std::string* path) { |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 176 | CreateLogicalPartitionParams params = { |
| 177 | .block_device = super_device, |
| 178 | .metadata_slot = slot, |
| 179 | .partition_name = target_partition_name, |
| 180 | .force_writable = force_writable, |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 181 | }; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 182 | bool success = false; |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 183 | if (GetVirtualAbFeatureFlag().IsEnabled() && target_supports_snapshot_ && |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 184 | force_writable && ExpectMetadataMounted()) { |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 185 | // Only target partitions are mapped with force_writable. On Virtual |
| 186 | // A/B devices, target partitions may overlap with source partitions, so |
| 187 | // they must be mapped with snapshot. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 188 | // One exception is when /metadata is not mounted. Fallback to |
| 189 | // CreateLogicalPartition as snapshots are not created in the first place. |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 190 | params.timeout_ms = kMapSnapshotTimeout; |
| 191 | success = snapshot_->MapUpdateSnapshot(params, path); |
| 192 | } else { |
| 193 | params.timeout_ms = kMapTimeout; |
| 194 | success = CreateLogicalPartition(params, path); |
| 195 | } |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 196 | |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 197 | if (!success) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 198 | LOG(ERROR) << "Cannot map " << target_partition_name << " in " |
| 199 | << super_device << " on device mapper."; |
| 200 | return false; |
| 201 | } |
| 202 | LOG(INFO) << "Succesfully mapped " << target_partition_name |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 203 | << " to device mapper (force_writable = " << force_writable |
| 204 | << "); device path at " << *path; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 205 | mapped_devices_.insert(target_partition_name); |
| 206 | return true; |
| 207 | } |
| 208 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 209 | bool DynamicPartitionControlAndroid::MapPartitionOnDeviceMapper( |
| 210 | const std::string& super_device, |
| 211 | const std::string& target_partition_name, |
| 212 | uint32_t slot, |
| 213 | bool force_writable, |
| 214 | std::string* path) { |
| 215 | DmDeviceState state = GetState(target_partition_name); |
| 216 | if (state == DmDeviceState::ACTIVE) { |
| 217 | if (mapped_devices_.find(target_partition_name) != mapped_devices_.end()) { |
| 218 | if (GetDmDevicePathByName(target_partition_name, path)) { |
| 219 | LOG(INFO) << target_partition_name |
| 220 | << " is mapped on device mapper: " << *path; |
| 221 | return true; |
| 222 | } |
| 223 | LOG(ERROR) << target_partition_name << " is mapped but path is unknown."; |
| 224 | return false; |
| 225 | } |
| 226 | // If target_partition_name is not in mapped_devices_ but state is ACTIVE, |
| 227 | // the device might be mapped incorrectly before. Attempt to unmap it. |
| 228 | // Note that for source partitions, if GetState() == ACTIVE, callers (e.g. |
| 229 | // BootControlAndroid) should not call MapPartitionOnDeviceMapper, but |
| 230 | // should directly call GetDmDevicePathByName. |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 231 | if (!UnmapPartitionOnDeviceMapper(target_partition_name)) { |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 232 | LOG(ERROR) << target_partition_name |
| 233 | << " is mapped before the update, and it cannot be unmapped."; |
| 234 | return false; |
| 235 | } |
| 236 | state = GetState(target_partition_name); |
| 237 | if (state != DmDeviceState::INVALID) { |
| 238 | LOG(ERROR) << target_partition_name << " is unmapped but state is " |
| 239 | << static_cast<std::underlying_type_t<DmDeviceState>>(state); |
| 240 | return false; |
| 241 | } |
| 242 | } |
| 243 | if (state == DmDeviceState::INVALID) { |
| 244 | return MapPartitionInternal( |
| 245 | super_device, target_partition_name, slot, force_writable, path); |
| 246 | } |
| 247 | |
| 248 | LOG(ERROR) << target_partition_name |
| 249 | << " is mapped on device mapper but state is unknown: " |
| 250 | << static_cast<std::underlying_type_t<DmDeviceState>>(state); |
| 251 | return false; |
| 252 | } |
| 253 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 254 | bool DynamicPartitionControlAndroid::UnmapPartitionOnDeviceMapper( |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 255 | const std::string& target_partition_name) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 256 | if (DeviceMapper::Instance().GetState(target_partition_name) != |
| 257 | DmDeviceState::INVALID) { |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 258 | // Partitions at target slot on non-Virtual A/B devices are mapped as |
| 259 | // dm-linear. Also, on Virtual A/B devices, system_other may be mapped for |
| 260 | // preopt apps as dm-linear. |
| 261 | // Call DestroyLogicalPartition to handle these cases. |
| 262 | bool success = DestroyLogicalPartition(target_partition_name); |
| 263 | |
| 264 | // On a Virtual A/B device, |target_partition_name| may be a leftover from |
| 265 | // a paused update. Clean up any underlying devices. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 266 | if (ExpectMetadataMounted()) { |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 267 | success &= snapshot_->UnmapUpdateSnapshot(target_partition_name); |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 268 | } else { |
| 269 | LOG(INFO) << "Skip UnmapUpdateSnapshot(" << target_partition_name |
| 270 | << ") because metadata is not mounted"; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | if (!success) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 274 | LOG(ERROR) << "Cannot unmap " << target_partition_name |
| 275 | << " from device mapper."; |
| 276 | return false; |
| 277 | } |
| 278 | LOG(INFO) << "Successfully unmapped " << target_partition_name |
| 279 | << " from device mapper."; |
| 280 | } |
| 281 | mapped_devices_.erase(target_partition_name); |
| 282 | return true; |
| 283 | } |
| 284 | |
Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 285 | bool DynamicPartitionControlAndroid::UnmapAllPartitions() { |
Kelvin Zhang | f7ef12a | 2021-03-22 12:59:06 -0400 | [diff] [blame] | 286 | snapshot_->UnmapAllSnapshots(); |
Tao Bao | 8c4d008 | 2019-08-08 08:56:16 -0700 | [diff] [blame] | 287 | if (mapped_devices_.empty()) { |
Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 288 | return false; |
Tao Bao | 8c4d008 | 2019-08-08 08:56:16 -0700 | [diff] [blame] | 289 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 290 | // UnmapPartitionOnDeviceMapper removes objects from mapped_devices_, hence |
| 291 | // a copy is needed for the loop. |
| 292 | std::set<std::string> mapped = mapped_devices_; |
| 293 | LOG(INFO) << "Destroying [" << Join(mapped, ", ") << "] from device mapper"; |
| 294 | for (const auto& partition_name : mapped) { |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 295 | ignore_result(UnmapPartitionOnDeviceMapper(partition_name)); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 296 | } |
Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 297 | return true; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void DynamicPartitionControlAndroid::Cleanup() { |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 301 | UnmapAllPartitions(); |
| 302 | metadata_device_.reset(); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | bool DynamicPartitionControlAndroid::DeviceExists(const std::string& path) { |
| 306 | return base::PathExists(base::FilePath(path)); |
| 307 | } |
| 308 | |
| 309 | android::dm::DmDeviceState DynamicPartitionControlAndroid::GetState( |
| 310 | const std::string& name) { |
| 311 | return DeviceMapper::Instance().GetState(name); |
| 312 | } |
| 313 | |
| 314 | bool DynamicPartitionControlAndroid::GetDmDevicePathByName( |
| 315 | const std::string& name, std::string* path) { |
| 316 | return DeviceMapper::Instance().GetDmDevicePathByName(name, path); |
| 317 | } |
| 318 | |
| 319 | std::unique_ptr<MetadataBuilder> |
| 320 | DynamicPartitionControlAndroid::LoadMetadataBuilder( |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 321 | const std::string& super_device, uint32_t slot) { |
| 322 | auto builder = MetadataBuilder::New(PartitionOpener(), super_device, slot); |
| 323 | if (builder == nullptr) { |
| 324 | LOG(WARNING) << "No metadata slot " << BootControlInterface::SlotName(slot) |
| 325 | << " in " << super_device; |
| 326 | return nullptr; |
| 327 | } |
| 328 | LOG(INFO) << "Loaded metadata from slot " |
| 329 | << BootControlInterface::SlotName(slot) << " in " << super_device; |
| 330 | return builder; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | std::unique_ptr<MetadataBuilder> |
| 334 | DynamicPartitionControlAndroid::LoadMetadataBuilder( |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 335 | const std::string& super_device, |
| 336 | uint32_t source_slot, |
| 337 | uint32_t target_slot) { |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 338 | bool always_keep_source_slot = !target_supports_snapshot_; |
| 339 | auto builder = MetadataBuilder::NewForUpdate(PartitionOpener(), |
| 340 | super_device, |
| 341 | source_slot, |
| 342 | target_slot, |
| 343 | always_keep_source_slot); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 344 | if (builder == nullptr) { |
| 345 | LOG(WARNING) << "No metadata slot " |
| 346 | << BootControlInterface::SlotName(source_slot) << " in " |
| 347 | << super_device; |
Yifan Hong | f48a005 | 2018-10-29 16:30:43 -0700 | [diff] [blame] | 348 | return nullptr; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 349 | } |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 350 | LOG(INFO) << "Created metadata for new update from slot " |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 351 | << BootControlInterface::SlotName(source_slot) << " in " |
| 352 | << super_device; |
| 353 | return builder; |
| 354 | } |
| 355 | |
| 356 | bool DynamicPartitionControlAndroid::StoreMetadata( |
| 357 | const std::string& super_device, |
| 358 | MetadataBuilder* builder, |
| 359 | uint32_t target_slot) { |
| 360 | auto metadata = builder->Export(); |
| 361 | if (metadata == nullptr) { |
| 362 | LOG(ERROR) << "Cannot export metadata to slot " |
| 363 | << BootControlInterface::SlotName(target_slot) << " in " |
| 364 | << super_device; |
| 365 | return false; |
| 366 | } |
| 367 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 368 | if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) { |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 369 | if (!FlashPartitionTable(super_device, *metadata)) { |
| 370 | LOG(ERROR) << "Cannot write metadata to " << super_device; |
| 371 | return false; |
| 372 | } |
| 373 | LOG(INFO) << "Written metadata to " << super_device; |
| 374 | } else { |
| 375 | if (!UpdatePartitionTable(super_device, *metadata, target_slot)) { |
| 376 | LOG(ERROR) << "Cannot write metadata to slot " |
| 377 | << BootControlInterface::SlotName(target_slot) << " in " |
| 378 | << super_device; |
| 379 | return false; |
| 380 | } |
| 381 | LOG(INFO) << "Copied metadata to slot " |
| 382 | << BootControlInterface::SlotName(target_slot) << " in " |
| 383 | << super_device; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 386 | return true; |
| 387 | } |
| 388 | |
| 389 | bool DynamicPartitionControlAndroid::GetDeviceDir(std::string* out) { |
| 390 | // We can't use fs_mgr to look up |partition_name| because fstab |
| 391 | // doesn't list every slot partition (it uses the slotselect option |
| 392 | // to mask the suffix). |
| 393 | // |
| 394 | // We can however assume that there's an entry for the /misc mount |
| 395 | // point and use that to get the device file for the misc |
| 396 | // partition. This helps us locate the disk that |partition_name| |
| 397 | // resides on. From there we'll assume that a by-name scheme is used |
| 398 | // so we can just replace the trailing "misc" by the given |
| 399 | // |partition_name| and suffix corresponding to |slot|, e.g. |
| 400 | // |
| 401 | // /dev/block/platform/soc.0/7824900.sdhci/by-name/misc -> |
| 402 | // /dev/block/platform/soc.0/7824900.sdhci/by-name/boot_a |
| 403 | // |
| 404 | // If needed, it's possible to relax the by-name assumption in the |
| 405 | // future by trawling /sys/block looking for the appropriate sibling |
| 406 | // of misc and then finding an entry in /dev matching the sysfs |
| 407 | // entry. |
| 408 | |
| 409 | std::string err, misc_device = get_bootloader_message_blk_device(&err); |
| 410 | if (misc_device.empty()) { |
| 411 | LOG(ERROR) << "Unable to get misc block device: " << err; |
| 412 | return false; |
| 413 | } |
| 414 | |
| 415 | if (!utils::IsSymlink(misc_device.c_str())) { |
| 416 | LOG(ERROR) << "Device file " << misc_device << " for /misc " |
| 417 | << "is not a symlink."; |
| 418 | return false; |
| 419 | } |
| 420 | *out = base::FilePath(misc_device).DirName().value(); |
| 421 | return true; |
| 422 | } |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 423 | |
| 424 | bool DynamicPartitionControlAndroid::PreparePartitionsForUpdate( |
| 425 | uint32_t source_slot, |
| 426 | uint32_t target_slot, |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 427 | const DeltaArchiveManifest& manifest, |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 428 | bool update, |
| 429 | uint64_t* required_size) { |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 430 | source_slot_ = source_slot; |
| 431 | target_slot_ = target_slot; |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 432 | if (required_size != nullptr) { |
| 433 | *required_size = 0; |
| 434 | } |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 435 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 436 | if (fs_mgr_overlayfs_is_setup()) { |
| 437 | // Non DAP devices can use overlayfs as well. |
| 438 | LOG(WARNING) |
| 439 | << "overlayfs overrides are active and can interfere with our " |
| 440 | "resources.\n" |
| 441 | << "run adb enable-verity to deactivate if required and try again."; |
| 442 | } |
| 443 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 444 | // If metadata is erased but not formatted, it is possible to not mount |
| 445 | // it in recovery. It is acceptable to skip mounting and choose fallback path |
| 446 | // (PrepareDynamicPartitionsForUpdate) when sideloading full OTAs. |
| 447 | TEST_AND_RETURN_FALSE(EnsureMetadataMounted() || IsRecovery()); |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 448 | |
| 449 | if (update) { |
| 450 | TEST_AND_RETURN_FALSE(EraseSystemOtherAvbFooter(source_slot, target_slot)); |
| 451 | } |
| 452 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 453 | if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) { |
| 454 | return true; |
| 455 | } |
| 456 | |
| 457 | if (target_slot == source_slot) { |
| 458 | LOG(ERROR) << "Cannot call PreparePartitionsForUpdate on current slot."; |
| 459 | return false; |
| 460 | } |
| 461 | |
Yifan Hong | f6f75c2 | 2020-07-31 15:20:25 -0700 | [diff] [blame] | 462 | if (!SetTargetBuildVars(manifest)) { |
| 463 | return false; |
| 464 | } |
| 465 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 466 | // Although the current build supports dynamic partitions, the given payload |
| 467 | // doesn't use it for target partitions. This could happen when applying a |
| 468 | // retrofit update. Skip updating the partition metadata for the target slot. |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 469 | if (!is_target_dynamic_) { |
| 470 | return true; |
| 471 | } |
| 472 | |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 473 | if (!update) |
| 474 | return true; |
| 475 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 476 | bool delete_source = false; |
| 477 | |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 478 | if (GetVirtualAbFeatureFlag().IsEnabled()) { |
| 479 | // On Virtual A/B device, either CancelUpdate() or BeginUpdate() must be |
| 480 | // called before calling UnmapUpdateSnapshot. |
| 481 | // - If target_supports_snapshot_, PrepareSnapshotPartitionsForUpdate() |
| 482 | // calls BeginUpdate() which resets update state |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 483 | // - If !target_supports_snapshot_ or PrepareSnapshotPartitionsForUpdate |
| 484 | // failed in recovery, explicitly CancelUpdate(). |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 485 | if (target_supports_snapshot_) { |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 486 | if (PrepareSnapshotPartitionsForUpdate( |
| 487 | source_slot, target_slot, manifest, required_size)) { |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | // Virtual A/B device doing Virtual A/B update in Android mode must use |
| 492 | // snapshots. |
| 493 | if (!IsRecovery()) { |
| 494 | LOG(ERROR) << "PrepareSnapshotPartitionsForUpdate failed in Android " |
| 495 | << "mode"; |
| 496 | return false; |
| 497 | } |
| 498 | |
| 499 | delete_source = true; |
| 500 | LOG(INFO) << "PrepareSnapshotPartitionsForUpdate failed in recovery. " |
| 501 | << "Attempt to overwrite existing partitions if possible"; |
| 502 | } else { |
| 503 | // Downgrading to an non-Virtual A/B build or is secondary OTA. |
| 504 | LOG(INFO) << "Using regular A/B on Virtual A/B because package disabled " |
| 505 | << "snapshots."; |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 506 | } |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 507 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 508 | // In recovery, if /metadata is not mounted, it is likely that metadata |
| 509 | // partition is erased and not formatted yet. After sideloading, when |
| 510 | // rebooting into the new version, init will erase metadata partition, |
| 511 | // hence the failure of CancelUpdate() can be ignored here. |
| 512 | // However, if metadata is mounted and CancelUpdate fails, sideloading |
| 513 | // should not proceed because during next boot, snapshots will overlay on |
| 514 | // the devices incorrectly. |
| 515 | if (ExpectMetadataMounted()) { |
| 516 | TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate()); |
| 517 | } else { |
| 518 | LOG(INFO) << "Skip canceling previous update because metadata is not " |
| 519 | << "mounted"; |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 520 | } |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 521 | } |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 522 | |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 523 | // TODO(xunchang) support partial update on non VAB enabled devices. |
Yifan Hong | 5c5743f | 2020-04-16 12:59:07 -0700 | [diff] [blame] | 524 | TEST_AND_RETURN_FALSE(PrepareDynamicPartitionsForUpdate( |
| 525 | source_slot, target_slot, manifest, delete_source)); |
| 526 | |
| 527 | if (required_size != nullptr) { |
| 528 | *required_size = 0; |
| 529 | } |
| 530 | return true; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Yifan Hong | f6f75c2 | 2020-07-31 15:20:25 -0700 | [diff] [blame] | 533 | bool DynamicPartitionControlAndroid::SetTargetBuildVars( |
| 534 | const DeltaArchiveManifest& manifest) { |
| 535 | // Precondition: current build supports dynamic partition. |
| 536 | CHECK(GetDynamicPartitionsFeatureFlag().IsEnabled()); |
| 537 | |
| 538 | bool is_target_dynamic = |
| 539 | !manifest.dynamic_partition_metadata().groups().empty(); |
| 540 | bool target_supports_snapshot = |
| 541 | manifest.dynamic_partition_metadata().snapshot_enabled(); |
| 542 | |
| 543 | if (manifest.partial_update()) { |
| 544 | // Partial updates requires DAP. On partial updates that does not involve |
| 545 | // dynamic partitions, groups() can be empty, so also assume |
| 546 | // is_target_dynamic in this case. This assumption should be safe because we |
| 547 | // also check target_supports_snapshot below, which presumably also implies |
| 548 | // target build supports dynamic partition. |
| 549 | if (!is_target_dynamic) { |
| 550 | LOG(INFO) << "Assuming target build supports dynamic partitions for " |
| 551 | "partial updates."; |
| 552 | is_target_dynamic = true; |
| 553 | } |
| 554 | |
| 555 | // Partial updates requires Virtual A/B. Double check that both current |
| 556 | // build and target build supports Virtual A/B. |
| 557 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 558 | LOG(ERROR) << "Partial update cannot be applied on a device that does " |
| 559 | "not support snapshots."; |
| 560 | return false; |
| 561 | } |
| 562 | if (!target_supports_snapshot) { |
| 563 | LOG(ERROR) << "Cannot apply partial update to a build that does not " |
| 564 | "support snapshots."; |
| 565 | return false; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | // Store the flags. |
| 570 | is_target_dynamic_ = is_target_dynamic; |
| 571 | // If !is_target_dynamic_, leave target_supports_snapshot_ unset because |
| 572 | // snapshots would not work without dynamic partition. |
| 573 | if (is_target_dynamic_) { |
| 574 | target_supports_snapshot_ = target_supports_snapshot; |
| 575 | } |
| 576 | return true; |
| 577 | } |
| 578 | |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 579 | namespace { |
| 580 | // Try our best to erase AVB footer. |
| 581 | class AvbFooterEraser { |
| 582 | public: |
| 583 | explicit AvbFooterEraser(const std::string& path) : path_(path) {} |
| 584 | bool Erase() { |
| 585 | // Try to mark the block device read-only. Ignore any |
| 586 | // failure since this won't work when passing regular files. |
| 587 | ignore_result(utils::SetBlockDeviceReadOnly(path_, false /* readonly */)); |
| 588 | |
| 589 | fd_.reset(new EintrSafeFileDescriptor()); |
| 590 | int flags = O_WRONLY | O_TRUNC | O_CLOEXEC | O_SYNC; |
| 591 | TEST_AND_RETURN_FALSE(fd_->Open(path_.c_str(), flags)); |
| 592 | |
| 593 | // Need to write end-AVB_FOOTER_SIZE to end. |
| 594 | static_assert(AVB_FOOTER_SIZE > 0); |
| 595 | off64_t offset = fd_->Seek(-AVB_FOOTER_SIZE, SEEK_END); |
| 596 | TEST_AND_RETURN_FALSE_ERRNO(offset >= 0); |
| 597 | uint64_t write_size = AVB_FOOTER_SIZE; |
| 598 | LOG(INFO) << "Zeroing " << path_ << " @ [" << offset << ", " |
| 599 | << (offset + write_size) << "] (" << write_size << " bytes)"; |
| 600 | brillo::Blob zeros(write_size); |
| 601 | TEST_AND_RETURN_FALSE(utils::WriteAll(fd_, zeros.data(), zeros.size())); |
| 602 | return true; |
| 603 | } |
| 604 | ~AvbFooterEraser() { |
| 605 | TEST_AND_RETURN(fd_ != nullptr && fd_->IsOpen()); |
| 606 | if (!fd_->Close()) { |
| 607 | LOG(WARNING) << "Failed to close fd for " << path_; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | private: |
| 612 | std::string path_; |
| 613 | FileDescriptorPtr fd_; |
| 614 | }; |
| 615 | |
| 616 | } // namespace |
| 617 | |
| 618 | std::optional<bool> |
| 619 | DynamicPartitionControlAndroid::IsAvbEnabledOnSystemOther() { |
| 620 | auto prefix = GetProperty(kPostinstallFstabPrefix, ""); |
| 621 | if (prefix.empty()) { |
| 622 | LOG(WARNING) << "Cannot get " << kPostinstallFstabPrefix; |
| 623 | return std::nullopt; |
| 624 | } |
| 625 | auto path = base::FilePath(prefix).Append("etc/fstab.postinstall").value(); |
| 626 | return IsAvbEnabledInFstab(path); |
| 627 | } |
| 628 | |
| 629 | std::optional<bool> DynamicPartitionControlAndroid::IsAvbEnabledInFstab( |
| 630 | const std::string& path) { |
| 631 | Fstab fstab; |
| 632 | if (!ReadFstabFromFile(path, &fstab)) { |
Yifan Hong | 93cde30 | 2020-04-27 12:59:29 -0700 | [diff] [blame] | 633 | PLOG(WARNING) << "Cannot read fstab from " << path; |
| 634 | if (errno == ENOENT) { |
| 635 | return false; |
| 636 | } |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 637 | return std::nullopt; |
| 638 | } |
| 639 | for (const auto& entry : fstab) { |
| 640 | if (!entry.avb_keys.empty()) { |
| 641 | return true; |
| 642 | } |
| 643 | } |
| 644 | return false; |
| 645 | } |
| 646 | |
| 647 | bool DynamicPartitionControlAndroid::GetSystemOtherPath( |
| 648 | uint32_t source_slot, |
| 649 | uint32_t target_slot, |
| 650 | const std::string& partition_name_suffix, |
| 651 | std::string* path, |
| 652 | bool* should_unmap) { |
| 653 | path->clear(); |
| 654 | *should_unmap = false; |
| 655 | |
P.Adarsh Reddy | 13e4195d | 2020-06-08 23:17:36 +0530 | [diff] [blame] | 656 | // Check that AVB is enabled on system_other before erasing. |
| 657 | auto has_avb = IsAvbEnabledOnSystemOther(); |
| 658 | TEST_AND_RETURN_FALSE(has_avb.has_value()); |
| 659 | if (!has_avb.value()) { |
| 660 | LOG(INFO) << "AVB is not enabled on system_other. Skip erasing."; |
| 661 | return true; |
| 662 | } |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 663 | |
P.Adarsh Reddy | 13e4195d | 2020-06-08 23:17:36 +0530 | [diff] [blame] | 664 | if (!IsRecovery()) { |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 665 | // Found unexpected avb_keys for system_other on devices retrofitting |
| 666 | // dynamic partitions. Previous crash in update_engine may leave logical |
| 667 | // partitions mapped on physical system_other partition. It is difficult to |
| 668 | // handle these cases. Just fail. |
| 669 | if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) { |
| 670 | LOG(ERROR) << "Cannot erase AVB footer on system_other on devices with " |
| 671 | << "retrofit dynamic partitions. They should not have AVB " |
| 672 | << "enabled on system_other."; |
| 673 | return false; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | std::string device_dir_str; |
| 678 | TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str)); |
| 679 | base::FilePath device_dir(device_dir_str); |
| 680 | |
| 681 | // On devices without dynamic partition, search for static partitions. |
| 682 | if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) { |
| 683 | *path = device_dir.Append(partition_name_suffix).value(); |
| 684 | TEST_AND_RETURN_FALSE(DeviceExists(*path)); |
| 685 | return true; |
| 686 | } |
| 687 | |
| 688 | auto source_super_device = |
| 689 | device_dir.Append(GetSuperPartitionName(source_slot)).value(); |
| 690 | |
| 691 | auto builder = LoadMetadataBuilder(source_super_device, source_slot); |
| 692 | if (builder == nullptr) { |
| 693 | if (IsRecovery()) { |
| 694 | // It might be corrupted for some reason. It should still be able to |
| 695 | // sideload. |
| 696 | LOG(WARNING) << "Super partition metadata cannot be read from the source " |
| 697 | << "slot, skip erasing."; |
| 698 | return true; |
| 699 | } else { |
| 700 | // Device has booted into Android mode, indicating that the super |
| 701 | // partition metadata should be there. |
| 702 | LOG(ERROR) << "Super partition metadata cannot be read from the source " |
| 703 | << "slot. This is unexpected on devices with dynamic " |
| 704 | << "partitions enabled."; |
| 705 | return false; |
| 706 | } |
| 707 | } |
| 708 | auto p = builder->FindPartition(partition_name_suffix); |
| 709 | if (p == nullptr) { |
| 710 | // If the source slot is flashed without system_other, it does not exist |
| 711 | // in super partition metadata at source slot. It is safe to skip it. |
| 712 | LOG(INFO) << "Can't find " << partition_name_suffix |
| 713 | << " in metadata source slot, skip erasing."; |
| 714 | return true; |
| 715 | } |
| 716 | // System_other created by flashing tools should be erased. |
| 717 | // If partition is created by update_engine (via NewForUpdate), it is a |
| 718 | // left-over partition from the previous update and does not contain |
| 719 | // system_other, hence there is no need to erase. |
| 720 | // Note the reverse is not necessary true. If the flag is not set, we don't |
| 721 | // know if the partition is created by update_engine or by flashing tools |
| 722 | // because older versions of super partition metadata does not contain this |
| 723 | // flag. It is okay to erase the AVB footer anyways. |
| 724 | if (p->attributes() & LP_PARTITION_ATTR_UPDATED) { |
| 725 | LOG(INFO) << partition_name_suffix |
| 726 | << " does not contain system_other, skip erasing."; |
| 727 | return true; |
| 728 | } |
| 729 | |
Yifan Hong | 64331b3 | 2020-05-13 16:50:40 -0700 | [diff] [blame] | 730 | if (p->size() < AVB_FOOTER_SIZE) { |
| 731 | LOG(INFO) << partition_name_suffix << " has length " << p->size() |
| 732 | << "( < AVB_FOOTER_SIZE " << AVB_FOOTER_SIZE |
| 733 | << "), skip erasing."; |
| 734 | return true; |
| 735 | } |
| 736 | |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 737 | // Delete any pre-existing device with name |partition_name_suffix| and |
| 738 | // also remove it from |mapped_devices_|. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 739 | // In recovery, metadata might not be mounted, and |
| 740 | // UnmapPartitionOnDeviceMapper might fail. However, |
| 741 | // it is unusual that system_other has already been mapped. Hence, just skip. |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 742 | TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix)); |
| 743 | // Use CreateLogicalPartition directly to avoid mapping with existing |
| 744 | // snapshots. |
| 745 | CreateLogicalPartitionParams params = { |
| 746 | .block_device = source_super_device, |
| 747 | .metadata_slot = source_slot, |
| 748 | .partition_name = partition_name_suffix, |
| 749 | .force_writable = true, |
| 750 | .timeout_ms = kMapTimeout, |
| 751 | }; |
| 752 | TEST_AND_RETURN_FALSE(CreateLogicalPartition(params, path)); |
| 753 | *should_unmap = true; |
| 754 | return true; |
| 755 | } |
| 756 | |
| 757 | bool DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter( |
| 758 | uint32_t source_slot, uint32_t target_slot) { |
| 759 | LOG(INFO) << "Erasing AVB footer of system_other partition before update."; |
| 760 | |
| 761 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 762 | const std::string partition_name_suffix = "system" + target_suffix; |
| 763 | |
| 764 | std::string path; |
| 765 | bool should_unmap = false; |
| 766 | |
| 767 | TEST_AND_RETURN_FALSE(GetSystemOtherPath( |
| 768 | source_slot, target_slot, partition_name_suffix, &path, &should_unmap)); |
| 769 | |
| 770 | if (path.empty()) { |
| 771 | return true; |
| 772 | } |
| 773 | |
| 774 | bool ret = AvbFooterEraser(path).Erase(); |
| 775 | |
| 776 | // Delete |partition_name_suffix| from device mapper and from |
| 777 | // |mapped_devices_| again so that it does not interfere with update process. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 778 | // In recovery, metadata might not be mounted, and |
| 779 | // UnmapPartitionOnDeviceMapper might fail. However, DestroyLogicalPartition |
| 780 | // should be called. If DestroyLogicalPartition does fail, it is still okay |
| 781 | // to skip the error here and let Prepare*() fail later. |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 782 | if (should_unmap) { |
| 783 | TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix)); |
| 784 | } |
| 785 | |
| 786 | return ret; |
| 787 | } |
| 788 | |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 789 | bool DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate( |
| 790 | uint32_t source_slot, |
| 791 | uint32_t target_slot, |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 792 | const DeltaArchiveManifest& manifest, |
| 793 | bool delete_source) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 794 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 795 | |
| 796 | // Unmap all the target dynamic partitions because they would become |
| 797 | // inconsistent with the new metadata. |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 798 | for (const auto& group : manifest.dynamic_partition_metadata().groups()) { |
| 799 | for (const auto& partition_name : group.partition_names()) { |
| 800 | if (!UnmapPartitionOnDeviceMapper(partition_name + target_suffix)) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 801 | return false; |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | std::string device_dir_str; |
| 807 | if (!GetDeviceDir(&device_dir_str)) { |
| 808 | return false; |
| 809 | } |
| 810 | base::FilePath device_dir(device_dir_str); |
| 811 | auto source_device = |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 812 | device_dir.Append(GetSuperPartitionName(source_slot)).value(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 813 | |
| 814 | auto builder = LoadMetadataBuilder(source_device, source_slot, target_slot); |
| 815 | if (builder == nullptr) { |
| 816 | LOG(ERROR) << "No metadata at " |
| 817 | << BootControlInterface::SlotName(source_slot); |
| 818 | return false; |
| 819 | } |
| 820 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 821 | if (delete_source) { |
| 822 | TEST_AND_RETURN_FALSE( |
| 823 | DeleteSourcePartitions(builder.get(), source_slot, manifest)); |
| 824 | } |
| 825 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 826 | if (!UpdatePartitionMetadata(builder.get(), target_slot, manifest)) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 827 | return false; |
| 828 | } |
| 829 | |
| 830 | auto target_device = |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 831 | device_dir.Append(GetSuperPartitionName(target_slot)).value(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 832 | return StoreMetadata(target_device, builder.get(), target_slot); |
| 833 | } |
| 834 | |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 835 | bool DynamicPartitionControlAndroid::PrepareSnapshotPartitionsForUpdate( |
| 836 | uint32_t source_slot, |
| 837 | uint32_t target_slot, |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 838 | const DeltaArchiveManifest& manifest, |
| 839 | uint64_t* required_size) { |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 840 | TEST_AND_RETURN_FALSE(ExpectMetadataMounted()); |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 841 | if (!snapshot_->BeginUpdate()) { |
| 842 | LOG(ERROR) << "Cannot begin new update."; |
| 843 | return false; |
| 844 | } |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 845 | auto ret = snapshot_->CreateUpdateSnapshots(manifest); |
| 846 | if (!ret) { |
| 847 | LOG(ERROR) << "Cannot create update snapshots: " << ret.string(); |
| 848 | if (required_size != nullptr && |
Yifan Hong | 0850bca | 2020-01-16 15:14:07 -0800 | [diff] [blame] | 849 | ret.error_code() == Return::ErrorCode::NO_SPACE) { |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 850 | *required_size = ret.required_size(); |
| 851 | } |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 852 | return false; |
| 853 | } |
| 854 | return true; |
| 855 | } |
| 856 | |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 857 | std::string DynamicPartitionControlAndroid::GetSuperPartitionName( |
| 858 | uint32_t slot) { |
| 859 | return fs_mgr_get_super_partition_name(slot); |
| 860 | } |
| 861 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 862 | bool DynamicPartitionControlAndroid::UpdatePartitionMetadata( |
| 863 | MetadataBuilder* builder, |
| 864 | uint32_t target_slot, |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 865 | const DeltaArchiveManifest& manifest) { |
Yifan Hong | 8d6df9a | 2020-08-13 13:59:54 -0700 | [diff] [blame] | 866 | // Check preconditions. |
Kelvin Zhang | 1c21eb8 | 2021-03-10 13:39:56 -0500 | [diff] [blame] | 867 | LOG_IF(WARNING, !GetVirtualAbFeatureFlag().IsEnabled() || IsRecovery()) |
Yifan Hong | 8d6df9a | 2020-08-13 13:59:54 -0700 | [diff] [blame] | 868 | << "UpdatePartitionMetadata is called on a Virtual A/B device " |
| 869 | "but source partitions is not deleted. This is not allowed."; |
| 870 | |
Yifan Hong | a4e7da3 | 2019-09-30 18:25:03 -0700 | [diff] [blame] | 871 | // If applying downgrade from Virtual A/B to non-Virtual A/B, the left-over |
| 872 | // COW group needs to be deleted to ensure there are enough space to create |
| 873 | // target partitions. |
| 874 | builder->RemoveGroupAndPartitions(android::snapshot::kCowGroupName); |
| 875 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 876 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 877 | DeleteGroupsWithSuffix(builder, target_suffix); |
| 878 | |
| 879 | uint64_t total_size = 0; |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 880 | for (const auto& group : manifest.dynamic_partition_metadata().groups()) { |
| 881 | total_size += group.size(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | std::string expr; |
| 885 | uint64_t allocatable_space = builder->AllocatableSpace(); |
Yifan Hong | 8d6df9a | 2020-08-13 13:59:54 -0700 | [diff] [blame] | 886 | // On device retrofitting dynamic partitions, allocatable_space = super. |
| 887 | // On device launching dynamic partitions w/o VAB, |
| 888 | // allocatable_space = super / 2. |
| 889 | // On device launching dynamic partitions with VAB, allocatable_space = super. |
| 890 | if (!GetDynamicPartitionsFeatureFlag().IsRetrofit() && |
| 891 | !GetVirtualAbFeatureFlag().IsEnabled()) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 892 | allocatable_space /= 2; |
| 893 | expr = "half of "; |
| 894 | } |
| 895 | if (total_size > allocatable_space) { |
| 896 | LOG(ERROR) << "The maximum size of all groups with suffix " << target_suffix |
| 897 | << " (" << total_size << ") has exceeded " << expr |
| 898 | << "allocatable space for dynamic partitions " |
| 899 | << allocatable_space << "."; |
| 900 | return false; |
| 901 | } |
| 902 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 903 | // name of partition(e.g. "system") -> size in bytes |
| 904 | std::map<std::string, uint64_t> partition_sizes; |
| 905 | for (const auto& partition : manifest.partitions()) { |
| 906 | partition_sizes.emplace(partition.partition_name(), |
| 907 | partition.new_partition_info().size()); |
| 908 | } |
| 909 | |
| 910 | for (const auto& group : manifest.dynamic_partition_metadata().groups()) { |
| 911 | auto group_name_suffix = group.name() + target_suffix; |
| 912 | if (!builder->AddGroup(group_name_suffix, group.size())) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 913 | LOG(ERROR) << "Cannot add group " << group_name_suffix << " with size " |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 914 | << group.size(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 915 | return false; |
| 916 | } |
| 917 | LOG(INFO) << "Added group " << group_name_suffix << " with size " |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 918 | << group.size(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 919 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 920 | for (const auto& partition_name : group.partition_names()) { |
| 921 | auto partition_sizes_it = partition_sizes.find(partition_name); |
| 922 | if (partition_sizes_it == partition_sizes.end()) { |
| 923 | // TODO(tbao): Support auto-filling partition info for framework-only |
| 924 | // OTA. |
| 925 | LOG(ERROR) << "dynamic_partition_metadata contains partition " |
| 926 | << partition_name << " but it is not part of the manifest. " |
| 927 | << "This is not supported."; |
| 928 | return false; |
| 929 | } |
| 930 | uint64_t partition_size = partition_sizes_it->second; |
| 931 | |
| 932 | auto partition_name_suffix = partition_name + target_suffix; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 933 | Partition* p = builder->AddPartition( |
| 934 | partition_name_suffix, group_name_suffix, LP_PARTITION_ATTR_READONLY); |
| 935 | if (!p) { |
| 936 | LOG(ERROR) << "Cannot add partition " << partition_name_suffix |
| 937 | << " to group " << group_name_suffix; |
| 938 | return false; |
| 939 | } |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 940 | if (!builder->ResizePartition(p, partition_size)) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 941 | LOG(ERROR) << "Cannot resize partition " << partition_name_suffix |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 942 | << " to size " << partition_size << ". Not enough space?"; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 943 | return false; |
| 944 | } |
David Anderson | 0e1c7fd | 2021-03-08 19:01:59 -0800 | [diff] [blame] | 945 | if (p->size() < partition_size) { |
| 946 | LOG(ERROR) << "Partition " << partition_name_suffix |
| 947 | << " was expected to have size " << partition_size |
| 948 | << ", but instead has size " << p->size(); |
| 949 | return false; |
| 950 | } |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 951 | LOG(INFO) << "Added partition " << partition_name_suffix << " to group " |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 952 | << group_name_suffix << " with size " << partition_size; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | return true; |
| 957 | } |
| 958 | |
Yifan Hong | 7b3910a | 2020-03-24 17:47:32 -0700 | [diff] [blame] | 959 | bool DynamicPartitionControlAndroid::FinishUpdate(bool powerwash_required) { |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 960 | if (ExpectMetadataMounted()) { |
| 961 | if (snapshot_->GetUpdateState() == UpdateState::Initiated) { |
| 962 | LOG(INFO) << "Snapshot writes are done."; |
| 963 | return snapshot_->FinishedSnapshotWrites(powerwash_required); |
| 964 | } |
| 965 | } else { |
| 966 | LOG(INFO) << "Skip FinishedSnapshotWrites() because /metadata is not " |
| 967 | << "mounted"; |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 968 | } |
| 969 | return true; |
Yifan Hong | a33bca4 | 2019-09-03 20:29:45 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 972 | bool DynamicPartitionControlAndroid::GetPartitionDevice( |
| 973 | const std::string& partition_name, |
| 974 | uint32_t slot, |
| 975 | uint32_t current_slot, |
Tianjie | 51a5a39 | 2020-06-03 14:39:32 -0700 | [diff] [blame] | 976 | bool not_in_payload, |
| 977 | std::string* device, |
| 978 | bool* is_dynamic) { |
Kelvin Zhang | 66a9ebb | 2021-01-25 13:35:10 -0500 | [diff] [blame] | 979 | auto partition_dev = |
| 980 | GetPartitionDevice(partition_name, slot, current_slot, not_in_payload); |
Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 981 | if (!partition_dev.has_value()) { |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 982 | return false; |
| 983 | } |
Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 984 | if (device) { |
| 985 | *device = std::move(partition_dev->rw_device_path); |
| 986 | } |
| 987 | if (is_dynamic) { |
| 988 | *is_dynamic = partition_dev->is_dynamic; |
| 989 | } |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 990 | return true; |
| 991 | } |
| 992 | |
Tianjie | 51a5a39 | 2020-06-03 14:39:32 -0700 | [diff] [blame] | 993 | bool DynamicPartitionControlAndroid::GetPartitionDevice( |
| 994 | const std::string& partition_name, |
| 995 | uint32_t slot, |
| 996 | uint32_t current_slot, |
| 997 | std::string* device) { |
| 998 | return GetPartitionDevice( |
| 999 | partition_name, slot, current_slot, false, device, nullptr); |
| 1000 | } |
| 1001 | |
Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 1002 | static std::string GetStaticDevicePath( |
| 1003 | const base::FilePath& device_dir, |
| 1004 | const std::string& partition_name_suffixed) { |
| 1005 | base::FilePath path = device_dir.Append(partition_name_suffixed); |
| 1006 | return path.value(); |
| 1007 | } |
| 1008 | |
| 1009 | std::optional<PartitionDevice> |
| 1010 | DynamicPartitionControlAndroid::GetPartitionDevice( |
| 1011 | const std::string& partition_name, |
| 1012 | uint32_t slot, |
| 1013 | uint32_t current_slot, |
| 1014 | bool not_in_payload) { |
| 1015 | std::string device_dir_str; |
| 1016 | if (!GetDeviceDir(&device_dir_str)) { |
| 1017 | LOG(ERROR) << "Failed to GetDeviceDir()"; |
| 1018 | return {}; |
| 1019 | } |
| 1020 | const base::FilePath device_dir(device_dir_str); |
| 1021 | // When VABC is enabled, we can't get device path for dynamic partitions in |
| 1022 | // target slot. |
| 1023 | const auto& partition_name_suffix = |
| 1024 | partition_name + SlotSuffixForSlotNumber(slot); |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1025 | if (UpdateUsesSnapshotCompression() && slot != current_slot && |
| 1026 | IsDynamicPartition(partition_name, slot)) { |
Kelvin Zhang | 91ad662 | 2021-03-01 13:46:17 -0500 | [diff] [blame] | 1027 | return { |
| 1028 | {.mountable_device_path = base::FilePath{std::string{VABC_DEVICE_DIR}} |
| 1029 | .Append(partition_name_suffix) |
| 1030 | .value(), |
| 1031 | .is_dynamic = true}}; |
Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | // When looking up target partition devices, treat them as static if the |
| 1035 | // current payload doesn't encode them as dynamic partitions. This may happen |
| 1036 | // when applying a retrofit update on top of a dynamic-partitions-enabled |
| 1037 | // build. |
| 1038 | std::string device; |
| 1039 | if (GetDynamicPartitionsFeatureFlag().IsEnabled() && |
| 1040 | (slot == current_slot || is_target_dynamic_)) { |
| 1041 | switch (GetDynamicPartitionDevice(device_dir, |
| 1042 | partition_name_suffix, |
| 1043 | slot, |
| 1044 | current_slot, |
| 1045 | not_in_payload, |
| 1046 | &device)) { |
| 1047 | case DynamicPartitionDeviceStatus::SUCCESS: |
| 1048 | return {{.rw_device_path = device, |
| 1049 | .mountable_device_path = device, |
| 1050 | .is_dynamic = true}}; |
| 1051 | |
| 1052 | case DynamicPartitionDeviceStatus::TRY_STATIC: |
| 1053 | break; |
| 1054 | case DynamicPartitionDeviceStatus::ERROR: // fallthrough |
| 1055 | default: |
| 1056 | return {}; |
| 1057 | } |
| 1058 | } |
| 1059 | // Try static partitions. |
| 1060 | auto static_path = GetStaticDevicePath(device_dir, partition_name_suffix); |
| 1061 | if (!DeviceExists(static_path)) { |
| 1062 | LOG(ERROR) << "Device file " << static_path << " does not exist."; |
| 1063 | return {}; |
| 1064 | } |
| 1065 | |
| 1066 | return {{.rw_device_path = static_path, |
| 1067 | .mountable_device_path = static_path, |
| 1068 | .is_dynamic = false}}; |
| 1069 | } |
| 1070 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 1071 | bool DynamicPartitionControlAndroid::IsSuperBlockDevice( |
| 1072 | const base::FilePath& device_dir, |
| 1073 | uint32_t current_slot, |
| 1074 | const std::string& partition_name_suffix) { |
| 1075 | std::string source_device = |
| 1076 | device_dir.Append(GetSuperPartitionName(current_slot)).value(); |
| 1077 | auto source_metadata = LoadMetadataBuilder(source_device, current_slot); |
| 1078 | return source_metadata->HasBlockDevice(partition_name_suffix); |
| 1079 | } |
| 1080 | |
| 1081 | DynamicPartitionControlAndroid::DynamicPartitionDeviceStatus |
| 1082 | DynamicPartitionControlAndroid::GetDynamicPartitionDevice( |
| 1083 | const base::FilePath& device_dir, |
| 1084 | const std::string& partition_name_suffix, |
| 1085 | uint32_t slot, |
| 1086 | uint32_t current_slot, |
Tianjie | 51a5a39 | 2020-06-03 14:39:32 -0700 | [diff] [blame] | 1087 | bool not_in_payload, |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 1088 | std::string* device) { |
| 1089 | std::string super_device = |
| 1090 | device_dir.Append(GetSuperPartitionName(slot)).value(); |
| 1091 | |
| 1092 | auto builder = LoadMetadataBuilder(super_device, slot); |
| 1093 | if (builder == nullptr) { |
| 1094 | LOG(ERROR) << "No metadata in slot " |
| 1095 | << BootControlInterface::SlotName(slot); |
| 1096 | return DynamicPartitionDeviceStatus::ERROR; |
| 1097 | } |
| 1098 | if (builder->FindPartition(partition_name_suffix) == nullptr) { |
| 1099 | LOG(INFO) << partition_name_suffix |
| 1100 | << " is not in super partition metadata."; |
| 1101 | |
| 1102 | if (IsSuperBlockDevice(device_dir, current_slot, partition_name_suffix)) { |
| 1103 | LOG(ERROR) << "The static partition " << partition_name_suffix |
| 1104 | << " is a block device for current metadata." |
| 1105 | << "It cannot be used as a logical partition."; |
| 1106 | return DynamicPartitionDeviceStatus::ERROR; |
| 1107 | } |
| 1108 | |
| 1109 | return DynamicPartitionDeviceStatus::TRY_STATIC; |
| 1110 | } |
| 1111 | |
| 1112 | if (slot == current_slot) { |
| 1113 | if (GetState(partition_name_suffix) != DmDeviceState::ACTIVE) { |
| 1114 | LOG(WARNING) << partition_name_suffix << " is at current slot but it is " |
| 1115 | << "not mapped. Now try to map it."; |
| 1116 | } else { |
| 1117 | if (GetDmDevicePathByName(partition_name_suffix, device)) { |
| 1118 | LOG(INFO) << partition_name_suffix |
| 1119 | << " is mapped on device mapper: " << *device; |
| 1120 | return DynamicPartitionDeviceStatus::SUCCESS; |
| 1121 | } |
| 1122 | LOG(ERROR) << partition_name_suffix << "is mapped but path is unknown."; |
| 1123 | return DynamicPartitionDeviceStatus::ERROR; |
| 1124 | } |
| 1125 | } |
| 1126 | |
Tianjie | 51a5a39 | 2020-06-03 14:39:32 -0700 | [diff] [blame] | 1127 | bool force_writable = (slot != current_slot) && !not_in_payload; |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 1128 | if (MapPartitionOnDeviceMapper( |
| 1129 | super_device, partition_name_suffix, slot, force_writable, device)) { |
| 1130 | return DynamicPartitionDeviceStatus::SUCCESS; |
| 1131 | } |
| 1132 | return DynamicPartitionDeviceStatus::ERROR; |
| 1133 | } |
| 1134 | |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 1135 | void DynamicPartitionControlAndroid::set_fake_mapped_devices( |
| 1136 | const std::set<std::string>& fake) { |
| 1137 | mapped_devices_ = fake; |
| 1138 | } |
| 1139 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 1140 | bool DynamicPartitionControlAndroid::IsRecovery() { |
Kelvin Zhang | a22ef55 | 2020-10-12 19:03:52 -0400 | [diff] [blame] | 1141 | return constants::kIsRecovery; |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | static bool IsIncrementalUpdate(const DeltaArchiveManifest& manifest) { |
| 1145 | const auto& partitions = manifest.partitions(); |
| 1146 | return std::any_of(partitions.begin(), partitions.end(), [](const auto& p) { |
| 1147 | return p.has_old_partition_info(); |
| 1148 | }); |
| 1149 | } |
| 1150 | |
| 1151 | bool DynamicPartitionControlAndroid::DeleteSourcePartitions( |
| 1152 | MetadataBuilder* builder, |
| 1153 | uint32_t source_slot, |
| 1154 | const DeltaArchiveManifest& manifest) { |
| 1155 | TEST_AND_RETURN_FALSE(IsRecovery()); |
| 1156 | |
| 1157 | if (IsIncrementalUpdate(manifest)) { |
| 1158 | LOG(ERROR) << "Cannot sideload incremental OTA because snapshots cannot " |
| 1159 | << "be created."; |
| 1160 | if (GetVirtualAbFeatureFlag().IsLaunch()) { |
| 1161 | LOG(ERROR) << "Sideloading incremental updates on devices launches " |
| 1162 | << " Virtual A/B is not supported."; |
| 1163 | } |
| 1164 | return false; |
| 1165 | } |
| 1166 | |
| 1167 | LOG(INFO) << "Will overwrite existing partitions. Slot " |
| 1168 | << BootControlInterface::SlotName(source_slot) |
| 1169 | << "may be unbootable until update finishes!"; |
| 1170 | const std::string source_suffix = SlotSuffixForSlotNumber(source_slot); |
| 1171 | DeleteGroupsWithSuffix(builder, source_suffix); |
| 1172 | |
| 1173 | return true; |
| 1174 | } |
| 1175 | |
Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame] | 1176 | std::unique_ptr<AbstractAction> |
| 1177 | DynamicPartitionControlAndroid::GetCleanupPreviousUpdateAction( |
| 1178 | BootControlInterface* boot_control, |
| 1179 | PrefsInterface* prefs, |
| 1180 | CleanupPreviousUpdateActionDelegateInterface* delegate) { |
| 1181 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1182 | return std::make_unique<NoOpAction>(); |
| 1183 | } |
| 1184 | return std::make_unique<CleanupPreviousUpdateAction>( |
| 1185 | prefs, boot_control, snapshot_.get(), delegate); |
| 1186 | } |
| 1187 | |
Yifan Hong | 6a6d0f1 | 2020-03-11 13:20:52 -0700 | [diff] [blame] | 1188 | bool DynamicPartitionControlAndroid::ResetUpdate(PrefsInterface* prefs) { |
| 1189 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1190 | return true; |
| 1191 | } |
| 1192 | |
| 1193 | LOG(INFO) << __func__ << " resetting update state and deleting snapshots."; |
| 1194 | TEST_AND_RETURN_FALSE(prefs != nullptr); |
| 1195 | |
| 1196 | // If the device has already booted into the target slot, |
| 1197 | // ResetUpdateProgress may pass but CancelUpdate fails. |
| 1198 | // This is expected. A scheduled CleanupPreviousUpdateAction should free |
| 1199 | // space when it is done. |
| 1200 | TEST_AND_RETURN_FALSE(DeltaPerformer::ResetUpdateProgress( |
| 1201 | prefs, false /* quick */, false /* skip dynamic partitions metadata */)); |
| 1202 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 1203 | if (ExpectMetadataMounted()) { |
| 1204 | TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate()); |
| 1205 | } else { |
| 1206 | LOG(INFO) << "Skip cancelling update in ResetUpdate because /metadata is " |
| 1207 | << "not mounted"; |
| 1208 | } |
Yifan Hong | 6a6d0f1 | 2020-03-11 13:20:52 -0700 | [diff] [blame] | 1209 | |
| 1210 | return true; |
| 1211 | } |
| 1212 | |
Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 1213 | bool DynamicPartitionControlAndroid::ListDynamicPartitionsForSlot( |
Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 1214 | uint32_t slot, |
| 1215 | uint32_t current_slot, |
| 1216 | std::vector<std::string>* partitions) { |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1217 | CHECK(slot == source_slot_ || target_slot_ != UINT32_MAX) |
| 1218 | << " source slot: " << source_slot_ << " target slot: " << target_slot_ |
| 1219 | << " slot: " << slot |
| 1220 | << " attempting to query dynamic partition metadata for target slot " |
| 1221 | "before PreparePartitionForUpdate() is called. The " |
| 1222 | "metadata in target slot isn't valid until " |
| 1223 | "PreparePartitionForUpdate() is called, contining execution would " |
| 1224 | "likely cause problems."; |
Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 1225 | bool slot_enables_dynamic_partitions = |
| 1226 | GetDynamicPartitionsFeatureFlag().IsEnabled(); |
| 1227 | // Check if the target slot has dynamic partitions, this may happen when |
| 1228 | // applying a retrofit package. |
| 1229 | if (slot != current_slot) { |
| 1230 | slot_enables_dynamic_partitions = |
| 1231 | slot_enables_dynamic_partitions && is_target_dynamic_; |
| 1232 | } |
| 1233 | |
| 1234 | if (!slot_enables_dynamic_partitions) { |
| 1235 | LOG(INFO) << "Dynamic partition is not enabled for slot " << slot; |
| 1236 | return true; |
Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | std::string device_dir_str; |
| 1240 | TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str)); |
| 1241 | base::FilePath device_dir(device_dir_str); |
Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 1242 | auto super_device = device_dir.Append(GetSuperPartitionName(slot)).value(); |
| 1243 | auto builder = LoadMetadataBuilder(super_device, slot); |
Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 1244 | TEST_AND_RETURN_FALSE(builder != nullptr); |
| 1245 | |
| 1246 | std::vector<std::string> result; |
Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 1247 | auto suffix = SlotSuffixForSlotNumber(slot); |
Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 1248 | for (const auto& group : builder->ListGroups()) { |
| 1249 | for (const auto& partition : builder->ListPartitionsInGroup(group)) { |
| 1250 | std::string_view partition_name = partition->name(); |
| 1251 | if (!android::base::ConsumeSuffix(&partition_name, suffix)) { |
| 1252 | continue; |
| 1253 | } |
| 1254 | result.emplace_back(partition_name); |
| 1255 | } |
| 1256 | } |
| 1257 | *partitions = std::move(result); |
| 1258 | return true; |
| 1259 | } |
| 1260 | |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 1261 | bool DynamicPartitionControlAndroid::VerifyExtentsForUntouchedPartitions( |
| 1262 | uint32_t source_slot, |
| 1263 | uint32_t target_slot, |
| 1264 | const std::vector<std::string>& partitions) { |
| 1265 | std::string device_dir_str; |
| 1266 | TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str)); |
| 1267 | base::FilePath device_dir(device_dir_str); |
| 1268 | |
| 1269 | auto source_super_device = |
| 1270 | device_dir.Append(GetSuperPartitionName(source_slot)).value(); |
| 1271 | auto source_builder = LoadMetadataBuilder(source_super_device, source_slot); |
| 1272 | TEST_AND_RETURN_FALSE(source_builder != nullptr); |
| 1273 | |
| 1274 | auto target_super_device = |
| 1275 | device_dir.Append(GetSuperPartitionName(target_slot)).value(); |
| 1276 | auto target_builder = LoadMetadataBuilder(target_super_device, target_slot); |
| 1277 | TEST_AND_RETURN_FALSE(target_builder != nullptr); |
| 1278 | |
| 1279 | return MetadataBuilder::VerifyExtentsAgainstSourceMetadata( |
| 1280 | *source_builder, source_slot, *target_builder, target_slot, partitions); |
| 1281 | } |
| 1282 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 1283 | bool DynamicPartitionControlAndroid::ExpectMetadataMounted() { |
| 1284 | // No need to mount metadata for non-Virtual A/B devices. |
| 1285 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1286 | return false; |
| 1287 | } |
| 1288 | // Intentionally not checking |metadata_device_| in Android mode. |
| 1289 | // /metadata should always be mounted in Android mode. If it isn't, let caller |
| 1290 | // fails when calling into SnapshotManager. |
| 1291 | if (!IsRecovery()) { |
| 1292 | return true; |
| 1293 | } |
| 1294 | // In recovery mode, explicitly check |metadata_device_|. |
| 1295 | return metadata_device_ != nullptr; |
| 1296 | } |
| 1297 | |
| 1298 | bool DynamicPartitionControlAndroid::EnsureMetadataMounted() { |
| 1299 | // No need to mount metadata for non-Virtual A/B devices. |
| 1300 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1301 | return true; |
| 1302 | } |
| 1303 | |
| 1304 | if (metadata_device_ == nullptr) { |
| 1305 | metadata_device_ = snapshot_->EnsureMetadataMounted(); |
| 1306 | } |
| 1307 | return metadata_device_ != nullptr; |
| 1308 | } |
| 1309 | |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 1310 | std::unique_ptr<android::snapshot::ISnapshotWriter> |
| 1311 | DynamicPartitionControlAndroid::OpenCowWriter( |
| 1312 | const std::string& partition_name, |
| 1313 | const std::optional<std::string>& source_path, |
| 1314 | bool is_append) { |
| 1315 | auto suffix = SlotSuffixForSlotNumber(target_slot_); |
| 1316 | |
Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 1317 | auto super_device = GetSuperDevice(); |
| 1318 | if (!super_device.has_value()) { |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 1319 | return nullptr; |
| 1320 | } |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 1321 | CreateLogicalPartitionParams params = { |
Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 1322 | .block_device = super_device->value(), |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 1323 | .metadata_slot = target_slot_, |
| 1324 | .partition_name = partition_name + suffix, |
| 1325 | .force_writable = true, |
Kelvin Zhang | 877ddbe | 2020-11-09 13:37:56 -0500 | [diff] [blame] | 1326 | .timeout_ms = kMapSnapshotTimeout}; |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 1327 | // TODO(zhangkelvin) Open an APPEND mode CowWriter once there's an API to do |
| 1328 | // it. |
| 1329 | return snapshot_->OpenSnapshotWriter(params, std::move(source_path)); |
Kelvin Zhang | 877ddbe | 2020-11-09 13:37:56 -0500 | [diff] [blame] | 1330 | } // namespace chromeos_update_engine |
Kelvin Zhang | 3461852 | 2020-09-28 09:21:02 -0400 | [diff] [blame] | 1331 | |
Kelvin Zhang | c82511c | 2020-11-06 16:01:24 -0500 | [diff] [blame] | 1332 | FileDescriptorPtr DynamicPartitionControlAndroid::OpenCowReader( |
| 1333 | const std::string& unsuffixed_partition_name, |
| 1334 | const std::optional<std::string>& source_path, |
| 1335 | bool is_append) { |
| 1336 | auto cow_writer = |
| 1337 | OpenCowWriter(unsuffixed_partition_name, source_path, is_append); |
| 1338 | if (cow_writer == nullptr) { |
| 1339 | return nullptr; |
| 1340 | } |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 1341 | cow_writer->InitializeAppend(kEndOfInstallLabel); |
Kelvin Zhang | c82511c | 2020-11-06 16:01:24 -0500 | [diff] [blame] | 1342 | return cow_writer->OpenReader(); |
| 1343 | } |
| 1344 | |
Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 1345 | std::optional<base::FilePath> DynamicPartitionControlAndroid::GetSuperDevice() { |
| 1346 | std::string device_dir_str; |
| 1347 | if (!GetDeviceDir(&device_dir_str)) { |
| 1348 | LOG(ERROR) << "Failed to get device dir!"; |
| 1349 | return {}; |
| 1350 | } |
| 1351 | base::FilePath device_dir(device_dir_str); |
| 1352 | auto super_device = device_dir.Append(GetSuperPartitionName(target_slot_)); |
| 1353 | return super_device; |
| 1354 | } |
| 1355 | |
| 1356 | bool DynamicPartitionControlAndroid::MapAllPartitions() { |
Kelvin Zhang | 877ddbe | 2020-11-09 13:37:56 -0500 | [diff] [blame] | 1357 | return snapshot_->MapAllSnapshots(kMapSnapshotTimeout); |
Kelvin Zhang | 9d87d6d | 2020-10-23 17:03:59 -0400 | [diff] [blame] | 1358 | } |
| 1359 | |
Kelvin Zhang | eb9de16 | 2020-11-16 15:47:28 -0500 | [diff] [blame] | 1360 | bool DynamicPartitionControlAndroid::IsDynamicPartition( |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1361 | const std::string& partition_name, uint32_t slot) { |
| 1362 | if (slot >= dynamic_partition_list_.size()) { |
| 1363 | LOG(ERROR) << "Seeing unexpected slot # " << slot << " currently assuming " |
| 1364 | << dynamic_partition_list_.size() << " slots"; |
| 1365 | return false; |
| 1366 | } |
| 1367 | auto& dynamic_partition_list = dynamic_partition_list_[slot]; |
| 1368 | if (dynamic_partition_list.empty() && |
Kelvin Zhang | eb9de16 | 2020-11-16 15:47:28 -0500 | [diff] [blame] | 1369 | GetDynamicPartitionsFeatureFlag().IsEnabled()) { |
Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 1370 | // Use the DAP config of the target slot. |
| 1371 | CHECK(ListDynamicPartitionsForSlot( |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1372 | slot, source_slot_, &dynamic_partition_list)); |
Kelvin Zhang | eb9de16 | 2020-11-16 15:47:28 -0500 | [diff] [blame] | 1373 | } |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1374 | return std::find(dynamic_partition_list.begin(), |
| 1375 | dynamic_partition_list.end(), |
| 1376 | partition_name) != dynamic_partition_list.end(); |
Kelvin Zhang | eb9de16 | 2020-11-16 15:47:28 -0500 | [diff] [blame] | 1377 | } |
Kelvin Zhang | 91d95fa | 2020-11-05 13:52:00 -0500 | [diff] [blame] | 1378 | |
Yifan Hong | b0cbd39 | 2021-02-04 11:11:45 -0800 | [diff] [blame] | 1379 | bool DynamicPartitionControlAndroid::UpdateUsesSnapshotCompression() { |
| 1380 | return snapshot_->UpdateUsesCompression(); |
| 1381 | } |
| 1382 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 1383 | } // namespace chromeos_update_engine |