diff options
author | Yifan Hong <elsk@google.com> | 2021-02-16 19:37:32 -0800 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2021-03-17 15:38:06 -0700 |
commit | bcd27702071cb12df042883c4b120e9b5ebe5ecb (patch) | |
tree | a95374490e58affc8b576b4151d7476e8132fd4c /fastboot/fastboot_driver.cpp | |
parent | 17d469bd579a83f5cad372dd8b1db47d3e874830 (diff) |
fastboot driver: add fetch command in driver
The `fastboot fetch` command is a wrapper around
the fetch protocol. It:
- getvar max-fetch-size
- get the size of the partition
- read the data by chunks, chunk size = max-fetch-size.
The name of the partition is passed directly to the device
(with the usual has-slot magic for flashing etc.) If we support
fetching partitions other than vendor_boot in the future, no change
in the driver is needed.
Bug: 173654501
Test: manual
Change-Id: Ie576eea668234df236b096a372e65c5e91c1e48c
Diffstat (limited to 'fastboot/fastboot_driver.cpp')
-rw-r--r-- | fastboot/fastboot_driver.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/fastboot/fastboot_driver.cpp b/fastboot/fastboot_driver.cpp index a516a9130..14ee78555 100644 --- a/fastboot/fastboot_driver.cpp +++ b/fastboot/fastboot_driver.cpp @@ -30,6 +30,7 @@ #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -42,6 +43,7 @@ #include <android-base/file.h> #include <android-base/mapped_file.h> +#include <android-base/parseint.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/unique_fd.h> @@ -357,6 +359,29 @@ RetCode FastBootDriver::UploadInner(const std::string& outfile, std::string* res return ret; } +RetCode FastBootDriver::FetchToFd(const std::string& partition, android::base::borrowed_fd fd, + int64_t offset, int64_t size, std::string* response, + std::vector<std::string>* info) { + prolog_(android::base::StringPrintf("Fetching %s (offset=%" PRIx64 ", size=%" PRIx64 ")", + partition.c_str(), offset, size)); + std::string cmd = FB_CMD_FETCH ":" + partition; + if (offset >= 0) { + cmd += android::base::StringPrintf(":0x%08" PRIx64, offset); + if (size >= 0) { + cmd += android::base::StringPrintf(":0x%08" PRIx64, size); + } + } + RetCode ret = RunAndReadBuffer(cmd, response, info, [&](const char* data, uint64_t size) { + if (!android::base::WriteFully(fd, data, size)) { + error_ = android::base::StringPrintf("Cannot write: %s", strerror(errno)); + return IO_ERROR; + } + return SUCCESS; + }); + epilog_(ret); + return ret; +} + // Helpers void FastBootDriver::SetInfoCallback(std::function<void(const std::string&)> info) { info_ = info; |