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

Commit 12211d16 authored by David Anderson's avatar David Anderson
Browse files

fastbootd: Enable erase and flash commands for physical partitions.

Bug: 78793464
Test: adb reboot fastboot && fastboot flashall

Change-Id: Ibe802c36f6efe20111a2315616ef34d3a027950f
parent 075c351a
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -94,6 +94,7 @@ cc_binary {
    srcs: [
    srcs: [
        "device/commands.cpp",
        "device/commands.cpp",
        "device/fastboot_device.cpp",
        "device/fastboot_device.cpp",
        "device/flashing.cpp",
        "device/main.cpp",
        "device/main.cpp",
        "device/usb_client.cpp",
        "device/usb_client.cpp",
        "device/utility.cpp",
        "device/utility.cpp",
+31 −3
Original line number Original line Diff line number Diff line
@@ -26,9 +26,11 @@
#include <android-base/strings.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <android-base/unique_fd.h>
#include <cutils/android_reboot.h>
#include <cutils/android_reboot.h>
#include <ext4_utils/wipe.h>


#include "constants.h"
#include "constants.h"
#include "fastboot_device.h"
#include "fastboot_device.h"
#include "flashing.h"
#include "utility.h"
#include "utility.h"


using ::android::hardware::hidl_string;
using ::android::hardware::hidl_string;
@@ -51,7 +53,8 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args)
            {FB_VAR_SLOT_COUNT, GetSlotCount},
            {FB_VAR_SLOT_COUNT, GetSlotCount},
            {FB_VAR_HAS_SLOT, GetHasSlot},
            {FB_VAR_HAS_SLOT, GetHasSlot},
            {FB_VAR_SLOT_SUCCESSFUL, GetSlotSuccessful},
            {FB_VAR_SLOT_SUCCESSFUL, GetSlotSuccessful},
            {FB_VAR_SLOT_UNBOOTABLE, GetSlotUnbootable}};
            {FB_VAR_SLOT_UNBOOTABLE, GetSlotUnbootable},
            {FB_VAR_PARTITION_SIZE, GetPartitionSize}};


    // args[0] is command name, args[1] is variable.
    // args[0] is command name, args[1] is variable.
    auto found_variable = kVariableMap.find(args[1]);
    auto found_variable = kVariableMap.find(args[1]);
@@ -63,6 +66,20 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args)
    return found_variable->second(device, getvar_args);
    return found_variable->second(device, getvar_args);
}
}


bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args) {
    if (args.size() < 2) {
        return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments");
    }
    PartitionHandle handle;
    if (!OpenPartition(device, args[1], &handle)) {
        return device->WriteStatus(FastbootResult::FAIL, "Partition doesn't exist");
    }
    if (wipe_block_device(handle.fd(), get_block_device_size(handle.fd())) == 0) {
        return device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded");
    }
    return device->WriteStatus(FastbootResult::FAIL, "Erasing failed");
}

bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& args) {
bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& args) {
    if (args.size() < 2) {
    if (args.size() < 2) {
        return device->WriteStatus(FastbootResult::FAIL, "size argument unspecified");
        return device->WriteStatus(FastbootResult::FAIL, "size argument unspecified");
@@ -72,12 +89,12 @@ bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& arg
    if (!android::base::ParseUint("0x" + args[1], &size, UINT_MAX)) {
    if (!android::base::ParseUint("0x" + args[1], &size, UINT_MAX)) {
        return device->WriteStatus(FastbootResult::FAIL, "Invalid size");
        return device->WriteStatus(FastbootResult::FAIL, "Invalid size");
    }
    }
    device->get_download_data().resize(size);
    device->download_data().resize(size);
    if (!device->WriteStatus(FastbootResult::DATA, android::base::StringPrintf("%08x", size))) {
    if (!device->WriteStatus(FastbootResult::DATA, android::base::StringPrintf("%08x", size))) {
        return false;
        return false;
    }
    }


    if (device->HandleData(true, &device->get_download_data())) {
    if (device->HandleData(true, &device->download_data())) {
        return device->WriteStatus(FastbootResult::OKAY, "");
        return device->WriteStatus(FastbootResult::OKAY, "");
    }
    }


@@ -85,6 +102,17 @@ bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& arg
    return device->WriteStatus(FastbootResult::FAIL, "Couldn't download data");
    return device->WriteStatus(FastbootResult::FAIL, "Couldn't download data");
}
}


bool FlashHandler(FastbootDevice* device, const std::vector<std::string>& args) {
    if (args.size() < 2) {
        return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments");
    }
    int ret = Flash(device, args[1]);
    if (ret < 0) {
        return device->WriteStatus(FastbootResult::FAIL, strerror(-ret));
    }
    return device->WriteStatus(FastbootResult::OKAY, "Flashing succeeded");
}

bool SetActiveHandler(FastbootDevice* device, const std::vector<std::string>& args) {
bool SetActiveHandler(FastbootDevice* device, const std::vector<std::string>& args) {
    if (args.size() < 2) {
    if (args.size() < 2) {
        return device->WriteStatus(FastbootResult::FAIL, "Missing slot argument");
        return device->WriteStatus(FastbootResult::FAIL, "Missing slot argument");
+2 −0
Original line number Original line Diff line number Diff line
@@ -39,3 +39,5 @@ bool RebootBootloaderHandler(FastbootDevice* device, const std::vector<std::stri
bool RebootFastbootHandler(FastbootDevice* device, const std::vector<std::string>& args);
bool RebootFastbootHandler(FastbootDevice* device, const std::vector<std::string>& args);
bool RebootRecoveryHandler(FastbootDevice* device, const std::vector<std::string>& args);
bool RebootRecoveryHandler(FastbootDevice* device, const std::vector<std::string>& args);
bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args);
bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& args);
bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args);
bool FlashHandler(FastbootDevice* device, const std::vector<std::string>& args);
+3 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include <algorithm>
#include <algorithm>


#include "constants.h"
#include "constants.h"
#include "flashing.h"
#include "usb_client.h"
#include "usb_client.h"


using ::android::hardware::hidl_string;
using ::android::hardware::hidl_string;
@@ -40,6 +41,8 @@ FastbootDevice::FastbootDevice()
              {FB_CMD_REBOOT_BOOTLOADER, RebootBootloaderHandler},
              {FB_CMD_REBOOT_BOOTLOADER, RebootBootloaderHandler},
              {FB_CMD_REBOOT_FASTBOOT, RebootFastbootHandler},
              {FB_CMD_REBOOT_FASTBOOT, RebootFastbootHandler},
              {FB_CMD_REBOOT_RECOVERY, RebootRecoveryHandler},
              {FB_CMD_REBOOT_RECOVERY, RebootRecoveryHandler},
              {FB_CMD_ERASE, EraseHandler},
              {FB_CMD_FLASH, FlashHandler},
      }),
      }),
      transport_(std::make_unique<ClientUsbTransport>()),
      transport_(std::make_unique<ClientUsbTransport>()),
      boot_control_hal_(IBootControl::getService()) {}
      boot_control_hal_(IBootControl::getService()) {}
+1 −4
Original line number Original line Diff line number Diff line
@@ -43,9 +43,7 @@ class FastbootDevice {
    bool WriteOkay(const std::string& message);
    bool WriteOkay(const std::string& message);
    bool WriteFail(const std::string& message);
    bool WriteFail(const std::string& message);


    std::vector<char>& get_download_data() { return download_data_; }
    std::vector<char>& download_data() { return download_data_; }
    void set_upload_data(const std::vector<char>& data) { upload_data_ = data; }
    void set_upload_data(std::vector<char>&& data) { upload_data_ = std::move(data); }
    Transport* get_transport() { return transport_.get(); }
    Transport* get_transport() { return transport_.get(); }
    android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal() {
    android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal() {
        return boot_control_hal_;
        return boot_control_hal_;
@@ -57,5 +55,4 @@ class FastbootDevice {
    std::unique_ptr<Transport> transport_;
    std::unique_ptr<Transport> transport_;
    android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
    android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
    std::vector<char> download_data_;
    std::vector<char> download_data_;
    std::vector<char> upload_data_;
};
};
Loading