diff --git a/include/mgos_ota.h b/include/mgos_ota.h index a1b7a91..c6c9458 100644 --- a/include/mgos_ota.h +++ b/include/mgos_ota.h @@ -6,8 +6,8 @@ /* * OTA API. * - * See https://mongoose-os.com/docs/mongoose-os/userguide/ota.md for more details about - * Mongoose OS OTA mechanism. + * See https://mongoose-os.com/docs/mongoose-os/userguide/ota.md for more + * details about Mongoose OS OTA mechanism. */ #pragma once @@ -34,6 +34,7 @@ struct mgos_ota_file_info { char name[50]; uint32_t size; uint32_t processed; + uint32_t crc32; /* Part that corresponds to this file (JSON). */ struct mg_str part; }; diff --git a/include/mgos_ota_backend.h b/include/mgos_ota_backend.h new file mode 100644 index 0000000..8cfba25 --- /dev/null +++ b/include/mgos_ota_backend.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2014-2018 Cesanta Software Limited + * All rights reserved + * + * Updater backend interface. + * A way to implement custom functionality during OTA. + * NB: Update can be aborted at any moment, including after finalize + * (if one of the backends fails to finalize). + */ + +#pragma once + +#include + +#include "common/mbuf.h" +#include "common/mg_str.h" + +#include "mgos_ota.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MGOS_UPD_BE_DATA_CHUNK_SIZE +#define MGOS_UPD_BE_DATA_CHUNK_SIZE 512 +#endif + +struct mgos_ota_be_ctx; /* Defined by backend implementation. */ + +struct mgos_ota_backend_if { + /* Create updater context. */ + struct mgos_ota_be_ctx *(*create_ctx)(void); + /* Get status message. */ + const char *(*get_status_msg)(struct mgos_ota_be_ctx *ctx); + /* + * Process the firmware manifest. + * Manifest info will remain valid for the duration of the update (until + * free_ctx). + * If returned value is SKIP, this backend will not get any files and move + * straight to free_ctx. + */ + enum mgos_ota_result (*begin)(struct mgos_ota_be_ctx *ctx, + const struct mgos_ota_manifest_info *mi); + /* + * Begin processing a file from the update package. + * If returned value is SKIP, there won't be DATA or END calls. + */ + enum mgos_ota_result (*file_begin)(struct mgos_ota_be_ctx *ctx, + const struct mgos_ota_file_info *fi); + + /* + * Process a chunk of file data. Data will be delivered to this function in + * MGOS_UPD_BE_DATA_CHUNK_SIZE chunks. + * Return number of bytes processed (0 .. data.len) + * or < 0 for error. In case of error, message should be provided in + * status_msg. + */ + int (*file_data)(struct mgos_ota_be_ctx *ctx, + const struct mgos_ota_file_info *fi, struct mg_str data); + + /* + * Finalize a file. Remainder of the data (if any) is passed, + * number of bytes of that data processed should be returned. The amount of + * data + * will be less than MGOS_UPD_BE_DATA_CHUNK_SIZE. + * Value equal to data.len is an indication of success, + * < 0 + ctx->status_msg on error. + */ + int (*file_end)(struct mgos_ota_be_ctx *ctx, + const struct mgos_ota_file_info *fi, struct mg_str data); + + /* + * Finalize the update. + * Return >= 0 if ok, < 0 + ctx->status_msg on error. + */ + enum mgos_ota_result (*finalize)(struct mgos_ota_be_ctx *ctx, + bool *need_reboot); + + void (*free_ctx)(struct mgos_ota_be_ctx *ctx); +}; + +void mgos_ota_register_backend(const struct mgos_ota_backend_if *be_if); + +#ifdef __cplusplus +} +#endif diff --git a/mos.yml b/mos.yml index 51e5127..e3f57f7 100644 --- a/mos.yml +++ b/mos.yml @@ -3,7 +3,7 @@ description: OTA common bits type: lib version: 1.0 -platforms: [ cc3200, esp32, esp8266, stm32 ] +platforms: [ cc3200, esp32, esp8266, rs14100, stm32 ] sources: - src @@ -26,6 +26,17 @@ config_schema: - ["update.timeout", "i", 600, {title : "Update will be aborted if it does not finish within this time"}] - ["update.commit_timeout", "i", {title : "After applying update, wait for commit up to this long"}] +conds: + - when: mos.platform == "rs14100" + apply: + libs: + - origin: https://github.com/mongoose-os-libs/bootloader + + - when: mos.platform == "stm32" + apply: + libs: + - origin: https://github.com/mongoose-os-libs/bootloader + tags: - c - core diff --git a/mos_stm32.yml b/mos_stm32.yml deleted file mode 100644 index e8d593e..0000000 --- a/mos_stm32.yml +++ /dev/null @@ -1,2 +0,0 @@ -libs: - - origin: https://github.com/mongoose-os-libs/bootloader