FwUpdate: binary firmware chunks over the mesh (REQ_TYPE_FW_OTA 0xF0)
This commit is contained in:
1 parent
5f8788c4b4
commit
637b0d78b7
7 files changed
+126
-28
No files matched your search
+21
-3
@@ -32,6 +32,18 @@
|
||||
#ifndef FW_OTA_CHUNK
|
||||
#define FW_OTA_CHUNK 96 // base64 = 128 chars, fits the 160 B CLI line
|
||||
#endif
|
||||
// Received data is tracked in units of FW_OTA_UNIT bytes, so text chunks (96 B)
|
||||
// and binary chunks (FW_OTA_BCHUNK) can both land in it.
|
||||
#define FW_OTA_UNIT 32
|
||||
#define FW_OTA_BCHUNK 160 // binary chunk: 5 units, fits one encrypted REQ (166 B max)
|
||||
|
||||
// Binary request carrying firmware data (over the mesh, admin only). Upstream
|
||||
// request types are 0x01..0x07; 0xF0 is far from them on purpose.
|
||||
// [0xF0]['w'][offset u32 LE][data] chunk, no reply (fire and forget)
|
||||
// [0xF0]['m'] reply: [state][units u16][count u16]
|
||||
// [missing unit index u16 ...]
|
||||
// state: 0 idle, 1 receiving, 2 ready, 3 failed, 4 busy (manifest/verify)
|
||||
#define REQ_TYPE_FW_OTA 0xF0
|
||||
#ifndef FW_OTA_MIN_MV
|
||||
#define FW_OTA_MIN_MV 3800 // ~50 % of a Li-ion cell at rest
|
||||
#endif
|
||||
@@ -48,6 +60,9 @@ public:
|
||||
|
||||
// sender_timestamp == 0 means the local console.
|
||||
bool handleCommand(uint32_t sender_timestamp, const char *command, char *reply);
|
||||
// Binary REQ_TYPE_FW_OTA payload (req[0] is the type). Returns the reply
|
||||
// length, 0 = no reply. The caller checks that the sender is an admin.
|
||||
int handleBinary(const uint8_t *req, int len, uint8_t *reply, int reply_max);
|
||||
void loop();
|
||||
|
||||
private:
|
||||
@@ -68,7 +83,10 @@ private:
|
||||
void cmdApply(uint32_t sender_timestamp, const char *arg, char *reply);
|
||||
void cmdBootloader(char *reply);
|
||||
uint16_t battMinMv();
|
||||
uint32_t received() const;
|
||||
uint32_t received() const; // units
|
||||
uint32_t units() const { return (_total + FW_OTA_UNIT - 1) / FW_OTA_UNIT; }
|
||||
bool haveUnit(uint32_t u) const { return _have[u >> 3] & (1 << (u & 7)); }
|
||||
const char *writeAt(uint32_t off, const uint8_t *buf, int len); // NULL = ok
|
||||
bool checkManifest(); // signature, target, base; sets _err
|
||||
const uint8_t *baseSha(); // sha256 of the running image, computed once
|
||||
|
||||
@@ -86,6 +104,6 @@ private:
|
||||
char _version[48] = { 0 };
|
||||
char _err[48] = { 0 };
|
||||
unsigned long _apply_at = 0;
|
||||
static constexpr uint32_t MAX_CHUNKS = (0x100000 / FW_OTA_CHUNK) + 1;
|
||||
uint8_t _have[(MAX_CHUNKS + 7) / 8];
|
||||
static constexpr uint32_t MAX_UNITS = (0xED000 - 0x27000) / FW_OTA_UNIT + 1; // whole stage
|
||||
uint8_t _have[(MAX_UNITS + 7) / 8];
|
||||
};
|
||||
Reference in new issue
Block a user