Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 954ff922 authored by David Anderson's avatar David Anderson
Browse files

fastbootd: Add better logging for flashing failures.

Bug: 233980876
Test: builds, fastboot flashall
Change-Id: Icc81ac4d9a4ca76f7eb757df5524d95f488fcd8c
parent d17cefe7
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -121,7 +121,12 @@ int FlashRawData(PartitionHandle* handle, const std::vector<char>& downloaded_da
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 @@ int FlashSparseData(PartitionHandle* handle, std::vector<char>& 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<void*>(handle));
@@ -175,10 +181,13 @@ int Flash(FastbootDevice* device, const std::string& partition_name) {

    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" ||
+17 −0
Original line number Diff line number Diff line
@@ -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();