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

Commit 90fe0a43 authored by David Anderson's avatar David Anderson
Browse files

fastboot: Query the name of the super partition.

This patch adds a new variable, "super-partition-name", to query the
name of the super partition (with a slot suffix if it has one). The
fastboot flashing tool has been updated to query this variable.

Since the super partition name can no longer be determined without
fastbootd, the presence of super_empty.img is used to test for
dynamic partition support rather than the presence of a super partition.

Bug: 116802789
Test: fastboot flashall on retrofit device
Change-Id: If830768eba6de7f31ac3183c64167fae973c77a4
parent 96a9fd40
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -64,3 +64,4 @@
#define FB_VAR_OFF_MODE_CHARGE_STATE "off-mode-charge"
#define FB_VAR_BATTERY_VOLTAGE "battery-voltage"
#define FB_VAR_BATTERY_SOC_OK "battery-soc-ok"
#define FB_VAR_SUPER_PARTITION_NAME "super-partition-name"
+2 −1
Original line number Diff line number Diff line
@@ -99,7 +99,8 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args)
            {FB_VAR_OFF_MODE_CHARGE_STATE, {GetOffModeChargeState, nullptr}},
            {FB_VAR_BATTERY_VOLTAGE, {GetBatteryVoltage, nullptr}},
            {FB_VAR_BATTERY_SOC_OK, {GetBatterySoCOk, nullptr}},
            {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}}};
            {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}},
            {FB_VAR_SUPER_PARTITION_NAME, {GetSuperPartitionName, nullptr}}};

    if (args.size() < 2) {
        return device->WriteFail("Missing argument");
+10 −0
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <ext4_utils/ext4_utils.h>
#include <fs_mgr.h>
#include <healthhalutils/HealthHalUtils.h>
#include <liblp/liblp.h>

#include "fastboot_device.h"
#include "flashing.h"
@@ -35,6 +37,7 @@ using ::android::hardware::boot::V1_0::Slot;
using ::android::hardware::fastboot::V1_0::FileSystemType;
using ::android::hardware::fastboot::V1_0::Result;
using ::android::hardware::fastboot::V1_0::Status;
using namespace android::fs_mgr;

constexpr char kFastbootProtocolVersion[] = "0.4";

@@ -417,3 +420,10 @@ bool GetHardwareRevision(FastbootDevice* /* device */, const std::vector<std::st
    *message = android::base::GetProperty("ro.revision", "");
    return true;
}

bool GetSuperPartitionName(FastbootDevice* device, const std::vector<std::string>& /* args */,
                           std::string* message) {
    uint32_t slot_number = SlotNumberForSlotSuffix(device->GetCurrentSlot());
    *message = fs_mgr_get_super_partition_name(slot_number);
    return true;
}
+2 −0
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ bool GetBatteryVoltage(FastbootDevice* device, const std::vector<std::string>& a
                       std::string* message);
bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& args,
                     std::string* message);
bool GetSuperPartitionName(FastbootDevice* device, const std::vector<std::string>& args,
                           std::string* message);

// Helpers for getvar all.
std::vector<std::vector<std::string>> GetAllPartitionArgsWithSlot(FastbootDevice* device);
+7 −25
Original line number Diff line number Diff line
@@ -1129,25 +1129,6 @@ static bool is_userspace_fastboot() {
    return fb->GetVar("is-userspace", &value) == fastboot::SUCCESS && value == "yes";
}

static bool if_partition_exists(const std::string& partition, const std::string& slot) {
    std::string has_slot;
    std::string partition_name = partition;

    if (fb->GetVar("has-slot:" + partition, &has_slot) == fastboot::SUCCESS && has_slot == "yes") {
        if (slot == "") {
            std::string current_slot = get_current_slot();
            if (current_slot == "") {
                die("Failed to identify current slot");
            }
            partition_name += "_" + current_slot;
        } else {
            partition_name += "_" + slot;
        }
    }
    std::string partition_size;
    return fb->GetVar("partition-size:" + partition_name, &partition_size) == fastboot::SUCCESS;
}

static void reboot_to_userspace_fastboot() {
    fb->RebootTo("fastboot");

@@ -1307,10 +1288,6 @@ void FlashAllTool::FlashImage(const Image& image, const std::string& slot, fastb
}

void FlashAllTool::UpdateSuperPartition() {
    if (!if_partition_exists("super", "")) {
        return;
    }

    int fd = source_.OpenFile("super_empty.img");
    if (fd < 0) {
        return;
@@ -1321,9 +1298,14 @@ void FlashAllTool::UpdateSuperPartition() {
    if (!is_userspace_fastboot()) {
        die("Failed to boot into userspace; one or more components might be unbootable.");
    }
    fb->Download("super", fd, get_file_size(fd));

    std::string command = "update-super:super";
    std::string super_name;
    if (fb->GetVar("super-partition-name", &super_name) != fastboot::RetCode::SUCCESS) {
        super_name = "super";
    }
    fb->Download(super_name, fd, get_file_size(fd));

    std::string command = "update-super:" + super_name;
    if (wipe_) {
        command += ":wipe";
    }
Loading