Skip to content

Commit 208cc32

Browse files
committed
OTA: STM32H7 use constants for filename and path
1 parent 8338d89 commit 208cc32

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/ota/implementation/OTASTM32H7.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
#include "OTASTM32H7.h"
1414
#include <STM32H747_System.h>
1515

16-
const char STM32H7OTACloudProcess::UPDATE_FILE_NAME[] = "/fs/UPDATE.BIN";
17-
1816
STM32H7OTACloudProcess::STM32H7OTACloudProcess(MessageStream *ms, Client* client)
1917
: OTADefaultCloudProcessInterface(ms, client)
2018
, decompressed(nullptr)
2119
, _bd_raw_qspi(nullptr)
2220
, _program_length(0)
2321
, _bd(nullptr)
24-
, _fs(nullptr) {
22+
, _fs(nullptr)
23+
, _filename("/" + String(STM32H747OTA::FOLDER) + "/" + String(STM32H747OTA::NAME)) {
2524

2625
}
2726

@@ -60,9 +59,9 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::startOTA() {
6059
}
6160

6261
// this could be useless, since we are writing over it
63-
remove(UPDATE_FILE_NAME);
62+
remove(_filename.c_str());
6463

65-
decompressed = fopen(UPDATE_FILE_NAME, "wb");
64+
decompressed = fopen(_filename.c_str(), "wb");
6665

6766
// start the download if the setup for ota storage is successful
6867
return OTADefaultCloudProcessInterface::startOTA();
@@ -101,7 +100,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::reboot() {
101100
void STM32H7OTACloudProcess::reset() {
102101
OTADefaultCloudProcessInterface::reset();
103102

104-
remove(UPDATE_FILE_NAME);
103+
remove(_filename.c_str());
105104

106105
storageClean();
107106
}
@@ -152,7 +151,7 @@ bool STM32H7OTACloudProcess::storageInit() {
152151
}
153152

154153
_bd = new mbed::MBRBlockDevice(_bd_raw_qspi, STM32H747OTA::PARTITION);
155-
_fs = new mbed::FATFileSystem("fs");
154+
_fs = new mbed::FATFileSystem(STM32H747OTA::FOLDER);
156155
err_mount = _fs->mount(_bd);
157156

158157
if (!err_mount) {
@@ -165,16 +164,17 @@ bool STM32H7OTACloudProcess::storageInit() {
165164
bool STM32H7OTACloudProcess::findProgramLength(uint32_t & program_length) {
166165
DIR * dir = NULL;
167166
struct dirent * entry = NULL;
167+
String dirName = "/" + String(STM32H747OTA::FOLDER);
168168
bool found = false;
169169

170-
if ((dir = opendir("/fs")) == NULL) {
170+
if ((dir = opendir(dirName.c_str())) == NULL) {
171171
return false;
172172
}
173173

174174
while ((entry = readdir(dir)) != NULL) {
175-
if (strcmp(entry->d_name, "UPDATE.BIN") == 0) { // FIXME use constants
175+
if (strcmp(entry->d_name, STM32H747OTA::NAME) == 0) {
176176
struct stat stat_buf;
177-
stat("/fs/UPDATE.BIN", &stat_buf);
177+
stat(_filename.c_str(), &stat_buf);
178178
program_length = stat_buf.st_size;
179179
found = true;
180180
}

src/ota/implementation/OTASTM32H7.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace STM32H747OTA {
2828
static const uint32_t constexpr PARTITION = 2;
2929
/* OTA Magic number */
3030
static const uint32_t constexpr MAGIC = 0x07AA;
31+
/* OTA download folder name */
32+
static const char constexpr FOLDER[] = "ota";
33+
/* OTA update filename */
34+
static const char constexpr NAME[] = "UPDATE.BIN";
3135
}
3236

3337
class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface {
@@ -70,5 +74,5 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface {
7074
mbed::BlockDevice* _bd;
7175
mbed::FATFileSystem* _fs;
7276

73-
static const char UPDATE_FILE_NAME[];
77+
String _filename;
7478
};

0 commit comments

Comments
 (0)