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

Commit f56e0dbf authored by Devin Moore's avatar Devin Moore Committed by Gerrit Code Review
Browse files

Merge "fastboot: make copy_boot_avb_footer more generic"

parents e664e8fb cb5098f5
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -1025,7 +1025,7 @@ static uint64_t get_partition_size(const std::string& partition) {
    return partition_size;
}

static void copy_boot_avb_footer(const std::string& partition, struct fastboot_buffer* buf) {
static void copy_avb_footer(const std::string& partition, struct fastboot_buffer* buf) {
    if (buf->sz < AVB_FOOTER_SIZE) {
        return;
    }
@@ -1040,9 +1040,9 @@ static void copy_boot_avb_footer(const std::string& partition, struct fastboot_b
    // In this case, partition_size will be zero.
    if (partition_size < buf->sz) {
        fprintf(stderr,
                "Warning: skip copying boot image avb footer"
                " (boot partition size: %" PRId64 ", boot image size: %" PRId64 ").\n",
                partition_size, buf->sz);
                "Warning: skip copying %s image avb footer"
                " (%s partition size: %" PRId64 ", %s image size: %" PRId64 ").\n",
                partition.c_str(), partition.c_str(), partition_size, partition.c_str(), buf->sz);
        return;
    }

@@ -1050,7 +1050,7 @@ static void copy_boot_avb_footer(const std::string& partition, struct fastboot_b
    // Because buf->fd will still be used afterwards.
    std::string data;
    if (!android::base::ReadFdToString(buf->fd, &data)) {
        die("Failed reading from boot");
        die("Failed reading from %s", partition.c_str());
    }

    uint64_t footer_offset = buf->sz - AVB_FOOTER_SIZE;
@@ -1059,13 +1059,14 @@ static void copy_boot_avb_footer(const std::string& partition, struct fastboot_b
        return;
    }

    unique_fd fd(make_temporary_fd("boot rewriting"));
    const std::string tmp_fd_template = partition + " rewriting";
    unique_fd fd(make_temporary_fd(tmp_fd_template.c_str()));
    if (!android::base::WriteStringToFd(data, fd)) {
        die("Failed writing to modified boot");
        die("Failed writing to modified %s", partition.c_str());
    }
    lseek(fd.get(), partition_size - AVB_FOOTER_SIZE, SEEK_SET);
    if (!android::base::WriteStringToFd(data.substr(footer_offset), fd)) {
        die("Failed copying AVB footer in boot");
        die("Failed copying AVB footer in %s", partition.c_str());
    }
    buf->fd = std::move(fd);
    buf->sz = partition_size;
@@ -1078,7 +1079,7 @@ static void flash_buf(const std::string& partition, struct fastboot_buffer *buf)

    if (partition == "boot" || partition == "boot_a" || partition == "boot_b" ||
        partition == "init_boot" || partition == "init_boot_a" || partition == "init_boot_b") {
        copy_boot_avb_footer(partition, buf);
        copy_avb_footer(partition, buf);
    }

    // Rewrite vbmeta if that's what we're flashing and modification has been requested.