Skip to content

Commit 30c2789

Browse files
replace filesystem version tracking with pending tag system, defer filesystem installation until after firmware flash, and clear pending tag only after successful filesystem update
1 parent a0f55a8 commit 30c2789

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

lib/Storage/Parameter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Parameter
1515

1616
static constexpr const char* UPDATE_INTERVAL_MIN = "update_interval_min";
1717

18-
static constexpr const char* FS_VERSION = "fs_version";
18+
static constexpr const char* FS_PENDING_TAG = "fs_pending_tag";
1919
static constexpr const char* FS_FAIL_COUNT = "fs_fail_count";
2020
};
2121

lib/Update/ReleaseUpdater.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@ void ReleaseUpdater::flashPendingAtBoot(Logger* logger, Storage* storage)
141141
fail(ST_WIFI_FAIL);
142142
return;
143143
}
144-
trace(ST_FS_FLASHING);
145-
if (!this->flashFilesystem(tag)) {
146-
trace(ST_FS_FAIL, this->lastError);
147-
this->log("filesystem update failed, continuing with firmware (retried on a later boot)");
148-
}
149-
150144
String fwUrl;
151145
if (!this->resolveAssetUrl(tag, "firmware.bin", fwUrl)) {
152146
fail(ST_REDIRECT_FAIL);
@@ -157,7 +151,10 @@ void ReleaseUpdater::flashPendingAtBoot(Logger* logger, Storage* storage)
157151
st.pending = 0;
158152
st.failures = 0;
159153
trace(ST_DONE);
160-
if (this->storage) this->storage->saveParameter(Parameter::FS_FAIL_COUNT, String("0"));
154+
if (this->storage) {
155+
this->storage->saveParameter(Parameter::FS_PENDING_TAG, tag);
156+
this->storage->saveParameter(Parameter::FS_FAIL_COUNT, String("0"));
157+
}
161158
delay(200);
162159
ESP.restart();
163160
}
@@ -174,10 +171,6 @@ bool ReleaseUpdater::flashFilesystem(const String& tag)
174171
}
175172
if (!this->downloadAndFlash(fsUrl, true)) return false;
176173

177-
if (this->storage) {
178-
this->storage->saveParameter(Parameter::FS_VERSION, tag);
179-
this->storage->saveParameter(Parameter::FS_FAIL_COUNT, String("0"));
180-
}
181174
this->log("filesystem updated to " + tag);
182175
return true;
183176
}
@@ -186,26 +179,33 @@ void ReleaseUpdater::repairFilesystemAtBoot()
186179
{
187180
if (!this->storage) return;
188181

189-
String current = FW_VERSION;
190-
if (current == "dev") return; // local build, nothing to match
191-
if (this->storage->getParameter(Parameter::FS_VERSION) == current) return;
182+
String tag = this->storage->getParameter(Parameter::FS_PENDING_TAG, "");
183+
if (tag.length() == 0) return; // filesystem is up to date
192184

193185
int failures = this->storage->getParameter(Parameter::FS_FAIL_COUNT, "0").toInt();
194-
if (failures >= MAX_FAILURES) return; // stop retrying at every boot
186+
if (failures >= MAX_FAILURES) {
187+
this->log("filesystem update for " + tag + " failed " + String(failures) +
188+
" times, giving up until the next release");
189+
this->storage->saveParameter(Parameter::FS_PENDING_TAG, String(""));
190+
return;
191+
}
195192

196-
this->log("filesystem is behind firmware " + current + ", repairing (attempt " +
193+
this->log("installing filesystem for " + tag + " (attempt " +
197194
String(failures + 1) + "/" + String(MAX_FAILURES) + ")");
198195

199196
if (!this->connectStoredWiFi(30000)) {
200-
this->log("filesystem repair: no WiFi");
197+
this->log("filesystem install: no WiFi, retrying next boot");
201198
return; // not counted: no attempt was made
202199
}
203200

204-
if (!this->flashFilesystem(current)) {
201+
if (!this->flashFilesystem(tag)) {
205202
this->storage->saveParameter(Parameter::FS_FAIL_COUNT, String(failures + 1));
206203
return;
207204
}
208205

206+
this->storage->saveParameter(Parameter::FS_PENDING_TAG, String(""));
207+
this->storage->saveParameter(Parameter::FS_FAIL_COUNT, String("0"));
208+
209209
delay(200);
210210
ESP.restart(); // reboot into the new filesystem
211211
}

0 commit comments

Comments
 (0)