fastbootd: Add better logging for flashing failures.
Bug: 233980876
Test: builds, fastboot flashall
Change-Id: Icc81ac4d9a4ca76f7eb757df5524d95f488fcd8c
diff --git a/fastboot/device/flashing.cpp b/fastboot/device/flashing.cpp
index 06ffe0f..05186a2 100644
--- a/fastboot/device/flashing.cpp
+++ b/fastboot/device/flashing.cpp
@@ -121,7 +121,12 @@
int WriteCallback(void* priv, const void* data, size_t len) {
PartitionHandle* handle = reinterpret_cast<PartitionHandle*>(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<const char*>(data), len);
}
@@ -131,6 +136,7 @@
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<void*>(handle));
@@ -175,10 +181,13 @@
std::vector<char> 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 df9c900..08c9358 100644
--- a/fastboot/device/main.cpp
+++ b/fastboot/device/main.cpp
@@ -14,13 +14,30 @@
* limitations under the License.
*/
+#include <stdarg.h>
+
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <sparse/sparse.h>
#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();