From 954ff922eafdfb0883d0119147bec1c35cfcc653 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 1 Jun 2022 22:45:25 -0700 Subject: [PATCH] fastbootd: Add better logging for flashing failures. Bug: 233980876 Test: builds, fastboot flashall Change-Id: Icc81ac4d9a4ca76f7eb757df5524d95f488fcd8c --- fastboot/device/flashing.cpp | 11 ++++++++++- fastboot/device/main.cpp | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/fastboot/device/flashing.cpp b/fastboot/device/flashing.cpp index 06ffe0f68..05186a2ef 100644 --- a/fastboot/device/flashing.cpp +++ b/fastboot/device/flashing.cpp @@ -121,7 +121,12 @@ int FlashRawData(PartitionHandle* handle, const std::vector& downloaded_da int WriteCallback(void* priv, const void* data, size_t len) { PartitionHandle* handle = reinterpret_cast(priv); if (!data) { - return lseek64(handle->fd(), len, SEEK_CUR) >= 0 ? 0 : -errno; + if (lseek64(handle->fd(), len, SEEK_CUR) < 0) { + int rv = -errno; + PLOG(ERROR) << "lseek failed"; + return rv; + } + return 0; } return FlashRawDataChunk(handle, reinterpret_cast(data), len); } @@ -131,6 +136,7 @@ int FlashSparseData(PartitionHandle* handle, std::vector& downloaded_data) downloaded_data.size(), true, false); if (!file) { // Invalid sparse format + LOG(ERROR) << "Unable to open sparse data for flashing"; return -EINVAL; } return sparse_file_callback(file, false, false, WriteCallback, reinterpret_cast(handle)); @@ -175,10 +181,13 @@ int Flash(FastbootDevice* device, const std::string& partition_name) { std::vector data = std::move(device->download_data()); if (data.size() == 0) { + LOG(ERROR) << "Cannot flash empty data vector"; return -EINVAL; } uint64_t block_device_size = get_block_device_size(handle.fd()); if (data.size() > block_device_size) { + LOG(ERROR) << "Cannot flash " << data.size() << " bytes to block device of size " + << block_device_size; return -EOVERFLOW; } else if (data.size() < block_device_size && (partition_name == "boot" || partition_name == "boot_a" || diff --git a/fastboot/device/main.cpp b/fastboot/device/main.cpp index df9c9007d..08c935877 100644 --- a/fastboot/device/main.cpp +++ b/fastboot/device/main.cpp @@ -14,13 +14,30 @@ * limitations under the License. */ +#include + #include +#include +#include #include "fastboot_device.h" +static void LogSparseVerboseMessage(const char* fmt, ...) { + std::string message; + + va_list ap; + va_start(ap, fmt); + android::base::StringAppendV(&message, fmt, ap); + va_end(ap); + + LOG(ERROR) << "libsparse message: " << message; +} + int main(int /*argc*/, char* argv[]) { android::base::InitLogging(argv, &android::base::KernelLogger); + sparse_print_verbose = LogSparseVerboseMessage; + while (true) { FastbootDevice device; device.ExecuteCommands();