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