Skip to content

Commit 8338d89

Browse files
committed
OTA: STM32H7 merge storageOpen and findProgramLength
1 parent 688662f commit 8338d89

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/ota/implementation/OTASTM32H7.cpp

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

16-
static bool findProgramLength(DIR * dir, uint32_t & program_length);
17-
1816
const char STM32H7OTACloudProcess::UPDATE_FILE_NAME[] = "/fs/UPDATE.BIN";
1917

2018
STM32H7OTACloudProcess::STM32H7OTACloudProcess(MessageStream *ms, Client* client)
@@ -76,7 +74,7 @@ OTACloudProcessInterface::State STM32H7OTACloudProcess::flashOTA() {
7674
decompressed = nullptr;
7775

7876
/* Schedule the firmware update. */
79-
if(!storageOpen()) {
77+
if(!findProgramLength(_program_length)) {
8078
return OtaStorageOpenFail;
8179
}
8280

@@ -164,33 +162,25 @@ bool STM32H7OTACloudProcess::storageInit() {
164162
return false;
165163
}
166164

167-
bool STM32H7OTACloudProcess::storageOpen() {
165+
bool STM32H7OTACloudProcess::findProgramLength(uint32_t & program_length) {
168166
DIR * dir = NULL;
169-
if ((dir = opendir("/fs")) != NULL)
170-
{
171-
if (findProgramLength(dir, _program_length))
172-
{
173-
closedir(dir);
174-
return true;
175-
}
176-
closedir(dir);
177-
}
167+
struct dirent * entry = NULL;
168+
bool found = false;
178169

179-
return false;
180-
}
170+
if ((dir = opendir("/fs")) == NULL) {
171+
return false;
172+
}
181173

182-
bool findProgramLength(DIR * dir, uint32_t & program_length) {
183-
struct dirent * entry = NULL;
184174
while ((entry = readdir(dir)) != NULL) {
185175
if (strcmp(entry->d_name, "UPDATE.BIN") == 0) { // FIXME use constants
186176
struct stat stat_buf;
187177
stat("/fs/UPDATE.BIN", &stat_buf);
188178
program_length = stat_buf.st_size;
189-
return true;
179+
found = true;
190180
}
191181
}
192-
193-
return false;
182+
closedir(dir);
183+
return found;
194184
}
195185

196186
extern uint32_t __etext;

src/ota/implementation/OTASTM32H7.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ class STM32H7OTACloudProcess: public OTADefaultCloudProcessInterface {
6060
bool appFlashClose() { return true; };
6161
private:
6262
bool storageInit();
63-
bool storageOpen();
64-
63+
bool findProgramLength(uint32_t & program_length);
6564
void storageClean();
6665

6766
FILE* decompressed;

0 commit comments

Comments
 (0)