Skip to content

Use the SARA U-201 modem for storing OTA update image. #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions extras/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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`
Expand All @@ -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
```
4 changes: 2 additions & 2 deletions extras/tools/bin2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion extras/tools/bin2ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion extras/tools/ota-upload.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/ArduinoIoTCloud_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#define OTA_STORAGE_MKRMEM (0)
#endif

#ifndef OTA_STORAGE_MKRGSM
#define OTA_STORAGE_MKRGSM (0)
#endif

/******************************************************************************
* AUTOMATIC CONFIGURED DEFINES
******************************************************************************/
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/utility/ota/OTAStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class OTAStorage
enum class Type : int
{
NotAvailable = -1,
MKRMEM = 0
MKRMEM = 0,
MKRGSMFile = 2,
};

virtual Type type () = 0;
Expand Down
90 changes: 90 additions & 0 deletions src/utility/ota/OTAStorage_MKRGSM.cpp
Original file line number Diff line number Diff line change
@@ -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 [email protected].
*/

/******************************************************************************
INCLUDE
******************************************************************************/

#include <ArduinoIoTCloud_Config.h>
#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 */
60 changes: 60 additions & 0 deletions src/utility/ota/OTAStorage_MKRGSM.h
Original file line number Diff line number Diff line change
@@ -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 [email protected].
*/

#ifndef ARDUINO_OTA_STORAGE_MKRGSM_H_
#define ARDUINO_OTA_STORAGE_MKRGSM_H_

/******************************************************************************
* INCLUDE
******************************************************************************/

#include <ArduinoIoTCloud_Config.h>
#if OTA_STORAGE_MKRGSM

#include "OTAStorage.h"

#include <GSMFileUtils.h>

/******************************************************************************
* 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_ */