diff options
author | David Anderson <dvander@google.com> | 2018-08-27 16:47:32 -0700 |
---|---|---|
committer | David Anderson <dvander@google.com> | 2018-08-28 09:07:40 -0700 |
commit | 1d887434daf1f8f7a8a4c13663b653941aa07673 (patch) | |
tree | 2cdb59d4f334f242f4040407078cce4deed1c08c /fastboot/engine.cpp | |
parent | 53ba407a891df5b7cff5f62592332af9222a68c8 (diff) |
fastboot: Automatically reboot to userspace fastboot.
In order to flash logical partitions, "flashall" must be run against
userspace fastboot. When the bootloader supports the "reboot-fastboot"
command, we now attempt to automatically reboot into userspace fastboot.
We do this by closing the transport, sleeping for one second, and then
polling for a new connection until one is available. FastBootDriver is
then assigned the new transport.
Bug: 78793464
Test: fastboot flashall on device with logical partitions, while booted
into bootloader fastboot
Change-Id: I6949871b93ab5e352784cabe0963c6ecfc0af36d
Diffstat (limited to 'fastboot/engine.cpp')
-rw-r--r-- | fastboot/engine.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp index 689064339..6a52b12bb 100644 --- a/fastboot/engine.cpp +++ b/fastboot/engine.cpp @@ -79,12 +79,18 @@ struct Action { static std::vector<std::unique_ptr<Action>> action_list; static fastboot::FastBootDriver* fb = nullptr; +static constexpr char kStatusFormat[] = "%-50s "; + void fb_init(fastboot::FastBootDriver& fbi) { fb = &fbi; auto cb = [](std::string& info) { fprintf(stderr, "(bootloader) %s\n", info.c_str()); }; fb->SetInfoCallback(cb); } +void fb_reinit(Transport* transport) { + fb->set_transport(transport); +} + const std::string fb_get_error() { return fb->Error(); } @@ -332,7 +338,7 @@ int64_t fb_execute_queue() { for (auto& a : action_list) { a->start = now(); if (!a->msg.empty()) { - fprintf(stderr, "%-50s ", a->msg.c_str()); + fprintf(stderr, kStatusFormat, a->msg.c_str()); verbose("\n"); } if (a->op == OP_DOWNLOAD) { @@ -372,3 +378,20 @@ int64_t fb_execute_queue() { action_list.clear(); return status; } + +bool fb_reboot_to_userspace() { + // First ensure that the queue is flushed. + fb_execute_queue(); + + fprintf(stderr, kStatusFormat, "Rebooting to userspace fastboot"); + verbose("\n"); + + if (fb->RebootTo("fastboot") != fastboot::RetCode::SUCCESS) { + fprintf(stderr, "FAILED (%s)\n", fb->Error().c_str()); + return false; + } + fprintf(stderr, "OKAY\n"); + + fb->set_transport(nullptr); + return true; +} |