blob: 09666aaa983009d786563c8d6cbd7241f1daeda8 [file] [log] [blame]
Tom Cherry9027af02018-09-24 15:48:09 -07001/*
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 Zheng1a01a1c2023-01-30 23:29:50 +000028#pragma once
Tom Cherry9027af02018-09-24 15:48:09 -070029
Daniel Zheng0d307182023-01-31 21:07:53 +000030#include <string>
Daniel Zheng7df2ab92023-02-21 18:22:08 +000031#include "fastboot_driver.h"
32#include "util.h"
Daniel Zheng0d307182023-01-31 21:07:53 +000033
Tom Cherry9027af02018-09-24 15:48:09 -070034#include <bootimg.h>
35
Dmitrii Merkurevcdbfa7a2023-03-01 23:50:05 +000036#include "result.h"
37#include "socket.h"
38#include "util.h"
39
Tom Cherry9027af02018-09-24 15:48:09 -070040class FastBootTool {
41 public:
42 int Main(int argc, char* argv[]);
43
44 void ParseOsPatchLevel(boot_img_hdr_v1*, const char*);
45 void ParseOsVersion(boot_img_hdr_v1*, const char*);
Jaegeuk Kim638d05e2020-11-09 08:54:13 -080046 unsigned ParseFsOption(const char*);
Tom Cherry9027af02018-09-24 15:48:09 -070047};
Daniel Zheng0d307182023-01-31 21:07:53 +000048
Daniel Zheng7df2ab92023-02-21 18:22:08 +000049enum class ImageType {
50 // Must be flashed for device to boot into the kernel.
51 BootCritical,
52 // Normal partition to be flashed during "flashall".
53 Normal,
54 // Partition that is never flashed during "flashall".
55 Extra
56};
57
58struct Image {
59 std::string nickname;
60 std::string img_name;
61 std::string sig_name;
62 std::string part_name;
63 bool optional_if_no_image;
64 ImageType type;
65 bool IsSecondary() const { return nickname.empty(); }
66};
67
68using ImageEntry = std::pair<const Image*, std::string>;
69
70struct FlashingPlan {
71 // If the image uses the default slot, or the user specified "all", then
72 // the paired string will be empty. If the image requests a specific slot
73 // (for example, system_other) it is specified instead.
74 ImageSource* source;
75 bool wants_wipe = false;
76 bool skip_reboot = false;
77 bool wants_set_active = false;
78 bool skip_secondary = false;
79 bool force_flash = false;
80
81 std::string slot;
82 std::string current_slot;
83 std::string secondary_slot;
84 fastboot::FastBootDriver* fb;
85
86};
87
Daniel Zheng0d307182023-01-31 21:07:53 +000088bool should_flash_in_userspace(const std::string& partition_name);
89bool is_userspace_fastboot();
90void do_flash(const char* pname, const char* fname);
91void do_for_partitions(const std::string& part, const std::string& slot,
92 const std::function<void(const std::string&)>& func, bool force_slot);
93std::string find_item(const std::string& item);
94void reboot_to_userspace_fastboot();
95void syntax_error(const char* fmt, ...);
Dmitrii Merkurevcdbfa7a2023-03-01 23:50:05 +000096
97struct NetworkSerial {
98 Socket::Protocol protocol;
99 std::string address;
100 int port;
101};
102
103Result<NetworkSerial, FastbootError> ParseNetworkSerial(const std::string& serial);