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

Commit 8568dcb0 authored by David Anderson's avatar David Anderson
Browse files

fastbootd: Only flash slots listed by the boot control HAL.

Bug: N/A
Test: flash when metadata slot count is >2
Change-Id: I67481be0de162cab5da8d32c2e318489427f1932
parent a63e1d77
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -329,12 +329,14 @@ class PartitionBuilder {
    MetadataBuilder* operator->() const { return builder_.get(); }
    MetadataBuilder* operator->() const { return builder_.get(); }


  private:
  private:
    FastbootDevice* device_;
    std::string super_device_;
    std::string super_device_;
    uint32_t slot_number_;
    uint32_t slot_number_;
    std::unique_ptr<MetadataBuilder> builder_;
    std::unique_ptr<MetadataBuilder> builder_;
};
};


PartitionBuilder::PartitionBuilder(FastbootDevice* device, const std::string& partition_name) {
PartitionBuilder::PartitionBuilder(FastbootDevice* device, const std::string& partition_name)
    : device_(device) {
    std::string slot_suffix = GetSuperSlotSuffix(device, partition_name);
    std::string slot_suffix = GetSuperSlotSuffix(device, partition_name);
    slot_number_ = SlotNumberForSlotSuffix(slot_suffix);
    slot_number_ = SlotNumberForSlotSuffix(slot_suffix);
    auto super_device = FindPhysicalPartition(fs_mgr_get_super_partition_name(slot_number_));
    auto super_device = FindPhysicalPartition(fs_mgr_get_super_partition_name(slot_number_));
@@ -350,7 +352,7 @@ bool PartitionBuilder::Write() {
    if (!metadata) {
    if (!metadata) {
        return false;
        return false;
    }
    }
    return UpdateAllPartitionMetadata(super_device_, *metadata.get());
    return UpdateAllPartitionMetadata(device_, super_device_, *metadata.get());
}
}


bool CreatePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args) {
bool CreatePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -184,7 +184,7 @@ bool UpdateSuper(FastbootDevice* device, const std::string& super_name, bool wip
    }
    }


    // Write the new table to every metadata slot.
    // Write the new table to every metadata slot.
    if (!UpdateAllPartitionMetadata(super_name, *new_metadata.get())) {
    if (!UpdateAllPartitionMetadata(device, super_name, *new_metadata.get())) {
        return device->WriteFail("Unable to write new partition table");
        return device->WriteFail("Unable to write new partition table");
    }
    }
    fs_mgr_overlayfs_teardown();
    fs_mgr_overlayfs_teardown();
+8 −2
Original line number Original line Diff line number Diff line
@@ -200,10 +200,16 @@ bool GetDeviceLockStatus() {
    return cmdline.find("androidboot.verifiedbootstate=orange") == std::string::npos;
    return cmdline.find("androidboot.verifiedbootstate=orange") == std::string::npos;
}
}


bool UpdateAllPartitionMetadata(const std::string& super_name,
bool UpdateAllPartitionMetadata(FastbootDevice* device, const std::string& super_name,
                                const android::fs_mgr::LpMetadata& metadata) {
                                const android::fs_mgr::LpMetadata& metadata) {
    size_t num_slots = 1;
    auto boot_control_hal = device->boot_control_hal();
    if (boot_control_hal) {
        num_slots = boot_control_hal->getNumberSlots();
    }

    bool ok = true;
    bool ok = true;
    for (size_t i = 0; i < metadata.geometry.metadata_slot_count; i++) {
    for (size_t i = 0; i < num_slots; i++) {
        ok &= UpdatePartitionTable(super_name, metadata, i);
        ok &= UpdatePartitionTable(super_name, metadata, i);
    }
    }
    return ok;
    return ok;
+1 −1
Original line number Original line Diff line number Diff line
@@ -68,5 +68,5 @@ std::vector<std::string> ListPartitions(FastbootDevice* device);
bool GetDeviceLockStatus();
bool GetDeviceLockStatus();


// Update all copies of metadata.
// Update all copies of metadata.
bool UpdateAllPartitionMetadata(const std::string& super_name,
bool UpdateAllPartitionMetadata(FastbootDevice* device, const std::string& super_name,
                                const android::fs_mgr::LpMetadata& metadata);
                                const android::fs_mgr::LpMetadata& metadata);