Merge "Cleaned up some slot logic"

This commit is contained in:
Daniel Zheng 2023-03-30 21:49:15 +00:00 committed by Gerrit Code Review
commit b16aba889a
3 changed files with 15 additions and 24 deletions

View file

@ -1560,10 +1560,10 @@ static void CancelSnapshotIfNeeded() {
} }
} }
std::string GetPartitionName(const ImageEntry& entry, std::string& current_slot) { std::string GetPartitionName(const ImageEntry& entry) {
auto slot = entry.second; auto slot = entry.second;
if (slot.empty()) { if (slot.empty()) {
slot = current_slot; slot = get_current_slot();
} }
if (slot.empty()) { if (slot.empty()) {
return entry.first->part_name; return entry.first->part_name;
@ -1582,7 +1582,7 @@ class FlashAllTool {
private: private:
void CheckRequirements(); void CheckRequirements();
void DetermineSlot(); void DetermineSecondarySlot();
void CollectImages(); void CollectImages();
void FlashImages(const std::vector<std::pair<const Image*, std::string>>& images); void FlashImages(const std::vector<std::pair<const Image*, std::string>>& images);
void FlashImage(const Image& image, const std::string& slot, fastboot_buffer* buf); void FlashImage(const Image& image, const std::string& slot, fastboot_buffer* buf);
@ -1600,15 +1600,13 @@ void FlashAllTool::Flash() {
// Change the slot first, so we boot into the correct recovery image when // Change the slot first, so we boot into the correct recovery image when
// using fastbootd. // using fastbootd.
if (fp_->slot == "all") { if (fp_->slot_override == "all") {
set_active("a"); set_active("a");
} else { } else {
set_active(fp_->slot); set_active(fp_->slot_override);
} }
DetermineSlot(); DetermineSecondarySlot();
CollectImages();
CancelSnapshotIfNeeded(); CancelSnapshotIfNeeded();
// First flash boot partitions. We allow this to happen either in userspace // First flash boot partitions. We allow this to happen either in userspace
@ -1653,18 +1651,12 @@ void FlashAllTool::CheckRequirements() {
::CheckRequirements({contents.data(), contents.size()}, fp_->force_flash); ::CheckRequirements({contents.data(), contents.size()}, fp_->force_flash);
} }
void FlashAllTool::DetermineSlot() { void FlashAllTool::DetermineSecondarySlot() {
if (fp_->slot.empty()) {
fp_->current_slot = get_current_slot();
} else {
fp_->current_slot = fp_->slot;
}
if (fp_->skip_secondary) { if (fp_->skip_secondary) {
return; return;
} }
if (fp_->slot != "" && fp_->slot != "all") { if (fp_->slot_override != "" && fp_->slot_override != "all") {
fp_->secondary_slot = get_other_slot(fp_->slot); fp_->secondary_slot = get_other_slot(fp_->slot_override);
} else { } else {
fp_->secondary_slot = get_other_slot(); fp_->secondary_slot = get_other_slot();
} }
@ -1678,7 +1670,7 @@ void FlashAllTool::DetermineSlot() {
void FlashAllTool::CollectImages() { void FlashAllTool::CollectImages() {
for (size_t i = 0; i < images.size(); ++i) { for (size_t i = 0; i < images.size(); ++i) {
std::string slot = fp_->slot; std::string slot = fp_->slot_override;
if (images[i].IsSecondary()) { if (images[i].IsSecondary()) {
if (fp_->skip_secondary) { if (fp_->skip_secondary) {
continue; continue;

View file

@ -80,8 +80,7 @@ struct FlashingPlan {
bool skip_secondary = false; bool skip_secondary = false;
bool force_flash = false; bool force_flash = false;
std::string slot; std::string slot_override;
std::string current_slot;
std::string secondary_slot; std::string secondary_slot;
fastboot::FastBootDriver* fb; fastboot::FastBootDriver* fb;
}; };
@ -103,7 +102,7 @@ struct NetworkSerial {
Result<NetworkSerial, FastbootError> ParseNetworkSerial(const std::string& serial); Result<NetworkSerial, FastbootError> ParseNetworkSerial(const std::string& serial);
bool supports_AB(); bool supports_AB();
std::string GetPartitionName(const ImageEntry& entry, std::string& current_slot_); std::string GetPartitionName(const ImageEntry& entry);
void flash_partition_files(const std::string& partition, const std::vector<SparsePtr>& files); 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);
std::vector<SparsePtr> resparse_file(sparse_file* s, int64_t max_size); std::vector<SparsePtr> resparse_file(sparse_file* s, int64_t max_size);

View file

@ -95,7 +95,7 @@ std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::Initialize(
LOG(VERBOSE) << "Cannot optimize flashing super on non-AB device"; LOG(VERBOSE) << "Cannot optimize flashing super on non-AB device";
return nullptr; return nullptr;
} }
if (fp->slot == "all") { if (fp->slot_override == "all") {
LOG(VERBOSE) << "Cannot optimize flashing super for all slots"; LOG(VERBOSE) << "Cannot optimize flashing super for all slots";
return nullptr; return nullptr;
} }
@ -132,7 +132,7 @@ std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::Initialize(
} }
for (const auto& entry : os_images) { for (const auto& entry : os_images) {
auto partition = GetPartitionName(entry, fp->current_slot); auto partition = GetPartitionName(entry);
auto image = entry.first; auto image = entry.first;
if (!helper->AddPartition(partition, image->img_name, image->optional_if_no_image)) { if (!helper->AddPartition(partition, image->img_name, image->optional_if_no_image)) {
@ -145,7 +145,7 @@ std::unique_ptr<FlashSuperLayoutTask> FlashSuperLayoutTask::Initialize(
// Remove images that we already flashed, just in case we have non-dynamic OS images. // Remove images that we already flashed, just in case we have non-dynamic OS images.
auto remove_if_callback = [&](const ImageEntry& entry) -> bool { auto remove_if_callback = [&](const ImageEntry& entry) -> bool {
return helper->WillFlash(GetPartitionName(entry, fp->current_slot)); return helper->WillFlash(GetPartitionName(entry));
}; };
os_images.erase(std::remove_if(os_images.begin(), os_images.end(), remove_if_callback), os_images.erase(std::remove_if(os_images.begin(), os_images.end(), remove_if_callback),
os_images.end()); os_images.end());