OTA steps 3-5: Update Service, Probation and Rollback, Update from SD

- EcdsaVerifier (mbedTLS, embedded public key) and EspOtaSink (writes
  the inactive app slot, esp_ota_end validates the image, then sets
  the boot partition)
- UpdateService: listens on TCP 3232 (and mDNS roro9stack-<id>) while
  Wi-Fi is Connected; streams into UpdateParser; replies OK/ERR to the
  sender; remembers the pending version so a Rollback is reported
  after the reboot
- Probation (host-tested): confirm after the first frame + 30 s + Wi-Fi
  (if configured); roll back if configured Wi-Fi never connects in 3 min
- Main loop: full-screen progress while receiving; restart once
  installed, waiting up to 60 s for Text Entry to end
- Settings > Firmware: version, Probation status, push address and
  name, and the .ota files in /updates on the SD card to install
- StorageService.runJob() runs work on the storage task (SD installs)
- wifi status prints IP and running version; RORO_TEST_CRASH test hook

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-03 21:35:33 +02:00
co-authored by Claude Opus 5.5
parent 90cb6ef9b2
commit 21b3d9e422
19 changed files with 655 additions and 10 deletions
+103
View File
@@ -0,0 +1,103 @@
#include "firmware_page.h"
#include <SD.h>
#include "ui/widgets.h"
#include "version.h"
namespace roro {
namespace {
constexpr const char* kUpdatesFolder = "/updates";
bool endsWith(const std::string& s, const std::string& suffix) {
return s.size() >= suffix.size() && s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0;
}
} // namespace
void FirmwarePage::enter() {
confirm_.reset();
{
std::lock_guard<std::mutex> g(lock_);
files_.clear();
listed_ = false;
}
list_.setCount(kFixed);
storage_.runJob([this]() {
std::vector<std::string> found;
File dir = SD.open(kUpdatesFolder);
if (dir && dir.isDirectory())
for (File f = dir.openNextFile(); f; f = dir.openNextFile())
if (!f.isDirectory() && endsWith(f.name(), ".ota")) found.push_back(std::string(kUpdatesFolder) + "/" + f.name());
std::lock_guard<std::mutex> g(lock_);
files_ = found;
listed_ = true;
});
}
std::vector<std::string> FirmwarePage::files() {
std::lock_guard<std::mutex> g(lock_);
return files_;
}
bool FirmwarePage::onKey(const KeyEvent& e) {
auto found = files();
if (confirm_) {
confirm_->onKey(e);
int pick = list_.selected() - kFixed;
if (confirm_->result() == 1 && pick >= 0 && pick < static_cast<int>(found.size())) update_.installFromSd(found[pick]);
if (confirm_->result() != DialogModel::kPending) confirm_.reset();
return true;
}
list_.setCount(kFixed + static_cast<int>(found.size()));
switch (e.key) {
case Key::Up: list_.up(); break;
case Key::Down: list_.down(); break;
case Key::Back: return false;
case Key::Select:
if (list_.selected() >= kFixed) confirm_.reset(new DialogModel({"Cancel", "Install"}));
break;
default: break;
}
return true;
}
void FirmwarePage::draw(Canvas& c) {
auto found = files();
bool listed;
{
std::lock_guard<std::mutex> g(lock_);
listed = listed_;
}
list_.setCount(kFixed + static_cast<int>(found.size()));
std::string ip = wifi_.ip();
widgets::list(
c, list_, theme::kContent,
[&](int i) -> std::string {
switch (i) {
case kVersion: return "Version";
case kStatus: return "Status";
case kAddress: return "Push to";
case kName: return "Name";
case kSdHeader: return listed ? (found.empty() ? "No .ota files in /updates" : "On the SD card:") : "Looking on the SD card...";
default: return " " + found[i - kFixed].substr(std::string(kUpdatesFolder).size() + 1);
}
},
[&](int i) -> std::string {
switch (i) {
case kVersion: return versionString();
case kStatus: return update_.onProbation() ? "on probation" : "confirmed";
case kAddress: return ip.empty() ? "Wi-Fi not connected" : ip + ":" + std::to_string(UpdateService::kPort);
case kName: return update_.hostname() + ".local";
case kSdHeader: return "";
default: return "install >";
}
});
if (confirm_) {
int pick = list_.selected() - kFixed;
std::string name = pick >= 0 && pick < static_cast<int>(found.size()) ? found[pick] : "";
widgets::dialog(c, "Install update?", name + " is checked before anything is written. The device restarts after.", *confirm_);
}
}
} // namespace roro
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "dialog_model.h"
#include "key_event.h"
#include "list_model.h"
#include "services/storage_service.h"
#include "services/update_service.h"
#include "services/wifi_service.h"
#include "ui/canvas.h"
#include "ui/theme.h"
namespace roro {
// Settings → Firmware: the running version and its Probation, where to push Firmware Updates, and
// the Update Files on the SD card (in /updates) to install from.
class FirmwarePage {
public:
FirmwarePage(UpdateService& update, WifiService& wifi, StorageService& storage)
: update_(update), wifi_(wifi), storage_(storage) {}
void enter();
bool onKey(const KeyEvent& e); // false: leave the page
void draw(Canvas& c);
private:
enum Row { kVersion, kStatus, kAddress, kName, kSdHeader, kFixed };
std::vector<std::string> files();
UpdateService& update_;
WifiService& wifi_;
StorageService& storage_;
ListModel list_{theme::kContent.h / theme::kLineHeight};
std::unique_ptr<DialogModel> confirm_;
// Filled on the storage task.
std::mutex lock_;
std::vector<std::string> files_;
bool listed_ = false;
};
} // namespace roro
+10 -1
View File
@@ -34,6 +34,9 @@ bool SettingsApp::onKey(const KeyEvent& e) {
case Page::Wifi:
if (!wifiPage_.onKey(e)) page_ = Page::Menu;
return true;
case Page::Firmware:
if (!firmwarePage_.onKey(e)) page_ = Page::Menu;
return true;
}
return false;
}
@@ -75,6 +78,10 @@ bool SettingsApp::onMenuKey(const KeyEvent& e) {
page_ = Page::Wifi;
wifiPage_.enter();
break;
case Row::Firmware:
page_ = Page::Firmware;
firmwarePage_.enter();
break;
default: page_ = Page::About; break;
}
break;
@@ -124,7 +131,8 @@ bool SettingsApp::onAboutKey(const KeyEvent& e) {
void SettingsApp::update(uint32_t nowMs) {
// Live values on Storage and About.
bool live = page_ == Page::Storage || page_ == Page::About || (page_ == Page::Wifi && wifiPage_.live());
bool live = page_ == Page::Storage || page_ == Page::About || page_ == Page::Firmware ||
(page_ == Page::Wifi && wifiPage_.live());
if (live && nowMs - lastRefreshMs_ >= 500) {
lastRefreshMs_ = nowMs;
requestRedraw();
@@ -183,6 +191,7 @@ void SettingsApp::draw(Canvas& c) {
case Page::Storage: storagePage_.draw(c); break;
case Page::About: widgets::textLines(c, aboutLines(), 0, area); break;
case Page::Wifi: wifiPage_.draw(c); break;
case Page::Firmware: firmwarePage_.draw(c); break;
}
}
+6 -2
View File
@@ -13,6 +13,7 @@
#include "services/battery_service.h"
#include "services/clock_service.h"
#include "services/storage_service.h"
#include "apps/firmware_page.h"
#include "apps/storage_page.h"
#include "apps/wifi_settings_page.h"
#include "settings_menu.h"
@@ -29,6 +30,7 @@ struct SettingsAppDeps {
ClockService& clock;
WifiService& wifi;
SavedNetworks& savedNetworks;
UpdateService& update;
};
// Settings: every user-facing setting, plus the Storage and About pages.
@@ -38,7 +40,8 @@ class SettingsApp : public App {
: d_(deps),
menu_(deps.settings),
wifiPage_(deps.settings, deps.savedNetworks, deps.wifi, deps.bus),
storagePage_(deps.storage, deps.clock, deps.bus) {}
storagePage_(deps.storage, deps.clock, deps.bus),
firmwarePage_(deps.update, deps.wifi, deps.storage) {}
void onEnter() override;
bool onKey(const KeyEvent& e) override;
void update(uint32_t nowMs) override;
@@ -48,7 +51,7 @@ class SettingsApp : public App {
void draw(Canvas& c) override;
private:
enum class Page { Menu, Text, Choice, Storage, About, Wifi };
enum class Page { Menu, Text, Choice, Storage, About, Wifi, Firmware };
bool onMenuKey(const KeyEvent& e);
bool onTextKey(const KeyEvent& e);
@@ -61,6 +64,7 @@ class SettingsApp : public App {
SettingsMenu menu_;
WifiSettingsPage wifiPage_;
StoragePage storagePage_;
FirmwarePage firmwarePage_;
Page page_ = Page::Menu;
ListModel list_{theme::kContent.h / theme::kLineHeight};
ListModel choices_{theme::kContent.h / theme::kLineHeight};