Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 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 | |
Alex Deymo | 1b03f9f | 2015-12-09 00:38:36 -0800 | [diff] [blame] | 17 | #include "update_engine/boot_control_android.h" |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 18 | |
Sen Jiang | d944faa | 2018-08-22 18:46:39 -0700 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <utility> |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 21 | #include <vector> |
Sen Jiang | d944faa | 2018-08-22 18:46:39 -0700 | [diff] [blame] | 22 | |
Alex Deymo | aa26f62 | 2015-09-16 18:21:27 -0700 | [diff] [blame] | 23 | #include <base/bind.h> |
Alex Deymo | aa26f62 | 2015-09-16 18:21:27 -0700 | [diff] [blame] | 24 | #include <base/logging.h> |
Sen Jiang | d944faa | 2018-08-22 18:46:39 -0700 | [diff] [blame] | 25 | #include <bootloader_message/bootloader_message.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 26 | #include <brillo/message_loops/message_loop.h> |
David Anderson | d63cb3c | 2018-10-01 14:15:00 -0700 | [diff] [blame] | 27 | #include <fs_mgr.h> |
Mark Salyzyn | 62b42c8 | 2018-12-05 13:33:17 -0800 | [diff] [blame] | 28 | #include <fs_mgr_overlayfs.h> |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 29 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 30 | #include "update_engine/common/utils.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 31 | #include "update_engine/dynamic_partition_control_android.h" |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 32 | |
| 33 | using std::string; |
| 34 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 35 | using android::dm::DmDeviceState; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 36 | using android::hardware::hidl_string; |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 37 | using android::hardware::Return; |
| 38 | using android::hardware::boot::V1_0::BoolResult; |
| 39 | using android::hardware::boot::V1_0::CommandResult; |
| 40 | using android::hardware::boot::V1_0::IBootControl; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 41 | using Slot = chromeos_update_engine::BootControlInterface::Slot; |
Yifan Hong | 6b0a984 | 2018-10-16 16:54:18 -0700 | [diff] [blame] | 42 | using PartitionMetadata = |
| 43 | chromeos_update_engine::BootControlInterface::PartitionMetadata; |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 44 | |
| 45 | namespace { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 46 | |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 47 | auto StoreResultCallback(CommandResult* dest) { |
| 48 | return [dest](const CommandResult& result) { *dest = result; }; |
| 49 | } |
| 50 | } // namespace |
Alex Deymo | 44348e0 | 2016-07-29 16:22:26 -0700 | [diff] [blame] | 51 | |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 52 | namespace chromeos_update_engine { |
| 53 | |
| 54 | namespace boot_control { |
| 55 | |
| 56 | // Factory defined in boot_control.h. |
| 57 | std::unique_ptr<BootControlInterface> CreateBootControl() { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 58 | auto boot_control = std::make_unique<BootControlAndroid>(); |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 59 | if (!boot_control->Init()) { |
| 60 | return nullptr; |
| 61 | } |
Alex Vakulenko | ce8c8ee | 2016-04-08 08:59:26 -0700 | [diff] [blame] | 62 | return std::move(boot_control); |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace boot_control |
| 66 | |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 67 | bool BootControlAndroid::Init() { |
Chris Phoenix | afde8e8 | 2017-01-17 23:14:58 -0800 | [diff] [blame] | 68 | module_ = IBootControl::getService(); |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 69 | if (module_ == nullptr) { |
Steven Moreland | 927e00d | 2017-01-04 12:58:40 -0800 | [diff] [blame] | 70 | LOG(ERROR) << "Error getting bootctrl HIDL module."; |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 71 | return false; |
| 72 | } |
| 73 | |
Steven Moreland | 927e00d | 2017-01-04 12:58:40 -0800 | [diff] [blame] | 74 | LOG(INFO) << "Loaded boot control hidl hal."; |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 75 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 76 | dynamic_control_ = std::make_unique<DynamicPartitionControlAndroid>(); |
| 77 | |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 78 | return true; |
| 79 | } |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 80 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 81 | void BootControlAndroid::Cleanup() { |
| 82 | dynamic_control_->Cleanup(); |
| 83 | } |
| 84 | |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 85 | unsigned int BootControlAndroid::GetNumSlots() const { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 86 | return module_->getNumberSlots(); |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | BootControlInterface::Slot BootControlAndroid::GetCurrentSlot() const { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 90 | return module_->getCurrentSlot(); |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 93 | bool BootControlAndroid::GetSuffix(Slot slot, string* suffix) const { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 94 | auto store_suffix_cb = [&suffix](hidl_string cb_suffix) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 95 | *suffix = cb_suffix.c_str(); |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 96 | }; |
| 97 | Return<void> ret = module_->getSuffix(slot, store_suffix_cb); |
| 98 | |
Yifan Hong | 7b514b4 | 2016-12-21 13:02:00 -0800 | [diff] [blame] | 99 | if (!ret.isOk()) { |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 100 | LOG(ERROR) << "boot_control impl returned no suffix for slot " |
| 101 | << SlotName(slot); |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 102 | return false; |
| 103 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 104 | return true; |
| 105 | } |
| 106 | |
Yifan Hong | 124a460 | 2018-11-14 13:17:01 -0800 | [diff] [blame] | 107 | bool BootControlAndroid::IsSuperBlockDevice( |
| 108 | const base::FilePath& device_dir, |
| 109 | Slot slot, |
| 110 | const string& partition_name_suffix) const { |
| 111 | string source_device = |
| 112 | device_dir.Append(fs_mgr_get_super_partition_name(slot)).value(); |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame^] | 113 | auto source_metadata = |
| 114 | dynamic_control_->LoadMetadataBuilder(source_device, slot); |
Yifan Hong | 124a460 | 2018-11-14 13:17:01 -0800 | [diff] [blame] | 115 | return source_metadata->HasBlockDevice(partition_name_suffix); |
| 116 | } |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 117 | |
Yifan Hong | 124a460 | 2018-11-14 13:17:01 -0800 | [diff] [blame] | 118 | BootControlAndroid::DynamicPartitionDeviceStatus |
| 119 | BootControlAndroid::GetDynamicPartitionDevice( |
| 120 | const base::FilePath& device_dir, |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 121 | const string& partition_name_suffix, |
| 122 | Slot slot, |
Yifan Hong | 124a460 | 2018-11-14 13:17:01 -0800 | [diff] [blame] | 123 | string* device) const { |
Yifan Hong | 124a460 | 2018-11-14 13:17:01 -0800 | [diff] [blame] | 124 | string super_device = |
| 125 | device_dir.Append(fs_mgr_get_super_partition_name(slot)).value(); |
| 126 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame^] | 127 | auto builder = dynamic_control_->LoadMetadataBuilder(super_device, slot); |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 128 | |
| 129 | if (builder == nullptr) { |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 130 | LOG(ERROR) << "No metadata in slot " |
| 131 | << BootControlInterface::SlotName(slot); |
| 132 | return DynamicPartitionDeviceStatus::ERROR; |
| 133 | } |
| 134 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 135 | Slot current_slot = GetCurrentSlot(); |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 136 | if (builder->FindPartition(partition_name_suffix) == nullptr) { |
| 137 | LOG(INFO) << partition_name_suffix |
| 138 | << " is not in super partition metadata."; |
Yifan Hong | 124a460 | 2018-11-14 13:17:01 -0800 | [diff] [blame] | 139 | |
Yifan Hong | 124a460 | 2018-11-14 13:17:01 -0800 | [diff] [blame] | 140 | if (IsSuperBlockDevice(device_dir, current_slot, partition_name_suffix)) { |
| 141 | LOG(ERROR) << "The static partition " << partition_name_suffix |
| 142 | << " is a block device for current metadata (" |
| 143 | << fs_mgr_get_super_partition_name(current_slot) << ", slot " |
| 144 | << BootControlInterface::SlotName(current_slot) |
| 145 | << "). It cannot be used as a logical partition."; |
| 146 | return DynamicPartitionDeviceStatus::ERROR; |
| 147 | } |
| 148 | |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 149 | return DynamicPartitionDeviceStatus::TRY_STATIC; |
| 150 | } |
| 151 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 152 | if (slot == current_slot) { |
| 153 | if (dynamic_control_->GetState(partition_name_suffix) != |
| 154 | DmDeviceState::ACTIVE) { |
| 155 | LOG(WARNING) << partition_name_suffix << " is at current slot but it is " |
| 156 | << "not mapped. Now try to map it."; |
| 157 | } else { |
| 158 | if (dynamic_control_->GetDmDevicePathByName(partition_name_suffix, |
| 159 | device)) { |
| 160 | LOG(INFO) << partition_name_suffix |
| 161 | << " is mapped on device mapper: " << *device; |
| 162 | return DynamicPartitionDeviceStatus::SUCCESS; |
| 163 | } |
| 164 | LOG(ERROR) << partition_name_suffix << "is mapped but path is unknown."; |
| 165 | return DynamicPartitionDeviceStatus::ERROR; |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 166 | } |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Yifan Hong | 8546a71 | 2019-03-28 14:42:53 -0700 | [diff] [blame] | 169 | bool force_writable = slot != current_slot; |
| 170 | if (dynamic_control_->MapPartitionOnDeviceMapper( |
| 171 | super_device, partition_name_suffix, slot, force_writable, device)) { |
| 172 | return DynamicPartitionDeviceStatus::SUCCESS; |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 173 | } |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 174 | return DynamicPartitionDeviceStatus::ERROR; |
| 175 | } |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 176 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 177 | bool BootControlAndroid::GetPartitionDevice(const string& partition_name, |
| 178 | Slot slot, |
| 179 | string* device) const { |
| 180 | string suffix; |
| 181 | if (!GetSuffix(slot, &suffix)) { |
| 182 | return false; |
| 183 | } |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 184 | const string partition_name_suffix = partition_name + suffix; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 185 | |
| 186 | string device_dir_str; |
| 187 | if (!dynamic_control_->GetDeviceDir(&device_dir_str)) { |
| 188 | return false; |
| 189 | } |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 190 | base::FilePath device_dir(device_dir_str); |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 191 | |
Yifan Hong | 1d9077f | 2018-12-07 12:09:37 -0800 | [diff] [blame] | 192 | // When looking up target partition devices, treat them as static if the |
| 193 | // current payload doesn't encode them as dynamic partitions. This may happen |
| 194 | // when applying a retrofit update on top of a dynamic-partitions-enabled |
| 195 | // build. |
| 196 | if (dynamic_control_->IsDynamicPartitionsEnabled() && |
| 197 | (slot == GetCurrentSlot() || is_target_dynamic_)) { |
| 198 | switch (GetDynamicPartitionDevice( |
| 199 | device_dir, partition_name_suffix, slot, device)) { |
| 200 | case DynamicPartitionDeviceStatus::SUCCESS: |
| 201 | return true; |
| 202 | case DynamicPartitionDeviceStatus::TRY_STATIC: |
| 203 | break; |
| 204 | case DynamicPartitionDeviceStatus::ERROR: // fallthrough |
| 205 | default: |
| 206 | return false; |
| 207 | } |
Yifan Hong | ae04e19 | 2018-10-29 11:00:28 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | base::FilePath path = device_dir.Append(partition_name_suffix); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 211 | if (!dynamic_control_->DeviceExists(path.value())) { |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 212 | LOG(ERROR) << "Device file " << path.value() << " does not exist."; |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | *device = path.value(); |
| 217 | return true; |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | bool BootControlAndroid::IsSlotBootable(Slot slot) const { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 221 | Return<BoolResult> ret = module_->isSlotBootable(slot); |
Yifan Hong | 7b514b4 | 2016-12-21 13:02:00 -0800 | [diff] [blame] | 222 | if (!ret.isOk()) { |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 223 | LOG(ERROR) << "Unable to determine if slot " << SlotName(slot) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 224 | << " is bootable: " << ret.description(); |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 225 | return false; |
| 226 | } |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 227 | if (ret == BoolResult::INVALID_SLOT) { |
| 228 | LOG(ERROR) << "Invalid slot: " << SlotName(slot); |
| 229 | return false; |
| 230 | } |
| 231 | return ret == BoolResult::TRUE; |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | bool BootControlAndroid::MarkSlotUnbootable(Slot slot) { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 235 | CommandResult result; |
| 236 | auto ret = module_->setSlotAsUnbootable(slot, StoreResultCallback(&result)); |
Yifan Hong | 7b514b4 | 2016-12-21 13:02:00 -0800 | [diff] [blame] | 237 | if (!ret.isOk()) { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 238 | LOG(ERROR) << "Unable to call MarkSlotUnbootable for slot " |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 239 | << SlotName(slot) << ": " << ret.description(); |
David Zeuthen | 753fadc | 2015-09-15 16:34:09 -0400 | [diff] [blame] | 240 | return false; |
| 241 | } |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 242 | if (!result.success) { |
| 243 | LOG(ERROR) << "Unable to mark slot " << SlotName(slot) |
| 244 | << " as unbootable: " << result.errMsg.c_str(); |
| 245 | } |
| 246 | return result.success; |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 249 | bool BootControlAndroid::SetActiveBootSlot(Slot slot) { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 250 | CommandResult result; |
| 251 | auto ret = module_->setActiveBootSlot(slot, StoreResultCallback(&result)); |
Yifan Hong | 7b514b4 | 2016-12-21 13:02:00 -0800 | [diff] [blame] | 252 | if (!ret.isOk()) { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 253 | LOG(ERROR) << "Unable to call SetActiveBootSlot for slot " << SlotName(slot) |
Yifan Hong | 7b514b4 | 2016-12-21 13:02:00 -0800 | [diff] [blame] | 254 | << ": " << ret.description(); |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 255 | return false; |
Alex Deymo | 29dcbf3 | 2016-10-06 13:33:20 -0700 | [diff] [blame] | 256 | } |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 257 | if (!result.success) { |
| 258 | LOG(ERROR) << "Unable to set the active slot to slot " << SlotName(slot) |
| 259 | << ": " << result.errMsg.c_str(); |
| 260 | } |
| 261 | return result.success; |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Alex Deymo | aa26f62 | 2015-09-16 18:21:27 -0700 | [diff] [blame] | 264 | bool BootControlAndroid::MarkBootSuccessfulAsync( |
| 265 | base::Callback<void(bool)> callback) { |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 266 | CommandResult result; |
| 267 | auto ret = module_->markBootSuccessful(StoreResultCallback(&result)); |
Yifan Hong | 7b514b4 | 2016-12-21 13:02:00 -0800 | [diff] [blame] | 268 | if (!ret.isOk()) { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 269 | LOG(ERROR) << "Unable to call MarkBootSuccessful: " << ret.description(); |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 270 | return false; |
| 271 | } |
| 272 | if (!result.success) { |
| 273 | LOG(ERROR) << "Unable to mark boot successful: " << result.errMsg.c_str(); |
Alex Deymo | aa26f62 | 2015-09-16 18:21:27 -0700 | [diff] [blame] | 274 | } |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 275 | return brillo::MessageLoop::current()->PostTask( |
Connor O'Brien | cee6ad9 | 2016-11-21 13:53:52 -0800 | [diff] [blame] | 276 | FROM_HERE, base::Bind(callback, result.success)) != |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 277 | brillo::MessageLoop::kTaskIdNull; |
Alex Deymo | aa26f62 | 2015-09-16 18:21:27 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 280 | bool BootControlAndroid::InitPartitionMetadata( |
Tao Bao | 3406c77 | 2019-01-02 15:34:35 -0800 | [diff] [blame] | 281 | Slot target_slot, |
| 282 | const PartitionMetadata& partition_metadata, |
| 283 | bool update_metadata) { |
Mark Salyzyn | 62b42c8 | 2018-12-05 13:33:17 -0800 | [diff] [blame] | 284 | if (fs_mgr_overlayfs_is_setup()) { |
| 285 | // Non DAP devices can use overlayfs as well. |
| 286 | LOG(WARNING) |
| 287 | << "overlayfs overrides are active and can interfere with our " |
| 288 | "resources.\n" |
| 289 | << "run adb enable-verity to deactivate if required and try again."; |
| 290 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 291 | if (!dynamic_control_->IsDynamicPartitionsEnabled()) { |
| 292 | return true; |
| 293 | } |
| 294 | |
Yifan Hong | 1d9077f | 2018-12-07 12:09:37 -0800 | [diff] [blame] | 295 | auto source_slot = GetCurrentSlot(); |
| 296 | if (target_slot == source_slot) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 297 | LOG(ERROR) << "Cannot call InitPartitionMetadata on current slot."; |
| 298 | return false; |
| 299 | } |
| 300 | |
Yifan Hong | 1d9077f | 2018-12-07 12:09:37 -0800 | [diff] [blame] | 301 | // Although the current build supports dynamic partitions, the given payload |
| 302 | // doesn't use it for target partitions. This could happen when applying a |
| 303 | // retrofit update. Skip updating the partition metadata for the target slot. |
| 304 | is_target_dynamic_ = !partition_metadata.groups.empty(); |
| 305 | if (!is_target_dynamic_) { |
| 306 | return true; |
| 307 | } |
| 308 | |
Tao Bao | 3406c77 | 2019-01-02 15:34:35 -0800 | [diff] [blame] | 309 | if (!update_metadata) { |
| 310 | return true; |
| 311 | } |
| 312 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame^] | 313 | return dynamic_control_->PreparePartitionsForUpdate( |
| 314 | source_slot, target_slot, partition_metadata); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Alex Deymo | b17327c | 2015-09-04 10:29:00 -0700 | [diff] [blame] | 317 | } // namespace chromeos_update_engine |