diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 29980afd0..6fc6f5ff7 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -173,7 +173,7 @@ static std::vector images = { // clang-format on }; -static char* get_android_product_out() { +char* get_android_product_out() { char* dir = getenv("ANDROID_PRODUCT_OUT"); if (dir == nullptr || dir[0] == '\0') { return nullptr; @@ -1787,13 +1787,25 @@ void FlashAllTool::Flash() { CancelSnapshotIfNeeded(); - tasks_ = CollectTasksFromImageList(); + tasks_ = CollectTasks(); for (auto& task : tasks_) { task->Run(); } return; } +std::vector> FlashAllTool::CollectTasks() { + std::vector> tasks; + if (fp_->should_use_fastboot_info) { + tasks = CollectTasksFromFastbootInfo(); + + } else { + tasks = CollectTasksFromImageList(); + } + + return tasks; +} + void FlashAllTool::CheckRequirements() { std::vector contents; if (!fp_->source->ReadFile("android-info.txt", &contents)) { @@ -1848,7 +1860,6 @@ std::vector> FlashAllTool::CollectTasksFromImageList() { // or in bootloader fastboot. std::vector> tasks; AddFlashTasks(boot_images_, tasks); - if (auto flash_super_task = OptimizedFlashSuperTask::Initialize(fp_, os_images_)) { tasks.emplace_back(std::move(flash_super_task)); } else { @@ -1871,10 +1882,23 @@ std::vector> FlashAllTool::CollectTasksFromImageList() { tasks.emplace_back(std::make_unique(fp_, image->part_name, "0", slot)); } } + AddFlashTasks(os_images_, tasks); return tasks; } +std::vector> FlashAllTool::CollectTasksFromFastbootInfo() { + std::vector> tasks; + std::vector contents; + if (!fp_->source->ReadFile("fastboot-info.txt", &contents)) { + LOG(VERBOSE) << "Flashing from hardcoded images. fastboot-info.txt is empty or does not " + "exist"; + return CollectTasksFromImageList(); + } + tasks = ParseFastbootInfo(fp_, Split({contents.data(), contents.size()}, "\n")); + return tasks; +} + void FlashAllTool::AddFlashTasks(const std::vector>& images, std::vector>& tasks) { for (const auto& [image, slot] : images) { diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h index 196bd6726..77430f05a 100644 --- a/fastboot/fastboot.h +++ b/fastboot/fastboot.h @@ -97,6 +97,7 @@ struct FlashingPlan { bool skip_secondary = false; bool force_flash = false; bool should_optimize_flash_super = true; + bool should_use_fastboot_info = false; uint64_t sparse_limit = 0; std::string slot_override; @@ -111,6 +112,7 @@ class FlashAllTool { FlashAllTool(FlashingPlan* fp); void Flash(); + std::vector> CollectTasks(); private: void CheckRequirements(); @@ -118,6 +120,8 @@ class FlashAllTool { void CollectImages(); void AddFlashTasks(const std::vector>& images, std::vector>& tasks); + + std::vector> CollectTasksFromFastbootInfo(); std::vector> CollectTasksFromImageList(); std::vector boot_images_; @@ -143,6 +147,7 @@ class LocalImageSource final : public ImageSource { unique_fd OpenFile(const std::string& name) const override; }; +char* get_android_product_out(); bool should_flash_in_userspace(const std::string& partition_name); bool is_userspace_fastboot(); void do_flash(const char* pname, const char* fname, const bool apply_vbmeta,