forked from arduino-libraries/Arduino_Portenta_OTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino_Portenta_OTA.h
134 lines (101 loc) · 4.16 KB
/
Arduino_Portenta_OTA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
This file is part of Arduino_Portenta_OTA.
Copyright 2019 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_PORTENTA_OTA_H_
#define ARDUINO_PORTENTA_OTA_H_
/******************************************************************************
* INCLUDE
******************************************************************************/
#include "Arduino_Portenta_OTA_Config.h"
#if defined(ARDUINO_PORTENTA_OTA_QSPI_SUPPORT)
#include <QSPIFBlockDevice.h>
#endif
#if defined(ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT)
#include <SDMMCBlockDevice.h>
#endif
#include <BlockDevice.h>
#include <MBRBlockDevice.h>
#include <FATFileSystem.h>
#include <LittleFileSystem.h>
#include <Arduino_DebugUtils.h>
/******************************************************************************
* DEFINE
******************************************************************************/
#define APOTA_QSPI_FLASH_FLAG (1 << 2)
#define APOTA_SDCARD_FLAG (1 << 3)
#define APOTA_RAW_FLAG (1 << 4)
#define APOTA_FATFS_FLAG (1 << 5)
#define APOTA_LITTLEFS_FLAG (1 << 6)
#define APOTA_MBR_FLAG (1 << 7)
#define ARDUINO_PORTENTA_OTA_HAS_WATCHDOG_FEED
/******************************************************************************
* TYPEDEF
******************************************************************************/
enum StorageTypePortenta {
QSPI_FLASH_FATFS = APOTA_QSPI_FLASH_FLAG | APOTA_FATFS_FLAG,
QSPI_FLASH_FATFS_MBR = APOTA_QSPI_FLASH_FLAG | APOTA_FATFS_FLAG | APOTA_MBR_FLAG,
SD_FATFS = APOTA_SDCARD_FLAG | APOTA_FATFS_FLAG,
SD_FATFS_MBR = APOTA_SDCARD_FLAG | APOTA_FATFS_FLAG | APOTA_MBR_FLAG,
};
typedef void(*ArduinoPortentaOtaWatchdogResetFuncPointer)(void);
/******************************************************************************
* CLASS DECLARATION
******************************************************************************/
class Arduino_Portenta_OTA
{
public:
enum class Error : int
{
None = 0,
NoCapableBootloader = -1,
NoOtaStorage = -2,
OtaStorageInit = -3,
OtaStorageOpen = -4,
OtaHeaderLength = -5,
OtaHeaderCrc = -6,
OtaHeaterMagicNumber = -7,
};
Arduino_Portenta_OTA(StorageTypePortenta const storage_type, uint32_t const data_offset);
virtual ~Arduino_Portenta_OTA();
bool isOtaCapable();
Error begin();
Error update();
void reset();
/* This functionality is intended for usage with the Arduino IoT Cloud for
* performing OTA firmware updates using the Arduino IoT Cloud servers.
*/
int download(const char * url, bool const is_https);
int decompress();
void setFeedWatchdogFunc(ArduinoPortentaOtaWatchdogResetFuncPointer func);
void feedWatchdog();
protected:
StorageTypePortenta _storage_type;
uint32_t _data_offset;
uint32_t _program_length;
virtual bool init() = 0;
virtual bool open() = 0;
static bool findProgramLength(DIR * dir, uint32_t & program_length);
private:
void write();
ArduinoPortentaOtaWatchdogResetFuncPointer _feed_watchdog_func = 0;
};
/******************************************************************************
* INCLUDE
******************************************************************************/
#if defined(ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT)
#include "Arduino_Portenta_OTA_SD.h"
#endif
#if defined(ARDUINO_PORTENTA_OTA_QSPI_SUPPORT)
#include "Arduino_Portenta_OTA_QSPI.h"
#endif
#endif /* ARDUINO_PORTENTA_OTA_H_ */