Loading fastboot/constants.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ #define FB_CMD_DELETE_PARTITION "delete-logical-partition" #define FB_CMD_DELETE_PARTITION "delete-logical-partition" #define FB_CMD_RESIZE_PARTITION "resize-logical-partition" #define FB_CMD_RESIZE_PARTITION "resize-logical-partition" #define FB_CMD_UPDATE_SUPER "update-super" #define FB_CMD_UPDATE_SUPER "update-super" #define FB_CMD_OEM "oem" #define RESPONSE_OKAY "OKAY" #define RESPONSE_OKAY "OKAY" #define RESPONSE_FAIL "FAIL" #define RESPONSE_FAIL "FAIL" Loading fastboot/device/commands.cpp +21 −0 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,9 @@ using ::android::hardware::hidl_string; using ::android::hardware::boot::V1_0::BoolResult; using ::android::hardware::boot::V1_0::BoolResult; using ::android::hardware::boot::V1_0::CommandResult; using ::android::hardware::boot::V1_0::CommandResult; using ::android::hardware::boot::V1_0::Slot; using ::android::hardware::boot::V1_0::Slot; using ::android::hardware::fastboot::V1_0::Result; using ::android::hardware::fastboot::V1_0::Status; using namespace android::fs_mgr; using namespace android::fs_mgr; struct VariableHandlers { struct VariableHandlers { Loading Loading @@ -133,6 +136,24 @@ bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args) return device->WriteStatus(FastbootResult::FAIL, "Erasing failed"); return device->WriteStatus(FastbootResult::FAIL, "Erasing failed"); } } bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args) { auto fastboot_hal = device->fastboot_hal(); if (!fastboot_hal) { return device->WriteStatus(FastbootResult::FAIL, "Unable to open fastboot HAL"); } Result ret; auto ret_val = fastboot_hal->doOemCommand(args[0], [&](Result result) { ret = result; }); if (!ret_val.isOk()) { return device->WriteStatus(FastbootResult::FAIL, "Unable to do OEM command"); } if (ret.status != Status::SUCCESS) { return device->WriteStatus(FastbootResult::FAIL, ret.message); } return device->WriteStatus(FastbootResult::OKAY, ret.message); } 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 fastboot/device/commands.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -45,3 +45,4 @@ bool CreatePartitionHandler(FastbootDevice* device, const std::vector<std::strin bool DeletePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool DeletePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool ResizePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool ResizePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool UpdateSuperHandler(FastbootDevice* device, const std::vector<std::string>& args); bool UpdateSuperHandler(FastbootDevice* device, const std::vector<std::string>& args); bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args); fastboot/device/fastboot_device.cpp +14 −3 Original line number Original line Diff line number Diff line Loading @@ -48,6 +48,7 @@ FastbootDevice::FastbootDevice() {FB_CMD_DELETE_PARTITION, DeletePartitionHandler}, {FB_CMD_DELETE_PARTITION, DeletePartitionHandler}, {FB_CMD_RESIZE_PARTITION, ResizePartitionHandler}, {FB_CMD_RESIZE_PARTITION, ResizePartitionHandler}, {FB_CMD_UPDATE_SUPER, UpdateSuperHandler}, {FB_CMD_UPDATE_SUPER, UpdateSuperHandler}, {FB_CMD_OEM, OemCmdHandler}, }), }), transport_(std::make_unique<ClientUsbTransport>()), transport_(std::make_unique<ClientUsbTransport>()), boot_control_hal_(IBootControl::getService()), boot_control_hal_(IBootControl::getService()), Loading Loading @@ -120,10 +121,20 @@ void FastbootDevice::ExecuteCommands() { command[bytes_read] = '\0'; command[bytes_read] = '\0'; LOG(INFO) << "Fastboot command: " << command; LOG(INFO) << "Fastboot command: " << command; auto args = android::base::Split(command, ":"); auto found_command = kCommandMap.find(args[0]); std::vector<std::string> args; std::string cmd_name; if (android::base::StartsWith(command, "oem ")) { args = {command}; cmd_name = "oem"; } else { args = android::base::Split(command, ":"); cmd_name = args[0]; } auto found_command = kCommandMap.find(cmd_name); if (found_command == kCommandMap.end()) { if (found_command == kCommandMap.end()) { WriteStatus(FastbootResult::FAIL, "Unrecognized command"); WriteStatus(FastbootResult::FAIL, "Unrecognized command " + args[0]); continue; continue; } } if (!found_command->second(this, args)) { if (!found_command->second(this, args)) { Loading Loading
fastboot/constants.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ #define FB_CMD_DELETE_PARTITION "delete-logical-partition" #define FB_CMD_DELETE_PARTITION "delete-logical-partition" #define FB_CMD_RESIZE_PARTITION "resize-logical-partition" #define FB_CMD_RESIZE_PARTITION "resize-logical-partition" #define FB_CMD_UPDATE_SUPER "update-super" #define FB_CMD_UPDATE_SUPER "update-super" #define FB_CMD_OEM "oem" #define RESPONSE_OKAY "OKAY" #define RESPONSE_OKAY "OKAY" #define RESPONSE_FAIL "FAIL" #define RESPONSE_FAIL "FAIL" Loading
fastboot/device/commands.cpp +21 −0 Original line number Original line Diff line number Diff line Loading @@ -40,6 +40,9 @@ using ::android::hardware::hidl_string; using ::android::hardware::boot::V1_0::BoolResult; using ::android::hardware::boot::V1_0::BoolResult; using ::android::hardware::boot::V1_0::CommandResult; using ::android::hardware::boot::V1_0::CommandResult; using ::android::hardware::boot::V1_0::Slot; using ::android::hardware::boot::V1_0::Slot; using ::android::hardware::fastboot::V1_0::Result; using ::android::hardware::fastboot::V1_0::Status; using namespace android::fs_mgr; using namespace android::fs_mgr; struct VariableHandlers { struct VariableHandlers { Loading Loading @@ -133,6 +136,24 @@ bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args) return device->WriteStatus(FastbootResult::FAIL, "Erasing failed"); return device->WriteStatus(FastbootResult::FAIL, "Erasing failed"); } } bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args) { auto fastboot_hal = device->fastboot_hal(); if (!fastboot_hal) { return device->WriteStatus(FastbootResult::FAIL, "Unable to open fastboot HAL"); } Result ret; auto ret_val = fastboot_hal->doOemCommand(args[0], [&](Result result) { ret = result; }); if (!ret_val.isOk()) { return device->WriteStatus(FastbootResult::FAIL, "Unable to do OEM command"); } if (ret.status != Status::SUCCESS) { return device->WriteStatus(FastbootResult::FAIL, ret.message); } return device->WriteStatus(FastbootResult::OKAY, ret.message); } 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
fastboot/device/commands.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -45,3 +45,4 @@ bool CreatePartitionHandler(FastbootDevice* device, const std::vector<std::strin bool DeletePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool DeletePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool ResizePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool ResizePartitionHandler(FastbootDevice* device, const std::vector<std::string>& args); bool UpdateSuperHandler(FastbootDevice* device, const std::vector<std::string>& args); bool UpdateSuperHandler(FastbootDevice* device, const std::vector<std::string>& args); bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args);
fastboot/device/fastboot_device.cpp +14 −3 Original line number Original line Diff line number Diff line Loading @@ -48,6 +48,7 @@ FastbootDevice::FastbootDevice() {FB_CMD_DELETE_PARTITION, DeletePartitionHandler}, {FB_CMD_DELETE_PARTITION, DeletePartitionHandler}, {FB_CMD_RESIZE_PARTITION, ResizePartitionHandler}, {FB_CMD_RESIZE_PARTITION, ResizePartitionHandler}, {FB_CMD_UPDATE_SUPER, UpdateSuperHandler}, {FB_CMD_UPDATE_SUPER, UpdateSuperHandler}, {FB_CMD_OEM, OemCmdHandler}, }), }), transport_(std::make_unique<ClientUsbTransport>()), transport_(std::make_unique<ClientUsbTransport>()), boot_control_hal_(IBootControl::getService()), boot_control_hal_(IBootControl::getService()), Loading Loading @@ -120,10 +121,20 @@ void FastbootDevice::ExecuteCommands() { command[bytes_read] = '\0'; command[bytes_read] = '\0'; LOG(INFO) << "Fastboot command: " << command; LOG(INFO) << "Fastboot command: " << command; auto args = android::base::Split(command, ":"); auto found_command = kCommandMap.find(args[0]); std::vector<std::string> args; std::string cmd_name; if (android::base::StartsWith(command, "oem ")) { args = {command}; cmd_name = "oem"; } else { args = android::base::Split(command, ":"); cmd_name = args[0]; } auto found_command = kCommandMap.find(cmd_name); if (found_command == kCommandMap.end()) { if (found_command == kCommandMap.end()) { WriteStatus(FastbootResult::FAIL, "Unrecognized command"); WriteStatus(FastbootResult::FAIL, "Unrecognized command " + args[0]); continue; continue; } } if (!found_command->second(this, args)) { if (!found_command->second(this, args)) { Loading