16
16
17
17
static bool findProgramLength (DIR * dir, uint32_t & program_length);
18
18
19
- // template<portenta::StorageType storage, uint32_t data_offset>
20
- static const char UPDATE_FILE_NAME[] = " /fs/UPDATE.BIN" ;
19
+ static const char STM32H7OTACloudProcess::UPDATE_FILE_NAME[] = " /fs/UPDATE.BIN" ;
21
20
22
- template <portenta::StorageType storage, uint32_t data_offset>
23
- STM32H7OTACloudProcess<storage, data_offset>::STM32H7OTACloudProcess(MessageStream *ms, Client* client)
21
+ STM32H7OTACloudProcess::STM32H7OTACloudProcess (MessageStream *ms, Client* client)
24
22
: OTADefaultCloudProcessInterface(ms, client)
25
23
, decompressed(nullptr )
26
24
, _bd_raw_qspi(nullptr )
@@ -35,8 +33,7 @@ STM32H7OTACloudProcess<storage, data_offset>::STM32H7OTACloudProcess(MessageStre
35
33
36
34
}
37
35
38
- template <portenta::StorageType storage, uint32_t data_offset>
39
- STM32H7OTACloudProcess<storage, data_offset>::~STM32H7OTACloudProcess () {
36
+ STM32H7OTACloudProcess::~STM32H7OTACloudProcess () {
40
37
if (decompressed != nullptr ) {
41
38
fclose (decompressed);
42
39
decompressed = nullptr ;
@@ -45,27 +42,23 @@ STM32H7OTACloudProcess<storage, data_offset>::~STM32H7OTACloudProcess() {
45
42
storageClean ();
46
43
}
47
44
48
- template <portenta::StorageType storage, uint32_t data_offset>
49
- OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::resume(Message* msg) {
45
+ OTACloudProcessInterface::State STM32H7OTACloudProcess::resume (Message* msg) {
50
46
return OtaBegin;
51
47
}
52
48
53
- template <portenta::StorageType storage, uint32_t data_offset>
54
- void STM32H7OTACloudProcess<storage, data_offset>::update() {
49
+ void STM32H7OTACloudProcess::update () {
55
50
OTADefaultCloudProcessInterface::update ();
56
51
watchdog_reset (); // FIXME this should npot be performed here
57
52
}
58
53
59
- template <portenta::StorageType storage, uint32_t data_offset>
60
- int STM32H7OTACloudProcess<storage, data_offset>::writeFlash(uint8_t * const buffer, size_t len) {
54
+ int STM32H7OTACloudProcess::writeFlash (uint8_t * const buffer, size_t len) {
61
55
if (decompressed == nullptr ) {
62
56
return -1 ;
63
57
}
64
58
return fwrite (buffer, sizeof (uint8_t ), len, decompressed);
65
59
}
66
60
67
- template <portenta::StorageType storage, uint32_t data_offset>
68
- OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::startOTA() {
61
+ OTACloudProcessInterface::State STM32H7OTACloudProcess::startOTA () {
69
62
if (!isOtaCapable ()) {
70
63
return NoCapableBootloaderFail;
71
64
}
@@ -85,7 +78,6 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::st
85
78
86
79
// this could be useless, since we are writing over it
87
80
remove (UPDATE_FILE_NAME);
88
- remove (" /fs/UPDATE.BIN.LZSS" );
89
81
90
82
decompressed = fopen (UPDATE_FILE_NAME, " wb" );
91
83
@@ -94,8 +86,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::st
94
86
}
95
87
96
88
97
- template <portenta::StorageType storage, uint32_t data_offset>
98
- OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::flashOTA() {
89
+ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA () {
99
90
fclose (decompressed);
100
91
decompressed = nullptr ;
101
92
@@ -113,8 +104,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::fl
113
104
return Reboot;
114
105
}
115
106
116
- template <portenta::StorageType storage, uint32_t data_offset>
117
- OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::reboot() {
107
+ OTACloudProcessInterface::State STM32H7OTACloudProcess::reboot () {
118
108
// TODO save information about the progress reached in the ota
119
109
120
110
// This command reboots the mcu
@@ -123,25 +113,22 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::re
123
113
return Resume; // This won't ever be reached
124
114
}
125
115
126
- template <portenta::StorageType storage, uint32_t data_offset>
127
- void STM32H7OTACloudProcess<storage, data_offset>::reset() {
116
+ void STM32H7OTACloudProcess::reset () {
128
117
OTADefaultCloudProcessInterface::reset ();
129
118
130
119
remove (UPDATE_FILE_NAME);
131
120
132
121
storageClean ();
133
122
}
134
123
135
- template <portenta::StorageType storage, uint32_t data_offset>
136
- void STM32H7OTACloudProcess<storage, data_offset>::storageClean() {
124
+ void STM32H7OTACloudProcess::storageClean () {
137
125
DEBUG_VERBOSE (F (" storage clean" ));
138
126
139
127
if (decompressed != nullptr ) {
140
128
fclose (decompressed);
141
129
decompressed = nullptr ;
142
130
}
143
131
144
- // TODO close storage
145
132
if (cert_bd_qspi != nullptr ) {
146
133
delete cert_bd_qspi;
147
134
cert_bd_qspi = nullptr ;
@@ -170,8 +157,7 @@ void STM32H7OTACloudProcess<storage, data_offset>::storageClean() {
170
157
#endif // ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT
171
158
}
172
159
173
- template <portenta::StorageType storage, uint32_t data_offset>
174
- bool STM32H7OTACloudProcess<storage, data_offset>::isOtaCapable() {
160
+ bool STM32H7OTACloudProcess::isOtaCapable () {
175
161
#define BOOTLOADER_ADDR (0x8000000 )
176
162
uint32_t bootloader_data_offset = 0x1F000 ;
177
163
uint8_t * bootloader_data = (uint8_t *)(BOOTLOADER_ADDR + bootloader_data_offset);
@@ -182,39 +168,36 @@ bool STM32H7OTACloudProcess<storage, data_offset>::isOtaCapable() {
182
168
return true ;
183
169
}
184
170
185
- template <portenta::StorageType storage, uint32_t data_offset>
186
- bool STM32H7OTACloudProcess<storage, data_offset>::caStorageInit() {
171
+ bool STM32H7OTACloudProcess::caStorageInit () {
187
172
_bd_raw_qspi = mbed::BlockDevice::get_default_instance ();
188
173
189
174
if (_bd_raw_qspi->init () != QSPIF_BD_ERROR_OK) {
190
- DEBUG_ERROR (F (" Error: QSPI init failure." ));
175
+ DEBUG_VERBOSE (F (" Error: QSPI init failure." ));
191
176
return false ;
192
177
}
193
178
194
179
cert_bd_qspi = new mbed::MBRBlockDevice (_bd_raw_qspi, 1 );
195
180
cert_fs_qspi = new mbed::FATFileSystem (" wlan" );
196
181
int const err_mount = cert_fs_qspi->mount (cert_bd_qspi);
197
182
if (err_mount) {
198
- DEBUG_ERROR (F (" Error while mounting the certificate filesystem. Err = %d" ), err_mount);
183
+ DEBUG_VERBOSE (F (" Error while mounting the certificate filesystem. Err = %d" ), err_mount);
199
184
return false ;
200
185
}
201
186
return true ;
202
187
}
203
188
204
- template <portenta::StorageType storage, uint32_t data_offset>
205
- bool STM32H7OTACloudProcess<storage, data_offset>::caStorageOpen() {
189
+ bool STM32H7OTACloudProcess::caStorageOpen () {
206
190
FILE* fp = fopen (" /wlan/cacert.pem" , " r" );
207
191
if (!fp) {
208
- DEBUG_ERROR (F (" Error while opening the certificate file." ));
192
+ DEBUG_VERBOSE (F (" Error while opening the certificate file." ));
209
193
return false ;
210
194
}
211
195
fclose (fp);
212
196
213
197
return true ;
214
198
}
215
199
216
- template <portenta::StorageType storage, uint32_t data_offset>
217
- bool STM32H7OTACloudProcess<storage, data_offset>::storageInit() {
200
+ bool STM32H7OTACloudProcess::storageInit () {
218
201
int err_mount=1 ;
219
202
220
203
if constexpr (storage == portenta::QSPI_FLASH_FATFS) {
@@ -243,12 +226,11 @@ bool STM32H7OTACloudProcess<storage, data_offset>::storageInit() {
243
226
if (!err_mount) {
244
227
return true ;
245
228
}
246
- DEBUG_ERROR (F (" Error while mounting the filesystem. Err = %d" ), err_mount);
229
+ DEBUG_VERBOSE (F (" Error while mounting the filesystem. Err = %d" ), err_mount);
247
230
return false ;
248
231
}
249
232
250
- template <portenta::StorageType storage, uint32_t data_offset>
251
- bool STM32H7OTACloudProcess<storage, data_offset>::storageOpen () {
233
+ bool STM32H7OTACloudProcess::storageOpen () {
252
234
DIR * dir = NULL ;
253
235
if ((dir = opendir (" /fs" )) != NULL )
254
236
{
@@ -282,14 +264,12 @@ extern uint32_t __etext;
282
264
extern uint32_t _sdata;
283
265
extern uint32_t _edata;
284
266
285
- template <portenta::StorageType storage, uint32_t data_offset>
286
- void * STM32H7OTACloudProcess<storage, data_offset>::appStartAddress () {
267
+ void * STM32H7OTACloudProcess::appStartAddress () {
287
268
return (void *)0x8040000 ;
288
269
// return &__stext;
289
270
}
290
271
291
- template <portenta::StorageType storage, uint32_t data_offset>
292
- uint32_t STM32H7OTACloudProcess<storage, data_offset>::appSize () {
272
+ uint32_t STM32H7OTACloudProcess::appSize () {
293
273
return ((&__etext - (uint32_t *)appStartAddress ()) + (&_edata - &_sdata))*sizeof (void *);
294
274
}
295
275
0 commit comments