From 2030bac88ba3c7824cdb422996cc1f04db007fe1 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 3 Nov 2015 08:14:43 -0800 Subject: [PATCH] Fix fastboot to cope with hammerhead's implicit hex. Before: wiping userdata... Couldn't parse partition size '3321fa800'. wiping cache... Couldn't parse partition size '2bc00000'. Groan. So much variation between bootloaders. I wish we had a reference bootloader like ChromeOS does. I've also removed a harmless warning: couldn't parse max-download-size '' Change-Id: Ia1099d2f87000ebb96622ad9171819a1326fa249 --- fastboot/fastboot.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 226f3effe..e2a0ead02 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -571,7 +571,7 @@ static struct sparse_file **load_sparse_files(int fd, int max_size) static int64_t get_target_sparse_limit(usb_handle* usb) { std::string max_download_size; - if (!fb_getvar(usb, "max-download-size", &max_download_size)) { + if (!fb_getvar(usb, "max-download-size", &max_download_size) || max_download_size.empty()) { fprintf(stderr, "target didn't report max-download-size\n"); return 0; } @@ -909,6 +909,10 @@ static void fb_perform_format(usb_handle* usb, return; } + // Some bootloaders (hammerhead, for example) use implicit hex. + // This code used to use strtol with base 16. + if (!android::base::StartsWith(partition_size, "0x")) partition_size = "0x" + partition_size; + int64_t size; if (!android::base::ParseInt(partition_size.c_str(), &size)) { fprintf(stderr, "Couldn't parse partition size '%s'.\n", partition_size.c_str());