From b6134a6d4e6196d2c3bb3094db55373fc068ab9f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 26 Oct 2018 13:08:44 -0700 Subject: [PATCH] fastbootd: Remove metadata merging code. The purpose of this code was to support preserving partitions across a flashall operation. Since we are not supporting persistent read-write partitions, this merging code is effectively useless - it is preserving only partitions that will be deleted. Additionally, this code does not merge partition group changes, since doing so accurately is difficult. Partition size changes aren't sent until after update-super resolves, so a valid re-grouping could be rejected during update-super if the existing partitions are too big. This patch removes the update-super merging code until a use case comes along and we can properly evaluate how it should work. Bug: N/A Test: fastboot flashall Change-Id: I1d622b23dabdf031897be9de49f59fc8cf3caf3b --- fastboot/device/flashing.cpp | 43 ++++-------------------------------- fastboot/device/flashing.h | 2 +- 2 files changed, 5 insertions(+), 40 deletions(-) diff --git a/fastboot/device/flashing.cpp b/fastboot/device/flashing.cpp index 2347496b9..e3d84e098 100644 --- a/fastboot/device/flashing.cpp +++ b/fastboot/device/flashing.cpp @@ -104,12 +104,7 @@ int Flash(FastbootDevice* device, const std::string& partition_name) { return FlashBlockDevice(handle.fd(), data); } -bool UpdateSuper(FastbootDevice* device, const std::string& partition_name, bool wipe) { - std::optional super = FindPhysicalPartition(partition_name); - if (!super) { - return device->WriteFail("Could not find partition: " + partition_name); - } - +bool UpdateSuper(FastbootDevice* device, const std::string& super_name, bool wipe) { std::vector data = std::move(device->download_data()); if (data.empty()) { return device->WriteFail("No data available"); @@ -125,47 +120,17 @@ bool UpdateSuper(FastbootDevice* device, const std::string& partition_name, bool // image. std::string slot_suffix = device->GetCurrentSlot(); uint32_t slot_number = SlotNumberForSlotSuffix(slot_suffix); - std::unique_ptr metadata = ReadMetadata(super->c_str(), slot_number); - if (!metadata || wipe) { - if (!FlashPartitionTable(super.value(), *new_metadata.get())) { + if (wipe || !ReadMetadata(super_name, slot_number)) { + if (!FlashPartitionTable(super_name, *new_metadata.get())) { return device->WriteFail("Unable to flash new partition table"); } return device->WriteOkay("Successfully flashed partition table"); } - // There's a working super partition, and we don't want to wipe it - it may - // may contain partitions created for the user. Instead, we create a zero- - // sized partition for each entry in the new partition table. It is then - // the host's responsibility to size it correctly via resize-logical-partition. - std::unique_ptr builder = MetadataBuilder::New(*metadata.get()); - if (!builder) { - return device->WriteFail("Unable to create a metadata builder"); - } - for (const auto& partition : new_metadata->partitions) { - std::string name = GetPartitionName(partition); - if (builder->FindPartition(name)) { - continue; - } - if (!builder->AddPartition(name, partition.attributes)) { - return device->WriteFail("Unable to add partition: " + name); - } - } - - // The scratch partition may exist as temporary storage, created for - // use by adb remount for overlayfs. If we're performing a flashall - // operation then we want to start over with a clean slate, so we - // remove the scratch partition until it is requested again. - builder->RemovePartition("scratch"); - - new_metadata = builder->Export(); - if (!new_metadata) { - return device->WriteFail("Unable to export new partition table"); - } - // Write the new table to every metadata slot. bool ok = true; for (size_t i = 0; i < new_metadata->geometry.metadata_slot_count; i++) { - ok &= UpdatePartitionTable(super.value(), *new_metadata.get(), i); + ok &= UpdatePartitionTable(super_name, *new_metadata.get(), i); } if (!ok) { diff --git a/fastboot/device/flashing.h b/fastboot/device/flashing.h index 89e20fce2..b15f28b96 100644 --- a/fastboot/device/flashing.h +++ b/fastboot/device/flashing.h @@ -22,4 +22,4 @@ class FastbootDevice; int Flash(FastbootDevice* device, const std::string& partition_name); -bool UpdateSuper(FastbootDevice* device, const std::string& partition_name, bool wipe); +bool UpdateSuper(FastbootDevice* device, const std::string& super_name, bool wipe);