diff --git a/extras/tools/README.md b/extras/tools/README.md index a44c544c5..475fe41f3 100644 --- a/extras/tools/README.md +++ b/extras/tools/README.md @@ -4,7 +4,7 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t ### How-To-Use ```bash -./bin2ota.py sketch.bin sketch-ota.bin +./bin2ota.py sketch.bin sketch.ota ``` #### `sketch.bin` ```bash @@ -17,7 +17,7 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t * `length(sketch.bin) = 0x0003'A5E0` * `CRC32(sketch.bin) = 0xA9D1'265B` -#### `sketch-ota.bin` +#### `sketch.ota` ```bash 0000000 A5E0 0003 265B A9D1 8000 2000 749D 0000 0000010 7485 0000 7485 0000 0000 0000 0000 0000 @@ -31,7 +31,7 @@ This tool converts the binary file into base64 encoded JSON which is necessary f ### How-To-Use ```bash -./bin2json.py sketch-ota.bin sketch-ota.json +./bin2json.py sketch.ota sketch.json ``` `ota-upload.sh` @@ -40,5 +40,5 @@ This tool allows to upload a OTA binary to a device via a Arduino cloud server. ### How-To-Use ```bash -./ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch-ota.json +./ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch.json ``` \ No newline at end of file diff --git a/extras/tools/bin2json.py b/extras/tools/bin2json.py index 0d01cbcef..b7371c87e 100755 --- a/extras/tools/bin2json.py +++ b/extras/tools/bin2json.py @@ -5,10 +5,10 @@ import base64 CHUNK_SIZE = 256 # This is the chunk size of how the binary is split on the server side for not overloading the embedded device receive buffers. -INTER_CHUNK_DELAY_MS = 100 # This is delay between 2 consecutive chunks so as to not over load the embedded device. +INTER_CHUNK_DELAY_MS = 250 # This is delay between 2 consecutive chunks so as to not over load the embedded device. if len(sys.argv) != 3: - print ("Usage: bin2json.py sketch-ota.bin sketch-ota.json") + print ("Usage: bin2json.py sketch.ota sketch.json") sys.exit() ifile = sys.argv[1] diff --git a/extras/tools/bin2ota.py b/extras/tools/bin2ota.py index 49ff4075d..0df4646ce 100755 --- a/extras/tools/bin2ota.py +++ b/extras/tools/bin2ota.py @@ -4,7 +4,7 @@ import crccheck if len(sys.argv) != 3: - print ("Usage: bin2ota.py sketch.bin sketch-ota.bin") + print ("Usage: bin2ota.py sketch.bin sketch.ota") sys.exit() ifile = sys.argv[1] diff --git a/extras/tools/ota-upload.sh b/extras/tools/ota-upload.sh index 0470ba979..d70f1b019 100755 --- a/extras/tools/ota-upload.sh +++ b/extras/tools/ota-upload.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ "$#" -ne 4 ]; then - echo "Usage: ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch-ota.base64" + echo "Usage: ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch.json" exit 1 fi diff --git a/src/ArduinoIoTCloud_Config.h b/src/ArduinoIoTCloud_Config.h index d6840558a..2d05b8d9e 100644 --- a/src/ArduinoIoTCloud_Config.h +++ b/src/ArduinoIoTCloud_Config.h @@ -26,6 +26,10 @@ #define OTA_STORAGE_MKRMEM (0) #endif +#ifndef OTA_STORAGE_MKRGSM + #define OTA_STORAGE_MKRGSM (0) +#endif + /****************************************************************************** * AUTOMATIC CONFIGURED DEFINES ******************************************************************************/ @@ -34,7 +38,7 @@ #define OTA_STORAGE_MKRMEM (0) #endif -#if OTA_STORAGE_MKRMEM +#if OTA_STORAGE_MKRMEM || OTA_STORAGE_MKRGSM #define OTA_ENABLED (1) #else #define OTA_ENABLED (0) diff --git a/src/utility/ota/OTAStorage.h b/src/utility/ota/OTAStorage.h index 29a09c752..19d38f7e4 100644 --- a/src/utility/ota/OTAStorage.h +++ b/src/utility/ota/OTAStorage.h @@ -40,7 +40,8 @@ class OTAStorage enum class Type : int { NotAvailable = -1, - MKRMEM = 0 + MKRMEM = 0, + MKRGSMFile = 2, }; virtual Type type () = 0; diff --git a/src/utility/ota/OTAStorage_MKRGSM.cpp b/src/utility/ota/OTAStorage_MKRGSM.cpp new file mode 100644 index 000000000..07731bacb --- /dev/null +++ b/src/utility/ota/OTAStorage_MKRGSM.cpp @@ -0,0 +1,90 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include +#if OTA_STORAGE_MKRGSM + +#include "OTAStorage_MKRGSM.h" + +/****************************************************************************** + CONSTANTS + ******************************************************************************/ + +static char const SSU_UPDATE_FILENAME[] = "UPDATE.BIN"; +static char const SSU_CHECK_FILE_NAME[] = "UPDATE.OK"; + +/****************************************************************************** + PUBLIC MEMBER FUNCTIONS + ******************************************************************************/ + +bool OTAStorage_MKRGSM::init() +{ + if (!_fileUtils.begin()) + return false; + + if (_fileUtils.listFile(SSU_UPDATE_FILENAME) > 0) + if (!_fileUtils.deleteFile(SSU_UPDATE_FILENAME)) + return false; + + if (_fileUtils.listFile(SSU_CHECK_FILE_NAME) > 0) + if (!_fileUtils.deleteFile(SSU_CHECK_FILE_NAME)) + return false; +} + +bool OTAStorage_MKRGSM::open(char const * /* file_name */) +{ + return true; +} + +size_t OTAStorage_MKRGSM::write(uint8_t const* const buf, size_t const num_bytes) +{ + _fileUtils.appendFile(SSU_UPDATE_FILENAME, (const char*)buf, num_bytes); + return num_bytes; +} + +void OTAStorage_MKRGSM::close() +{ + /* Nothing to do */ +} + +void OTAStorage_MKRGSM::remove(char const * /* file_name */) +{ + _fileUtils.deleteFile(SSU_UPDATE_FILENAME); +} + +bool OTAStorage_MKRGSM::rename(char const * /* old_file_name */, char const * /* new_file_name */) +{ + /* Create a file 'UPDATE.OK' which is used by the SSU + * 2nd stage bootloader to recognise that the update + * went okay. Normally this is done by renaming 'UPDATE.BIN.TMP' + * to 'UPDATE.BIN' but the SARE module does not support + * a rename function. + */ + char c = 'X'; + return (_fileUtils.appendFile(SSU_CHECK_FILE_NAME, &c, sizeof(c)) == sizeof(c)); +} + +void OTAStorage_MKRGSM::deinit() +{ + /* Nothing to do */ +} + +#endif /* OTA_STORAGE_MKRGSM */ diff --git a/src/utility/ota/OTAStorage_MKRGSM.h b/src/utility/ota/OTAStorage_MKRGSM.h new file mode 100644 index 000000000..748ead1aa --- /dev/null +++ b/src/utility/ota/OTAStorage_MKRGSM.h @@ -0,0 +1,60 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef ARDUINO_OTA_STORAGE_MKRGSM_H_ +#define ARDUINO_OTA_STORAGE_MKRGSM_H_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include +#if OTA_STORAGE_MKRGSM + +#include "OTAStorage.h" + +#include + +/****************************************************************************** + * CLASS DECLARATION + ******************************************************************************/ + +class OTAStorage_MKRGSM : public OTAStorage +{ +public: + + virtual ~OTAStorage_MKRGSM() { } + + + virtual Type type () override { return Type::MKRGSMFile; } + virtual bool init () override; + virtual bool open (char const * file_name) override; + virtual size_t write (uint8_t const * const buf, size_t const num_bytes) override; + virtual void close () override; + virtual void remove(char const * file_name) override; + virtual bool rename(char const * old_file_name, char const * new_file_name) override; + virtual void deinit() override; + +private: + + GSMFileUtils _fileUtils; + +}; + +#endif /* OTA_STORAGE_MKRGSM */ + +#endif /* ARDUINO_OTA_STORAGE_MKRGSM_H_ */