Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2023 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 | #include "task.h" |
Daniel Zheng | 7627b54 | 2023-04-13 13:43:17 -0700 | [diff] [blame] | 17 | |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 18 | #include <iostream> |
Daniel Zheng | 7627b54 | 2023-04-13 13:43:17 -0700 | [diff] [blame] | 19 | |
| 20 | #include <android-base/logging.h> |
| 21 | #include <android-base/parseint.h> |
| 22 | |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 23 | #include "fastboot.h" |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 24 | #include "filesystem.h" |
| 25 | #include "super_flash_helper.h" |
Daniel Zheng | 29a211c | 2023-03-10 07:23:49 +0000 | [diff] [blame] | 26 | #include "util.h" |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 27 | |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 28 | using namespace std::string_literals; |
Daniel Zheng | 5a9905a | 2023-05-23 10:51:01 -0700 | [diff] [blame] | 29 | FlashTask::FlashTask(const std::string& slot, const std::string& pname, const std::string& fname, |
Daniel Zheng | 791a83b | 2023-05-23 10:42:39 -0700 | [diff] [blame] | 30 | const bool apply_vbmeta, const FlashingPlan* fp) |
| 31 | : pname_(pname), fname_(fname), slot_(slot), apply_vbmeta_(apply_vbmeta), fp_(fp) {} |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 32 | |
| 33 | void FlashTask::Run() { |
| 34 | auto flash = [&](const std::string& partition) { |
Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 35 | if (should_flash_in_userspace(partition) && !is_userspace_fastboot()) { |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 36 | die("The partition you are trying to flash is dynamic, and " |
| 37 | "should be flashed via fastbootd. Please run:\n" |
| 38 | "\n" |
| 39 | " fastboot reboot fastboot\n" |
| 40 | "\n" |
| 41 | "And try again. If you are intentionally trying to " |
| 42 | "overwrite a fixed partition, use --force."); |
| 43 | } |
Daniel Zheng | 791a83b | 2023-05-23 10:42:39 -0700 | [diff] [blame] | 44 | do_flash(partition.c_str(), fname_.c_str(), apply_vbmeta_, fp_); |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 45 | }; |
| 46 | do_for_partitions(pname_, slot_, flash, true); |
| 47 | } |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 48 | |
Daniel Zheng | 665a460 | 2023-06-05 11:24:59 -0700 | [diff] [blame] | 49 | std::string FlashTask::ToString() { |
| 50 | std::string apply_vbmeta_string = ""; |
| 51 | if (apply_vbmeta_) { |
| 52 | apply_vbmeta_string = " --apply_vbmeta"; |
| 53 | } |
| 54 | return "flash" + apply_vbmeta_string + " " + pname_ + " " + fname_; |
| 55 | } |
| 56 | |
Daniel Zheng | 29a211c | 2023-03-10 07:23:49 +0000 | [diff] [blame] | 57 | std::string FlashTask::GetPartitionAndSlot() { |
| 58 | auto slot = slot_; |
| 59 | if (slot.empty()) { |
| 60 | slot = get_current_slot(); |
| 61 | } |
| 62 | if (slot.empty()) { |
| 63 | return pname_; |
| 64 | } |
| 65 | if (slot == "all") { |
| 66 | LOG(FATAL) << "Cannot retrieve a singular name when using all slots"; |
| 67 | } |
| 68 | return pname_ + "_" + slot; |
| 69 | } |
| 70 | |
Daniel Zheng | e6dbd4f | 2023-04-10 09:53:08 -0700 | [diff] [blame] | 71 | RebootTask::RebootTask(const FlashingPlan* fp) : fp_(fp){}; |
| 72 | RebootTask::RebootTask(const FlashingPlan* fp, const std::string& reboot_target) |
Daniel Zheng | 43987c9 | 2023-03-07 18:20:53 +0000 | [diff] [blame] | 73 | : reboot_target_(reboot_target), fp_(fp){}; |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 74 | |
| 75 | void RebootTask::Run() { |
Daniel Zheng | 77af6af | 2023-04-20 14:30:28 -0700 | [diff] [blame] | 76 | if (reboot_target_ == "fastboot") { |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 77 | if (!is_userspace_fastboot()) { |
| 78 | reboot_to_userspace_fastboot(); |
Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 79 | fp_->fb->WaitForDisconnect(); |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 80 | } |
| 81 | } else if (reboot_target_ == "recovery") { |
Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 82 | fp_->fb->RebootTo("recovery"); |
| 83 | fp_->fb->WaitForDisconnect(); |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 84 | } else if (reboot_target_ == "bootloader") { |
Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 85 | fp_->fb->RebootTo("bootloader"); |
| 86 | fp_->fb->WaitForDisconnect(); |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 87 | } else if (reboot_target_ == "") { |
Daniel Zheng | bc01da5 | 2023-02-23 03:25:52 +0000 | [diff] [blame] | 88 | fp_->fb->Reboot(); |
| 89 | fp_->fb->WaitForDisconnect(); |
Daniel Zheng | 71b3b43 | 2023-01-30 17:43:00 +0000 | [diff] [blame] | 90 | } else { |
| 91 | syntax_error("unknown reboot target %s", reboot_target_.c_str()); |
| 92 | } |
| 93 | } |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 94 | |
Daniel Zheng | 665a460 | 2023-06-05 11:24:59 -0700 | [diff] [blame] | 95 | std::string RebootTask::ToString() { |
| 96 | return "reboot " + reboot_target_; |
| 97 | } |
| 98 | |
Daniel Zheng | 3e04857 | 2023-06-21 15:21:06 -0700 | [diff] [blame^] | 99 | OptimizedFlashSuperTask::OptimizedFlashSuperTask(const std::string& super_name, |
| 100 | std::unique_ptr<SuperFlashHelper> helper, |
| 101 | SparsePtr sparse_layout, uint64_t super_size, |
| 102 | const FlashingPlan* fp) |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 103 | : super_name_(super_name), |
| 104 | helper_(std::move(helper)), |
David Anderson | 74c7807 | 2023-03-16 21:21:28 -0700 | [diff] [blame] | 105 | sparse_layout_(std::move(sparse_layout)), |
Daniel Zheng | 5769b26 | 2023-06-21 14:41:11 -0700 | [diff] [blame] | 106 | super_size_(super_size), |
| 107 | fp_(fp) {} |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 108 | |
Daniel Zheng | 3e04857 | 2023-06-21 15:21:06 -0700 | [diff] [blame^] | 109 | void OptimizedFlashSuperTask::Run() { |
David Anderson | 74c7807 | 2023-03-16 21:21:28 -0700 | [diff] [blame] | 110 | // Use the reported super partition size as the upper limit, rather than |
| 111 | // sparse_file_len, which (1) can fail and (2) is kind of expensive, since |
| 112 | // it will map in all of the embedded fds. |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 113 | std::vector<SparsePtr> files; |
Daniel Zheng | 5769b26 | 2023-06-21 14:41:11 -0700 | [diff] [blame] | 114 | if (int limit = get_sparse_limit(super_size_, fp_)) { |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 115 | files = resparse_file(sparse_layout_.get(), limit); |
| 116 | } else { |
| 117 | files.emplace_back(std::move(sparse_layout_)); |
| 118 | } |
| 119 | |
| 120 | // Send the data to the device. |
| 121 | flash_partition_files(super_name_, files); |
| 122 | } |
Daniel Zheng | 3e04857 | 2023-06-21 15:21:06 -0700 | [diff] [blame^] | 123 | std::string OptimizedFlashSuperTask::ToString() { |
Daniel Zheng | 665a460 | 2023-06-05 11:24:59 -0700 | [diff] [blame] | 124 | return "optimized-flash-super"; |
| 125 | } |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 126 | |
Daniel Zheng | 3e04857 | 2023-06-21 15:21:06 -0700 | [diff] [blame^] | 127 | std::unique_ptr<OptimizedFlashSuperTask> OptimizedFlashSuperTask::Initialize( |
Daniel Zheng | 29a211c | 2023-03-10 07:23:49 +0000 | [diff] [blame] | 128 | const FlashingPlan* fp, std::vector<ImageEntry>& os_images) { |
Daniel Zheng | d62002c | 2023-06-21 14:27:35 -0700 | [diff] [blame] | 129 | if (!fp->should_optimize_flash_super) { |
| 130 | LOG(INFO) << "super optimization is disabled"; |
| 131 | return nullptr; |
| 132 | } |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 133 | if (!supports_AB()) { |
| 134 | LOG(VERBOSE) << "Cannot optimize flashing super on non-AB device"; |
| 135 | return nullptr; |
| 136 | } |
Daniel Zheng | 1e6456b | 2023-04-10 09:35:48 -0700 | [diff] [blame] | 137 | if (fp->slot_override == "all") { |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 138 | LOG(VERBOSE) << "Cannot optimize flashing super for all slots"; |
| 139 | return nullptr; |
| 140 | } |
| 141 | |
| 142 | // Does this device use dynamic partitions at all? |
| 143 | unique_fd fd = fp->source->OpenFile("super_empty.img"); |
| 144 | |
| 145 | if (fd < 0) { |
| 146 | LOG(VERBOSE) << "could not open super_empty.img"; |
| 147 | return nullptr; |
| 148 | } |
| 149 | |
| 150 | std::string super_name; |
| 151 | // Try to find whether there is a super partition. |
| 152 | if (fp->fb->GetVar("super-partition-name", &super_name) != fastboot::SUCCESS) { |
| 153 | super_name = "super"; |
| 154 | } |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 155 | |
David Anderson | 74c7807 | 2023-03-16 21:21:28 -0700 | [diff] [blame] | 156 | uint64_t partition_size; |
| 157 | std::string partition_size_str; |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 158 | if (fp->fb->GetVar("partition-size:" + super_name, &partition_size_str) != fastboot::SUCCESS) { |
| 159 | LOG(VERBOSE) << "Cannot optimize super flashing: could not determine super partition"; |
| 160 | return nullptr; |
| 161 | } |
David Anderson | 74c7807 | 2023-03-16 21:21:28 -0700 | [diff] [blame] | 162 | partition_size_str = fb_fix_numeric_var(partition_size_str); |
| 163 | if (!android::base::ParseUint(partition_size_str, &partition_size)) { |
| 164 | LOG(VERBOSE) << "Could not parse " << super_name << " size: " << partition_size_str; |
| 165 | return nullptr; |
| 166 | } |
| 167 | |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 168 | std::unique_ptr<SuperFlashHelper> helper = std::make_unique<SuperFlashHelper>(*fp->source); |
| 169 | if (!helper->Open(fd)) { |
| 170 | return nullptr; |
| 171 | } |
| 172 | |
| 173 | for (const auto& entry : os_images) { |
Kelvin Zhang | 2a4a45f | 2023-04-03 20:44:05 +0000 | [diff] [blame] | 174 | auto partition = GetPartitionName(entry, fp->current_slot); |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 175 | auto image = entry.first; |
| 176 | |
| 177 | if (!helper->AddPartition(partition, image->img_name, image->optional_if_no_image)) { |
| 178 | return nullptr; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | auto s = helper->GetSparseLayout(); |
| 183 | if (!s) return nullptr; |
| 184 | |
| 185 | // Remove images that we already flashed, just in case we have non-dynamic OS images. |
| 186 | auto remove_if_callback = [&](const ImageEntry& entry) -> bool { |
Kelvin Zhang | 2a4a45f | 2023-04-03 20:44:05 +0000 | [diff] [blame] | 187 | return helper->WillFlash(GetPartitionName(entry, fp->current_slot)); |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 188 | }; |
| 189 | os_images.erase(std::remove_if(os_images.begin(), os_images.end(), remove_if_callback), |
| 190 | os_images.end()); |
Daniel Zheng | 3e04857 | 2023-06-21 15:21:06 -0700 | [diff] [blame^] | 191 | return std::make_unique<OptimizedFlashSuperTask>(super_name, std::move(helper), std::move(s), |
| 192 | partition_size, fp); |
Daniel Zheng | 47d70a5 | 2023-02-14 17:44:40 +0000 | [diff] [blame] | 193 | } |
Daniel Zheng | 6bb8baa | 2023-03-03 07:14:23 +0000 | [diff] [blame] | 194 | |
Daniel Zheng | 3e04857 | 2023-06-21 15:21:06 -0700 | [diff] [blame^] | 195 | std::unique_ptr<OptimizedFlashSuperTask> OptimizedFlashSuperTask::InitializeFromTasks( |
Daniel Zheng | 29a211c | 2023-03-10 07:23:49 +0000 | [diff] [blame] | 196 | const FlashingPlan* fp, std::vector<std::unique_ptr<Task>>& tasks) { |
Daniel Zheng | d62002c | 2023-06-21 14:27:35 -0700 | [diff] [blame] | 197 | if (!fp->should_optimize_flash_super) { |
| 198 | LOG(INFO) << "super optimization is disabled"; |
| 199 | return nullptr; |
| 200 | } |
Daniel Zheng | 29a211c | 2023-03-10 07:23:49 +0000 | [diff] [blame] | 201 | if (!supports_AB()) { |
| 202 | LOG(VERBOSE) << "Cannot optimize flashing super on non-AB device"; |
| 203 | return nullptr; |
| 204 | } |
| 205 | if (fp->slot_override == "all") { |
| 206 | LOG(VERBOSE) << "Cannot optimize flashing super for all slots"; |
| 207 | return nullptr; |
| 208 | } |
| 209 | |
| 210 | // Does this device use dynamic partitions at all? |
| 211 | unique_fd fd = fp->source->OpenFile("super_empty.img"); |
| 212 | |
| 213 | if (fd < 0) { |
| 214 | LOG(VERBOSE) << "could not open super_empty.img"; |
| 215 | return nullptr; |
| 216 | } |
| 217 | |
| 218 | std::string super_name; |
| 219 | // Try to find whether there is a super partition. |
| 220 | if (fp->fb->GetVar("super-partition-name", &super_name) != fastboot::SUCCESS) { |
| 221 | super_name = "super"; |
| 222 | } |
| 223 | uint64_t partition_size; |
| 224 | std::string partition_size_str; |
| 225 | if (fp->fb->GetVar("partition-size:" + super_name, &partition_size_str) != fastboot::SUCCESS) { |
| 226 | LOG(VERBOSE) << "Cannot optimize super flashing: could not determine super partition"; |
| 227 | return nullptr; |
| 228 | } |
| 229 | partition_size_str = fb_fix_numeric_var(partition_size_str); |
| 230 | if (!android::base::ParseUint(partition_size_str, &partition_size)) { |
| 231 | LOG(VERBOSE) << "Could not parse " << super_name << " size: " << partition_size_str; |
| 232 | return nullptr; |
| 233 | } |
| 234 | |
| 235 | std::unique_ptr<SuperFlashHelper> helper = std::make_unique<SuperFlashHelper>(*fp->source); |
| 236 | if (!helper->Open(fd)) { |
| 237 | return nullptr; |
| 238 | } |
| 239 | |
| 240 | for (const auto& task : tasks) { |
| 241 | if (auto flash_task = task->AsFlashTask()) { |
Daniel Zheng | 2775df6 | 2023-05-25 15:14:59 -0700 | [diff] [blame] | 242 | auto partition = flash_task->GetPartitionAndSlot(); |
| 243 | if (!helper->AddPartition(partition, flash_task->GetImageName(), false)) { |
| 244 | return nullptr; |
Daniel Zheng | 29a211c | 2023-03-10 07:23:49 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | auto s = helper->GetSparseLayout(); |
| 250 | if (!s) return nullptr; |
| 251 | // Remove images that we already flashed, just in case we have non-dynamic OS images. |
| 252 | auto remove_if_callback = [&](const auto& task) -> bool { |
| 253 | if (auto flash_task = task->AsFlashTask()) { |
| 254 | return helper->WillFlash(flash_task->GetPartitionAndSlot()); |
| 255 | } else if (auto update_super_task = task->AsUpdateSuperTask()) { |
| 256 | return true; |
| 257 | } else if (auto reboot_task = task->AsRebootTask()) { |
| 258 | return true; |
| 259 | } |
| 260 | return false; |
| 261 | }; |
| 262 | tasks.erase(std::remove_if(tasks.begin(), tasks.end(), remove_if_callback), tasks.end()); |
| 263 | |
Daniel Zheng | 3e04857 | 2023-06-21 15:21:06 -0700 | [diff] [blame^] | 264 | return std::make_unique<OptimizedFlashSuperTask>(super_name, std::move(helper), std::move(s), |
| 265 | partition_size, fp); |
Daniel Zheng | 29a211c | 2023-03-10 07:23:49 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Daniel Zheng | e6dbd4f | 2023-04-10 09:53:08 -0700 | [diff] [blame] | 268 | UpdateSuperTask::UpdateSuperTask(const FlashingPlan* fp) : fp_(fp) {} |
Daniel Zheng | 6bb8baa | 2023-03-03 07:14:23 +0000 | [diff] [blame] | 269 | |
| 270 | void UpdateSuperTask::Run() { |
| 271 | unique_fd fd = fp_->source->OpenFile("super_empty.img"); |
| 272 | if (fd < 0) { |
| 273 | return; |
| 274 | } |
| 275 | if (!is_userspace_fastboot()) { |
| 276 | reboot_to_userspace_fastboot(); |
| 277 | } |
| 278 | |
| 279 | std::string super_name; |
| 280 | if (fp_->fb->GetVar("super-partition-name", &super_name) != fastboot::RetCode::SUCCESS) { |
| 281 | super_name = "super"; |
| 282 | } |
| 283 | fp_->fb->Download(super_name, fd, get_file_size(fd)); |
| 284 | |
| 285 | std::string command = "update-super:" + super_name; |
| 286 | if (fp_->wants_wipe) { |
| 287 | command += ":wipe"; |
| 288 | } |
| 289 | fp_->fb->RawCommand(command, "Updating super partition"); |
| 290 | } |
Daniel Zheng | 665a460 | 2023-06-05 11:24:59 -0700 | [diff] [blame] | 291 | std::string UpdateSuperTask::ToString() { |
| 292 | return "update-super"; |
| 293 | } |
Daniel Zheng | 9f7bf7e | 2023-03-03 07:16:46 +0000 | [diff] [blame] | 294 | |
Daniel Zheng | e6dbd4f | 2023-04-10 09:53:08 -0700 | [diff] [blame] | 295 | ResizeTask::ResizeTask(const FlashingPlan* fp, const std::string& pname, const std::string& size, |
Daniel Zheng | 9f7bf7e | 2023-03-03 07:16:46 +0000 | [diff] [blame] | 296 | const std::string& slot) |
| 297 | : fp_(fp), pname_(pname), size_(size), slot_(slot) {} |
| 298 | |
| 299 | void ResizeTask::Run() { |
| 300 | auto resize_partition = [this](const std::string& partition) -> void { |
| 301 | if (is_logical(partition)) { |
| 302 | fp_->fb->ResizePartition(partition, size_); |
| 303 | } |
| 304 | }; |
| 305 | do_for_partitions(pname_, slot_, resize_partition, false); |
| 306 | } |
Daniel Zheng | aa70f4c | 2023-03-07 18:59:51 +0000 | [diff] [blame] | 307 | |
Daniel Zheng | 665a460 | 2023-06-05 11:24:59 -0700 | [diff] [blame] | 308 | std::string ResizeTask::ToString() { |
| 309 | return "resize " + pname_; |
| 310 | } |
| 311 | |
Daniel Zheng | e6dbd4f | 2023-04-10 09:53:08 -0700 | [diff] [blame] | 312 | DeleteTask::DeleteTask(const FlashingPlan* fp, const std::string& pname) : fp_(fp), pname_(pname){}; |
Daniel Zheng | aa70f4c | 2023-03-07 18:59:51 +0000 | [diff] [blame] | 313 | |
| 314 | void DeleteTask::Run() { |
| 315 | fp_->fb->DeletePartition(pname_); |
Daniel Zheng | 15e7783 | 2023-03-13 17:09:43 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Daniel Zheng | 665a460 | 2023-06-05 11:24:59 -0700 | [diff] [blame] | 318 | std::string DeleteTask::ToString() { |
| 319 | return "delete " + pname_; |
| 320 | } |
| 321 | |
Daniel Zheng | e6dbd4f | 2023-04-10 09:53:08 -0700 | [diff] [blame] | 322 | WipeTask::WipeTask(const FlashingPlan* fp, const std::string& pname) : fp_(fp), pname_(pname){}; |
Daniel Zheng | 15e7783 | 2023-03-13 17:09:43 +0000 | [diff] [blame] | 323 | |
| 324 | void WipeTask::Run() { |
| 325 | std::string partition_type; |
| 326 | if (fp_->fb->GetVar("partition-type:" + pname_, &partition_type) != fastboot::SUCCESS) { |
Daniel Zheng | 6f213b2 | 2023-03-28 22:47:04 +0000 | [diff] [blame] | 327 | LOG(ERROR) << "wipe task partition not found: " << pname_; |
Daniel Zheng | 15e7783 | 2023-03-13 17:09:43 +0000 | [diff] [blame] | 328 | return; |
| 329 | } |
| 330 | if (partition_type.empty()) return; |
Daniel Zheng | 6f213b2 | 2023-03-28 22:47:04 +0000 | [diff] [blame] | 331 | if (fp_->fb->Erase(pname_) != fastboot::SUCCESS) { |
| 332 | LOG(ERROR) << "wipe task erase failed with partition: " << pname_; |
| 333 | return; |
| 334 | } |
Daniel Zheng | 5769b26 | 2023-06-21 14:41:11 -0700 | [diff] [blame] | 335 | fb_perform_format(pname_, 1, partition_type, "", fp_->fs_options, fp_); |
Daniel Zheng | 15e7783 | 2023-03-13 17:09:43 +0000 | [diff] [blame] | 336 | } |
Daniel Zheng | 665a460 | 2023-06-05 11:24:59 -0700 | [diff] [blame] | 337 | |
| 338 | std::string WipeTask::ToString() { |
| 339 | return "erase " + pname_; |
| 340 | } |