diff --git a/BUILD.gn b/BUILD.gn index 0fd5474356e990d498f6eb1ebf9d418683ecd2e0..1f6eff4eca306129b0e9b08ee1499aea8d9a732f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -14,6 +14,10 @@ import("//build/ohos.gni") HDC_PATH = "//developtools/hdc_standard" +declare_args() { + hdc_support_flashd = true +} + hdc_common_sources = [ "${HDC_PATH}/src/common/async_cmd.cpp", "${HDC_PATH}/src/common/auth.cpp", @@ -35,6 +39,60 @@ config("hdc_config") { cflags_cc = [ "-std=c++17" ] } +ohos_source_set("hdc_deamon_flashd") { + sources = [ + "${HDC_PATH}/src/daemon/daemon.cpp", + "${HDC_PATH}/src/daemon/daemon_app.cpp", + "${HDC_PATH}/src/daemon/daemon_forward.cpp", + "${HDC_PATH}/src/daemon/daemon_tcp.cpp", + "${HDC_PATH}/src/daemon/daemon_unity.cpp", + "${HDC_PATH}/src/daemon/daemon_usb.cpp", + "${HDC_PATH}/src/daemon/jdwp.cpp", + "${HDC_PATH}/src/daemon/shell.cpp", + ] + + sources += hdc_common_sources + + defines = [ + "HARMONY_PROJECT", + "HDC_SUPPORT_FLASHD", + ] + + configs = [ ":hdc_config" ] + + deps = [ + "//third_party/libuv:uv_static", + "//third_party/lz4:liblz4_static", + "//third_party/openssl:libcrypto_static", + "//utils/native/base:utils", + ] + + if (use_musl) { + deps += [ + "//base/startup/init_lite/interfaces/innerkits/reboot:libreboot", + "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", + ] + } + + include_dirs = [ + "${HDC_PATH}/src/daemon", + "//base/update/updater/services/flashd", + "//base/update/updater/services/flashd/daemon", + "//base/update/updater/services/flashd/common", + "//utils/native/base/include", + "//third_party/lz4/lib", + "//third_party/openssl/include", + "//third_party/libuv", + ] + + if (use_musl) { + include_dirs += [ + "//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include", + "//base/startup/init_lite/interfaces/innerkits/include", + ] + } +} + ohos_executable("hdcd") { sources = [ "src/daemon/daemon.cpp", @@ -66,7 +124,7 @@ ohos_executable("hdcd") { ] } include_dirs = [ - "${HDC_PATH}/daemon", + "${HDC_PATH}/src/daemon", "//utils/native/base/include", "//third_party/lz4/lib", "//third_party/openssl/include", @@ -111,6 +169,11 @@ ohos_executable("hdc_std") { ] sources += hdc_common_sources + if (hdc_support_flashd) { + defines += [ "HDC_SUPPORT_FLASHD" ] + sources += [ "//base/update/updater/services/flashd/host/host_updater.cpp" ] + } + deps = [ "//third_party/libusb:libusb", "//third_party/libuv:uv_static", @@ -120,12 +183,19 @@ ohos_executable("hdc_std") { ] include_dirs = [ - "${HDC_PATH}/daemon", + "${HDC_PATH}/src/host", "//utils/native/base/include", "//third_party/lz4/lib", "//third_party/openssl/include", "//third_party/libuv", ] + + if (hdc_support_flashd) { + include_dirs += [ + "//base/update/updater/services/flashd/host", + "//base/update/updater/services/flashd/common", + ] + } subsystem_name = "developtools" part_name = "hdc_standard" } diff --git a/src/common/base.cpp b/src/common/base.cpp index f92c4865d5d76e3a1918b93420cec916069db44b..957b3ab2a3cdf6a9457599d7e145e345225a0b83 100644 --- a/src/common/base.cpp +++ b/src/common/base.cpp @@ -141,7 +141,11 @@ namespace Base { printf("%s", logBuf.c_str()); fflush(stdout); // logfile, not thread-safe +#ifdef HDC_SUPPORT_FLASHD + FILE *fp = fopen("/tmp/flashd_hdc.log", "a"); +#else FILE *fp = fopen("/data/local/tmp/hdc.log", "a"); +#endif if (fp == nullptr) { return; } @@ -257,7 +261,7 @@ namespace Base { constexpr int maxRetry = 3; for (closeRetry = 0; closeRetry < maxRetry; ++closeRetry) { if (uv_loop_close(ptrLoop) == UV_EBUSY) { - if (closeRetry > 2) { + if (closeRetry > 2) { // 2 try count WRITE_LOG(LOG_WARN, "%s close busy,try:%d", callerName, closeRetry); } @@ -537,17 +541,18 @@ namespace Base { bool SetHdcProperty(const char *key, const char *value) { -#ifndef __MUSL__ +#if (defined __MUSL__) && (!defined HDC_SUPPORT_FLASHD) + SetParameter(key, value); +#else #ifdef HDC_PCDEBUG WRITE_LOG(LOG_DEBUG, "Setproperty, key:%s value:%s", key, value); #else string sKey = key; string sValue = value; - string sBuf = "setprop " + sKey + " " + value; + string sBuf = "param set " + sKey + " " + value; + WRITE_LOG(LOG_DEBUG, "Setproperty, %s", sBuf.c_str()); system(sBuf.c_str()); #endif -#else - SetParameter(key, value); #endif return true; } diff --git a/src/common/define.h b/src/common/define.h index 7b1f6396c42872e158383b9adc951a9f5f55ab22..d0e410082a0c6668f81d198b13d18398ab9cfe76 100644 --- a/src/common/define.h +++ b/src/common/define.h @@ -93,5 +93,9 @@ constexpr char PREF_SEPARATOR = '\\'; #else constexpr char PREF_SEPARATOR = '/'; #endif +const string CMDSTR_UPDATE_SYSTEM = "update"; +const string CMDSTR_FLASH_PARTITION = "flash"; +const string CMDSTR_ERASE_PARTITION = "erase"; +const string CMDSTR_FORMAT_PARTITION = "format"; } // namespace Hdc #endif // HDC_DEFINE_H diff --git a/src/common/define_plus.h b/src/common/define_plus.h index d74797b65bde3a5d982b3f68be952a433f565c5c..4a157cbd764068b7ab37d770d6b8eaa45110e20d 100644 --- a/src/common/define_plus.h +++ b/src/common/define_plus.h @@ -152,6 +152,16 @@ enum HdcCommand { CMD_APP_DATA, CMD_APP_FINISH, CMD_APP_UNINSTALL, + // update + CMD_UPDATER_UPDATE_INIT = 4000, + CMD_UPDATER_FLASH_INIT, + CMD_UPDATER_CHECK, + CMD_UPDATER_BEGIN, + CMD_UPDATER_DATA, + CMD_UPDATER_FINISH = 4005, + CMD_UPDATER_ERASE, + CMD_UPDATER_FORMAT, + CMD_UPDATER_PROGRESS }; enum UsbProtocolOption { diff --git a/src/common/session.h b/src/common/session.h index ce0b760c929d2ab03342ee3449ec01f9fa60261f..fe5807171e0947556c411d5411319f3914198538 100644 --- a/src/common/session.h +++ b/src/common/session.h @@ -17,7 +17,7 @@ #include "common.h" namespace Hdc { -enum TaskType { TYPE_UNITY, TYPE_SHELL, TASK_FILE, TASK_FORWARD, TASK_APP }; +enum TaskType { TYPE_UNITY, TYPE_SHELL, TASK_FILE, TASK_FORWARD, TASK_APP, TASK_UPDATER }; class HdcSessionBase { public: diff --git a/src/common/task.cpp b/src/common/task.cpp index 13383b310b4df8d9945fb2a5a2227d6d227013e5..114618581236c1e1b4b81d6f63a10a91c3e929d1 100644 --- a/src/common/task.cpp +++ b/src/common/task.cpp @@ -65,6 +65,13 @@ void HdcTaskBase::LogMsg(MessageLevel level, const char *msg, ...) sessionBase->LogMsg(taskInfo->sessionId, taskInfo->channelId, level, log.c_str()); } +void HdcTaskBase::SendRawData(uint8_t *bufPtr, const int size) +{ + HdcSessionBase *sessionBase = (HdcSessionBase *)clsSession; + sessionBase->ServerCommand(taskInfo->sessionId, + taskInfo->channelId, CMD_KERNEL_ECHO_RAW, bufPtr, size); +} + bool HdcTaskBase::ServerCommand(const uint16_t command, uint8_t *bufPtr, const int size) { HdcSessionBase *hSession = (HdcSessionBase *)taskInfo->ownerSessionClass; diff --git a/src/common/task.h b/src/common/task.h index 1af6126ae93216e1f0d151b5b60498424ad92a18..0d0d5a67e3fad383058d9b70f637aa141df6efa0 100644 --- a/src/common/task.h +++ b/src/common/task.h @@ -34,7 +34,7 @@ public: } bool ReadyForRelease(); void TaskFinish(); - + void SendRawData(uint8_t *bufPtr, const int size); protected: // D/S==daemon/server bool SendToAnother(const uint16_t command, uint8_t *bufPtr, const int size); // D / S corresponds to the Task class void LogMsg(MessageLevel level, const char *msg, ...); // D / S log Send to Client diff --git a/src/common/transfer.h b/src/common/transfer.h index 9fbc18ffaa6ff8d17a2b684f127e8b8b42e029b1..f546298ae575254cc2b81a2c2c371482b4cbefbc 100644 --- a/src/common/transfer.h +++ b/src/common/transfer.h @@ -91,7 +91,7 @@ protected: CtxFile ctxNow; uint16_t commandBegin; uint16_t commandData; - + const uint8_t payloadPrefixReserve = 64; private: // dynamic IO context struct CtxFileIO { @@ -99,7 +99,7 @@ private: uint8_t *bufIO; CtxFile *context; }; - const uint8_t payloadPrefixReserve = 64; + static void OnFileIO(uv_fs_t *req); int SimpleFileIO(CtxFile *context, uint64_t index, uint8_t *sendBuf, int bytesIO); bool SendIOPayload(CtxFile *context, int index, uint8_t *data, int dataSize); diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index eb8ba1a815a7dfb4b65afd82118e7fdb44ddc66e..d18e5d7ecf3d846cd511f709dd5a67d586dc9dc9 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -92,11 +92,47 @@ void HdcDaemon::InitMod(bool bEnableTCP, bool bEnableUSB) } // clang-format off +#ifdef HDC_SUPPORT_FLASHD +bool HdcDaemon::RedirectToTaskForFlashd(HTaskInfo hTaskInfo, HSession hSession, const uint32_t channelId, + const uint16_t command, uint8_t *payload, const int payloadSize) +{ + bool ret = true; + hTaskInfo->ownerSessionClass = this; + switch (command) { + case CMD_UNITY_REBOOT: + ret = TaskCommandDispatch(hTaskInfo, TYPE_UNITY, command, payload, payloadSize); + break; + case CMD_UPDATER_UPDATE_INIT: + case CMD_UPDATER_FLASH_INIT: + case CMD_UPDATER_CHECK: + case CMD_UPDATER_BEGIN: + case CMD_UPDATER_DATA: + case CMD_UPDATER_FINISH: + case CMD_UPDATER_ERASE: + case CMD_UPDATER_FORMAT: + case CMD_UPDATER_PROGRESS: + ret = TaskCommandDispatch(hTaskInfo, TASK_UPDATER, command, payload, payloadSize); + break; + default: { + std::string info = "Command not support in flashd\n"; + Send(hSession->sessionId, channelId, CMD_KERNEL_ECHO_RAW, (uint8_t *)info.data(), info.size()); + uint8_t count = 1; + Send(hSession->sessionId, channelId, CMD_KERNEL_CHANNEL_CLOSE, &count, 1); + break; + } + } + return ret; +} +#endif + bool HdcDaemon::RedirectToTask(HTaskInfo hTaskInfo, HSession hSession, const uint32_t channelId, const uint16_t command, uint8_t *payload, const int payloadSize) { bool ret = true; hTaskInfo->ownerSessionClass = this; +#ifdef HDC_SUPPORT_FLASHD + return RedirectToTaskForFlashd(hTaskInfo, hSession, channelId, command, payload, payloadSize); +#endif switch (command) { case CMD_UNITY_EXECUTE: case CMD_UNITY_REMOUNT: @@ -134,9 +170,13 @@ bool HdcDaemon::RedirectToTask(HTaskInfo hTaskInfo, HSession hSession, const uin case CMD_FORWARD_CHECK_RESULT: ret = TaskCommandDispatch(hTaskInfo, TASK_FORWARD, command, payload, payloadSize); break; - default: - ret = false; + default: { + std::string info = "Command not support in hdcd\n"; + Send(hSession->sessionId, channelId, CMD_KERNEL_ECHO_RAW, (uint8_t *)info.data(), info.size()); + uint8_t count = 1; + Send(hSession->sessionId, channelId, CMD_KERNEL_CHANNEL_CLOSE, &count, 1); break; + } } return ret; } @@ -229,7 +269,7 @@ bool HdcDaemon::DaemonSessionHandshake(HSession hSession, const uint32_t channel } bool HdcDaemon::FetchCommand(HSession hSession, const uint32_t channelId, const uint16_t command, uint8_t *payload, - int payloadSize) + const int payloadSize) { bool ret = true; if (!hSession->handshakeOK && command != CMD_KERNEL_HANDSHAKE) { @@ -277,6 +317,11 @@ bool HdcDaemon::RemoveInstanceTask(const uint8_t op, HTaskInfo hTask) case TASK_APP: ret = DoTaskRemove(hTask, op); break; +#ifdef HDC_SUPPORT_FLASHD + case TASK_UPDATER: + ret = DoTaskRemove(hTask, op); + break; +#endif default: ret = false; break; diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h index b25929f4747a8f1517715a82ab183d5d0b3df743..d6c39b47874892e703b4b05c0c427d8e8a976d2b 100644 --- a/src/daemon/daemon.h +++ b/src/daemon/daemon.h @@ -33,7 +33,11 @@ public: private: bool RemoveInstanceTask(const uint8_t op, HTaskInfo hTask); bool RedirectToTask(HTaskInfo hTaskInfo, HSession hSession, const uint32_t channelId, const uint16_t command, - uint8_t *payload, const int payloadSize); + uint8_t *payload, const int payloadSize); +#ifdef HDC_SUPPORT_FLASHD + bool RedirectToTaskForFlashd(HTaskInfo hTaskInfo, HSession hSession, const uint32_t channelId, + const uint16_t command, uint8_t *payload, const int payloadSize); +#endif void JdwpNewFileDescriptor(const uint8_t *buf, const int bytesIO); bool HandDaemonAuth(HSession hSession, const uint32_t channelId, SessionHandShake &handshake); void ClearInstanceResource(); diff --git a/src/daemon/daemon_common.h b/src/daemon/daemon_common.h index e1563cebbed15c5c274f8eb45a64c659c69ad3bf..35786e03d0ba5a340faaec48984b47db6f2aea33 100644 --- a/src/daemon/daemon_common.h +++ b/src/daemon/daemon_common.h @@ -29,6 +29,9 @@ #include "daemon_app.h" #include "daemon_usb.h" #include "daemon_forward.h" +#ifdef HDC_SUPPORT_FLASHD +#include "daemon_updater.h" +#endif #include "shell.h" // clang-format on diff --git a/src/daemon/daemon_unity.cpp b/src/daemon/daemon_unity.cpp index c4dc63af94d50de34ffdc51f87ff05aa67aaca29..5a4aa0671e2d33a131b00e2a8310cdb71c8a85db 100644 --- a/src/daemon/daemon_unity.cpp +++ b/src/daemon/daemon_unity.cpp @@ -191,6 +191,8 @@ bool HdcDaemonUnity::RebootDevice(const string &cmd) reason = "updater"; } else if (cmd == "bootloader") { reason = "NoArgument"; + } else { + reason = cmd; } return DoReboot(reason.c_str()); #endif diff --git a/src/host/client.cpp b/src/host/client.cpp index 0878fe4a06f62cd612a9721614d978bd4e6be15a..2f4beca6995687995f654a51f6be4cc436b53465 100644 --- a/src/host/client.cpp +++ b/src/host/client.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ #include "client.h" + +#include #include "server.h" namespace Hdc { @@ -25,6 +27,11 @@ HdcClient::HdcClient(const bool serverOrClient, const string &addrString, uv_loo HdcClient::~HdcClient() { +#ifndef _WIN32 + if (terminalChanged) { + tcsetattr(STDIN_FILENO, TCSAFLUSH, &terminalState); + } +#endif Base::TryCloseLoop(loopMain, "ExecuteCommand finish"); } @@ -203,11 +210,66 @@ void HdcClient::CommandWorker(uv_timer_t *handle) return; } uv_timer_stop(handle); - WRITE_LOG(LOG_DEBUG, "Connect server successful"); + if (!thisClass->ConfirmCommand(thisClass->command)) { + uv_timer_stop(handle); + uv_stop(thisClass->loopMain); + WRITE_LOG(LOG_DEBUG, "Cmd \'%s\' has been canceld", thisClass->command.c_str()); + return; + } + thisClass->ForbitInputForCommand(thisClass->command); + thisClass->Send(thisClass->channel->channelId, (uint8_t *)thisClass->command.c_str(), thisClass->command.size() + 1); } +bool HdcClient::ConfirmCommand(const string &commandIn) +{ + bool needConfirm = false; + std::string tip = ""; + WRITE_LOG(LOG_DEBUG, "ConfirmCommand %s \n", commandIn.c_str()); + if (!strncmp(commandIn.c_str(), CMDSTR_FLASH_PARTITION.c_str(), CMDSTR_FLASH_PARTITION.size())) { + tip = "Confirm flash partition"; + } else if (!strncmp(commandIn.c_str(), CMDSTR_ERASE_PARTITION.c_str(), CMDSTR_ERASE_PARTITION.size())) { + tip = "Confirm erase partition"; + } else if (!strncmp(commandIn.c_str(), CMDSTR_FORMAT_PARTITION.c_str(), CMDSTR_FORMAT_PARTITION.size())) { + tip = "Confirm format partition"; + } + if (tip.empty()) { + return true; + } + // check if -f + if (strstr(commandIn.c_str(), " -f") != nullptr) { + return true; + } + const size_t minLen = strlen("yes"); + do { + printf(" %s ? (Yes/No) ", tip.c_str()); + fflush(stdin); + std::string info = {}; + size_t i = 0; + while (1) { + char c = getchar(); + if (c == '\r' || c == '\n') { + break; + } + if (c == ' ') { + continue; + } + if (i < minLen && isprint(c)) { + info.append(1, std::tolower(c)); + i++; + } + } + if (info == "n" || info == "no") { + return false; + } + if (info == "y" || info == "yes") { + return true; + } + } while (1); + return true; +} + void HdcClient::AllocStdbuf(uv_handle_t *handle, size_t sizeWanted, uv_buf_t *buf) { if (sizeWanted <= 0) { @@ -337,5 +399,26 @@ int HdcClient::ReadChannel(HChannel hChannel, uint8_t *buf, const int bytesIO) fprintf(stdout, "%s", s.c_str()); fflush(stdout); return 0; -}; +} + +void HdcClient::ForbitInputForCommand(const string &commandIn) +{ +#ifndef _WIN32 + WRITE_LOG(LOG_DEBUG, "ForbitInputForCommand %s \n", commandIn.c_str()); + if ((strncmp(commandIn.c_str(), CMDSTR_FLASH_PARTITION.c_str(), CMDSTR_FLASH_PARTITION.size()) != 0) && + (strncmp(commandIn.c_str(), CMDSTR_UPDATE_SYSTEM.c_str(), CMDSTR_ERASE_PARTITION.size()) != 0)) { + return; + } + if (tcgetattr(STDIN_FILENO, &terminalState)) + return; + termios tio; + if (tcgetattr(STDIN_FILENO, &tio)) + return; + cfmakeraw(&tio); + tio.c_cc[VTIME] = 0; + tio.c_cc[VMIN] = 1; + tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio); + terminalChanged = true; +#endif +} } // namespace Hdc \ No newline at end of file diff --git a/src/host/client.h b/src/host/client.h index 6d315d549b4d9582e57f4bce39f9100ed56157d6..560446b82010c22924b0601bc5d44b0b1c301623 100644 --- a/src/host/client.h +++ b/src/host/client.h @@ -24,7 +24,8 @@ public: int Initial(const string &connectKeyIn); int ExecuteCommand(const string &commandIn); int CtrlServiceWork(const char *commandIn); - + bool ConfirmCommand(const string &commandIn); + void ForbitInputForCommand(const string &commandIn); protected: private: static void DoCtrlServiceWork(uv_check_t *handle); @@ -45,6 +46,7 @@ private: #ifndef _WIN32 termios terminalState; + bool terminalChanged = false; #endif string connectKey; string command; diff --git a/src/host/host_common.h b/src/host/host_common.h index 88dfaea55b1cff40ab8f73ea0793592faf373238..7fdd7c0b732449b7dbdf5be77b990aa7aea18c39 100644 --- a/src/host/host_common.h +++ b/src/host/host_common.h @@ -31,6 +31,9 @@ #include "host_app.h" #include "host_forward.h" #include "host_unity.h" +#ifdef HDC_SUPPORT_FLASHD +#include "host_updater.h" +#endif // clang-format on #endif \ No newline at end of file diff --git a/src/host/main.cpp b/src/host/main.cpp index 80d8c2caef06c6684fc4e26681cb4c2181861ac5..0364e651a6afd028aeea331df1546a3ef522cfe9 100644 --- a/src/host/main.cpp +++ b/src/host/main.cpp @@ -66,6 +66,10 @@ int IsRegisterCommand(string &outCommand, const char *cmd, const char *cmdnext) registerCommand.push_back(CMDSTR_TARGET_REBOOT); registerCommand.push_back(CMDSTR_LIST_JDWP); + registerCommand.push_back(CMDSTR_UPDATE_SYSTEM); + registerCommand.push_back(CMDSTR_FLASH_PARTITION); + registerCommand.push_back(CMDSTR_ERASE_PARTITION); + registerCommand.push_back(CMDSTR_FORMAT_PARTITION); for (string v : registerCommand) { if (doubleCommand == v) { outCommand = doubleCommand; diff --git a/src/host/server.cpp b/src/host/server.cpp index faf9834f27f0886e7be9123912cc385b21cebfcf..9f357ec3a5698bb80c0d55053b94f887bf633c50 100644 --- a/src/host/server.cpp +++ b/src/host/server.cpp @@ -422,7 +422,7 @@ bool HdcServer::ServerSessionHandshake(HSession hSession, uint8_t *payload, int } bool HdcServer::FetchCommand(HSession hSession, const uint32_t channelId, const uint16_t command, uint8_t *payload, - int payloadSize) + const int payloadSize) { bool ret = true; HdcServerForClient *pSfc = static_cast(clsServerForClient); @@ -735,6 +735,19 @@ bool HdcServer::RedirectToTask(HTaskInfo hTaskInfo, HSession hSession, const uin case CMD_APP_UNINSTALL: ret = TaskCommandDispatch(hTaskInfo, TASK_APP, command, payload, payloadSize); break; +#ifdef HDC_SUPPORT_FLASHD + case CMD_UPDATER_UPDATE_INIT: + case CMD_UPDATER_FLASH_INIT: + case CMD_UPDATER_CHECK: + case CMD_UPDATER_BEGIN: + case CMD_UPDATER_DATA: + case CMD_UPDATER_FINISH: + case CMD_UPDATER_ERASE: + case CMD_UPDATER_FORMAT: + case CMD_UPDATER_PROGRESS: + ret = TaskCommandDispatch(hTaskInfo, TASK_UPDATER, command, payload, payloadSize); + break; +#endif default: ret = false; break; @@ -761,6 +774,11 @@ bool HdcServer::RemoveInstanceTask(const uint8_t op, HTaskInfo hTask) case TASK_APP: ret = DoTaskRemove(hTask, op); break; +#ifdef HDC_SUPPORT_FLASHD + case TASK_UPDATER: + ret = DoTaskRemove(hTask, op); + break; +#endif default: ret = false; break; diff --git a/src/host/server.h b/src/host/server.h index 9562b2052fd23c9458610a5707f3cfdb5f299505..cd177c2209ee202a1c8e382386ce8f8e50bf4779 100644 --- a/src/host/server.h +++ b/src/host/server.h @@ -39,7 +39,7 @@ public: private: void ClearInstanceResource(); - void BuildDaemonVisableLine(HDaemonInfo hDaemonInfoInOut, bool fullDisplay, string &out); + void BuildDaemonVisableLine(HDaemonInfo hdi, bool fullDisplay, string &out); void BuildForwardVisableLine(bool fullOrSimble, HForwardInfo hfi, string &echo); void ClearMapDaemonInfo(); bool ServerCommand(const uint32_t sessionId, const uint32_t channelId, const uint16_t command, uint8_t *bufPtr, diff --git a/src/host/server_for_client.cpp b/src/host/server_for_client.cpp index 44745368abff1921aff6a000c98f9fe9a242a0d1..373e48036aa1ba2e29dac06b30ec484e3e8afa14 100644 --- a/src/host/server_for_client.cpp +++ b/src/host/server_for_client.cpp @@ -418,7 +418,13 @@ bool HdcServerForClient::TaskCommand(HChannel hChannel, void *formatCommandInput sizeCmdFlag = 10; // 10: cmdFlag bugreport size } else if (CMD_APP_SIDELOAD == formatCommand->cmdFlag) { cmdFlag = "sideload "; - sizeCmdFlag = 9; + sizeCmdFlag = 9; // 9: cmdFlag sideload size + } else if (CMD_UPDATER_UPDATE_INIT == formatCommand->cmdFlag) { + cmdFlag = "update "; + sizeCmdFlag = 7; // 7: cmdFlag update size + } else if (CMD_UPDATER_FLASH_INIT == formatCommand->cmdFlag) { + cmdFlag = "flash "; + sizeCmdFlag = 6; // 6: cmdFlag flash size } if (!strncmp(formatCommand->paraments.c_str(), cmdFlag.c_str(), sizeCmdFlag)) { // local do HSession hSession = FindAliveSession(hChannel->targetSessionId); @@ -467,7 +473,11 @@ bool HdcServerForClient::DoCommandRemote(HChannel hChannel, void *formatCommandI case CMD_APP_INIT: case CMD_APP_UNINSTALL: case CMD_UNITY_BUGREPORT_INIT: - case CMD_APP_SIDELOAD: { + case CMD_APP_SIDELOAD: + case CMD_UPDATER_UPDATE_INIT: + case CMD_UPDATER_FLASH_INIT: + case CMD_UPDATER_ERASE: + case CMD_UPDATER_FORMAT: { TaskCommand(hChannel, formatCommandInput); ret = true; break; diff --git a/src/host/translate.cpp b/src/host/translate.cpp index be05056ae3a098181d6072bd0766011abc060ad7..0f079f68776b780844395eb11a7fe7fc4dacba90 100644 --- a/src/host/translate.cpp +++ b/src/host/translate.cpp @@ -40,7 +40,7 @@ namespace TranslateCommand { "\n" "service commands(on daemon):\n" " target mount - Set /system /vendor partition read-write\n" - " target boot [-bootloader|-recovery] - Reboot the device or boot into bootloader\\recovery.\n" + " target boot [-bootloader|-recovery] - Reboot the device or boot into bootloader\\recovery\n" " smode [-r] - Restart daemon with root permissions, '-r' to cancel root\n" " permissions\n" " tmode usb - Reboot the device, listening on USB\n" @@ -88,7 +88,15 @@ namespace TranslateCommand { " sideload [PATH] - Sideload the given full OTA package\n" "\n" "security commands:\n" - " keygen FILE - Generate public/private key; key stored in FILE and FILE.pub\n"; + " keygen FILE - Generate public/private key; key stored in FILE and FILE.pub\n" + "\n" + "---------------------------------flash commands:-------------------------------------\n" + "flash commands:\n" + " target boot [-flash] - Reboot the device or boot into flash\n" + " update packagename - Update system by packagename\n" + " flash partition filename - Flash partition by filename\n" + " erase partition [-f] - erase partition\n" + " format partition [-f] -t fs_type - format partition -t [ext4 | f2fs]\n"; return ret; } @@ -125,10 +133,10 @@ namespace TranslateCommand { const char *pExtra = input + 6; // CMDSTR_FORWARD_FPORT CMDSTR_FORWARD_RPORT + " " size if (!strcmp(pExtra, "ls")) { outCmd->cmdFlag = CMD_FORWARD_LIST; - } else if (!strncmp(pExtra, "rm", 2)) { + } else if (!strncmp(pExtra, "rm", 2)) { // 2 rm size outCmd->cmdFlag = CMD_FORWARD_REMOVE; if (strcmp(pExtra, "rm")) { - outCmd->paraments = input + 9; + outCmd->paraments = input + 9; // 9 rm extra size } } else { const char *p = input + 6; @@ -170,7 +178,8 @@ namespace TranslateCommand { outCmd->cmdFlag = CMD_UNITY_REBOOT; if (strcmp(input, CMDSTR_TARGET_REBOOT.c_str())) { outCmd->paraments = input + 12; - if (outCmd->paraments != "-bootloader" && outCmd->paraments != "-recovery") { + if (outCmd->paraments != "-bootloader" + && outCmd->paraments != "-recovery" && outCmd->paraments != "-flash") { stringError = "Error reboot paramenter"; outCmd->bJumpDo = true; } else { @@ -180,6 +189,31 @@ namespace TranslateCommand { return stringError; } + static bool CheckMatchUpdate(const char *input, std::string &stringError, FormatCommand *outCmd) + { + int cmdLen = CMDSTR_UPDATE_SYSTEM.size(); + if (!strncmp(input, CMDSTR_UPDATE_SYSTEM.c_str(), CMDSTR_UPDATE_SYSTEM.size())) { + outCmd->cmdFlag = CMD_UPDATER_UPDATE_INIT; + cmdLen = CMDSTR_UPDATE_SYSTEM.size(); + } else if (!strncmp(input, CMDSTR_FLASH_PARTITION.c_str(), CMDSTR_FLASH_PARTITION.size())) { + outCmd->cmdFlag = CMD_UPDATER_FLASH_INIT; + cmdLen = CMDSTR_FLASH_PARTITION.size(); + } else if (!strncmp(input, CMDSTR_ERASE_PARTITION.c_str(), CMDSTR_ERASE_PARTITION.size())) { + outCmd->cmdFlag = CMD_UPDATER_ERASE; + cmdLen = CMDSTR_ERASE_PARTITION.size(); + } else if (!strncmp(input, CMDSTR_FORMAT_PARTITION.c_str(), CMDSTR_FORMAT_PARTITION.size())) { + outCmd->cmdFlag = CMD_UPDATER_FORMAT; + cmdLen = CMDSTR_FORMAT_PARTITION.size(); + } else { + return false; + } + if (strlen(input) <= cmdLen) { + stringError = "Incorrect command"; + outCmd->bJumpDo = true; + } + return true; + } + // command input // client side:Enter string data formatting conversion to module see internal processing command string String2FormatCommand(const char *input, int sizeInput, FormatCommand *outCmd) @@ -238,7 +272,7 @@ namespace TranslateCommand { } else if (!strcmp(input, CMDSTR_LIST_JDWP.c_str())) { outCmd->cmdFlag = CMD_UNITY_JPID; } else if (!strncmp(input, CMDSTR_TARGET_REBOOT.c_str(), CMDSTR_TARGET_REBOOT.size())) { - TargetReboot(input, outCmd); + stringError = TargetReboot(input, outCmd); } else if (!strncmp(input, CMDSTR_TARGET_MODE.c_str(), CMDSTR_TARGET_MODE.size())) { RunMode(input, outCmd); } else if (!strcmp(input, CMDSTR_CONNECT_ANY.c_str())) { @@ -266,6 +300,8 @@ namespace TranslateCommand { if (outCmd->paraments.size() == CMDSTR_BUGREPORT.size()) { outCmd->paraments += " "; } + } else if (CheckMatchUpdate(input, stringError, outCmd)) { + outCmd->paraments = input; } else { stringError = "Unknow command..."; outCmd->bJumpDo = true;