Merge "Changed FlashTask and RebootTask to take in FlashingPlan"
This commit is contained in:
commit
78a0f7f1b2
3 changed files with 30 additions and 36 deletions
|
@ -2301,6 +2301,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
|||
|
||||
fastboot::FastBootDriver fastboot_driver(transport, driver_callbacks, false);
|
||||
fb = &fastboot_driver;
|
||||
fp->fb = &fastboot_driver;
|
||||
|
||||
const double start = now();
|
||||
|
||||
|
@ -2376,17 +2377,17 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
|||
} else if (command == FB_CMD_REBOOT) {
|
||||
if (args.size() == 1) {
|
||||
std::string reboot_target = next_arg(&args);
|
||||
reboot_task = std::make_unique<RebootTask>(fb, reboot_target);
|
||||
reboot_task = std::make_unique<RebootTask>(fp.get(), reboot_target);
|
||||
} else {
|
||||
reboot_task = std::make_unique<RebootTask>(fb);
|
||||
reboot_task = std::make_unique<RebootTask>(fp.get());
|
||||
}
|
||||
if (!args.empty()) syntax_error("junk after reboot command");
|
||||
} else if (command == FB_CMD_REBOOT_BOOTLOADER) {
|
||||
reboot_task = std::make_unique<RebootTask>(fb, "bootloader");
|
||||
reboot_task = std::make_unique<RebootTask>(fp.get(), "bootloader");
|
||||
} else if (command == FB_CMD_REBOOT_RECOVERY) {
|
||||
reboot_task = std::make_unique<RebootTask>(fb, "recovery");
|
||||
reboot_task = std::make_unique<RebootTask>(fp.get(), "recovery");
|
||||
} else if (command == FB_CMD_REBOOT_FASTBOOT) {
|
||||
reboot_task = std::make_unique<RebootTask>(fb, "fastboot");
|
||||
reboot_task = std::make_unique<RebootTask>(fp.get(), "fastboot");
|
||||
} else if (command == FB_CMD_CONTINUE) {
|
||||
fb->Continue();
|
||||
} else if (command == FB_CMD_BOOT) {
|
||||
|
@ -2407,7 +2408,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
|||
fname = find_item(pname);
|
||||
}
|
||||
if (fname.empty()) die("cannot determine image filename for '%s'", pname.c_str());
|
||||
FlashTask task(slot_override, fp->force_flash, pname, fname);
|
||||
FlashTask task(slot_override, pname, fname);
|
||||
task.Run();
|
||||
} else if (command == "flash:raw") {
|
||||
std::string partition = next_arg(&args);
|
||||
|
@ -2431,7 +2432,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
|||
} else {
|
||||
do_flashall(fp.get());
|
||||
}
|
||||
reboot_task = std::make_unique<RebootTask>(fb);
|
||||
reboot_task = std::make_unique<RebootTask>(fp.get());
|
||||
} else if (command == "update") {
|
||||
bool slot_all = (slot_override == "all");
|
||||
if (slot_all) {
|
||||
|
@ -2443,7 +2444,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
|
|||
filename = next_arg(&args);
|
||||
}
|
||||
do_update(filename.c_str(), fp.get());
|
||||
reboot_task = std::make_unique<RebootTask>(fb);
|
||||
reboot_task = std::make_unique<RebootTask>(fp.get());
|
||||
} else if (command == FB_CMD_SET_ACTIVE) {
|
||||
std::string slot = verify_slot(next_arg(&args), false);
|
||||
fb->SetActive(slot);
|
||||
|
|
|
@ -20,20 +20,16 @@
|
|||
#include "fastboot.h"
|
||||
#include "util.h"
|
||||
|
||||
FlashTask::FlashTask(const std::string& _slot) : slot_(_slot){};
|
||||
FlashTask::FlashTask(const std::string& _slot, bool _force_flash)
|
||||
: slot_(_slot), force_flash_(_force_flash) {}
|
||||
FlashTask::FlashTask(const std::string& _slot, bool _force_flash, const std::string& _pname)
|
||||
: pname_(_pname), fname_(find_item(_pname)), slot_(_slot), force_flash_(_force_flash) {
|
||||
FlashTask::FlashTask(const std::string& _slot, const std::string& _pname)
|
||||
: pname_(_pname), fname_(find_item(_pname)), slot_(_slot) {
|
||||
if (fname_.empty()) die("cannot determine image filename for '%s'", pname_.c_str());
|
||||
}
|
||||
FlashTask::FlashTask(const std::string& _slot, bool _force_flash, const std::string& _pname,
|
||||
const std::string& _fname)
|
||||
: pname_(_pname), fname_(_fname), slot_(_slot), force_flash_(_force_flash) {}
|
||||
FlashTask::FlashTask(const std::string& _slot, const std::string& _pname, const std::string& _fname)
|
||||
: pname_(_pname), fname_(_fname), slot_(_slot) {}
|
||||
|
||||
void FlashTask::Run() {
|
||||
auto flash = [&](const std::string& partition) {
|
||||
if (should_flash_in_userspace(partition) && !is_userspace_fastboot() && !force_flash_) {
|
||||
if (should_flash_in_userspace(partition) && !is_userspace_fastboot()) {
|
||||
die("The partition you are trying to flash is dynamic, and "
|
||||
"should be flashed via fastbootd. Please run:\n"
|
||||
"\n"
|
||||
|
@ -47,25 +43,25 @@ void FlashTask::Run() {
|
|||
do_for_partitions(pname_, slot_, flash, true);
|
||||
}
|
||||
|
||||
RebootTask::RebootTask(fastboot::FastBootDriver* _fb) : fb_(_fb){};
|
||||
RebootTask::RebootTask(fastboot::FastBootDriver* _fb, std::string _reboot_target)
|
||||
: reboot_target_(std::move(_reboot_target)), fb_(_fb){};
|
||||
RebootTask::RebootTask(FlashingPlan* _fp) : fp_(_fp){};
|
||||
RebootTask::RebootTask(FlashingPlan* _fp, const std::string& _reboot_target)
|
||||
: reboot_target_(_reboot_target), fp_(_fp){};
|
||||
|
||||
void RebootTask::Run() {
|
||||
if ((reboot_target_ == "userspace" || reboot_target_ == "fastboot")) {
|
||||
if (!is_userspace_fastboot()) {
|
||||
reboot_to_userspace_fastboot();
|
||||
fb_->WaitForDisconnect();
|
||||
fp_->fb->WaitForDisconnect();
|
||||
}
|
||||
} else if (reboot_target_ == "recovery") {
|
||||
fb_->RebootTo("recovery");
|
||||
fb_->WaitForDisconnect();
|
||||
fp_->fb->RebootTo("recovery");
|
||||
fp_->fb->WaitForDisconnect();
|
||||
} else if (reboot_target_ == "bootloader") {
|
||||
fb_->RebootTo("bootloader");
|
||||
fb_->WaitForDisconnect();
|
||||
fp_->fb->RebootTo("bootloader");
|
||||
fp_->fb->WaitForDisconnect();
|
||||
} else if (reboot_target_ == "") {
|
||||
fb_->Reboot();
|
||||
fb_->WaitForDisconnect();
|
||||
fp_->fb->Reboot();
|
||||
fp_->fb->WaitForDisconnect();
|
||||
} else {
|
||||
syntax_error("unknown reboot target %s", reboot_target_.c_str());
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "fastboot.h"
|
||||
#include "fastboot_driver.h"
|
||||
|
||||
class Task {
|
||||
|
@ -29,11 +30,8 @@ class Task {
|
|||
|
||||
class FlashTask : public Task {
|
||||
public:
|
||||
FlashTask(const std::string& _slot);
|
||||
FlashTask(const std::string& _slot, bool _force_flash);
|
||||
FlashTask(const std::string& _slot, bool _force_flash, const std::string& _pname);
|
||||
FlashTask(const std::string& _slot, bool _force_flash, const std::string& _pname,
|
||||
const std::string& _fname);
|
||||
FlashTask(const std::string& _slot, const std::string& _pname);
|
||||
FlashTask(const std::string& _slot, const std::string& _pname, const std::string& _fname);
|
||||
|
||||
void Run() override;
|
||||
~FlashTask() {}
|
||||
|
@ -42,17 +40,16 @@ class FlashTask : public Task {
|
|||
const std::string pname_;
|
||||
const std::string fname_;
|
||||
const std::string slot_;
|
||||
bool force_flash_ = false;
|
||||
};
|
||||
|
||||
class RebootTask : public Task {
|
||||
public:
|
||||
RebootTask(fastboot::FastBootDriver* _fb);
|
||||
RebootTask(fastboot::FastBootDriver* _fb, const std::string _reboot_target);
|
||||
RebootTask(FlashingPlan* _fp);
|
||||
RebootTask(FlashingPlan* _fp, const std::string& _reboot_target);
|
||||
void Run() override;
|
||||
~RebootTask() {}
|
||||
|
||||
private:
|
||||
const std::string reboot_target_ = "";
|
||||
fastboot::FastBootDriver* fb_;
|
||||
FlashingPlan* fp_;
|
||||
};
|
Loading…
Reference in a new issue