Tom Cherry | 9027af0 | 2018-09-24 15:48:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
Daniel Zheng | 1a01a1c | 2023-01-30 23:29:50 +0000 | [diff] [blame] | 28 | #pragma once |
Tom Cherry | 9027af0 | 2018-09-24 15:48:09 -0700 | [diff] [blame] | 29 | |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 30 | #include <string> |
Daniel Zheng | 7df2ab9 | 2023-02-21 18:22:08 +0000 | [diff] [blame^] | 31 | #include "fastboot_driver.h" |
| 32 | #include "util.h" |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 33 | |
Tom Cherry | 9027af0 | 2018-09-24 15:48:09 -0700 | [diff] [blame] | 34 | #include <bootimg.h> |
| 35 | |
| 36 | class FastBootTool { |
| 37 | public: |
| 38 | int Main(int argc, char* argv[]); |
| 39 | |
| 40 | void ParseOsPatchLevel(boot_img_hdr_v1*, const char*); |
| 41 | void ParseOsVersion(boot_img_hdr_v1*, const char*); |
Jaegeuk Kim | 638d05e | 2020-11-09 08:54:13 -0800 | [diff] [blame] | 42 | unsigned ParseFsOption(const char*); |
Tom Cherry | 9027af0 | 2018-09-24 15:48:09 -0700 | [diff] [blame] | 43 | }; |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 44 | |
Daniel Zheng | 7df2ab9 | 2023-02-21 18:22:08 +0000 | [diff] [blame^] | 45 | enum class ImageType { |
| 46 | // Must be flashed for device to boot into the kernel. |
| 47 | BootCritical, |
| 48 | // Normal partition to be flashed during "flashall". |
| 49 | Normal, |
| 50 | // Partition that is never flashed during "flashall". |
| 51 | Extra |
| 52 | }; |
| 53 | |
| 54 | struct Image { |
| 55 | std::string nickname; |
| 56 | std::string img_name; |
| 57 | std::string sig_name; |
| 58 | std::string part_name; |
| 59 | bool optional_if_no_image; |
| 60 | ImageType type; |
| 61 | bool IsSecondary() const { return nickname.empty(); } |
| 62 | }; |
| 63 | |
| 64 | using ImageEntry = std::pair<const Image*, std::string>; |
| 65 | |
| 66 | struct FlashingPlan { |
| 67 | // If the image uses the default slot, or the user specified "all", then |
| 68 | // the paired string will be empty. If the image requests a specific slot |
| 69 | // (for example, system_other) it is specified instead. |
| 70 | ImageSource* source; |
| 71 | bool wants_wipe = false; |
| 72 | bool skip_reboot = false; |
| 73 | bool wants_set_active = false; |
| 74 | bool skip_secondary = false; |
| 75 | bool force_flash = false; |
| 76 | |
| 77 | std::string slot; |
| 78 | std::string current_slot; |
| 79 | std::string secondary_slot; |
| 80 | fastboot::FastBootDriver* fb; |
| 81 | |
| 82 | }; |
| 83 | |
Daniel Zheng | 0d30718 | 2023-01-31 21:07:53 +0000 | [diff] [blame] | 84 | bool should_flash_in_userspace(const std::string& partition_name); |
| 85 | bool is_userspace_fastboot(); |
| 86 | void do_flash(const char* pname, const char* fname); |
| 87 | void do_for_partitions(const std::string& part, const std::string& slot, |
| 88 | const std::function<void(const std::string&)>& func, bool force_slot); |
| 89 | std::string find_item(const std::string& item); |
| 90 | void reboot_to_userspace_fastboot(); |
| 91 | void syntax_error(const char* fmt, ...); |