SD-card firmware update + X3 bootloader compatibility (#1786)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "activities/Activity.h"
|
||||
|
||||
/**
|
||||
* SD-card based firmware update activity.
|
||||
*
|
||||
* Flow:
|
||||
* 1) onEnter -> push FileBrowserActivity in PickFirmware mode (only .bin files visible).
|
||||
* 2) On result: validate the .bin (header magic, size fits OTA partition).
|
||||
* 3) Push ConfirmationActivity ("Update firmware?").
|
||||
* 4) On confirm: stream the file into the OTA partition via raw esp_partition APIs,
|
||||
* drawing a progress bar; on success ESP.restart().
|
||||
*
|
||||
* Used both from Settings -> System -> "SD Card Firmware Update", and as the only
|
||||
* activity launched in boot recovery mode (left side button + power on X3).
|
||||
*/
|
||||
class SdFirmwareUpdateActivity : public Activity {
|
||||
public:
|
||||
enum class State {
|
||||
PICKING,
|
||||
VALIDATING,
|
||||
CONFIRMING,
|
||||
UPDATING,
|
||||
SUCCESS,
|
||||
FAILED,
|
||||
};
|
||||
|
||||
explicit SdFirmwareUpdateActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, bool recoveryMode = false)
|
||||
: Activity("SdFirmwareUpdate", renderer, mappedInput), recoveryMode(recoveryMode) {}
|
||||
|
||||
void onEnter() override;
|
||||
void loop() override;
|
||||
void render(RenderLock&&) override;
|
||||
bool preventAutoSleep() override { return state == State::UPDATING || state == State::VALIDATING; }
|
||||
bool skipLoopDelay() override { return state == State::UPDATING; }
|
||||
|
||||
private:
|
||||
State state = State::PICKING;
|
||||
bool recoveryMode = false;
|
||||
|
||||
std::string firmwarePath;
|
||||
size_t firmwareSize = 0;
|
||||
size_t writtenBytes = 0;
|
||||
unsigned int lastRenderedPercent = 101;
|
||||
std::string errorMessage;
|
||||
|
||||
void launchPicker();
|
||||
void onPickerResult(const ActivityResult& result);
|
||||
bool validateFirmware();
|
||||
void promptConfirmation();
|
||||
void onConfirmationResult(const ActivityResult& result);
|
||||
void performUpdate();
|
||||
};
|
||||
Reference in New Issue
Block a user