From 1870facf5636ee237b217c5950bb64597ee21a51 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Fri, 29 May 2020 22:14:22 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - radio-cmd implementation Implemented a command for delta radio firmware upgrade file uploads. --- main.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 5169d4e..8ac634d 100644 --- a/main.cpp +++ b/main.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "Version.h" const std::string DEFAULT_PORT("/dev/modem_at1"); @@ -68,6 +70,7 @@ std::string g_sConfigFile; Json::Value g_jData; std::string g_sSimPin; std::string g_sCellularMode; +std::string g_sDeltaFwPath; MTS::AutoPtr g_apRadio; @@ -108,6 +111,8 @@ const uint32_t OPT_SET_CELLULAR_MODE = 0x08000000; const uint32_t OPT_UNLOCK_SIM_CARD = 0x20000000; const uint32_t OPT_RESET_RADIO = 0x40000000; +int32_t g_iAuxOptions = 0; +const uint32_t AOPT_DFU_UPLOAD = 0x00000001; void handle_sigterm(int signum); void printHelp(const std::string& sApp); @@ -152,11 +157,13 @@ static struct option long_options[] = { { "init-activation", no_argument, &iOption, OPT_INIT_ACTIVATION }, { "factory-default", no_argument, &iOption, OPT_INIT_RTN }, { "set-cellular-mode", required_argument, 0, 'w' }, + { "delta-fwu-upload", required_argument, 0, 'x' }, { 0, 0, 0, 0 } }; Json::Value getStaticData(); Json::Value getNetworkData(); +MTS::IO::ICellularRadio::CODE handleDeltaFwUpload(const std::string& sPath); MTS::IO::ICellularRadio::UpdateCb cb = [](const Json::Value& s)->void { if(s.isString()) { @@ -386,6 +393,8 @@ int main(int argc, char** argv) { } else { printf("Invalid argument: %s\n", g_sCellularMode.c_str()); } + } else if (g_iAuxOptions & AOPT_DFU_UPLOAD) { + result = handleDeltaFwUpload(g_sDeltaFwPath); } shutdown(); @@ -606,6 +615,12 @@ void parseOptions(int argc, char** argv) g_iOptions |= OPT_SET_CELLULAR_MODE; break; + case 'x': + if (optarg) + g_sDeltaFwPath = optarg; + g_iAuxOptions |= AOPT_DFU_UPLOAD; + break; + default: printf("OPTION: [%d] ABORTING!!\n", c); abort(); @@ -656,13 +671,14 @@ void printHelp(const std::string& sApp) { printf("\t--factory-default [ --msl ] : reset to factory defaults\n"); printf("\t--unlock-sim-card : unlock the SIM card using the PIN code provided\n"); printf("\t--reset-radio : reset the radio module using AT commands\n"); + printf("\t--delta-fwu-upload : upload a delta radio FWU file to the radio\n"); printf("\n"); printf("\t--printlvl (p) : sets the printlvl [0-100]\n"); printf("\t--version (v) : returns version\n"); printf("\t--help (?) : returns this message\n"); printf("\n"); printf("\tSupported Radios:\n"); - printf("\t\tLE910, HE910, GE910, DE910, CE910\n"); + printf("\t\tLE910, HE910, GE910, DE910, CE910, ME910, EG95\n"); } const char *code2str(MTS::IO::ICellularRadio::CODE code) { @@ -704,3 +720,16 @@ MTS::IO::ICellularRadio::CELLULAR_MODES cellularModeFlags(const std::string netw } return static_cast(result); } + +MTS::IO::ICellularRadio::CODE handleDeltaFwUpload(const std::string& sPath) { + int fd = open(sPath.c_str(), O_RDONLY); + if (fd < 0) { + printf("Failed to open file [%s]: %d\n", sPath.c_str(), errno); + return MTS::IO::ICellularRadio::CODE::ERROR; + } + + auto rc = g_apRadio->uploadDeltaFirmwareFile(fd, cb); + close(fd); + + return rc; +} -- cgit v1.2.3