Loading fastboot/fastboot.cpp +18 −18 Original line number Diff line number Diff line Loading @@ -104,7 +104,6 @@ static bool g_long_listing = false; // libsparse will support INT_MAX, but this results in large allocations, so // let's keep it at 1GB to avoid memory pressure on the host. static constexpr int64_t RESPARSE_LIMIT = 1 * 1024 * 1024 * 1024; static uint64_t sparse_limit = 0; static int64_t target_sparse_limit = -1; static unsigned g_base_addr = 0x10000000; Loading Loading @@ -1016,8 +1015,8 @@ static uint64_t get_uint_var(const char* var_name) { return value; } int64_t get_sparse_limit(int64_t size) { int64_t limit = sparse_limit; int64_t get_sparse_limit(int64_t size, const FlashingPlan* fp) { int64_t limit = int64_t(fp->sparse_limit); if (limit == 0) { // Unlimited, so see what the target device's limit is. // TODO: shouldn't we apply this limit even if you've used -S? Loading @@ -1038,7 +1037,7 @@ int64_t get_sparse_limit(int64_t size) { return 0; } static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) { static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf, const FlashingPlan* fp) { int64_t sz = get_file_size(fd); if (sz == -1) { return false; Loading @@ -1056,7 +1055,7 @@ static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) { } lseek(fd.get(), 0, SEEK_SET); int64_t limit = get_sparse_limit(sz); int64_t limit = get_sparse_limit(sz, fp); buf->fd = std::move(fd); if (limit) { buf->files = load_sparse_files(buf->fd.get(), limit); Loading @@ -1072,7 +1071,7 @@ static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) { return true; } static bool load_buf(const char* fname, struct fastboot_buffer* buf) { static bool load_buf(const char* fname, struct fastboot_buffer* buf, const FlashingPlan* fp) { unique_fd fd(TEMP_FAILURE_RETRY(open(fname, O_RDONLY | O_BINARY))); if (fd == -1) { Loading @@ -1088,7 +1087,7 @@ static bool load_buf(const char* fname, struct fastboot_buffer* buf) { return false; } return load_buf_fd(std::move(fd), buf); return load_buf_fd(std::move(fd), buf, fp); } static void rewrite_vbmeta_buffer(struct fastboot_buffer* buf, bool vbmeta_in_boot) { Loading Loading @@ -1490,12 +1489,12 @@ void do_flash(const char* pname, const char* fname, const bool apply_vbmeta, verbose("Do flash %s %s", pname, fname); struct fastboot_buffer buf; if (fp->source) { if (fp && fp->source) { unique_fd fd = fp->source->OpenFile(fname); if (fd < 0 || !load_buf_fd(std::move(fd), &buf)) { if (fd < 0 || !load_buf_fd(std::move(fd), &buf, fp)) { die("could not load '%s': %s", fname, strerror(errno)); } } else if (!load_buf(fname, &buf)) { } else if (!load_buf(fname, &buf, fp)) { die("cannot load '%s': %s", fname, strerror(errno)); } Loading Loading @@ -1873,7 +1872,7 @@ void FlashAllTool::FlashImages(const std::vector<std::pair<const Image*, std::st for (const auto& [image, slot] : images) { fastboot_buffer buf; unique_fd fd = fp_->source->OpenFile(image->img_name); if (fd < 0 || !load_buf_fd(std::move(fd), &buf)) { if (fd < 0 || !load_buf_fd(std::move(fd), &buf, fp_)) { if (image->optional_if_no_image) { continue; } Loading Loading @@ -1982,7 +1981,7 @@ static unsigned fb_get_flash_block_size(std::string name) { void fb_perform_format(const std::string& partition, int skip_if_not_supported, const std::string& type_override, const std::string& size_override, const unsigned fs_options) { const unsigned fs_options, const FlashingPlan* fp) { std::string partition_type, partition_size; struct fastboot_buffer buf; Loading @@ -1995,8 +1994,8 @@ void fb_perform_format(const std::string& partition, int skip_if_not_supported, if (target_sparse_limit > 0 && target_sparse_limit < limit) { limit = target_sparse_limit; } if (sparse_limit > 0 && sparse_limit < limit) { limit = sparse_limit; if (fp->sparse_limit > 0 && fp->sparse_limit < limit) { limit = fp->sparse_limit; } if (fb->GetVar("partition-type:" + partition, &partition_type) != fastboot::SUCCESS) { Loading Loading @@ -2051,7 +2050,7 @@ void fb_perform_format(const std::string& partition, int skip_if_not_supported, if (fd == -1) { die("Cannot open generated image: %s", strerror(errno)); } if (!load_buf_fd(std::move(fd), &buf)) { if (!load_buf_fd(std::move(fd), &buf, fp)) { die("Cannot read image: %s", strerror(errno)); } flash_buf(partition, &buf, is_vbmeta_partition(partition)); Loading Loading @@ -2286,7 +2285,7 @@ int FastBootTool::Main(int argc, char* argv[]) { serial = optarg; break; case 'S': if (!android::base::ParseByteCount(optarg, &sparse_limit)) { if (!android::base::ParseByteCount(optarg, &fp->sparse_limit)) { die("invalid sparse limit %s", optarg); } break; Loading Loading @@ -2404,7 +2403,8 @@ int FastBootTool::Main(int argc, char* argv[]) { std::string partition = next_arg(&args); auto format = [&](const std::string& partition) { fb_perform_format(partition, 0, type_override, size_override, fp->fs_options); fb_perform_format(partition, 0, type_override, size_override, fp->fs_options, fp.get()); }; do_for_partitions(partition, fp->slot_override, format, true); } else if (command == "signature") { Loading Loading @@ -2498,7 +2498,7 @@ int FastBootTool::Main(int argc, char* argv[]) { std::string filename = next_arg(&args); struct fastboot_buffer buf; if (!load_buf(filename.c_str(), &buf) || buf.type != FB_BUFFER_FD) { if (!load_buf(filename.c_str(), &buf, fp.get()) || buf.type != FB_BUFFER_FD) { die("cannot load '%s'", filename.c_str()); } fb->Download(filename, buf.fd.get(), buf.sz); Loading fastboot/fastboot.h +3 −2 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ struct FlashingPlan { bool skip_secondary = false; bool force_flash = false; bool should_optimize_flash_super = true; uint64_t sparse_limit = 0; std::string slot_override; std::string current_slot; Loading Loading @@ -176,11 +177,11 @@ Result<NetworkSerial, FastbootError> ParseNetworkSerial(const std::string& seria bool supports_AB(); std::string GetPartitionName(const ImageEntry& entry, const std::string& current_slot_); void flash_partition_files(const std::string& partition, const std::vector<SparsePtr>& files); int64_t get_sparse_limit(int64_t size); int64_t get_sparse_limit(int64_t size, const FlashingPlan* fp); std::vector<SparsePtr> resparse_file(sparse_file* s, int64_t max_size); bool is_retrofit_device(); bool is_logical(const std::string& partition); void fb_perform_format(const std::string& partition, int skip_if_not_supported, const std::string& type_override, const std::string& size_override, const unsigned fs_options); const unsigned fs_options, const FlashingPlan* fp); fastboot/task.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -98,18 +98,20 @@ std::string RebootTask::ToString() { FlashSuperLayoutTask::FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper, SparsePtr sparse_layout, uint64_t super_size) SparsePtr sparse_layout, uint64_t super_size, const FlashingPlan* fp) : super_name_(super_name), helper_(std::move(helper)), sparse_layout_(std::move(sparse_layout)), super_size_(super_size) {} super_size_(super_size), fp_(fp) {} void FlashSuperLayoutTask::Run() { // Use the reported super partition size as the upper limit, rather than // sparse_file_len, which (1) can fail and (2) is kind of expensive, since // it will map in all of the embedded fds. std::vector<SparsePtr> files; if (int limit = get_sparse_limit(super_size_)) { if (int limit = get_sparse_limit(super_size_, fp_)) { files = resparse_file(sparse_layout_.get(), limit); } else { files.emplace_back(std::move(sparse_layout_)); Loading Loading @@ -187,7 +189,7 @@ std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::Initialize( os_images.erase(std::remove_if(os_images.begin(), os_images.end(), remove_if_callback), os_images.end()); return std::make_unique<FlashSuperLayoutTask>(super_name, std::move(helper), std::move(s), partition_size); partition_size, fp); } std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::InitializeFromTasks( Loading Loading @@ -260,7 +262,7 @@ std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::InitializeFromTasks( tasks.erase(std::remove_if(tasks.begin(), tasks.end(), remove_if_callback), tasks.end()); return std::make_unique<FlashSuperLayoutTask>(super_name, std::move(helper), std::move(s), partition_size); partition_size, fp); } UpdateSuperTask::UpdateSuperTask(const FlashingPlan* fp) : fp_(fp) {} Loading Loading @@ -330,7 +332,7 @@ void WipeTask::Run() { LOG(ERROR) << "wipe task erase failed with partition: " << pname_; return; } fb_perform_format(pname_, 1, partition_type, "", fp_->fs_options); fb_perform_format(pname_, 1, partition_type, "", fp_->fs_options, fp_); } std::string WipeTask::ToString() { Loading fastboot/task.h +2 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ class RebootTask : public Task { class FlashSuperLayoutTask : public Task { public: FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper, SparsePtr sparse_layout, uint64_t super_size); SparsePtr sparse_layout, uint64_t super_size, const FlashingPlan* fp); static std::unique_ptr<FlashSuperLayoutTask> Initialize(const FlashingPlan* fp, std::vector<ImageEntry>& os_images); static std::unique_ptr<FlashSuperLayoutTask> InitializeFromTasks( Loading @@ -96,6 +96,7 @@ class FlashSuperLayoutTask : public Task { std::unique_ptr<SuperFlashHelper> helper_; SparsePtr sparse_layout_; uint64_t super_size_; const FlashingPlan* fp_; }; class UpdateSuperTask : public Task { Loading Loading
fastboot/fastboot.cpp +18 −18 Original line number Diff line number Diff line Loading @@ -104,7 +104,6 @@ static bool g_long_listing = false; // libsparse will support INT_MAX, but this results in large allocations, so // let's keep it at 1GB to avoid memory pressure on the host. static constexpr int64_t RESPARSE_LIMIT = 1 * 1024 * 1024 * 1024; static uint64_t sparse_limit = 0; static int64_t target_sparse_limit = -1; static unsigned g_base_addr = 0x10000000; Loading Loading @@ -1016,8 +1015,8 @@ static uint64_t get_uint_var(const char* var_name) { return value; } int64_t get_sparse_limit(int64_t size) { int64_t limit = sparse_limit; int64_t get_sparse_limit(int64_t size, const FlashingPlan* fp) { int64_t limit = int64_t(fp->sparse_limit); if (limit == 0) { // Unlimited, so see what the target device's limit is. // TODO: shouldn't we apply this limit even if you've used -S? Loading @@ -1038,7 +1037,7 @@ int64_t get_sparse_limit(int64_t size) { return 0; } static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) { static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf, const FlashingPlan* fp) { int64_t sz = get_file_size(fd); if (sz == -1) { return false; Loading @@ -1056,7 +1055,7 @@ static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) { } lseek(fd.get(), 0, SEEK_SET); int64_t limit = get_sparse_limit(sz); int64_t limit = get_sparse_limit(sz, fp); buf->fd = std::move(fd); if (limit) { buf->files = load_sparse_files(buf->fd.get(), limit); Loading @@ -1072,7 +1071,7 @@ static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) { return true; } static bool load_buf(const char* fname, struct fastboot_buffer* buf) { static bool load_buf(const char* fname, struct fastboot_buffer* buf, const FlashingPlan* fp) { unique_fd fd(TEMP_FAILURE_RETRY(open(fname, O_RDONLY | O_BINARY))); if (fd == -1) { Loading @@ -1088,7 +1087,7 @@ static bool load_buf(const char* fname, struct fastboot_buffer* buf) { return false; } return load_buf_fd(std::move(fd), buf); return load_buf_fd(std::move(fd), buf, fp); } static void rewrite_vbmeta_buffer(struct fastboot_buffer* buf, bool vbmeta_in_boot) { Loading Loading @@ -1490,12 +1489,12 @@ void do_flash(const char* pname, const char* fname, const bool apply_vbmeta, verbose("Do flash %s %s", pname, fname); struct fastboot_buffer buf; if (fp->source) { if (fp && fp->source) { unique_fd fd = fp->source->OpenFile(fname); if (fd < 0 || !load_buf_fd(std::move(fd), &buf)) { if (fd < 0 || !load_buf_fd(std::move(fd), &buf, fp)) { die("could not load '%s': %s", fname, strerror(errno)); } } else if (!load_buf(fname, &buf)) { } else if (!load_buf(fname, &buf, fp)) { die("cannot load '%s': %s", fname, strerror(errno)); } Loading Loading @@ -1873,7 +1872,7 @@ void FlashAllTool::FlashImages(const std::vector<std::pair<const Image*, std::st for (const auto& [image, slot] : images) { fastboot_buffer buf; unique_fd fd = fp_->source->OpenFile(image->img_name); if (fd < 0 || !load_buf_fd(std::move(fd), &buf)) { if (fd < 0 || !load_buf_fd(std::move(fd), &buf, fp_)) { if (image->optional_if_no_image) { continue; } Loading Loading @@ -1982,7 +1981,7 @@ static unsigned fb_get_flash_block_size(std::string name) { void fb_perform_format(const std::string& partition, int skip_if_not_supported, const std::string& type_override, const std::string& size_override, const unsigned fs_options) { const unsigned fs_options, const FlashingPlan* fp) { std::string partition_type, partition_size; struct fastboot_buffer buf; Loading @@ -1995,8 +1994,8 @@ void fb_perform_format(const std::string& partition, int skip_if_not_supported, if (target_sparse_limit > 0 && target_sparse_limit < limit) { limit = target_sparse_limit; } if (sparse_limit > 0 && sparse_limit < limit) { limit = sparse_limit; if (fp->sparse_limit > 0 && fp->sparse_limit < limit) { limit = fp->sparse_limit; } if (fb->GetVar("partition-type:" + partition, &partition_type) != fastboot::SUCCESS) { Loading Loading @@ -2051,7 +2050,7 @@ void fb_perform_format(const std::string& partition, int skip_if_not_supported, if (fd == -1) { die("Cannot open generated image: %s", strerror(errno)); } if (!load_buf_fd(std::move(fd), &buf)) { if (!load_buf_fd(std::move(fd), &buf, fp)) { die("Cannot read image: %s", strerror(errno)); } flash_buf(partition, &buf, is_vbmeta_partition(partition)); Loading Loading @@ -2286,7 +2285,7 @@ int FastBootTool::Main(int argc, char* argv[]) { serial = optarg; break; case 'S': if (!android::base::ParseByteCount(optarg, &sparse_limit)) { if (!android::base::ParseByteCount(optarg, &fp->sparse_limit)) { die("invalid sparse limit %s", optarg); } break; Loading Loading @@ -2404,7 +2403,8 @@ int FastBootTool::Main(int argc, char* argv[]) { std::string partition = next_arg(&args); auto format = [&](const std::string& partition) { fb_perform_format(partition, 0, type_override, size_override, fp->fs_options); fb_perform_format(partition, 0, type_override, size_override, fp->fs_options, fp.get()); }; do_for_partitions(partition, fp->slot_override, format, true); } else if (command == "signature") { Loading Loading @@ -2498,7 +2498,7 @@ int FastBootTool::Main(int argc, char* argv[]) { std::string filename = next_arg(&args); struct fastboot_buffer buf; if (!load_buf(filename.c_str(), &buf) || buf.type != FB_BUFFER_FD) { if (!load_buf(filename.c_str(), &buf, fp.get()) || buf.type != FB_BUFFER_FD) { die("cannot load '%s'", filename.c_str()); } fb->Download(filename, buf.fd.get(), buf.sz); Loading
fastboot/fastboot.h +3 −2 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ struct FlashingPlan { bool skip_secondary = false; bool force_flash = false; bool should_optimize_flash_super = true; uint64_t sparse_limit = 0; std::string slot_override; std::string current_slot; Loading Loading @@ -176,11 +177,11 @@ Result<NetworkSerial, FastbootError> ParseNetworkSerial(const std::string& seria bool supports_AB(); std::string GetPartitionName(const ImageEntry& entry, const std::string& current_slot_); void flash_partition_files(const std::string& partition, const std::vector<SparsePtr>& files); int64_t get_sparse_limit(int64_t size); int64_t get_sparse_limit(int64_t size, const FlashingPlan* fp); std::vector<SparsePtr> resparse_file(sparse_file* s, int64_t max_size); bool is_retrofit_device(); bool is_logical(const std::string& partition); void fb_perform_format(const std::string& partition, int skip_if_not_supported, const std::string& type_override, const std::string& size_override, const unsigned fs_options); const unsigned fs_options, const FlashingPlan* fp);
fastboot/task.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -98,18 +98,20 @@ std::string RebootTask::ToString() { FlashSuperLayoutTask::FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper, SparsePtr sparse_layout, uint64_t super_size) SparsePtr sparse_layout, uint64_t super_size, const FlashingPlan* fp) : super_name_(super_name), helper_(std::move(helper)), sparse_layout_(std::move(sparse_layout)), super_size_(super_size) {} super_size_(super_size), fp_(fp) {} void FlashSuperLayoutTask::Run() { // Use the reported super partition size as the upper limit, rather than // sparse_file_len, which (1) can fail and (2) is kind of expensive, since // it will map in all of the embedded fds. std::vector<SparsePtr> files; if (int limit = get_sparse_limit(super_size_)) { if (int limit = get_sparse_limit(super_size_, fp_)) { files = resparse_file(sparse_layout_.get(), limit); } else { files.emplace_back(std::move(sparse_layout_)); Loading Loading @@ -187,7 +189,7 @@ std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::Initialize( os_images.erase(std::remove_if(os_images.begin(), os_images.end(), remove_if_callback), os_images.end()); return std::make_unique<FlashSuperLayoutTask>(super_name, std::move(helper), std::move(s), partition_size); partition_size, fp); } std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::InitializeFromTasks( Loading Loading @@ -260,7 +262,7 @@ std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::InitializeFromTasks( tasks.erase(std::remove_if(tasks.begin(), tasks.end(), remove_if_callback), tasks.end()); return std::make_unique<FlashSuperLayoutTask>(super_name, std::move(helper), std::move(s), partition_size); partition_size, fp); } UpdateSuperTask::UpdateSuperTask(const FlashingPlan* fp) : fp_(fp) {} Loading Loading @@ -330,7 +332,7 @@ void WipeTask::Run() { LOG(ERROR) << "wipe task erase failed with partition: " << pname_; return; } fb_perform_format(pname_, 1, partition_type, "", fp_->fs_options); fb_perform_format(pname_, 1, partition_type, "", fp_->fs_options, fp_); } std::string WipeTask::ToString() { Loading
fastboot/task.h +2 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ class RebootTask : public Task { class FlashSuperLayoutTask : public Task { public: FlashSuperLayoutTask(const std::string& super_name, std::unique_ptr<SuperFlashHelper> helper, SparsePtr sparse_layout, uint64_t super_size); SparsePtr sparse_layout, uint64_t super_size, const FlashingPlan* fp); static std::unique_ptr<FlashSuperLayoutTask> Initialize(const FlashingPlan* fp, std::vector<ImageEntry>& os_images); static std::unique_ptr<FlashSuperLayoutTask> InitializeFromTasks( Loading @@ -96,6 +96,7 @@ class FlashSuperLayoutTask : public Task { std::unique_ptr<SuperFlashHelper> helper_; SparsePtr sparse_layout_; uint64_t super_size_; const FlashingPlan* fp_; }; class UpdateSuperTask : public Task { Loading