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