Merge "Fastbootd: Use Fastboot AIDL with the help of fastbootshim for legacy fastboot HAL"
This commit is contained in:
commit
7a866d5ac2
5 changed files with 69 additions and 61 deletions
|
|
@ -168,6 +168,7 @@ cc_binary {
|
||||||
"android.hardware.boot-V1-ndk",
|
"android.hardware.boot-V1-ndk",
|
||||||
"libboot_control_client",
|
"libboot_control_client",
|
||||||
"android.hardware.fastboot@1.1",
|
"android.hardware.fastboot@1.1",
|
||||||
|
"android.hardware.fastboot-V1-ndk",
|
||||||
"android.hardware.health@2.0",
|
"android.hardware.health@2.0",
|
||||||
"android.hardware.health-V1-ndk",
|
"android.hardware.health-V1-ndk",
|
||||||
"libasyncio",
|
"libasyncio",
|
||||||
|
|
@ -192,6 +193,7 @@ cc_binary {
|
||||||
"libc++fs",
|
"libc++fs",
|
||||||
"libhealthhalutils",
|
"libhealthhalutils",
|
||||||
"libhealthshim",
|
"libhealthshim",
|
||||||
|
"libfastbootshim",
|
||||||
"libsnapshot_cow",
|
"libsnapshot_cow",
|
||||||
"liblz4",
|
"liblz4",
|
||||||
"libsnapshot_nobinder",
|
"libsnapshot_nobinder",
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,6 @@ static constexpr bool kEnableFetch = false;
|
||||||
using android::fs_mgr::MetadataBuilder;
|
using android::fs_mgr::MetadataBuilder;
|
||||||
using android::hal::CommandResult;
|
using android::hal::CommandResult;
|
||||||
using ::android::hardware::hidl_string;
|
using ::android::hardware::hidl_string;
|
||||||
using ::android::hardware::fastboot::V1_0::Result;
|
|
||||||
using ::android::hardware::fastboot::V1_0::Status;
|
|
||||||
using android::snapshot::SnapshotManager;
|
using android::snapshot::SnapshotManager;
|
||||||
using MergeStatus = android::hal::BootControlClient::MergeStatus;
|
using MergeStatus = android::hal::BootControlClient::MergeStatus;
|
||||||
|
|
||||||
|
|
@ -203,20 +201,21 @@ bool OemPostWipeData(FastbootDevice* device) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ret;
|
auto status = fastboot_hal->doOemSpecificErase();
|
||||||
auto ret_val = fastboot_hal->doOemSpecificErase([&](Result result) { ret = result; });
|
if (status.isOk()) {
|
||||||
if (!ret_val.isOk()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ret.status == Status::NOT_SUPPORTED) {
|
|
||||||
return false;
|
|
||||||
} else if (ret.status != Status::SUCCESS) {
|
|
||||||
device->WriteStatus(FastbootResult::FAIL, ret.message);
|
|
||||||
} else {
|
|
||||||
device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded");
|
device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (status.getExceptionCode()) {
|
||||||
|
case EX_UNSUPPORTED_OPERATION:
|
||||||
|
return false;
|
||||||
|
case EX_SERVICE_SPECIFIC:
|
||||||
|
device->WriteStatus(FastbootResult::FAIL, status.getDescription());
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
LOG(ERROR) << "Erase operation failed" << status.getDescription();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args) {
|
bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args) {
|
||||||
|
|
@ -266,18 +265,16 @@ bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args)
|
||||||
if (args[0] == "oem postwipedata userdata") {
|
if (args[0] == "oem postwipedata userdata") {
|
||||||
return device->WriteStatus(FastbootResult::FAIL, "Unable to do oem postwipedata userdata");
|
return device->WriteStatus(FastbootResult::FAIL, "Unable to do oem postwipedata userdata");
|
||||||
}
|
}
|
||||||
|
std::string message;
|
||||||
Result ret;
|
auto status = fastboot_hal->doOemCommand(args[0], &message);
|
||||||
auto ret_val = fastboot_hal->doOemCommand(args[0], [&](Result result) { ret = result; });
|
if (!status.isOk()) {
|
||||||
if (!ret_val.isOk()) {
|
LOG(ERROR) << "Unable to do OEM command " << args[0].c_str() << status.getDescription();
|
||||||
return device->WriteStatus(FastbootResult::FAIL, "Unable to do OEM command");
|
return device->WriteStatus(FastbootResult::FAIL,
|
||||||
}
|
"Unable to do OEM command " + status.getDescription());
|
||||||
if (ret.status != Status::SUCCESS) {
|
|
||||||
return device->WriteStatus(FastbootResult::FAIL, ret.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
device->WriteInfo(ret.message);
|
device->WriteInfo(message);
|
||||||
return device->WriteStatus(FastbootResult::OKAY, ret.message);
|
return device->WriteStatus(FastbootResult::OKAY, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& args) {
|
bool DownloadHandler(FastbootDevice* device, const std::vector<std::string>& args) {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include <android/binder_manager.h>
|
#include <android/binder_manager.h>
|
||||||
#include <android/hardware/boot/1.0/IBootControl.h>
|
#include <android/hardware/boot/1.0/IBootControl.h>
|
||||||
#include <android/hardware/fastboot/1.1/IFastboot.h>
|
#include <android/hardware/fastboot/1.1/IFastboot.h>
|
||||||
|
#include <fastbootshim.h>
|
||||||
#include <fs_mgr.h>
|
#include <fs_mgr.h>
|
||||||
#include <fs_mgr/roots.h>
|
#include <fs_mgr/roots.h>
|
||||||
#include <health-shim/shim.h>
|
#include <health-shim/shim.h>
|
||||||
|
|
@ -64,6 +65,27 @@ std::shared_ptr<aidl::android::hardware::health::IHealth> get_health_service() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<aidl::android::hardware::fastboot::IFastboot> get_fastboot_service() {
|
||||||
|
using aidl::android::hardware::fastboot::IFastboot;
|
||||||
|
using HidlFastboot = android::hardware::fastboot::V1_1::IFastboot;
|
||||||
|
using aidl::android::hardware::fastboot::FastbootShim;
|
||||||
|
auto service_name = IFastboot::descriptor + "/default"s;
|
||||||
|
ndk::SpAIBinder binder(AServiceManager_getService(service_name.c_str()));
|
||||||
|
std::shared_ptr<IFastboot> fastboot = IFastboot::fromBinder(binder);
|
||||||
|
if (fastboot != nullptr) {
|
||||||
|
LOG(INFO) << "Using AIDL fastboot service";
|
||||||
|
return fastboot;
|
||||||
|
}
|
||||||
|
LOG(INFO) << "Unable to get AIDL fastboot service, trying HIDL...";
|
||||||
|
android::sp<HidlFastboot> hidl_fastboot = HidlFastboot::getService();
|
||||||
|
if (hidl_fastboot != nullptr) {
|
||||||
|
LOG(INFO) << "Found and now using fastboot HIDL implementation";
|
||||||
|
return ndk::SharedRefBase::make<FastbootShim>(hidl_fastboot);
|
||||||
|
}
|
||||||
|
LOG(WARNING) << "No fastboot implementation is found.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
FastbootDevice::FastbootDevice()
|
FastbootDevice::FastbootDevice()
|
||||||
: kCommandMap({
|
: kCommandMap({
|
||||||
{FB_CMD_SET_ACTIVE, SetActiveHandler},
|
{FB_CMD_SET_ACTIVE, SetActiveHandler},
|
||||||
|
|
@ -87,7 +109,7 @@ FastbootDevice::FastbootDevice()
|
||||||
}),
|
}),
|
||||||
boot_control_hal_(BootControlClient::WaitForService()),
|
boot_control_hal_(BootControlClient::WaitForService()),
|
||||||
health_hal_(get_health_service()),
|
health_hal_(get_health_service()),
|
||||||
fastboot_hal_(IFastboot::getService()),
|
fastboot_hal_(get_fastboot_service()),
|
||||||
active_slot_("") {
|
active_slot_("") {
|
||||||
if (android::base::GetProperty("fastbootd.protocol", "usb") == "tcp") {
|
if (android::base::GetProperty("fastbootd.protocol", "usb") == "tcp") {
|
||||||
transport_ = std::make_unique<ClientTcpTransport>();
|
transport_ = std::make_unique<ClientTcpTransport>();
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <BootControlClient.h>
|
#include <BootControlClient.h>
|
||||||
|
#include <aidl/android/hardware/fastboot/IFastboot.h>
|
||||||
#include <aidl/android/hardware/health/IHealth.h>
|
#include <aidl/android/hardware/health/IHealth.h>
|
||||||
#include <android/hardware/fastboot/1.1/IFastboot.h>
|
|
||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
|
@ -52,7 +52,7 @@ class FastbootDevice {
|
||||||
Transport* get_transport() { return transport_.get(); }
|
Transport* get_transport() { return transport_.get(); }
|
||||||
BootControlClient* boot_control_hal() const { return boot_control_hal_.get(); }
|
BootControlClient* boot_control_hal() const { return boot_control_hal_.get(); }
|
||||||
BootControlClient* boot1_1() const;
|
BootControlClient* boot1_1() const;
|
||||||
android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal() {
|
std::shared_ptr<aidl::android::hardware::fastboot::IFastboot> fastboot_hal() {
|
||||||
return fastboot_hal_;
|
return fastboot_hal_;
|
||||||
}
|
}
|
||||||
std::shared_ptr<aidl::android::hardware::health::IHealth> health_hal() { return health_hal_; }
|
std::shared_ptr<aidl::android::hardware::health::IHealth> health_hal() { return health_hal_; }
|
||||||
|
|
@ -65,7 +65,7 @@ class FastbootDevice {
|
||||||
std::unique_ptr<Transport> transport_;
|
std::unique_ptr<Transport> transport_;
|
||||||
std::unique_ptr<BootControlClient> boot_control_hal_;
|
std::unique_ptr<BootControlClient> boot_control_hal_;
|
||||||
std::shared_ptr<aidl::android::hardware::health::IHealth> health_hal_;
|
std::shared_ptr<aidl::android::hardware::health::IHealth> health_hal_;
|
||||||
android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal_;
|
std::shared_ptr<aidl::android::hardware::fastboot::IFastboot> fastboot_hal_;
|
||||||
std::vector<char> download_data_;
|
std::vector<char> download_data_;
|
||||||
std::string active_slot_;
|
std::string active_slot_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,7 @@ static constexpr bool kEnableFetch = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using MergeStatus = android::hal::BootControlClient::MergeStatus;
|
using MergeStatus = android::hal::BootControlClient::MergeStatus;
|
||||||
using ::android::hardware::fastboot::V1_0::FileSystemType;
|
using aidl::android::hardware::fastboot::FileSystemType;
|
||||||
using ::android::hardware::fastboot::V1_0::Result;
|
|
||||||
using ::android::hardware::fastboot::V1_0::Status;
|
|
||||||
using namespace android::fs_mgr;
|
using namespace android::fs_mgr;
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
|
|
@ -104,17 +102,16 @@ bool GetVariant(FastbootDevice* device, const std::vector<std::string>& /* args
|
||||||
*message = "Fastboot HAL not found";
|
*message = "Fastboot HAL not found";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
std::string device_variant = "";
|
||||||
|
auto status = fastboot_hal->getVariant(&device_variant);
|
||||||
|
|
||||||
Result ret;
|
if (!status.isOk()) {
|
||||||
auto ret_val = fastboot_hal->getVariant([&](std::string device_variant, Result result) {
|
|
||||||
*message = device_variant;
|
|
||||||
ret = result;
|
|
||||||
});
|
|
||||||
if (!ret_val.isOk() || ret.status != Status::SUCCESS) {
|
|
||||||
*message = "Unable to get device variant";
|
*message = "Unable to get device variant";
|
||||||
|
LOG(ERROR) << message->c_str() << status.getDescription();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*message = device_variant;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -147,17 +144,14 @@ bool GetBatterySoCOk(FastbootDevice* device, const std::vector<std::string>& /*
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ret;
|
auto voltage_threshold = 0;
|
||||||
auto ret_val = fastboot_hal->getBatteryVoltageFlashingThreshold(
|
auto status = fastboot_hal->getBatteryVoltageFlashingThreshold(&voltage_threshold);
|
||||||
[&](int32_t voltage_threshold, Result result) {
|
if (!status.isOk()) {
|
||||||
*message = battery_voltage >= voltage_threshold ? "yes" : "no";
|
|
||||||
ret = result;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!ret_val.isOk() || ret.status != Status::SUCCESS) {
|
|
||||||
*message = "Unable to get battery voltage flashing threshold";
|
*message = "Unable to get battery voltage flashing threshold";
|
||||||
|
LOG(ERROR) << message->c_str() << status.getDescription();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*message = battery_voltage >= voltage_threshold ? "yes" : "no";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -169,18 +163,14 @@ bool GetOffModeChargeState(FastbootDevice* device, const std::vector<std::string
|
||||||
*message = "Fastboot HAL not found";
|
*message = "Fastboot HAL not found";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool off_mode_charging_state = false;
|
||||||
Result ret;
|
auto status = fastboot_hal->getOffModeChargeState(&off_mode_charging_state);
|
||||||
auto ret_val =
|
if (!status.isOk()) {
|
||||||
fastboot_hal->getOffModeChargeState([&](bool off_mode_charging_state, Result result) {
|
|
||||||
*message = off_mode_charging_state ? "1" : "0";
|
|
||||||
ret = result;
|
|
||||||
});
|
|
||||||
if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) {
|
|
||||||
*message = "Unable to get off mode charge state";
|
*message = "Unable to get off mode charge state";
|
||||||
|
LOG(ERROR) << message->c_str() << status.getDescription();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*message = off_mode_charging_state ? "1" : "0";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,14 +327,11 @@ bool GetPartitionType(FastbootDevice* device, const std::vector<std::string>& ar
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystemType type;
|
FileSystemType type;
|
||||||
Result ret;
|
auto status = fastboot_hal->getPartitionType(args[0], &type);
|
||||||
auto ret_val =
|
|
||||||
fastboot_hal->getPartitionType(args[0], [&](FileSystemType fs_type, Result result) {
|
if (!status.isOk()) {
|
||||||
type = fs_type;
|
|
||||||
ret = result;
|
|
||||||
});
|
|
||||||
if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) {
|
|
||||||
*message = "Unable to retrieve partition type";
|
*message = "Unable to retrieve partition type";
|
||||||
|
LOG(ERROR) << message->c_str() << status.getDescription();
|
||||||
} else {
|
} else {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FileSystemType::RAW:
|
case FileSystemType::RAW:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue