Skip to content

Commit 53c404a

Browse files
fixup! implemented stm32h7 ota class
1 parent d68a978 commit 53c404a

File tree

2 files changed

+27
-43
lines changed

2 files changed

+27
-43
lines changed

src/ota/implementation/OTASTM32H7.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ namespace portenta {
4343
};
4444
}
4545

46-
template<portenta::StorageType storage=portenta::QSPI_FLASH_FATFS_MBR, uint32_t data_offset=2>
4746
class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface {
4847
public:
4948
STM32H7OTACloudProcess(MessageStream *ms, Client* client=nullptr);
@@ -93,6 +92,11 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface {
9392

9493
mbed::MBRBlockDevice* cert_bd_qspi;
9594
mbed::FATFileSystem* cert_fs_qspi;
95+
96+
const portenta::StorageType storage=portenta::QSPI_FLASH_FATFS_MBR;
97+
const uint32_t data_offset=2;
98+
99+
static const char UPDATE_FILE_NAME[];
96100
};
97101

98102
#include "OTASTM32H7.ipp"

src/ota/implementation/OTASTM32H7.ipp

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
static bool findProgramLength(DIR * dir, uint32_t & program_length);
1818

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";
2120

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)
2422
: OTADefaultCloudProcessInterface(ms, client)
2523
, decompressed(nullptr)
2624
, _bd_raw_qspi(nullptr)
@@ -35,8 +33,7 @@ STM32H7OTACloudProcess<storage, data_offset>::STM32H7OTACloudProcess(MessageStre
3533

3634
}
3735

38-
template<portenta::StorageType storage, uint32_t data_offset>
39-
STM32H7OTACloudProcess<storage, data_offset>::~STM32H7OTACloudProcess() {
36+
STM32H7OTACloudProcess::~STM32H7OTACloudProcess() {
4037
if(decompressed != nullptr) {
4138
fclose(decompressed);
4239
decompressed = nullptr;
@@ -45,27 +42,23 @@ STM32H7OTACloudProcess<storage, data_offset>::~STM32H7OTACloudProcess() {
4542
storageClean();
4643
}
4744

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) {
5046
return OtaBegin;
5147
}
5248

53-
template<portenta::StorageType storage, uint32_t data_offset>
54-
void STM32H7OTACloudProcess<storage, data_offset>::update() {
49+
void STM32H7OTACloudProcess::update() {
5550
OTADefaultCloudProcessInterface::update();
5651
watchdog_reset(); // FIXME this should npot be performed here
5752
}
5853

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) {
6155
if (decompressed == nullptr) {
6256
return -1;
6357
}
6458
return fwrite(buffer, sizeof(uint8_t), len, decompressed);
6559
}
6660

67-
template<portenta::StorageType storage, uint32_t data_offset>
68-
OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::startOTA() {
61+
OTACloudProcessInterface::State STM32H7OTACloudProcess::startOTA() {
6962
if (!isOtaCapable()) {
7063
return NoCapableBootloaderFail;
7164
}
@@ -85,7 +78,6 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::st
8578

8679
// this could be useless, since we are writing over it
8780
remove(UPDATE_FILE_NAME);
88-
remove("/fs/UPDATE.BIN.LZSS");
8981

9082
decompressed = fopen(UPDATE_FILE_NAME, "wb");
9183

@@ -94,8 +86,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::st
9486
}
9587

9688

97-
template<portenta::StorageType storage, uint32_t data_offset>
98-
OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::flashOTA() {
89+
OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() {
9990
fclose(decompressed);
10091
decompressed = nullptr;
10192

@@ -113,8 +104,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::fl
113104
return Reboot;
114105
}
115106

116-
template<portenta::StorageType storage, uint32_t data_offset>
117-
OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::reboot() {
107+
OTACloudProcessInterface::State STM32H7OTACloudProcess::reboot() {
118108
// TODO save information about the progress reached in the ota
119109

120110
// This command reboots the mcu
@@ -123,25 +113,22 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess<storage, data_offset>::re
123113
return Resume; // This won't ever be reached
124114
}
125115

126-
template<portenta::StorageType storage, uint32_t data_offset>
127-
void STM32H7OTACloudProcess<storage, data_offset>::reset() {
116+
void STM32H7OTACloudProcess::reset() {
128117
OTADefaultCloudProcessInterface::reset();
129118

130119
remove(UPDATE_FILE_NAME);
131120

132121
storageClean();
133122
}
134123

135-
template<portenta::StorageType storage, uint32_t data_offset>
136-
void STM32H7OTACloudProcess<storage, data_offset>::storageClean() {
124+
void STM32H7OTACloudProcess::storageClean() {
137125
DEBUG_VERBOSE(F("storage clean"));
138126

139127
if(decompressed != nullptr) {
140128
fclose(decompressed);
141129
decompressed = nullptr;
142130
}
143131

144-
// TODO close storage
145132
if(cert_bd_qspi != nullptr) {
146133
delete cert_bd_qspi;
147134
cert_bd_qspi = nullptr;
@@ -170,8 +157,7 @@ void STM32H7OTACloudProcess<storage, data_offset>::storageClean() {
170157
#endif // ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT
171158
}
172159

173-
template<portenta::StorageType storage, uint32_t data_offset>
174-
bool STM32H7OTACloudProcess<storage, data_offset>::isOtaCapable() {
160+
bool STM32H7OTACloudProcess::isOtaCapable() {
175161
#define BOOTLOADER_ADDR (0x8000000)
176162
uint32_t bootloader_data_offset = 0x1F000;
177163
uint8_t* bootloader_data = (uint8_t*)(BOOTLOADER_ADDR + bootloader_data_offset);
@@ -182,39 +168,36 @@ bool STM32H7OTACloudProcess<storage, data_offset>::isOtaCapable() {
182168
return true;
183169
}
184170

185-
template<portenta::StorageType storage, uint32_t data_offset>
186-
bool STM32H7OTACloudProcess<storage, data_offset>::caStorageInit() {
171+
bool STM32H7OTACloudProcess::caStorageInit() {
187172
_bd_raw_qspi = mbed::BlockDevice::get_default_instance();
188173

189174
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."));
191176
return false;
192177
}
193178

194179
cert_bd_qspi = new mbed::MBRBlockDevice(_bd_raw_qspi, 1);
195180
cert_fs_qspi = new mbed::FATFileSystem("wlan");
196181
int const err_mount = cert_fs_qspi->mount(cert_bd_qspi);
197182
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);
199184
return false;
200185
}
201186
return true;
202187
}
203188

204-
template<portenta::StorageType storage, uint32_t data_offset>
205-
bool STM32H7OTACloudProcess<storage, data_offset>::caStorageOpen() {
189+
bool STM32H7OTACloudProcess::caStorageOpen() {
206190
FILE* fp = fopen("/wlan/cacert.pem", "r");
207191
if (!fp) {
208-
DEBUG_ERROR(F("Error while opening the certificate file."));
192+
DEBUG_VERBOSE(F("Error while opening the certificate file."));
209193
return false;
210194
}
211195
fclose(fp);
212196

213197
return true;
214198
}
215199

216-
template<portenta::StorageType storage, uint32_t data_offset>
217-
bool STM32H7OTACloudProcess<storage, data_offset>::storageInit() {
200+
bool STM32H7OTACloudProcess::storageInit() {
218201
int err_mount=1;
219202

220203
if constexpr (storage == portenta::QSPI_FLASH_FATFS) {
@@ -243,12 +226,11 @@ bool STM32H7OTACloudProcess<storage, data_offset>::storageInit() {
243226
if (!err_mount) {
244227
return true;
245228
}
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);
247230
return false;
248231
}
249232

250-
template<portenta::StorageType storage, uint32_t data_offset>
251-
bool STM32H7OTACloudProcess<storage, data_offset>::storageOpen() {
233+
bool STM32H7OTACloudProcess::storageOpen() {
252234
DIR * dir = NULL;
253235
if ((dir = opendir("/fs")) != NULL)
254236
{
@@ -282,14 +264,12 @@ extern uint32_t __etext;
282264
extern uint32_t _sdata;
283265
extern uint32_t _edata;
284266

285-
template<portenta::StorageType storage, uint32_t data_offset>
286-
void* STM32H7OTACloudProcess<storage, data_offset>::appStartAddress() {
267+
void* STM32H7OTACloudProcess::appStartAddress() {
287268
return (void*)0x8040000;
288269
// return &__stext;
289270
}
290271

291-
template<portenta::StorageType storage, uint32_t data_offset>
292-
uint32_t STM32H7OTACloudProcess<storage, data_offset>::appSize() {
272+
uint32_t STM32H7OTACloudProcess::appSize() {
293273
return ((&__etext - (uint32_t*)appStartAddress()) + (&_edata - &_sdata))*sizeof(void*);
294274
}
295275

0 commit comments

Comments
 (0)