Skip to content

Commit

Permalink
RS14100 OTA support, bootloader refactoring
Browse files Browse the repository at this point in the history
CL: RS14100 OTA support, bootloader refactoring

PUBLISHED_FROM=c6188a86d605f89d8ed64a90d5d087c476aa7e4d
  • Loading branch information
Deomid Ryabkov authored and cesantabot committed Apr 24, 2019
1 parent 890549e commit 5f56e7a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 5 deletions.
5 changes: 3 additions & 2 deletions include/mgos_ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};
Expand Down
86 changes: 86 additions & 0 deletions include/mgos_ota_backend.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>

#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
13 changes: 12 additions & 1 deletion mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions mos_stm32.yml

This file was deleted.

0 comments on commit 5f56e7a

Please sign in to comment.