fastboot: Don't fail when unable to get boot partition size
* Some devices don't report boot partition size
Change-Id: If83f785e235569ee8ef0de2b37f11dbd2a9a71f4
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 48d5521..30fa9a7 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -986,6 +986,11 @@
fb->GetVar("partition-type:vbmeta_b", &partition_type) == fastboot::SUCCESS;
}
+static bool is_logical(const std::string& partition) {
+ std::string value;
+ return fb->GetVar("is-logical:" + partition, &value) == fastboot::SUCCESS && value == "yes";
+}
+
static std::string fb_fix_numeric_var(std::string var) {
// Some bootloaders (angler, for example), send spurious leading whitespace.
var = android::base::Trim(var);
@@ -1002,20 +1007,20 @@
std::string partition_size_str;
if (fb->GetVar("partition-size:" + partition, &partition_size_str) != fastboot::SUCCESS) {
+ if (!is_logical(partition)) {
+ return;
+ }
die("cannot get partition size for %s", partition.c_str());
}
partition_size_str = fb_fix_numeric_var(partition_size_str);
int64_t partition_size;
if (!android::base::ParseInt(partition_size_str, &partition_size)) {
+ if (!is_logical(partition)) {
+ return;
+ }
die("Couldn't parse partition size '%s'.", partition_size_str.c_str());
}
- if (partition_size == buf->sz) {
- return;
- }
- if (partition_size < buf->sz) {
- die("boot partition is smaller than boot image");
- }
std::string data;
if (!android::base::ReadFdToString(buf->fd, &data)) {
@@ -1026,6 +1031,12 @@
if (0 != data.compare(footer_offset, AVB_FOOTER_MAGIC_LEN, AVB_FOOTER_MAGIC)) {
return;
}
+ if (partition_size == buf->sz) {
+ return;
+ }
+ if (partition_size < buf->sz) {
+ die("boot partition is smaller than boot image");
+ }
int fd = make_temporary_fd("boot rewriting");
if (!android::base::WriteStringToFd(data, fd)) {
@@ -1216,11 +1227,6 @@
}
}
-static bool is_logical(const std::string& partition) {
- std::string value;
- return fb->GetVar("is-logical:" + partition, &value) == fastboot::SUCCESS && value == "yes";
-}
-
static bool is_retrofit_device() {
std::string value;
if (fb->GetVar("super-partition-name", &value) != fastboot::SUCCESS) {