OTA API refactoring: renamed files and defines

This commit is contained in:
robert 2023-09-26 08:28:55 -04:00
parent 822b0c011a
commit fa54a22aed
13 changed files with 536 additions and 536 deletions

View File

@ -176,7 +176,7 @@ mongoose.c: Makefile $(wildcard src/*.c) $(wildcard src/drivers/*.c)
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/drivers/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
mongoose.h: $(HDRS) Makefile
(cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_ft.h src/net_lwip.h src/net_rl.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/ota.h src/sys.h src/net_builtin.h src/drivers/*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
(cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_ft.h src/net_lwip.h src/net_rl.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/ota.h src/device.h src/net_builtin.h src/drivers/*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
clean: clean_examples clean_embedded

View File

@ -222,7 +222,7 @@ static void handle_firmware_upload(struct mg_connection *c,
mg_http_reply(c, 200, s_json_header, "true\n");
if (data.len == 0) {
// Successful mg_ota_end() called, schedule device reboot
mg_timer_add(c->mgr, 500, 0, (void (*)(void *)) mg_sys_reset, NULL);
mg_timer_add(c->mgr, 500, 0, (void (*)(void *)) mg_device_reset, NULL);
}
}
}
@ -250,9 +250,9 @@ static void handle_firmware_status(struct mg_connection *c) {
MG_FIRMWARE_CURRENT, print_status, MG_FIRMWARE_PREVIOUS);
}
static void handle_sys_reset(struct mg_connection *c) {
static void handle_device_reset(struct mg_connection *c) {
mg_http_reply(c, 200, s_json_header, "true\n");
mg_timer_add(c->mgr, 500, 0, (void (*)(void *)) mg_sys_reset, NULL);
mg_timer_add(c->mgr, 500, 0, (void (*)(void *)) mg_device_reset, NULL);
}
// HTTP request handler function
@ -292,8 +292,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
handle_firmware_rollback(c);
} else if (mg_http_match_uri(hm, "/api/firmware/status")) {
handle_firmware_status(c);
} else if (mg_http_match_uri(hm, "/api/sys/reset")) {
handle_sys_reset(c);
} else if (mg_http_match_uri(hm, "/api/device/reset")) {
handle_device_reset(c);
} else {
struct mg_http_serve_opts opts;
memset(&opts, 0, sizeof(opts));

View File

@ -211,7 +211,7 @@ function FirmwareUpdate({}) {
const oncommit = ev => fetch('api/firmware/commit')
.then(r => r.json())
.then(refresh);
const onreboot = ev => fetch('api/sys/reset')
const onreboot = ev => fetch('api/device/reset')
.then(r => r.json())
.then(r => new Promise(r => setTimeout(ev => { refresh(); r(); }, 3000)));
const onrollback = ev => fetch('api/firmware/rollback')

View File

@ -2,7 +2,7 @@
#define MG_ARCH MG_ARCH_NEWLIB
#define MG_OTA MG_OTA_FLASH
#define MG_SYS MG_SYS_STM32H5
#define MG_DEVICE MG_DEVICE_STM32H5
#define MG_ENABLE_TCPIP 1
#define MG_ENABLE_CUSTOM_MILLIS 1

View File

@ -2,7 +2,7 @@
#define MG_ARCH MG_ARCH_NEWLIB
#define MG_OTA MG_OTA_FLASH
#define MG_SYS MG_SYS_STM32H7
#define MG_DEVICE MG_DEVICE_STM32H7
#define MG_ENABLE_TCPIP 1
#define MG_ENABLE_CUSTOM_MILLIS 1

1000
mongoose.c

File diff suppressed because it is too large Load Diff

View File

@ -1701,13 +1701,13 @@ bool mg_ota_rollback(void); // Rollback to the previous firmware
#define MG_SYS_NONE 0 // Dummy system
#define MG_SYS_STM32H5 1 // STM32 H5
#define MG_SYS_STM32H7 2 // STM32 H7
#define MG_SYS_CUSTOM 100 // Custom implementation
#define MG_DEVICE_NONE 0 // Dummy system
#define MG_DEVICE_STM32H5 1 // STM32 H5
#define MG_DEVICE_STM32H7 2 // STM32 H7
#define MG_DEVICE_CUSTOM 100 // Custom implementation
#ifndef MG_SYS
#define MG_SYS MG_SYS_NONE
#ifndef MG_DEVICE
#define MG_DEVICE MG_DEVICE_NONE
#endif
// Flash information
@ -1727,7 +1727,7 @@ bool mg_flash_swap_bank(void);
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_sys_reset(void); // Reboot device immediately
void mg_device_reset(void); // Reboot device immediately

View File

@ -5,13 +5,13 @@
#include "arch.h"
#define MG_SYS_NONE 0 // Dummy system
#define MG_SYS_STM32H5 1 // STM32 H5
#define MG_SYS_STM32H7 2 // STM32 H7
#define MG_SYS_CUSTOM 100 // Custom implementation
#define MG_DEVICE_NONE 0 // Dummy system
#define MG_DEVICE_STM32H5 1 // STM32 H5
#define MG_DEVICE_STM32H7 2 // STM32 H7
#define MG_DEVICE_CUSTOM 100 // Custom implementation
#ifndef MG_SYS
#define MG_SYS MG_SYS_NONE
#ifndef MG_DEVICE
#define MG_DEVICE MG_DEVICE_NONE
#endif
// Flash information
@ -31,4 +31,4 @@ bool mg_flash_swap_bank(void);
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_sys_reset(void); // Reboot device immediately
void mg_device_reset(void); // Reboot device immediately

View File

@ -1,6 +1,6 @@
#include "sys.h"
#include "device.h"
#if MG_SYS == MG_SYS_NONE
#if MG_DEVICE == MG_DEVICE_NONE
void *mg_flash_start(void) {
return NULL;
}
@ -27,6 +27,6 @@ bool mg_flash_write(void *addr, const void *buf, size_t len) {
(void) addr, (void) buf, (void) len;
return false;
}
void mg_sys_reset(void) {
void mg_device_reset(void) {
}
#endif

View File

@ -1,6 +1,6 @@
#include "sys.h"
#include "device.h"
#if MG_SYS == MG_SYS_STM32H7 || MG_SYS == MG_SYS_STM32H5
#if MG_DEVICE == MG_DEVICE_STM32H7 || MG_DEVICE == MG_DEVICE_STM32H5
// Flash can be written only if it is erased. Erased flash is 0xff (all bits 1)
// Writes must be mg_flash_write_align() - aligned. Thus if we want to save an
// object, we pad it at the end for alignment.

View File

@ -1,7 +1,7 @@
#include "log.h"
#include "sys.h"
#include "device.h"
#if MG_SYS == MG_SYS_STM32H5
#if MG_DEVICE == MG_DEVICE_STM32H5
#define FLASH_BASE 0x40022000 // Base address of the flash controller
#define FLASH_KEYR (FLASH_BASE + 0x4) // See RM0481 7.11
@ -135,7 +135,7 @@ bool mg_flash_write(void *addr, const void *buf, size_t len) {
return ok;
}
void mg_sys_reset(void) {
void mg_device_reset(void) {
// SCB->AIRCR = ((0x5fa << SCB_AIRCR_VECTKEY_Pos)|SCB_AIRCR_SYSRESETREQ_Msk);
*(volatile unsigned long *) 0xe000ed0c = 0x5fa0004;
}

View File

@ -1,7 +1,7 @@
#include "log.h"
#include "sys.h"
#include "device.h"
#if MG_SYS == MG_SYS_STM32H7
#if MG_DEVICE == MG_DEVICE_STM32H7
#define FLASH_BASE1 0x52002000 // Base address for bank1
#define FLASH_BASE2 0x52002100 // Base address for bank2
@ -141,7 +141,7 @@ bool mg_flash_write(void *addr, const void *buf, size_t len) {
return ok;
}
void mg_sys_reset(void) {
void mg_device_reset(void) {
// SCB->AIRCR = ((0x5fa << SCB_AIRCR_VECTKEY_Pos)|SCB_AIRCR_SYSRESETREQ_Msk);
*(volatile unsigned long *) 0xe000ed0c = 0x5fa0004;
}

View File

@ -1,9 +1,9 @@
#include "arch.h"
#include "log.h"
#include "ota.h"
#include "sys.h"
#include "device.h"
// This OTA implementation uses the internal flash API outlined in sys.h
// This OTA implementation uses the internal flash API outlined in device.h
// It splits flash into 2 equal partitions, and stores OTA status in the
// last sector of the partition.