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" |
| 17 | |
| 18 | #include "fastboot.h" |
| 19 | #include "util.h" |
| 20 | |
| 21 | FlashTask::FlashTask(const std::string& _slot) : slot_(_slot){}; |
| 22 | FlashTask::FlashTask(const std::string& _slot, bool _force_flash) |
| 23 | : slot_(_slot), force_flash_(_force_flash) {} |
| 24 | FlashTask::FlashTask(const std::string& _slot, bool _force_flash, const std::string& _pname) |
| 25 | : pname_(_pname), fname_(find_item(_pname)), slot_(_slot), force_flash_(_force_flash) { |
| 26 | if (fname_.empty()) die("cannot determine image filename for '%s'", pname_.c_str()); |
| 27 | } |
| 28 | FlashTask::FlashTask(const std::string& _slot, bool _force_flash, const std::string& _pname, |
| 29 | const std::string& _fname) |
| 30 | : pname_(_pname), fname_(_fname), slot_(_slot), force_flash_(_force_flash) {} |
| 31 | |
| 32 | void FlashTask::Run() { |
| 33 | auto flash = [&](const std::string& partition) { |
| 34 | if (should_flash_in_userspace(partition) && !is_userspace_fastboot() && !force_flash_) { |
| 35 | die("The partition you are trying to flash is dynamic, and " |
| 36 | "should be flashed via fastbootd. Please run:\n" |
| 37 | "\n" |
| 38 | " fastboot reboot fastboot\n" |
| 39 | "\n" |
| 40 | "And try again. If you are intentionally trying to " |
| 41 | "overwrite a fixed partition, use --force."); |
| 42 | } |
| 43 | do_flash(partition.c_str(), fname_.c_str()); |
| 44 | }; |
| 45 | do_for_partitions(pname_, slot_, flash, true); |
| 46 | } |