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 | |
| 17 | #include "update_engine/dynamic_partition_control_android.h" |
| 18 | |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 19 | #include <chrono> // NOLINT(build/c++11) - using libsnapshot / liblp API |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 20 | #include <map> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 21 | #include <memory> |
| 22 | #include <set> |
| 23 | #include <string> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 24 | #include <vector> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 25 | |
| 26 | #include <android-base/properties.h> |
| 27 | #include <android-base/strings.h> |
| 28 | #include <base/files/file_util.h> |
| 29 | #include <base/logging.h> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 30 | #include <base/strings/string_util.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 31 | #include <bootloader_message/bootloader_message.h> |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 32 | #include <fs_mgr.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 33 | #include <fs_mgr_dm_linear.h> |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 34 | #include <fs_mgr_overlayfs.h> |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 35 | #include <libavb/libavb.h> |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 36 | #include <libdm/dm.h> |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 37 | #include <libsnapshot/snapshot.h> |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 38 | #include <libsnapshot/snapshot_stub.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 39 | |
Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame] | 40 | #include "update_engine/cleanup_previous_update_action.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 41 | #include "update_engine/common/boot_control_interface.h" |
| 42 | #include "update_engine/common/utils.h" |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 43 | #include "update_engine/dynamic_partition_utils.h" |
Yifan Hong | 6a6d0f1 | 2020-03-11 13:20:52 -0700 | [diff] [blame] | 44 | #include "update_engine/payload_consumer/delta_performer.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 45 | |
| 46 | using android::base::GetBoolProperty; |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 47 | using android::base::GetProperty; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 48 | using android::base::Join; |
| 49 | using android::dm::DeviceMapper; |
| 50 | using android::dm::DmDeviceState; |
| 51 | using android::fs_mgr::CreateLogicalPartition; |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 52 | using android::fs_mgr::CreateLogicalPartitionParams; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 53 | using android::fs_mgr::DestroyLogicalPartition; |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 54 | using android::fs_mgr::Fstab; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 55 | using android::fs_mgr::MetadataBuilder; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 56 | using android::fs_mgr::Partition; |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 57 | using android::fs_mgr::PartitionOpener; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 58 | using android::fs_mgr::SlotSuffixForSlotNumber; |
Yifan Hong | f526156 | 2020-03-10 10:28:10 -0700 | [diff] [blame] | 59 | using android::snapshot::OptimizeSourceCopyOperation; |
Yifan Hong | 0850bca | 2020-01-16 15:14:07 -0800 | [diff] [blame] | 60 | using android::snapshot::Return; |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 61 | using android::snapshot::SnapshotManager; |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 62 | using android::snapshot::SnapshotManagerStub; |
Yifan Hong | 2257ee1 | 2020-01-13 18:33:00 -0800 | [diff] [blame] | 63 | using android::snapshot::UpdateState; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 64 | |
| 65 | namespace chromeos_update_engine { |
| 66 | |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 67 | constexpr char kUseDynamicPartitions[] = "ro.boot.dynamic_partitions"; |
| 68 | constexpr char kRetrfoitDynamicPartitions[] = |
| 69 | "ro.boot.dynamic_partitions_retrofit"; |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 70 | constexpr char kVirtualAbEnabled[] = "ro.virtual_ab.enabled"; |
| 71 | constexpr char kVirtualAbRetrofit[] = "ro.virtual_ab.retrofit"; |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 72 | constexpr char kPostinstallFstabPrefix[] = "ro.postinstall.fstab.prefix"; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 73 | // Map timeout for dynamic partitions. |
| 74 | constexpr std::chrono::milliseconds kMapTimeout{1000}; |
| 75 | // Map timeout for dynamic partitions with snapshots. Since several devices |
| 76 | // needs to be mapped, this timeout is longer than |kMapTimeout|. |
| 77 | constexpr std::chrono::milliseconds kMapSnapshotTimeout{5000}; |
| 78 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 79 | #ifdef __ANDROID_RECOVERY__ |
| 80 | constexpr bool kIsRecovery = true; |
| 81 | #else |
| 82 | constexpr bool kIsRecovery = false; |
| 83 | #endif |
| 84 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 85 | DynamicPartitionControlAndroid::~DynamicPartitionControlAndroid() { |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 86 | Cleanup(); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 89 | static FeatureFlag GetFeatureFlag(const char* enable_prop, |
| 90 | const char* retrofit_prop) { |
| 91 | bool retrofit = GetBoolProperty(retrofit_prop, false); |
| 92 | bool enabled = GetBoolProperty(enable_prop, false); |
| 93 | if (retrofit && !enabled) { |
| 94 | LOG(ERROR) << retrofit_prop << " is true but " << enable_prop |
| 95 | << " is not. These sysprops are inconsistent. Assume that " |
| 96 | << enable_prop << " is true from now on."; |
| 97 | } |
| 98 | if (retrofit) { |
| 99 | return FeatureFlag(FeatureFlag::Value::RETROFIT); |
| 100 | } |
| 101 | if (enabled) { |
| 102 | return FeatureFlag(FeatureFlag::Value::LAUNCH); |
| 103 | } |
| 104 | return FeatureFlag(FeatureFlag::Value::NONE); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 107 | DynamicPartitionControlAndroid::DynamicPartitionControlAndroid() |
| 108 | : dynamic_partitions_( |
| 109 | GetFeatureFlag(kUseDynamicPartitions, kRetrfoitDynamicPartitions)), |
| 110 | virtual_ab_(GetFeatureFlag(kVirtualAbEnabled, kVirtualAbRetrofit)) { |
| 111 | if (GetVirtualAbFeatureFlag().IsEnabled()) { |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 112 | snapshot_ = SnapshotManager::New(); |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 113 | } else { |
| 114 | snapshot_ = SnapshotManagerStub::New(); |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 115 | } |
Yifan Hong | f9cb449 | 2020-04-15 13:00:20 -0700 | [diff] [blame] | 116 | CHECK(snapshot_ != nullptr) << "Cannot initialize SnapshotManager."; |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 119 | FeatureFlag DynamicPartitionControlAndroid::GetDynamicPartitionsFeatureFlag() { |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 120 | return dynamic_partitions_; |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 123 | FeatureFlag DynamicPartitionControlAndroid::GetVirtualAbFeatureFlag() { |
Yifan Hong | b38e1af | 2019-10-17 14:59:22 -0700 | [diff] [blame] | 124 | return virtual_ab_; |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Yifan Hong | f526156 | 2020-03-10 10:28:10 -0700 | [diff] [blame] | 127 | bool DynamicPartitionControlAndroid::OptimizeOperation( |
| 128 | const std::string& partition_name, |
| 129 | const InstallOperation& operation, |
| 130 | InstallOperation* optimized) { |
Alessio Balsini | 2a3b4a2 | 2019-11-25 16:46:51 +0000 | [diff] [blame] | 131 | switch (operation.type()) { |
| 132 | case InstallOperation::SOURCE_COPY: |
| 133 | return target_supports_snapshot_ && |
| 134 | GetVirtualAbFeatureFlag().IsEnabled() && |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 135 | mapped_devices_.count(partition_name + |
| 136 | SlotSuffixForSlotNumber(target_slot_)) > 0 && |
Yifan Hong | f526156 | 2020-03-10 10:28:10 -0700 | [diff] [blame] | 137 | OptimizeSourceCopyOperation(operation, optimized); |
Alessio Balsini | 2a3b4a2 | 2019-11-25 16:46:51 +0000 | [diff] [blame] | 138 | break; |
| 139 | default: |
| 140 | break; |
| 141 | } |
Alessio Balsini | 14980e2 | 2019-11-26 11:46:06 +0000 | [diff] [blame] | 142 | return false; |
| 143 | } |
| 144 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 145 | bool DynamicPartitionControlAndroid::MapPartitionInternal( |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 146 | const std::string& super_device, |
| 147 | const std::string& target_partition_name, |
| 148 | uint32_t slot, |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 149 | bool force_writable, |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 150 | std::string* path) { |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 151 | CreateLogicalPartitionParams params = { |
| 152 | .block_device = super_device, |
| 153 | .metadata_slot = slot, |
| 154 | .partition_name = target_partition_name, |
| 155 | .force_writable = force_writable, |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 156 | }; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 157 | bool success = false; |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 158 | if (GetVirtualAbFeatureFlag().IsEnabled() && target_supports_snapshot_ && |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 159 | force_writable && ExpectMetadataMounted()) { |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 160 | // Only target partitions are mapped with force_writable. On Virtual |
| 161 | // A/B devices, target partitions may overlap with source partitions, so |
| 162 | // they must be mapped with snapshot. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 163 | // One exception is when /metadata is not mounted. Fallback to |
| 164 | // CreateLogicalPartition as snapshots are not created in the first place. |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 165 | params.timeout_ms = kMapSnapshotTimeout; |
| 166 | success = snapshot_->MapUpdateSnapshot(params, path); |
| 167 | } else { |
| 168 | params.timeout_ms = kMapTimeout; |
| 169 | success = CreateLogicalPartition(params, path); |
| 170 | } |
David Anderson | bb90dfb | 2019-08-13 14:14:56 -0700 | [diff] [blame] | 171 | |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 172 | if (!success) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 173 | LOG(ERROR) << "Cannot map " << target_partition_name << " in " |
| 174 | << super_device << " on device mapper."; |
| 175 | return false; |
| 176 | } |
| 177 | LOG(INFO) << "Succesfully mapped " << target_partition_name |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 178 | << " to device mapper (force_writable = " << force_writable |
| 179 | << "); device path at " << *path; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 180 | mapped_devices_.insert(target_partition_name); |
| 181 | return true; |
| 182 | } |
| 183 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 184 | bool DynamicPartitionControlAndroid::MapPartitionOnDeviceMapper( |
| 185 | const std::string& super_device, |
| 186 | const std::string& target_partition_name, |
| 187 | uint32_t slot, |
| 188 | bool force_writable, |
| 189 | std::string* path) { |
| 190 | DmDeviceState state = GetState(target_partition_name); |
| 191 | if (state == DmDeviceState::ACTIVE) { |
| 192 | if (mapped_devices_.find(target_partition_name) != mapped_devices_.end()) { |
| 193 | if (GetDmDevicePathByName(target_partition_name, path)) { |
| 194 | LOG(INFO) << target_partition_name |
| 195 | << " is mapped on device mapper: " << *path; |
| 196 | return true; |
| 197 | } |
| 198 | LOG(ERROR) << target_partition_name << " is mapped but path is unknown."; |
| 199 | return false; |
| 200 | } |
| 201 | // If target_partition_name is not in mapped_devices_ but state is ACTIVE, |
| 202 | // the device might be mapped incorrectly before. Attempt to unmap it. |
| 203 | // Note that for source partitions, if GetState() == ACTIVE, callers (e.g. |
| 204 | // BootControlAndroid) should not call MapPartitionOnDeviceMapper, but |
| 205 | // should directly call GetDmDevicePathByName. |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 206 | if (!UnmapPartitionOnDeviceMapper(target_partition_name)) { |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 207 | LOG(ERROR) << target_partition_name |
| 208 | << " is mapped before the update, and it cannot be unmapped."; |
| 209 | return false; |
| 210 | } |
| 211 | state = GetState(target_partition_name); |
| 212 | if (state != DmDeviceState::INVALID) { |
| 213 | LOG(ERROR) << target_partition_name << " is unmapped but state is " |
| 214 | << static_cast<std::underlying_type_t<DmDeviceState>>(state); |
| 215 | return false; |
| 216 | } |
| 217 | } |
| 218 | if (state == DmDeviceState::INVALID) { |
| 219 | return MapPartitionInternal( |
| 220 | super_device, target_partition_name, slot, force_writable, path); |
| 221 | } |
| 222 | |
| 223 | LOG(ERROR) << target_partition_name |
| 224 | << " is mapped on device mapper but state is unknown: " |
| 225 | << static_cast<std::underlying_type_t<DmDeviceState>>(state); |
| 226 | return false; |
| 227 | } |
| 228 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 229 | bool DynamicPartitionControlAndroid::UnmapPartitionOnDeviceMapper( |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 230 | const std::string& target_partition_name) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 231 | if (DeviceMapper::Instance().GetState(target_partition_name) != |
| 232 | DmDeviceState::INVALID) { |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 233 | // Partitions at target slot on non-Virtual A/B devices are mapped as |
| 234 | // dm-linear. Also, on Virtual A/B devices, system_other may be mapped for |
| 235 | // preopt apps as dm-linear. |
| 236 | // Call DestroyLogicalPartition to handle these cases. |
| 237 | bool success = DestroyLogicalPartition(target_partition_name); |
| 238 | |
| 239 | // On a Virtual A/B device, |target_partition_name| may be a leftover from |
| 240 | // a paused update. Clean up any underlying devices. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 241 | if (ExpectMetadataMounted()) { |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 242 | success &= snapshot_->UnmapUpdateSnapshot(target_partition_name); |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 243 | } else { |
| 244 | LOG(INFO) << "Skip UnmapUpdateSnapshot(" << target_partition_name |
| 245 | << ") because metadata is not mounted"; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | if (!success) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 249 | LOG(ERROR) << "Cannot unmap " << target_partition_name |
| 250 | << " from device mapper."; |
| 251 | return false; |
| 252 | } |
| 253 | LOG(INFO) << "Successfully unmapped " << target_partition_name |
| 254 | << " from device mapper."; |
| 255 | } |
| 256 | mapped_devices_.erase(target_partition_name); |
| 257 | return true; |
| 258 | } |
| 259 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 260 | void DynamicPartitionControlAndroid::UnmapAllPartitions() { |
Tao Bao | 8c4d008 | 2019-08-08 08:56:16 -0700 | [diff] [blame] | 261 | if (mapped_devices_.empty()) { |
| 262 | return; |
| 263 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 264 | // UnmapPartitionOnDeviceMapper removes objects from mapped_devices_, hence |
| 265 | // a copy is needed for the loop. |
| 266 | std::set<std::string> mapped = mapped_devices_; |
| 267 | LOG(INFO) << "Destroying [" << Join(mapped, ", ") << "] from device mapper"; |
| 268 | for (const auto& partition_name : mapped) { |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 269 | ignore_result(UnmapPartitionOnDeviceMapper(partition_name)); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | void DynamicPartitionControlAndroid::Cleanup() { |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 274 | UnmapAllPartitions(); |
| 275 | metadata_device_.reset(); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | bool DynamicPartitionControlAndroid::DeviceExists(const std::string& path) { |
| 279 | return base::PathExists(base::FilePath(path)); |
| 280 | } |
| 281 | |
| 282 | android::dm::DmDeviceState DynamicPartitionControlAndroid::GetState( |
| 283 | const std::string& name) { |
| 284 | return DeviceMapper::Instance().GetState(name); |
| 285 | } |
| 286 | |
| 287 | bool DynamicPartitionControlAndroid::GetDmDevicePathByName( |
| 288 | const std::string& name, std::string* path) { |
| 289 | return DeviceMapper::Instance().GetDmDevicePathByName(name, path); |
| 290 | } |
| 291 | |
| 292 | std::unique_ptr<MetadataBuilder> |
| 293 | DynamicPartitionControlAndroid::LoadMetadataBuilder( |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 294 | const std::string& super_device, uint32_t source_slot) { |
| 295 | return LoadMetadataBuilder( |
| 296 | super_device, source_slot, BootControlInterface::kInvalidSlot); |
| 297 | } |
| 298 | |
| 299 | std::unique_ptr<MetadataBuilder> |
| 300 | DynamicPartitionControlAndroid::LoadMetadataBuilder( |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 301 | const std::string& super_device, |
| 302 | uint32_t source_slot, |
| 303 | uint32_t target_slot) { |
Yifan Hong | 30fa5f5 | 2019-08-05 16:39:59 -0700 | [diff] [blame] | 304 | std::unique_ptr<MetadataBuilder> builder; |
| 305 | if (target_slot == BootControlInterface::kInvalidSlot) { |
| 306 | builder = |
| 307 | MetadataBuilder::New(PartitionOpener(), super_device, source_slot); |
| 308 | } else { |
Yifan Hong | 50a56c6 | 2019-10-14 19:35:05 -0700 | [diff] [blame] | 309 | bool always_keep_source_slot = !target_supports_snapshot_; |
| 310 | builder = MetadataBuilder::NewForUpdate(PartitionOpener(), |
| 311 | super_device, |
| 312 | source_slot, |
| 313 | target_slot, |
| 314 | always_keep_source_slot); |
Yifan Hong | 30fa5f5 | 2019-08-05 16:39:59 -0700 | [diff] [blame] | 315 | } |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 316 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 317 | if (builder == nullptr) { |
| 318 | LOG(WARNING) << "No metadata slot " |
| 319 | << BootControlInterface::SlotName(source_slot) << " in " |
| 320 | << super_device; |
Yifan Hong | f48a005 | 2018-10-29 16:30:43 -0700 | [diff] [blame] | 321 | return nullptr; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 322 | } |
| 323 | LOG(INFO) << "Loaded metadata from slot " |
| 324 | << BootControlInterface::SlotName(source_slot) << " in " |
| 325 | << super_device; |
| 326 | return builder; |
| 327 | } |
| 328 | |
| 329 | bool DynamicPartitionControlAndroid::StoreMetadata( |
| 330 | const std::string& super_device, |
| 331 | MetadataBuilder* builder, |
| 332 | uint32_t target_slot) { |
| 333 | auto metadata = builder->Export(); |
| 334 | if (metadata == nullptr) { |
| 335 | LOG(ERROR) << "Cannot export metadata to slot " |
| 336 | << BootControlInterface::SlotName(target_slot) << " in " |
| 337 | << super_device; |
| 338 | return false; |
| 339 | } |
| 340 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 341 | if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) { |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 342 | if (!FlashPartitionTable(super_device, *metadata)) { |
| 343 | LOG(ERROR) << "Cannot write metadata to " << super_device; |
| 344 | return false; |
| 345 | } |
| 346 | LOG(INFO) << "Written metadata to " << super_device; |
| 347 | } else { |
| 348 | if (!UpdatePartitionTable(super_device, *metadata, target_slot)) { |
| 349 | LOG(ERROR) << "Cannot write metadata to slot " |
| 350 | << BootControlInterface::SlotName(target_slot) << " in " |
| 351 | << super_device; |
| 352 | return false; |
| 353 | } |
| 354 | LOG(INFO) << "Copied metadata to slot " |
| 355 | << BootControlInterface::SlotName(target_slot) << " in " |
| 356 | << super_device; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 359 | return true; |
| 360 | } |
| 361 | |
| 362 | bool DynamicPartitionControlAndroid::GetDeviceDir(std::string* out) { |
| 363 | // We can't use fs_mgr to look up |partition_name| because fstab |
| 364 | // doesn't list every slot partition (it uses the slotselect option |
| 365 | // to mask the suffix). |
| 366 | // |
| 367 | // We can however assume that there's an entry for the /misc mount |
| 368 | // point and use that to get the device file for the misc |
| 369 | // partition. This helps us locate the disk that |partition_name| |
| 370 | // resides on. From there we'll assume that a by-name scheme is used |
| 371 | // so we can just replace the trailing "misc" by the given |
| 372 | // |partition_name| and suffix corresponding to |slot|, e.g. |
| 373 | // |
| 374 | // /dev/block/platform/soc.0/7824900.sdhci/by-name/misc -> |
| 375 | // /dev/block/platform/soc.0/7824900.sdhci/by-name/boot_a |
| 376 | // |
| 377 | // If needed, it's possible to relax the by-name assumption in the |
| 378 | // future by trawling /sys/block looking for the appropriate sibling |
| 379 | // of misc and then finding an entry in /dev matching the sysfs |
| 380 | // entry. |
| 381 | |
| 382 | std::string err, misc_device = get_bootloader_message_blk_device(&err); |
| 383 | if (misc_device.empty()) { |
| 384 | LOG(ERROR) << "Unable to get misc block device: " << err; |
| 385 | return false; |
| 386 | } |
| 387 | |
| 388 | if (!utils::IsSymlink(misc_device.c_str())) { |
| 389 | LOG(ERROR) << "Device file " << misc_device << " for /misc " |
| 390 | << "is not a symlink."; |
| 391 | return false; |
| 392 | } |
| 393 | *out = base::FilePath(misc_device).DirName().value(); |
| 394 | return true; |
| 395 | } |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 396 | |
| 397 | bool DynamicPartitionControlAndroid::PreparePartitionsForUpdate( |
| 398 | uint32_t source_slot, |
| 399 | uint32_t target_slot, |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 400 | const DeltaArchiveManifest& manifest, |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 401 | bool update, |
| 402 | uint64_t* required_size) { |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 403 | source_slot_ = source_slot; |
| 404 | target_slot_ = target_slot; |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 405 | if (required_size != nullptr) { |
| 406 | *required_size = 0; |
| 407 | } |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 408 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 409 | if (fs_mgr_overlayfs_is_setup()) { |
| 410 | // Non DAP devices can use overlayfs as well. |
| 411 | LOG(WARNING) |
| 412 | << "overlayfs overrides are active and can interfere with our " |
| 413 | "resources.\n" |
| 414 | << "run adb enable-verity to deactivate if required and try again."; |
| 415 | } |
| 416 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 417 | // If metadata is erased but not formatted, it is possible to not mount |
| 418 | // it in recovery. It is acceptable to skip mounting and choose fallback path |
| 419 | // (PrepareDynamicPartitionsForUpdate) when sideloading full OTAs. |
| 420 | TEST_AND_RETURN_FALSE(EnsureMetadataMounted() || IsRecovery()); |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 421 | |
| 422 | if (update) { |
| 423 | TEST_AND_RETURN_FALSE(EraseSystemOtherAvbFooter(source_slot, target_slot)); |
| 424 | } |
| 425 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 426 | if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) { |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | if (target_slot == source_slot) { |
| 431 | LOG(ERROR) << "Cannot call PreparePartitionsForUpdate on current slot."; |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | // Although the current build supports dynamic partitions, the given payload |
| 436 | // doesn't use it for target partitions. This could happen when applying a |
| 437 | // retrofit update. Skip updating the partition metadata for the target slot. |
| 438 | is_target_dynamic_ = !manifest.dynamic_partition_metadata().groups().empty(); |
| 439 | if (!is_target_dynamic_) { |
| 440 | return true; |
| 441 | } |
| 442 | |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 443 | target_supports_snapshot_ = |
| 444 | manifest.dynamic_partition_metadata().snapshot_enabled(); |
| 445 | |
| 446 | if (!update) |
| 447 | return true; |
| 448 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 449 | bool delete_source = false; |
| 450 | |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 451 | if (GetVirtualAbFeatureFlag().IsEnabled()) { |
| 452 | // On Virtual A/B device, either CancelUpdate() or BeginUpdate() must be |
| 453 | // called before calling UnmapUpdateSnapshot. |
| 454 | // - If target_supports_snapshot_, PrepareSnapshotPartitionsForUpdate() |
| 455 | // calls BeginUpdate() which resets update state |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 456 | // - If !target_supports_snapshot_ or PrepareSnapshotPartitionsForUpdate |
| 457 | // failed in recovery, explicitly CancelUpdate(). |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 458 | if (target_supports_snapshot_) { |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 459 | if (PrepareSnapshotPartitionsForUpdate( |
| 460 | source_slot, target_slot, manifest, required_size)) { |
| 461 | return true; |
| 462 | } |
| 463 | |
| 464 | // Virtual A/B device doing Virtual A/B update in Android mode must use |
| 465 | // snapshots. |
| 466 | if (!IsRecovery()) { |
| 467 | LOG(ERROR) << "PrepareSnapshotPartitionsForUpdate failed in Android " |
| 468 | << "mode"; |
| 469 | return false; |
| 470 | } |
| 471 | |
| 472 | delete_source = true; |
| 473 | LOG(INFO) << "PrepareSnapshotPartitionsForUpdate failed in recovery. " |
| 474 | << "Attempt to overwrite existing partitions if possible"; |
| 475 | } else { |
| 476 | // Downgrading to an non-Virtual A/B build or is secondary OTA. |
| 477 | LOG(INFO) << "Using regular A/B on Virtual A/B because package disabled " |
| 478 | << "snapshots."; |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 479 | } |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 480 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 481 | // In recovery, if /metadata is not mounted, it is likely that metadata |
| 482 | // partition is erased and not formatted yet. After sideloading, when |
| 483 | // rebooting into the new version, init will erase metadata partition, |
| 484 | // hence the failure of CancelUpdate() can be ignored here. |
| 485 | // However, if metadata is mounted and CancelUpdate fails, sideloading |
| 486 | // should not proceed because during next boot, snapshots will overlay on |
| 487 | // the devices incorrectly. |
| 488 | if (ExpectMetadataMounted()) { |
| 489 | TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate()); |
| 490 | } else { |
| 491 | LOG(INFO) << "Skip canceling previous update because metadata is not " |
| 492 | << "mounted"; |
Yifan Hong | 6d88856 | 2019-10-01 13:00:31 -0700 | [diff] [blame] | 493 | } |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 494 | } |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 495 | |
Yifan Hong | 5c5743f | 2020-04-16 12:59:07 -0700 | [diff] [blame^] | 496 | TEST_AND_RETURN_FALSE(PrepareDynamicPartitionsForUpdate( |
| 497 | source_slot, target_slot, manifest, delete_source)); |
| 498 | |
| 499 | if (required_size != nullptr) { |
| 500 | *required_size = 0; |
| 501 | } |
| 502 | return true; |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 505 | namespace { |
| 506 | // Try our best to erase AVB footer. |
| 507 | class AvbFooterEraser { |
| 508 | public: |
| 509 | explicit AvbFooterEraser(const std::string& path) : path_(path) {} |
| 510 | bool Erase() { |
| 511 | // Try to mark the block device read-only. Ignore any |
| 512 | // failure since this won't work when passing regular files. |
| 513 | ignore_result(utils::SetBlockDeviceReadOnly(path_, false /* readonly */)); |
| 514 | |
| 515 | fd_.reset(new EintrSafeFileDescriptor()); |
| 516 | int flags = O_WRONLY | O_TRUNC | O_CLOEXEC | O_SYNC; |
| 517 | TEST_AND_RETURN_FALSE(fd_->Open(path_.c_str(), flags)); |
| 518 | |
| 519 | // Need to write end-AVB_FOOTER_SIZE to end. |
| 520 | static_assert(AVB_FOOTER_SIZE > 0); |
| 521 | off64_t offset = fd_->Seek(-AVB_FOOTER_SIZE, SEEK_END); |
| 522 | TEST_AND_RETURN_FALSE_ERRNO(offset >= 0); |
| 523 | uint64_t write_size = AVB_FOOTER_SIZE; |
| 524 | LOG(INFO) << "Zeroing " << path_ << " @ [" << offset << ", " |
| 525 | << (offset + write_size) << "] (" << write_size << " bytes)"; |
| 526 | brillo::Blob zeros(write_size); |
| 527 | TEST_AND_RETURN_FALSE(utils::WriteAll(fd_, zeros.data(), zeros.size())); |
| 528 | return true; |
| 529 | } |
| 530 | ~AvbFooterEraser() { |
| 531 | TEST_AND_RETURN(fd_ != nullptr && fd_->IsOpen()); |
| 532 | if (!fd_->Close()) { |
| 533 | LOG(WARNING) << "Failed to close fd for " << path_; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | private: |
| 538 | std::string path_; |
| 539 | FileDescriptorPtr fd_; |
| 540 | }; |
| 541 | |
| 542 | } // namespace |
| 543 | |
| 544 | std::optional<bool> |
| 545 | DynamicPartitionControlAndroid::IsAvbEnabledOnSystemOther() { |
| 546 | auto prefix = GetProperty(kPostinstallFstabPrefix, ""); |
| 547 | if (prefix.empty()) { |
| 548 | LOG(WARNING) << "Cannot get " << kPostinstallFstabPrefix; |
| 549 | return std::nullopt; |
| 550 | } |
| 551 | auto path = base::FilePath(prefix).Append("etc/fstab.postinstall").value(); |
| 552 | return IsAvbEnabledInFstab(path); |
| 553 | } |
| 554 | |
| 555 | std::optional<bool> DynamicPartitionControlAndroid::IsAvbEnabledInFstab( |
| 556 | const std::string& path) { |
| 557 | Fstab fstab; |
| 558 | if (!ReadFstabFromFile(path, &fstab)) { |
| 559 | LOG(WARNING) << "Cannot read fstab from " << path; |
| 560 | return std::nullopt; |
| 561 | } |
| 562 | for (const auto& entry : fstab) { |
| 563 | if (!entry.avb_keys.empty()) { |
| 564 | return true; |
| 565 | } |
| 566 | } |
| 567 | return false; |
| 568 | } |
| 569 | |
| 570 | bool DynamicPartitionControlAndroid::GetSystemOtherPath( |
| 571 | uint32_t source_slot, |
| 572 | uint32_t target_slot, |
| 573 | const std::string& partition_name_suffix, |
| 574 | std::string* path, |
| 575 | bool* should_unmap) { |
| 576 | path->clear(); |
| 577 | *should_unmap = false; |
| 578 | |
| 579 | // In recovery, just erase no matter what. |
| 580 | // - On devices with retrofit dynamic partitions, no logical partitions |
| 581 | // should be mounted at this point. Hence it should be safe to erase. |
| 582 | // Otherwise, do check that AVB is enabled on system_other before erasing. |
| 583 | if (!IsRecovery()) { |
| 584 | auto has_avb = IsAvbEnabledOnSystemOther(); |
| 585 | TEST_AND_RETURN_FALSE(has_avb.has_value()); |
| 586 | if (!has_avb.value()) { |
| 587 | LOG(INFO) << "AVB is not enabled on system_other. Skip erasing."; |
| 588 | return true; |
| 589 | } |
| 590 | |
| 591 | // Found unexpected avb_keys for system_other on devices retrofitting |
| 592 | // dynamic partitions. Previous crash in update_engine may leave logical |
| 593 | // partitions mapped on physical system_other partition. It is difficult to |
| 594 | // handle these cases. Just fail. |
| 595 | if (GetDynamicPartitionsFeatureFlag().IsRetrofit()) { |
| 596 | LOG(ERROR) << "Cannot erase AVB footer on system_other on devices with " |
| 597 | << "retrofit dynamic partitions. They should not have AVB " |
| 598 | << "enabled on system_other."; |
| 599 | return false; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | std::string device_dir_str; |
| 604 | TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str)); |
| 605 | base::FilePath device_dir(device_dir_str); |
| 606 | |
| 607 | // On devices without dynamic partition, search for static partitions. |
| 608 | if (!GetDynamicPartitionsFeatureFlag().IsEnabled()) { |
| 609 | *path = device_dir.Append(partition_name_suffix).value(); |
| 610 | TEST_AND_RETURN_FALSE(DeviceExists(*path)); |
| 611 | return true; |
| 612 | } |
| 613 | |
| 614 | auto source_super_device = |
| 615 | device_dir.Append(GetSuperPartitionName(source_slot)).value(); |
| 616 | |
| 617 | auto builder = LoadMetadataBuilder(source_super_device, source_slot); |
| 618 | if (builder == nullptr) { |
| 619 | if (IsRecovery()) { |
| 620 | // It might be corrupted for some reason. It should still be able to |
| 621 | // sideload. |
| 622 | LOG(WARNING) << "Super partition metadata cannot be read from the source " |
| 623 | << "slot, skip erasing."; |
| 624 | return true; |
| 625 | } else { |
| 626 | // Device has booted into Android mode, indicating that the super |
| 627 | // partition metadata should be there. |
| 628 | LOG(ERROR) << "Super partition metadata cannot be read from the source " |
| 629 | << "slot. This is unexpected on devices with dynamic " |
| 630 | << "partitions enabled."; |
| 631 | return false; |
| 632 | } |
| 633 | } |
| 634 | auto p = builder->FindPartition(partition_name_suffix); |
| 635 | if (p == nullptr) { |
| 636 | // If the source slot is flashed without system_other, it does not exist |
| 637 | // in super partition metadata at source slot. It is safe to skip it. |
| 638 | LOG(INFO) << "Can't find " << partition_name_suffix |
| 639 | << " in metadata source slot, skip erasing."; |
| 640 | return true; |
| 641 | } |
| 642 | // System_other created by flashing tools should be erased. |
| 643 | // If partition is created by update_engine (via NewForUpdate), it is a |
| 644 | // left-over partition from the previous update and does not contain |
| 645 | // system_other, hence there is no need to erase. |
| 646 | // Note the reverse is not necessary true. If the flag is not set, we don't |
| 647 | // know if the partition is created by update_engine or by flashing tools |
| 648 | // because older versions of super partition metadata does not contain this |
| 649 | // flag. It is okay to erase the AVB footer anyways. |
| 650 | if (p->attributes() & LP_PARTITION_ATTR_UPDATED) { |
| 651 | LOG(INFO) << partition_name_suffix |
| 652 | << " does not contain system_other, skip erasing."; |
| 653 | return true; |
| 654 | } |
| 655 | |
| 656 | // Delete any pre-existing device with name |partition_name_suffix| and |
| 657 | // also remove it from |mapped_devices_|. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 658 | // In recovery, metadata might not be mounted, and |
| 659 | // UnmapPartitionOnDeviceMapper might fail. However, |
| 660 | // 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] | 661 | TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix)); |
| 662 | // Use CreateLogicalPartition directly to avoid mapping with existing |
| 663 | // snapshots. |
| 664 | CreateLogicalPartitionParams params = { |
| 665 | .block_device = source_super_device, |
| 666 | .metadata_slot = source_slot, |
| 667 | .partition_name = partition_name_suffix, |
| 668 | .force_writable = true, |
| 669 | .timeout_ms = kMapTimeout, |
| 670 | }; |
| 671 | TEST_AND_RETURN_FALSE(CreateLogicalPartition(params, path)); |
| 672 | *should_unmap = true; |
| 673 | return true; |
| 674 | } |
| 675 | |
| 676 | bool DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter( |
| 677 | uint32_t source_slot, uint32_t target_slot) { |
| 678 | LOG(INFO) << "Erasing AVB footer of system_other partition before update."; |
| 679 | |
| 680 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 681 | const std::string partition_name_suffix = "system" + target_suffix; |
| 682 | |
| 683 | std::string path; |
| 684 | bool should_unmap = false; |
| 685 | |
| 686 | TEST_AND_RETURN_FALSE(GetSystemOtherPath( |
| 687 | source_slot, target_slot, partition_name_suffix, &path, &should_unmap)); |
| 688 | |
| 689 | if (path.empty()) { |
| 690 | return true; |
| 691 | } |
| 692 | |
| 693 | bool ret = AvbFooterEraser(path).Erase(); |
| 694 | |
| 695 | // Delete |partition_name_suffix| from device mapper and from |
| 696 | // |mapped_devices_| again so that it does not interfere with update process. |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 697 | // In recovery, metadata might not be mounted, and |
| 698 | // UnmapPartitionOnDeviceMapper might fail. However, DestroyLogicalPartition |
| 699 | // should be called. If DestroyLogicalPartition does fail, it is still okay |
| 700 | // to skip the error here and let Prepare*() fail later. |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 701 | if (should_unmap) { |
| 702 | TEST_AND_RETURN_FALSE(UnmapPartitionOnDeviceMapper(partition_name_suffix)); |
| 703 | } |
| 704 | |
| 705 | return ret; |
| 706 | } |
| 707 | |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 708 | bool DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate( |
| 709 | uint32_t source_slot, |
| 710 | uint32_t target_slot, |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 711 | const DeltaArchiveManifest& manifest, |
| 712 | bool delete_source) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 713 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 714 | |
| 715 | // Unmap all the target dynamic partitions because they would become |
| 716 | // inconsistent with the new metadata. |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 717 | for (const auto& group : manifest.dynamic_partition_metadata().groups()) { |
| 718 | for (const auto& partition_name : group.partition_names()) { |
| 719 | if (!UnmapPartitionOnDeviceMapper(partition_name + target_suffix)) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 720 | return false; |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | std::string device_dir_str; |
| 726 | if (!GetDeviceDir(&device_dir_str)) { |
| 727 | return false; |
| 728 | } |
| 729 | base::FilePath device_dir(device_dir_str); |
| 730 | auto source_device = |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 731 | device_dir.Append(GetSuperPartitionName(source_slot)).value(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 732 | |
| 733 | auto builder = LoadMetadataBuilder(source_device, source_slot, target_slot); |
| 734 | if (builder == nullptr) { |
| 735 | LOG(ERROR) << "No metadata at " |
| 736 | << BootControlInterface::SlotName(source_slot); |
| 737 | return false; |
| 738 | } |
| 739 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 740 | if (delete_source) { |
| 741 | TEST_AND_RETURN_FALSE( |
| 742 | DeleteSourcePartitions(builder.get(), source_slot, manifest)); |
| 743 | } |
| 744 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 745 | if (!UpdatePartitionMetadata(builder.get(), target_slot, manifest)) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 746 | return false; |
| 747 | } |
| 748 | |
| 749 | auto target_device = |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 750 | device_dir.Append(GetSuperPartitionName(target_slot)).value(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 751 | return StoreMetadata(target_device, builder.get(), target_slot); |
| 752 | } |
| 753 | |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 754 | bool DynamicPartitionControlAndroid::PrepareSnapshotPartitionsForUpdate( |
| 755 | uint32_t source_slot, |
| 756 | uint32_t target_slot, |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 757 | const DeltaArchiveManifest& manifest, |
| 758 | uint64_t* required_size) { |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 759 | TEST_AND_RETURN_FALSE(ExpectMetadataMounted()); |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 760 | if (!snapshot_->BeginUpdate()) { |
| 761 | LOG(ERROR) << "Cannot begin new update."; |
| 762 | return false; |
| 763 | } |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 764 | auto ret = snapshot_->CreateUpdateSnapshots(manifest); |
| 765 | if (!ret) { |
| 766 | LOG(ERROR) << "Cannot create update snapshots: " << ret.string(); |
| 767 | if (required_size != nullptr && |
Yifan Hong | 0850bca | 2020-01-16 15:14:07 -0800 | [diff] [blame] | 768 | ret.error_code() == Return::ErrorCode::NO_SPACE) { |
Yifan Hong | f033ecb | 2020-01-07 18:13:56 -0800 | [diff] [blame] | 769 | *required_size = ret.required_size(); |
| 770 | } |
Yifan Hong | 420db9b | 2019-07-23 20:50:33 -0700 | [diff] [blame] | 771 | return false; |
| 772 | } |
| 773 | return true; |
| 774 | } |
| 775 | |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 776 | std::string DynamicPartitionControlAndroid::GetSuperPartitionName( |
| 777 | uint32_t slot) { |
| 778 | return fs_mgr_get_super_partition_name(slot); |
| 779 | } |
| 780 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 781 | bool DynamicPartitionControlAndroid::UpdatePartitionMetadata( |
| 782 | MetadataBuilder* builder, |
| 783 | uint32_t target_slot, |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 784 | const DeltaArchiveManifest& manifest) { |
Yifan Hong | a4e7da3 | 2019-09-30 18:25:03 -0700 | [diff] [blame] | 785 | // If applying downgrade from Virtual A/B to non-Virtual A/B, the left-over |
| 786 | // COW group needs to be deleted to ensure there are enough space to create |
| 787 | // target partitions. |
| 788 | builder->RemoveGroupAndPartitions(android::snapshot::kCowGroupName); |
| 789 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 790 | const std::string target_suffix = SlotSuffixForSlotNumber(target_slot); |
| 791 | DeleteGroupsWithSuffix(builder, target_suffix); |
| 792 | |
| 793 | uint64_t total_size = 0; |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 794 | for (const auto& group : manifest.dynamic_partition_metadata().groups()) { |
| 795 | total_size += group.size(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | std::string expr; |
| 799 | uint64_t allocatable_space = builder->AllocatableSpace(); |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 800 | if (!GetDynamicPartitionsFeatureFlag().IsRetrofit()) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 801 | allocatable_space /= 2; |
| 802 | expr = "half of "; |
| 803 | } |
| 804 | if (total_size > allocatable_space) { |
| 805 | LOG(ERROR) << "The maximum size of all groups with suffix " << target_suffix |
| 806 | << " (" << total_size << ") has exceeded " << expr |
| 807 | << "allocatable space for dynamic partitions " |
| 808 | << allocatable_space << "."; |
| 809 | return false; |
| 810 | } |
| 811 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 812 | // name of partition(e.g. "system") -> size in bytes |
| 813 | std::map<std::string, uint64_t> partition_sizes; |
| 814 | for (const auto& partition : manifest.partitions()) { |
| 815 | partition_sizes.emplace(partition.partition_name(), |
| 816 | partition.new_partition_info().size()); |
| 817 | } |
| 818 | |
| 819 | for (const auto& group : manifest.dynamic_partition_metadata().groups()) { |
| 820 | auto group_name_suffix = group.name() + target_suffix; |
| 821 | if (!builder->AddGroup(group_name_suffix, group.size())) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 822 | LOG(ERROR) << "Cannot add group " << group_name_suffix << " with size " |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 823 | << group.size(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 824 | return false; |
| 825 | } |
| 826 | LOG(INFO) << "Added group " << group_name_suffix << " with size " |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 827 | << group.size(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 828 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 829 | for (const auto& partition_name : group.partition_names()) { |
| 830 | auto partition_sizes_it = partition_sizes.find(partition_name); |
| 831 | if (partition_sizes_it == partition_sizes.end()) { |
| 832 | // TODO(tbao): Support auto-filling partition info for framework-only |
| 833 | // OTA. |
| 834 | LOG(ERROR) << "dynamic_partition_metadata contains partition " |
| 835 | << partition_name << " but it is not part of the manifest. " |
| 836 | << "This is not supported."; |
| 837 | return false; |
| 838 | } |
| 839 | uint64_t partition_size = partition_sizes_it->second; |
| 840 | |
| 841 | auto partition_name_suffix = partition_name + target_suffix; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 842 | Partition* p = builder->AddPartition( |
| 843 | partition_name_suffix, group_name_suffix, LP_PARTITION_ATTR_READONLY); |
| 844 | if (!p) { |
| 845 | LOG(ERROR) << "Cannot add partition " << partition_name_suffix |
| 846 | << " to group " << group_name_suffix; |
| 847 | return false; |
| 848 | } |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 849 | if (!builder->ResizePartition(p, partition_size)) { |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 850 | LOG(ERROR) << "Cannot resize partition " << partition_name_suffix |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 851 | << " to size " << partition_size << ". Not enough space?"; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 852 | return false; |
| 853 | } |
| 854 | LOG(INFO) << "Added partition " << partition_name_suffix << " to group " |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 855 | << group_name_suffix << " with size " << partition_size; |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | |
| 859 | return true; |
| 860 | } |
| 861 | |
Yifan Hong | 7b3910a | 2020-03-24 17:47:32 -0700 | [diff] [blame] | 862 | bool DynamicPartitionControlAndroid::FinishUpdate(bool powerwash_required) { |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 863 | if (ExpectMetadataMounted()) { |
| 864 | if (snapshot_->GetUpdateState() == UpdateState::Initiated) { |
| 865 | LOG(INFO) << "Snapshot writes are done."; |
| 866 | return snapshot_->FinishedSnapshotWrites(powerwash_required); |
| 867 | } |
| 868 | } else { |
| 869 | LOG(INFO) << "Skip FinishedSnapshotWrites() because /metadata is not " |
| 870 | << "mounted"; |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 871 | } |
| 872 | return true; |
Yifan Hong | a33bca4 | 2019-09-03 20:29:45 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Yifan Hong | 3a1a561 | 2019-11-05 16:34:32 -0800 | [diff] [blame] | 875 | bool DynamicPartitionControlAndroid::GetPartitionDevice( |
| 876 | const std::string& partition_name, |
| 877 | uint32_t slot, |
| 878 | uint32_t current_slot, |
| 879 | std::string* device) { |
| 880 | const auto& partition_name_suffix = |
| 881 | partition_name + SlotSuffixForSlotNumber(slot); |
| 882 | std::string device_dir_str; |
| 883 | TEST_AND_RETURN_FALSE(GetDeviceDir(&device_dir_str)); |
| 884 | base::FilePath device_dir(device_dir_str); |
| 885 | |
| 886 | // When looking up target partition devices, treat them as static if the |
| 887 | // current payload doesn't encode them as dynamic partitions. This may happen |
| 888 | // when applying a retrofit update on top of a dynamic-partitions-enabled |
| 889 | // build. |
| 890 | if (GetDynamicPartitionsFeatureFlag().IsEnabled() && |
| 891 | (slot == current_slot || is_target_dynamic_)) { |
| 892 | switch (GetDynamicPartitionDevice( |
| 893 | device_dir, partition_name_suffix, slot, current_slot, device)) { |
| 894 | case DynamicPartitionDeviceStatus::SUCCESS: |
| 895 | return true; |
| 896 | case DynamicPartitionDeviceStatus::TRY_STATIC: |
| 897 | break; |
| 898 | case DynamicPartitionDeviceStatus::ERROR: // fallthrough |
| 899 | default: |
| 900 | return false; |
| 901 | } |
| 902 | } |
| 903 | base::FilePath path = device_dir.Append(partition_name_suffix); |
| 904 | if (!DeviceExists(path.value())) { |
| 905 | LOG(ERROR) << "Device file " << path.value() << " does not exist."; |
| 906 | return false; |
| 907 | } |
| 908 | |
| 909 | *device = path.value(); |
| 910 | return true; |
| 911 | } |
| 912 | |
| 913 | bool DynamicPartitionControlAndroid::IsSuperBlockDevice( |
| 914 | const base::FilePath& device_dir, |
| 915 | uint32_t current_slot, |
| 916 | const std::string& partition_name_suffix) { |
| 917 | std::string source_device = |
| 918 | device_dir.Append(GetSuperPartitionName(current_slot)).value(); |
| 919 | auto source_metadata = LoadMetadataBuilder(source_device, current_slot); |
| 920 | return source_metadata->HasBlockDevice(partition_name_suffix); |
| 921 | } |
| 922 | |
| 923 | DynamicPartitionControlAndroid::DynamicPartitionDeviceStatus |
| 924 | DynamicPartitionControlAndroid::GetDynamicPartitionDevice( |
| 925 | const base::FilePath& device_dir, |
| 926 | const std::string& partition_name_suffix, |
| 927 | uint32_t slot, |
| 928 | uint32_t current_slot, |
| 929 | std::string* device) { |
| 930 | std::string super_device = |
| 931 | device_dir.Append(GetSuperPartitionName(slot)).value(); |
| 932 | |
| 933 | auto builder = LoadMetadataBuilder(super_device, slot); |
| 934 | if (builder == nullptr) { |
| 935 | LOG(ERROR) << "No metadata in slot " |
| 936 | << BootControlInterface::SlotName(slot); |
| 937 | return DynamicPartitionDeviceStatus::ERROR; |
| 938 | } |
| 939 | if (builder->FindPartition(partition_name_suffix) == nullptr) { |
| 940 | LOG(INFO) << partition_name_suffix |
| 941 | << " is not in super partition metadata."; |
| 942 | |
| 943 | if (IsSuperBlockDevice(device_dir, current_slot, partition_name_suffix)) { |
| 944 | LOG(ERROR) << "The static partition " << partition_name_suffix |
| 945 | << " is a block device for current metadata." |
| 946 | << "It cannot be used as a logical partition."; |
| 947 | return DynamicPartitionDeviceStatus::ERROR; |
| 948 | } |
| 949 | |
| 950 | return DynamicPartitionDeviceStatus::TRY_STATIC; |
| 951 | } |
| 952 | |
| 953 | if (slot == current_slot) { |
| 954 | if (GetState(partition_name_suffix) != DmDeviceState::ACTIVE) { |
| 955 | LOG(WARNING) << partition_name_suffix << " is at current slot but it is " |
| 956 | << "not mapped. Now try to map it."; |
| 957 | } else { |
| 958 | if (GetDmDevicePathByName(partition_name_suffix, device)) { |
| 959 | LOG(INFO) << partition_name_suffix |
| 960 | << " is mapped on device mapper: " << *device; |
| 961 | return DynamicPartitionDeviceStatus::SUCCESS; |
| 962 | } |
| 963 | LOG(ERROR) << partition_name_suffix << "is mapped but path is unknown."; |
| 964 | return DynamicPartitionDeviceStatus::ERROR; |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | bool force_writable = slot != current_slot; |
| 969 | if (MapPartitionOnDeviceMapper( |
| 970 | super_device, partition_name_suffix, slot, force_writable, device)) { |
| 971 | return DynamicPartitionDeviceStatus::SUCCESS; |
| 972 | } |
| 973 | return DynamicPartitionDeviceStatus::ERROR; |
| 974 | } |
| 975 | |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 976 | void DynamicPartitionControlAndroid::set_fake_mapped_devices( |
| 977 | const std::set<std::string>& fake) { |
| 978 | mapped_devices_ = fake; |
| 979 | } |
| 980 | |
Yifan Hong | bae2784 | 2019-10-24 16:56:12 -0700 | [diff] [blame] | 981 | bool DynamicPartitionControlAndroid::IsRecovery() { |
| 982 | return kIsRecovery; |
| 983 | } |
| 984 | |
| 985 | static bool IsIncrementalUpdate(const DeltaArchiveManifest& manifest) { |
| 986 | const auto& partitions = manifest.partitions(); |
| 987 | return std::any_of(partitions.begin(), partitions.end(), [](const auto& p) { |
| 988 | return p.has_old_partition_info(); |
| 989 | }); |
| 990 | } |
| 991 | |
| 992 | bool DynamicPartitionControlAndroid::DeleteSourcePartitions( |
| 993 | MetadataBuilder* builder, |
| 994 | uint32_t source_slot, |
| 995 | const DeltaArchiveManifest& manifest) { |
| 996 | TEST_AND_RETURN_FALSE(IsRecovery()); |
| 997 | |
| 998 | if (IsIncrementalUpdate(manifest)) { |
| 999 | LOG(ERROR) << "Cannot sideload incremental OTA because snapshots cannot " |
| 1000 | << "be created."; |
| 1001 | if (GetVirtualAbFeatureFlag().IsLaunch()) { |
| 1002 | LOG(ERROR) << "Sideloading incremental updates on devices launches " |
| 1003 | << " Virtual A/B is not supported."; |
| 1004 | } |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | LOG(INFO) << "Will overwrite existing partitions. Slot " |
| 1009 | << BootControlInterface::SlotName(source_slot) |
| 1010 | << "may be unbootable until update finishes!"; |
| 1011 | const std::string source_suffix = SlotSuffixForSlotNumber(source_slot); |
| 1012 | DeleteGroupsWithSuffix(builder, source_suffix); |
| 1013 | |
| 1014 | return true; |
| 1015 | } |
| 1016 | |
Yifan Hong | 9096550 | 2020-02-19 15:22:47 -0800 | [diff] [blame] | 1017 | std::unique_ptr<AbstractAction> |
| 1018 | DynamicPartitionControlAndroid::GetCleanupPreviousUpdateAction( |
| 1019 | BootControlInterface* boot_control, |
| 1020 | PrefsInterface* prefs, |
| 1021 | CleanupPreviousUpdateActionDelegateInterface* delegate) { |
| 1022 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1023 | return std::make_unique<NoOpAction>(); |
| 1024 | } |
| 1025 | return std::make_unique<CleanupPreviousUpdateAction>( |
| 1026 | prefs, boot_control, snapshot_.get(), delegate); |
| 1027 | } |
| 1028 | |
Yifan Hong | 6a6d0f1 | 2020-03-11 13:20:52 -0700 | [diff] [blame] | 1029 | bool DynamicPartitionControlAndroid::ResetUpdate(PrefsInterface* prefs) { |
| 1030 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1031 | return true; |
| 1032 | } |
| 1033 | |
| 1034 | LOG(INFO) << __func__ << " resetting update state and deleting snapshots."; |
| 1035 | TEST_AND_RETURN_FALSE(prefs != nullptr); |
| 1036 | |
| 1037 | // If the device has already booted into the target slot, |
| 1038 | // ResetUpdateProgress may pass but CancelUpdate fails. |
| 1039 | // This is expected. A scheduled CleanupPreviousUpdateAction should free |
| 1040 | // space when it is done. |
| 1041 | TEST_AND_RETURN_FALSE(DeltaPerformer::ResetUpdateProgress( |
| 1042 | prefs, false /* quick */, false /* skip dynamic partitions metadata */)); |
| 1043 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 1044 | if (ExpectMetadataMounted()) { |
| 1045 | TEST_AND_RETURN_FALSE(snapshot_->CancelUpdate()); |
| 1046 | } else { |
| 1047 | LOG(INFO) << "Skip cancelling update in ResetUpdate because /metadata is " |
| 1048 | << "not mounted"; |
| 1049 | } |
Yifan Hong | 6a6d0f1 | 2020-03-11 13:20:52 -0700 | [diff] [blame] | 1050 | |
| 1051 | return true; |
| 1052 | } |
| 1053 | |
Yifan Hong | 4d7c5eb | 2020-04-03 11:31:50 -0700 | [diff] [blame] | 1054 | bool DynamicPartitionControlAndroid::ExpectMetadataMounted() { |
| 1055 | // No need to mount metadata for non-Virtual A/B devices. |
| 1056 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1057 | return false; |
| 1058 | } |
| 1059 | // Intentionally not checking |metadata_device_| in Android mode. |
| 1060 | // /metadata should always be mounted in Android mode. If it isn't, let caller |
| 1061 | // fails when calling into SnapshotManager. |
| 1062 | if (!IsRecovery()) { |
| 1063 | return true; |
| 1064 | } |
| 1065 | // In recovery mode, explicitly check |metadata_device_|. |
| 1066 | return metadata_device_ != nullptr; |
| 1067 | } |
| 1068 | |
| 1069 | bool DynamicPartitionControlAndroid::EnsureMetadataMounted() { |
| 1070 | // No need to mount metadata for non-Virtual A/B devices. |
| 1071 | if (!GetVirtualAbFeatureFlag().IsEnabled()) { |
| 1072 | return true; |
| 1073 | } |
| 1074 | |
| 1075 | if (metadata_device_ == nullptr) { |
| 1076 | metadata_device_ = snapshot_->EnsureMetadataMounted(); |
| 1077 | } |
| 1078 | return metadata_device_ != nullptr; |
| 1079 | } |
| 1080 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 1081 | } // namespace chromeos_update_engine |