Loading fastboot/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -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", Loading fastboot/device/commands.cpp +31 −3 Original line number Original line Diff line number Diff line Loading @@ -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; Loading @@ -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]); Loading @@ -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"); Loading @@ -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, ""); } } Loading @@ -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"); Loading fastboot/device/commands.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -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); fastboot/device/fastboot_device.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading @@ -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()) {} Loading fastboot/device/fastboot_device.h +1 −4 Original line number Original line Diff line number Diff line Loading @@ -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_; Loading @@ -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
fastboot/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -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", Loading
fastboot/device/commands.cpp +31 −3 Original line number Original line Diff line number Diff line Loading @@ -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; Loading @@ -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]); Loading @@ -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"); Loading @@ -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, ""); } } Loading @@ -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"); Loading
fastboot/device/commands.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -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);
fastboot/device/fastboot_device.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading @@ -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()) {} Loading
fastboot/device/fastboot_device.h +1 −4 Original line number Original line Diff line number Diff line Loading @@ -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_; Loading @@ -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_; }; };