mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-23 20:11:49 +00:00
Refactor OTA API
This commit is contained in:
1 parent
3319ce78d3
commit
9b99f62311
27 files changed
+1716
-2143
No files matched your search
+22
-65
@@ -2640,49 +2640,43 @@ void mg_rpc_list(struct mg_rpc_req *r);
|
||||
|
||||
|
||||
|
||||
#define MG_OTA_NONE 0 // No OTA support
|
||||
#define MG_OTA_FLASH 1 // OTA via an internal flash
|
||||
#define MG_OTA_ESP32 2 // ESP32 OTA implementation
|
||||
#define MG_OTA_STM32H5 3 // STM32H5 OTA implementation
|
||||
#define MG_OTA_CUSTOM 100 // Custom implementation
|
||||
#define MG_OTA_NONE 0 // No OTA support
|
||||
#define MG_OTA_STM32H5 1 // STM32 H5
|
||||
#define MG_OTA_STM32H7 2 // STM32 H7
|
||||
#define MG_OTA_CH32V307 100 // WCH CH32V307
|
||||
#define MG_OTA_U2A 200 // Renesas U2A16, U2A8, U2A6
|
||||
#define MG_OTA_RT1020 300 // IMXRT1020
|
||||
#define MG_OTA_RT1060 301 // IMXRT1060
|
||||
#define MG_OTA_MCXN 310 // MCXN947
|
||||
#define MG_OTA_FLASH 900 // OTA via an internal flash
|
||||
#define MG_OTA_ESP32 910 // ESP32 OTA implementation
|
||||
#define MG_OTA_CUSTOM 1000 // Custom implementation
|
||||
|
||||
#ifndef MG_OTA
|
||||
#define MG_OTA MG_OTA_NONE
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && !defined(__APPLE__)
|
||||
#else
|
||||
#ifndef MG_IRAM
|
||||
#if defined(__GNUC__)
|
||||
#define MG_IRAM __attribute__((section(".iram")))
|
||||
#else
|
||||
#define MG_IRAM
|
||||
#endif
|
||||
#endif // compiler
|
||||
#endif // IRAM
|
||||
#endif // OTA
|
||||
|
||||
// Firmware update API
|
||||
bool mg_ota_begin(size_t new_firmware_size); // Start writing
|
||||
bool mg_ota_write(const void *buf, size_t len); // Write chunk, aligned to 1k
|
||||
bool mg_ota_end(void); // Stop writing
|
||||
|
||||
enum {
|
||||
MG_OTA_UNAVAILABLE = 0, // No OTA information is present
|
||||
MG_OTA_FIRST_BOOT = 1, // Device booting the first time after the OTA
|
||||
MG_OTA_UNCOMMITTED = 2, // Ditto, but marking us for the rollback
|
||||
MG_OTA_COMMITTED = 3 // The firmware is good
|
||||
};
|
||||
enum { MG_FIRMWARE_CURRENT = 0, MG_FIRMWARE_PREVIOUS = 1 };
|
||||
|
||||
int mg_ota_status(int firmware); // Return firmware status MG_OTA_*
|
||||
uint32_t mg_ota_crc32(int firmware); // Return firmware checksum
|
||||
uint32_t mg_ota_timestamp(int firmware); // Firmware timestamp, UNIX UTC epoch
|
||||
size_t mg_ota_size(int firmware); // Firmware size
|
||||
|
||||
bool mg_ota_commit(void); // Commit current firmware
|
||||
bool mg_ota_rollback(void); // Rollback to the previous firmware
|
||||
MG_IRAM void mg_ota_boot(void); // Bootloader function
|
||||
|
||||
#if MG_OTA != MG_OTA_NONE && MG_OTA != MG_OTA_CUSTOM
|
||||
|
||||
struct mg_flash {
|
||||
void *start; // Address at which flash starts
|
||||
size_t size; // Flash size
|
||||
size_t align; // Write alignment
|
||||
void *start; // Address at which flash starts
|
||||
size_t size; // Flash size
|
||||
size_t secsz; // Sector size
|
||||
size_t align; // Write alignment
|
||||
bool (*write_fn)(void *, const void *, size_t); // Write function
|
||||
bool (*swap_fn)(void); // Swap partitions
|
||||
};
|
||||
@@ -2690,46 +2684,9 @@ struct mg_flash {
|
||||
bool mg_ota_flash_begin(size_t new_firmware_size, struct mg_flash *flash);
|
||||
bool mg_ota_flash_write(const void *buf, size_t len, struct mg_flash *flash);
|
||||
bool mg_ota_flash_end(struct mg_flash *flash);
|
||||
// Copyright (c) 2023 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define MG_DEVICE_NONE 0 // Dummy system
|
||||
|
||||
#define MG_DEVICE_STM32H5 1 // STM32 H5
|
||||
#define MG_DEVICE_STM32H7 2 // STM32 H7
|
||||
#define MG_DEVICE_CH32V307 100 // WCH CH32V307
|
||||
#define MG_DEVICE_U2A 200 // Renesas U2A16, U2A8, U2A6
|
||||
#define MG_DEVICE_RT1020 300 // IMXRT1020
|
||||
#define MG_DEVICE_RT1060 301 // IMXRT1060
|
||||
#define MG_DEVICE_CUSTOM 1000 // Custom implementation
|
||||
|
||||
#ifndef MG_DEVICE
|
||||
#define MG_DEVICE MG_DEVICE_NONE
|
||||
#endif
|
||||
|
||||
// Flash information
|
||||
void *mg_flash_start(void); // Return flash start address
|
||||
size_t mg_flash_size(void); // Return flash size
|
||||
size_t mg_flash_sector_size(void); // Return flash sector size
|
||||
size_t mg_flash_write_align(void); // Return flash write align, minimum 4
|
||||
int mg_flash_bank(void); // 0: not dual bank, 1: bank1, 2: bank2
|
||||
|
||||
// Write, erase, swap bank
|
||||
bool mg_flash_write(void *addr, const void *buf, size_t len);
|
||||
bool mg_flash_erase(void *sector);
|
||||
bool mg_flash_swap_bank(void);
|
||||
|
||||
// Convenience functions to store data on a flash sector with wear levelling
|
||||
// If `sector` is NULL, then the last sector of flash is used
|
||||
bool mg_flash_load(void *sector, uint32_t key, void *buf, size_t len);
|
||||
bool mg_flash_save(void *sector, uint32_t key, const void *buf, size_t len);
|
||||
|
||||
void mg_device_reset(void); // Reboot device immediately
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user