From a869130fd5926cf6c649e3431254c5caaf05bd92 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 09:43:22 +0200 Subject: [PATCH 01/13] OTA: STM32H7 remove watchdog kik --- src/ota/implementation/OTASTM32H7.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index c3cefdd8..20b1d377 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -11,8 +11,6 @@ #include "AIoTC_Config.h" #if defined(BOARD_STM32H7) && OTA_ENABLED #include "OTASTM32H7.h" - -#include "utility/watchdog/Watchdog.h" #include static bool findProgramLength(DIR * dir, uint32_t & program_length); @@ -44,7 +42,6 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::resume(Message* msg) { void STM32H7OTACloudProcess::update() { OTADefaultCloudProcessInterface::update(); - watchdog_reset(); // FIXME this should npot be performed here } int STM32H7OTACloudProcess::writeFlash(uint8_t* const buffer, size_t len) { From e5eca055a80047a3cef60372e5c7d0a60fc0f873 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 09:50:11 +0200 Subject: [PATCH 02/13] OTA: STM32H7 remove unused variables --- src/ota/implementation/OTASTM32H7.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index ac102171..d87bfe42 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -79,9 +79,6 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { mbed::BlockDevice* _bd; mbed::FATFileSystem* _fs; - mbed::MBRBlockDevice* cert_bd_qspi; - mbed::FATFileSystem* cert_fs_qspi; - const portenta::StorageType storage=portenta::QSPI_FLASH_FATFS_MBR; const uint32_t data_offset=2; From 44b5dc30ad1c692252a7bf12726f063a8c0a90c1 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 09:51:25 +0200 Subject: [PATCH 03/13] OTA: STM32H7 remove commented code --- src/ota/implementation/OTASTM32H7.cpp | 2 -- src/ota/implementation/OTASTM32H7.h | 1 - 2 files changed, 3 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index 20b1d377..b41df505 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -198,14 +198,12 @@ bool findProgramLength(DIR * dir, uint32_t & program_length) { return false; } -// extern uint32_t __stext = ~0; extern uint32_t __etext; extern uint32_t _sdata; extern uint32_t _edata; void* STM32H7OTACloudProcess::appStartAddress() { return (void*)0x8040000; - // return &__stext; } uint32_t STM32H7OTACloudProcess::appSize() { diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index d87bfe42..13f5d33f 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -72,7 +72,6 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { void storageClean(); FILE* decompressed; - // static const char UPDATE_FILE_NAME[]; mbed::BlockDevice* _bd_raw_qspi; uint32_t _program_length; From 5956436d9871bc508db105a825bdd2656975ab2a Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 09:57:29 +0200 Subject: [PATCH 04/13] OTA: STM32H7 storage type is always QSPI_FLASH_FATFS_MBR --- src/ota/implementation/OTASTM32H7.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index b41df505..cc301318 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -153,14 +153,9 @@ bool STM32H7OTACloudProcess::storageInit() { } } - if (storage == portenta::QSPI_FLASH_FATFS) { - _fs = new mbed::FATFileSystem("fs"); - err_mount = _fs->mount(_bd_raw_qspi); - } else if (storage == portenta::QSPI_FLASH_FATFS_MBR) { - _bd = new mbed::MBRBlockDevice(_bd_raw_qspi, data_offset); - _fs = new mbed::FATFileSystem("fs"); - err_mount = _fs->mount(_bd); - } + _bd = new mbed::MBRBlockDevice(_bd_raw_qspi, data_offset); + _fs = new mbed::FATFileSystem("fs"); + err_mount = _fs->mount(_bd); if (!err_mount) { return true; From 603acd5e6fbf37b827ecb2308cce90d543be7591 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 10:01:01 +0200 Subject: [PATCH 05/13] OTA: STM32H7 rename portenta namespace in STM32H747OTA --- src/ota/implementation/OTASTM32H7.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index 13f5d33f..22e5cac0 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -28,7 +28,7 @@ #define APOTA_LITTLEFS_FLAG (1 << 6) #define APOTA_MBR_FLAG (1 << 7) -namespace portenta { +namespace STM32H747OTA { enum StorageType { QSPI_FLASH_FATFS = APOTA_QSPI_FLASH_FLAG | APOTA_FATFS_FLAG, QSPI_FLASH_FATFS_MBR = APOTA_QSPI_FLASH_FLAG | APOTA_FATFS_FLAG | APOTA_MBR_FLAG, @@ -78,7 +78,7 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { mbed::BlockDevice* _bd; mbed::FATFileSystem* _fs; - const portenta::StorageType storage=portenta::QSPI_FLASH_FATFS_MBR; + const STM32H747OTA::StorageType storage=STM32H747OTA::QSPI_FLASH_FATFS_MBR; const uint32_t data_offset=2; static const char UPDATE_FILE_NAME[]; From 4888d274bf4e654e5690c724d5659d4631bf3c8d Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 10:02:22 +0200 Subject: [PATCH 06/13] OTA: STM32H7 remove storage variable --- src/ota/implementation/OTASTM32H7.cpp | 2 +- src/ota/implementation/OTASTM32H7.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index cc301318..6b24edbf 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -84,7 +84,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() { // this sets the registries in RTC to load the firmware from the storage selected at the next reboot STM32H747::writeBackupRegister(RTCBackup::DR0, 0x07AA); - STM32H747::writeBackupRegister(RTCBackup::DR1, storage); + STM32H747::writeBackupRegister(RTCBackup::DR1, STM32H747OTA::StorageType::QSPI_FLASH_FATFS_MBR); STM32H747::writeBackupRegister(RTCBackup::DR2, data_offset); STM32H747::writeBackupRegister(RTCBackup::DR3, _program_length); diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index 22e5cac0..c31ba804 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -78,7 +78,6 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { mbed::BlockDevice* _bd; mbed::FATFileSystem* _fs; - const STM32H747OTA::StorageType storage=STM32H747OTA::QSPI_FLASH_FATFS_MBR; const uint32_t data_offset=2; static const char UPDATE_FILE_NAME[]; From 9f1117a2263580b7e11df360fc1557d578a9a3ba Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 10:15:01 +0200 Subject: [PATCH 07/13] OTA: STM32H7 Add storage type constexpr --- src/ota/implementation/OTASTM32H7.cpp | 2 +- src/ota/implementation/OTASTM32H7.h | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index 6b24edbf..dc3396eb 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -84,7 +84,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() { // this sets the registries in RTC to load the firmware from the storage selected at the next reboot STM32H747::writeBackupRegister(RTCBackup::DR0, 0x07AA); - STM32H747::writeBackupRegister(RTCBackup::DR1, STM32H747OTA::StorageType::QSPI_FLASH_FATFS_MBR); + STM32H747::writeBackupRegister(RTCBackup::DR1, STM32H747OTA::STORAGE_TYPE); STM32H747::writeBackupRegister(RTCBackup::DR2, data_offset); STM32H747::writeBackupRegister(RTCBackup::DR3, _program_length); diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index c31ba804..506481f5 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -21,20 +21,9 @@ #include "WiFi.h" /* WiFi from ArduinoCore-mbed */ #include -#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) - namespace STM32H747OTA { - enum StorageType { - 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, - }; + /* External QSPI flash + MBR + FatFs */ + static const uint32_t constexpr STORAGE_TYPE = ((1 << 2) | (1 << 5) | (1 << 7)); } class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { From af07e716a385ba9a0ae406f759268e00250db70e Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 10:16:39 +0200 Subject: [PATCH 08/13] OTA: STM32H7 add partition constexpr --- src/ota/implementation/OTASTM32H7.cpp | 4 ++-- src/ota/implementation/OTASTM32H7.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index dc3396eb..3c3a0eb8 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -85,7 +85,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() { // this sets the registries in RTC to load the firmware from the storage selected at the next reboot STM32H747::writeBackupRegister(RTCBackup::DR0, 0x07AA); STM32H747::writeBackupRegister(RTCBackup::DR1, STM32H747OTA::STORAGE_TYPE); - STM32H747::writeBackupRegister(RTCBackup::DR2, data_offset); + STM32H747::writeBackupRegister(RTCBackup::DR2, STM32H747OTA::PARTITION); STM32H747::writeBackupRegister(RTCBackup::DR3, _program_length); return Reboot; @@ -153,7 +153,7 @@ bool STM32H7OTACloudProcess::storageInit() { } } - _bd = new mbed::MBRBlockDevice(_bd_raw_qspi, data_offset); + _bd = new mbed::MBRBlockDevice(_bd_raw_qspi, STM32H747OTA::PARTITION); _fs = new mbed::FATFileSystem("fs"); err_mount = _fs->mount(_bd); diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index 506481f5..adac10db 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -24,6 +24,8 @@ namespace STM32H747OTA { /* External QSPI flash + MBR + FatFs */ static const uint32_t constexpr STORAGE_TYPE = ((1 << 2) | (1 << 5) | (1 << 7)); + /* Default OTA partition */ + static const uint32_t constexpr PARTITION = 2; } class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { @@ -67,7 +69,5 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { mbed::BlockDevice* _bd; mbed::FATFileSystem* _fs; - const uint32_t data_offset=2; - static const char UPDATE_FILE_NAME[]; }; From 66949808f04ac16c8fbcfc137d3cbebb0da70d69 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 10:18:19 +0200 Subject: [PATCH 09/13] OTA: STM32H7 add OTA magic number constexpr --- src/ota/implementation/OTASTM32H7.cpp | 2 +- src/ota/implementation/OTASTM32H7.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index 3c3a0eb8..346561de 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -83,7 +83,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() { storageClean(); // this sets the registries in RTC to load the firmware from the storage selected at the next reboot - STM32H747::writeBackupRegister(RTCBackup::DR0, 0x07AA); + STM32H747::writeBackupRegister(RTCBackup::DR0, STM32H747OTA::MAGIC); STM32H747::writeBackupRegister(RTCBackup::DR1, STM32H747OTA::STORAGE_TYPE); STM32H747::writeBackupRegister(RTCBackup::DR2, STM32H747OTA::PARTITION); STM32H747::writeBackupRegister(RTCBackup::DR3, _program_length); diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index adac10db..3c1946dc 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -26,6 +26,8 @@ namespace STM32H747OTA { static const uint32_t constexpr STORAGE_TYPE = ((1 << 2) | (1 << 5) | (1 << 7)); /* Default OTA partition */ static const uint32_t constexpr PARTITION = 2; + /* OTA Magic number */ + static const uint32_t constexpr MAGIC = 0x07AA; } class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { From 7671c39677751c8d93a3f9b91bf44312a8b183e5 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 10:41:08 +0200 Subject: [PATCH 10/13] OTA: STM32H7 merge storageOpen and findProgramLength --- src/ota/implementation/OTASTM32H7.cpp | 30 +++++++++------------------ src/ota/implementation/OTASTM32H7.h | 3 +-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index 346561de..e7e46888 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -13,8 +13,6 @@ #include "OTASTM32H7.h" #include -static bool findProgramLength(DIR * dir, uint32_t & program_length); - const char STM32H7OTACloudProcess::UPDATE_FILE_NAME[] = "/fs/UPDATE.BIN"; STM32H7OTACloudProcess::STM32H7OTACloudProcess(MessageStream *ms, Client* client) @@ -76,7 +74,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() { decompressed = nullptr; /* Schedule the firmware update. */ - if(!storageOpen()) { + if(!findProgramLength(_program_length)) { return OtaStorageOpenFail; } @@ -164,33 +162,25 @@ bool STM32H7OTACloudProcess::storageInit() { return false; } -bool STM32H7OTACloudProcess::storageOpen() { +bool STM32H7OTACloudProcess::findProgramLength(uint32_t & program_length) { DIR * dir = NULL; - if ((dir = opendir("/fs")) != NULL) - { - if (findProgramLength(dir, _program_length)) - { - closedir(dir); - return true; - } - closedir(dir); - } + struct dirent * entry = NULL; + bool found = false; - return false; -} + if ((dir = opendir("/fs")) == NULL) { + return false; + } -bool findProgramLength(DIR * dir, uint32_t & program_length) { - struct dirent * entry = NULL; while ((entry = readdir(dir)) != NULL) { if (strcmp(entry->d_name, "UPDATE.BIN") == 0) { // FIXME use constants struct stat stat_buf; stat("/fs/UPDATE.BIN", &stat_buf); program_length = stat_buf.st_size; - return true; + found = true; } } - - return false; + closedir(dir); + return found; } extern uint32_t __etext; diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index 3c1946dc..a71c276f 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -60,8 +60,7 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { bool appFlashClose() { return true; }; private: bool storageInit(); - bool storageOpen(); - + bool findProgramLength(uint32_t & program_length); void storageClean(); FILE* decompressed; From 340ab063892f7bd15eb8bbbeeb9c4ef6d049779d Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 29 May 2024 17:46:21 +0200 Subject: [PATCH 11/13] OTA: STM32H7 use constants for filename and path --- src/ota/implementation/OTASTM32H7.cpp | 20 ++++++++++---------- src/ota/implementation/OTASTM32H7.h | 6 +++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index e7e46888..0f0e757e 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -13,15 +13,14 @@ #include "OTASTM32H7.h" #include -const char STM32H7OTACloudProcess::UPDATE_FILE_NAME[] = "/fs/UPDATE.BIN"; - STM32H7OTACloudProcess::STM32H7OTACloudProcess(MessageStream *ms, Client* client) : OTADefaultCloudProcessInterface(ms, client) , decompressed(nullptr) , _bd_raw_qspi(nullptr) , _program_length(0) , _bd(nullptr) -, _fs(nullptr) { +, _fs(nullptr) +, _filename("/" + String(STM32H747OTA::FOLDER) + "/" + String(STM32H747OTA::NAME)) { } @@ -60,9 +59,9 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::startOTA() { } // this could be useless, since we are writing over it - remove(UPDATE_FILE_NAME); + remove(_filename.c_str()); - decompressed = fopen(UPDATE_FILE_NAME, "wb"); + decompressed = fopen(_filename.c_str(), "wb"); // start the download if the setup for ota storage is successful return OTADefaultCloudProcessInterface::startOTA(); @@ -101,7 +100,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::reboot() { void STM32H7OTACloudProcess::reset() { OTADefaultCloudProcessInterface::reset(); - remove(UPDATE_FILE_NAME); + remove(_filename.c_str()); storageClean(); } @@ -152,7 +151,7 @@ bool STM32H7OTACloudProcess::storageInit() { } _bd = new mbed::MBRBlockDevice(_bd_raw_qspi, STM32H747OTA::PARTITION); - _fs = new mbed::FATFileSystem("fs"); + _fs = new mbed::FATFileSystem(STM32H747OTA::FOLDER); err_mount = _fs->mount(_bd); if (!err_mount) { @@ -165,16 +164,17 @@ bool STM32H7OTACloudProcess::storageInit() { bool STM32H7OTACloudProcess::findProgramLength(uint32_t & program_length) { DIR * dir = NULL; struct dirent * entry = NULL; + String dirName = "/" + String(STM32H747OTA::FOLDER); bool found = false; - if ((dir = opendir("/fs")) == NULL) { + if ((dir = opendir(dirName.c_str())) == NULL) { return false; } while ((entry = readdir(dir)) != NULL) { - if (strcmp(entry->d_name, "UPDATE.BIN") == 0) { // FIXME use constants + if (strcmp(entry->d_name, STM32H747OTA::NAME) == 0) { struct stat stat_buf; - stat("/fs/UPDATE.BIN", &stat_buf); + stat(_filename.c_str(), &stat_buf); program_length = stat_buf.st_size; found = true; } diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index a71c276f..28b6308a 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -28,6 +28,10 @@ namespace STM32H747OTA { static const uint32_t constexpr PARTITION = 2; /* OTA Magic number */ static const uint32_t constexpr MAGIC = 0x07AA; + /* OTA download folder name */ + static const char constexpr FOLDER[] = "ota"; + /* OTA update filename */ + static const char constexpr NAME[] = "UPDATE.BIN"; } class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { @@ -70,5 +74,5 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { mbed::BlockDevice* _bd; mbed::FATFileSystem* _fs; - static const char UPDATE_FILE_NAME[]; + String _filename; }; From 4edf9b4f70ade343ed908a595e8c1ba2b7bcaf0b Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 31 May 2024 11:33:59 +0200 Subject: [PATCH 12/13] OTA: STM32H7 remove _private_length private variable --- src/ota/implementation/OTASTM32H7.cpp | 7 ++++--- src/ota/implementation/OTASTM32H7.h | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index 0f0e757e..cf9bb701 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -17,7 +17,6 @@ STM32H7OTACloudProcess::STM32H7OTACloudProcess(MessageStream *ms, Client* client : OTADefaultCloudProcessInterface(ms, client) , decompressed(nullptr) , _bd_raw_qspi(nullptr) -, _program_length(0) , _bd(nullptr) , _fs(nullptr) , _filename("/" + String(STM32H747OTA::FOLDER) + "/" + String(STM32H747OTA::NAME)) { @@ -72,8 +71,10 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() { fclose(decompressed); decompressed = nullptr; + uint32_t updateLength = 0; + /* Schedule the firmware update. */ - if(!findProgramLength(_program_length)) { + if(!findProgramLength(updateLength)) { return OtaStorageOpenFail; } @@ -83,7 +84,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() { STM32H747::writeBackupRegister(RTCBackup::DR0, STM32H747OTA::MAGIC); STM32H747::writeBackupRegister(RTCBackup::DR1, STM32H747OTA::STORAGE_TYPE); STM32H747::writeBackupRegister(RTCBackup::DR2, STM32H747OTA::PARTITION); - STM32H747::writeBackupRegister(RTCBackup::DR3, _program_length); + STM32H747::writeBackupRegister(RTCBackup::DR3, updateLength); return Reboot; } diff --git a/src/ota/implementation/OTASTM32H7.h b/src/ota/implementation/OTASTM32H7.h index 28b6308a..0b56f20f 100644 --- a/src/ota/implementation/OTASTM32H7.h +++ b/src/ota/implementation/OTASTM32H7.h @@ -69,7 +69,6 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface { FILE* decompressed; mbed::BlockDevice* _bd_raw_qspi; - uint32_t _program_length; mbed::BlockDevice* _bd; mbed::FATFileSystem* _fs; From 81437415a3e65b2c81ef6d2a91c74accb26e647b Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 10 Jun 2024 10:02:41 +0200 Subject: [PATCH 13/13] OTA: STM32H7 add check on fopen failures Co-authored-by: Andrea Gilardoni <4046444+andreagilardoni@users.noreply.github.com> --- src/ota/implementation/OTASTM32H7.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ota/implementation/OTASTM32H7.cpp b/src/ota/implementation/OTASTM32H7.cpp index cf9bb701..d9675aa2 100644 --- a/src/ota/implementation/OTASTM32H7.cpp +++ b/src/ota/implementation/OTASTM32H7.cpp @@ -62,6 +62,9 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::startOTA() { decompressed = fopen(_filename.c_str(), "wb"); + if(decompressed == nullptr) { + return ErrorOpenUpdateFileFail; + } // start the download if the setup for ota storage is successful return OTADefaultCloudProcessInterface::startOTA(); }