Skip to content

Commit cdf9714

Browse files
authored
Merge pull request #153 from arduino-libraries/ota-gsm
Use the SARA U-201 modem for storing OTA update image.
2 parents d589f5b + 4b7b489 commit cdf9714

File tree

8 files changed

+165
-10
lines changed

8 files changed

+165
-10
lines changed

extras/tools/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t
44

55
### How-To-Use
66
```bash
7-
./bin2ota.py sketch.bin sketch-ota.bin
7+
./bin2ota.py sketch.bin sketch.ota
88
```
99
#### `sketch.bin`
1010
```bash
@@ -17,7 +17,7 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t
1717
* `length(sketch.bin) = 0x0003'A5E0`
1818
* `CRC32(sketch.bin) = 0xA9D1'265B`
1919

20-
#### `sketch-ota.bin`
20+
#### `sketch.ota`
2121
```bash
2222
0000000 A5E0 0003 265B A9D1 8000 2000 749D 0000
2323
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
3131

3232
### How-To-Use
3333
```bash
34-
./bin2json.py sketch-ota.bin sketch-ota.json
34+
./bin2json.py sketch.ota sketch.json
3535
```
3636

3737
`ota-upload.sh`
@@ -40,5 +40,5 @@ This tool allows to upload a OTA binary to a device via a Arduino cloud server.
4040

4141
### How-To-Use
4242
```bash
43-
./ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch-ota.json
43+
./ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch.json
4444
```

extras/tools/bin2json.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import base64
66

77
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.
8-
INTER_CHUNK_DELAY_MS = 100 # This is delay between 2 consecutive chunks so as to not over load the embedded device.
8+
INTER_CHUNK_DELAY_MS = 250 # This is delay between 2 consecutive chunks so as to not over load the embedded device.
99

1010
if len(sys.argv) != 3:
11-
print ("Usage: bin2json.py sketch-ota.bin sketch-ota.json")
11+
print ("Usage: bin2json.py sketch.ota sketch.json")
1212
sys.exit()
1313

1414
ifile = sys.argv[1]

extras/tools/bin2ota.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import crccheck
55

66
if len(sys.argv) != 3:
7-
print ("Usage: bin2ota.py sketch.bin sketch-ota.bin")
7+
print ("Usage: bin2ota.py sketch.bin sketch.ota")
88
sys.exit()
99

1010
ifile = sys.argv[1]

extras/tools/ota-upload.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
if [ "$#" -ne 4 ]; then
4-
echo "Usage: ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch-ota.base64"
4+
echo "Usage: ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch.json"
55
exit 1
66
fi
77

src/ArduinoIoTCloud_Config.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#define OTA_STORAGE_MKRMEM (0)
2727
#endif
2828

29+
#ifndef OTA_STORAGE_MKRGSM
30+
#define OTA_STORAGE_MKRGSM (0)
31+
#endif
32+
2933
/******************************************************************************
3034
* AUTOMATIC CONFIGURED DEFINES
3135
******************************************************************************/
@@ -34,7 +38,7 @@
3438
#define OTA_STORAGE_MKRMEM (0)
3539
#endif
3640

37-
#if OTA_STORAGE_MKRMEM
41+
#if OTA_STORAGE_MKRMEM || OTA_STORAGE_MKRGSM
3842
#define OTA_ENABLED (1)
3943
#else
4044
#define OTA_ENABLED (0)

src/utility/ota/OTAStorage.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class OTAStorage
4040
enum class Type : int
4141
{
4242
NotAvailable = -1,
43-
MKRMEM = 0
43+
MKRMEM = 0,
44+
MKRGSMFile = 2,
4445
};
4546

4647
virtual Type type () = 0;

src/utility/ota/OTAStorage_MKRGSM.cpp

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
This file is part of ArduinoIoTCloud.
3+
4+
Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of arduino-cli.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to modify or
13+
otherwise use the software for commercial activities involving the Arduino
14+
software without disclosing the source code of your own applications. To purchase
15+
a commercial license, send an email to [email protected].
16+
*/
17+
18+
/******************************************************************************
19+
INCLUDE
20+
******************************************************************************/
21+
22+
#include <ArduinoIoTCloud_Config.h>
23+
#if OTA_STORAGE_MKRGSM
24+
25+
#include "OTAStorage_MKRGSM.h"
26+
27+
/******************************************************************************
28+
CONSTANTS
29+
******************************************************************************/
30+
31+
static char const SSU_UPDATE_FILENAME[] = "UPDATE.BIN";
32+
static char const SSU_CHECK_FILE_NAME[] = "UPDATE.OK";
33+
34+
/******************************************************************************
35+
PUBLIC MEMBER FUNCTIONS
36+
******************************************************************************/
37+
38+
bool OTAStorage_MKRGSM::init()
39+
{
40+
if (!_fileUtils.begin())
41+
return false;
42+
43+
if (_fileUtils.listFile(SSU_UPDATE_FILENAME) > 0)
44+
if (!_fileUtils.deleteFile(SSU_UPDATE_FILENAME))
45+
return false;
46+
47+
if (_fileUtils.listFile(SSU_CHECK_FILE_NAME) > 0)
48+
if (!_fileUtils.deleteFile(SSU_CHECK_FILE_NAME))
49+
return false;
50+
}
51+
52+
bool OTAStorage_MKRGSM::open(char const * /* file_name */)
53+
{
54+
return true;
55+
}
56+
57+
size_t OTAStorage_MKRGSM::write(uint8_t const* const buf, size_t const num_bytes)
58+
{
59+
_fileUtils.appendFile(SSU_UPDATE_FILENAME, (const char*)buf, num_bytes);
60+
return num_bytes;
61+
}
62+
63+
void OTAStorage_MKRGSM::close()
64+
{
65+
/* Nothing to do */
66+
}
67+
68+
void OTAStorage_MKRGSM::remove(char const * /* file_name */)
69+
{
70+
_fileUtils.deleteFile(SSU_UPDATE_FILENAME);
71+
}
72+
73+
bool OTAStorage_MKRGSM::rename(char const * /* old_file_name */, char const * /* new_file_name */)
74+
{
75+
/* Create a file 'UPDATE.OK' which is used by the SSU
76+
* 2nd stage bootloader to recognise that the update
77+
* went okay. Normally this is done by renaming 'UPDATE.BIN.TMP'
78+
* to 'UPDATE.BIN' but the SARE module does not support
79+
* a rename function.
80+
*/
81+
char c = 'X';
82+
return (_fileUtils.appendFile(SSU_CHECK_FILE_NAME, &c, sizeof(c)) == sizeof(c));
83+
}
84+
85+
void OTAStorage_MKRGSM::deinit()
86+
{
87+
/* Nothing to do */
88+
}
89+
90+
#endif /* OTA_STORAGE_MKRGSM */

src/utility/ota/OTAStorage_MKRGSM.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
This file is part of ArduinoIoTCloud.
3+
4+
Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of arduino-cli.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to modify or
13+
otherwise use the software for commercial activities involving the Arduino
14+
software without disclosing the source code of your own applications. To purchase
15+
a commercial license, send an email to [email protected].
16+
*/
17+
18+
#ifndef ARDUINO_OTA_STORAGE_MKRGSM_H_
19+
#define ARDUINO_OTA_STORAGE_MKRGSM_H_
20+
21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
24+
25+
#include <ArduinoIoTCloud_Config.h>
26+
#if OTA_STORAGE_MKRGSM
27+
28+
#include "OTAStorage.h"
29+
30+
#include <GSMFileUtils.h>
31+
32+
/******************************************************************************
33+
* CLASS DECLARATION
34+
******************************************************************************/
35+
36+
class OTAStorage_MKRGSM : public OTAStorage
37+
{
38+
public:
39+
40+
virtual ~OTAStorage_MKRGSM() { }
41+
42+
43+
virtual Type type () override { return Type::MKRGSMFile; }
44+
virtual bool init () override;
45+
virtual bool open (char const * file_name) override;
46+
virtual size_t write (uint8_t const * const buf, size_t const num_bytes) override;
47+
virtual void close () override;
48+
virtual void remove(char const * file_name) override;
49+
virtual bool rename(char const * old_file_name, char const * new_file_name) override;
50+
virtual void deinit() override;
51+
52+
private:
53+
54+
GSMFileUtils _fileUtils;
55+
56+
};
57+
58+
#endif /* OTA_STORAGE_MKRGSM */
59+
60+
#endif /* ARDUINO_OTA_STORAGE_MKRGSM_H_ */

0 commit comments

Comments
 (0)