rename ota to dualbank

This commit is contained in:
microDev 2020-12-18 00:34:56 +05:30
parent 37ee5e683d
commit 4863413bc9
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
10 changed files with 102 additions and 126 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-10 16:56+0530\n" "POT-Creation-Date: 2020-12-17 19:42+0530\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -936,6 +936,10 @@ msgstr ""
msgid "Filters too complex" msgid "Filters too complex"
msgstr "" msgstr ""
#: ports/esp32s2/common-hal/dualbank/__init__.c
msgid "Firmware image is invalid"
msgstr ""
#: ports/cxd56/common-hal/camera/Camera.c #: ports/cxd56/common-hal/camera/Camera.c
msgid "Format not supported" msgid "Format not supported"
msgstr "" msgstr ""
@ -1420,10 +1424,6 @@ msgstr ""
msgid "Not settable" msgid "Not settable"
msgstr "" msgstr ""
#: ports/esp32s2/common-hal/ota/__init__.c
msgid "OTA Update Failed"
msgstr ""
#: shared-bindings/util.c #: shared-bindings/util.c
msgid "" msgid ""
"Object has been deinitialized and can no longer be used. Create a new object." "Object has been deinitialized and can no longer be used. Create a new object."
@ -1911,10 +1911,6 @@ msgstr ""
msgid "Unable to read color palette data" msgid "Unable to read color palette data"
msgstr "" msgstr ""
#: ports/esp32s2/common-hal/ota/__init__.c
msgid "Unable to switch boot partition"
msgstr ""
#: shared-bindings/nvm/ByteArray.c #: shared-bindings/nvm/ByteArray.c
msgid "Unable to write to nvm." msgid "Unable to write to nvm."
msgstr "" msgstr ""
@ -1983,6 +1979,10 @@ msgstr ""
msgid "Unsupported pull value." msgid "Unsupported pull value."
msgstr "" msgstr ""
#: ports/esp32s2/common-hal/dualbank/__init__.c
msgid "Update Failed"
msgstr ""
#: ports/nrf/common-hal/_bleio/Characteristic.c #: ports/nrf/common-hal/_bleio/Characteristic.c
#: ports/nrf/common-hal/_bleio/Descriptor.c #: ports/nrf/common-hal/_bleio/Descriptor.c
msgid "Value length != required fixed length" msgid "Value length != required fixed length"
@ -3210,7 +3210,7 @@ msgstr ""
msgid "offset is too large" msgid "offset is too large"
msgstr "" msgstr ""
#: shared-bindings/ota/__init__.c #: shared-bindings/dualbank/__init__.c
msgid "offset must be >= 0" msgid "offset must be >= 0"
msgstr "" msgstr ""

View File

@ -24,8 +24,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "common-hal/ota/__init__.h" #include "common-hal/dualbank/__init__.h"
#include "shared-bindings/ota/__init__.h" #include "shared-bindings/dualbank/__init__.h"
#include <string.h> #include <string.h>
@ -35,21 +35,24 @@
static const esp_partition_t *update_partition = NULL; static const esp_partition_t *update_partition = NULL;
static esp_ota_handle_t update_handle = 0; static esp_ota_handle_t update_handle = 0;
static bool ota_inited = false; static const char *TAG = "dualbank";
static const char *TAG = "OTA";
void ota_reset(void) { void dualbank_reset(void) {
// should use `abort` instead of `end`
// but not in idf v4.2
// esp_ota_abort(update_handle);
if (esp_ota_end(update_handle) == ESP_OK) {
update_handle = 0; update_handle = 0;
update_partition = NULL; update_partition = NULL;
ota_inited = false; }
} }
static void __attribute__((noreturn)) task_fatal_error(void) { static void __attribute__((noreturn)) task_fatal_error(void) {
ESP_LOGE(TAG, "Exiting task due to fatal error..."); ESP_LOGE(TAG, "Exiting task due to fatal error...");
mp_raise_RuntimeError(translate("OTA Update Failed")); mp_raise_RuntimeError(translate("Update Failed"));
} }
void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset) { void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t offset) {
esp_err_t err; esp_err_t err;
const esp_partition_t *running = esp_ota_get_running_partition(); const esp_partition_t *running = esp_ota_get_running_partition();
@ -67,7 +70,7 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse
assert(update_partition != NULL); assert(update_partition != NULL);
} }
if (!ota_inited) { if (update_handle == 0) {
if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) { if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) {
esp_app_desc_t new_app_info; esp_app_desc_t new_app_info;
memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t)); memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t));
@ -102,14 +105,13 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
task_fatal_error(); task_fatal_error();
} }
ota_inited = true;
} else { } else {
ESP_LOGE(TAG, "received package is not fit len"); ESP_LOGE(TAG, "received package is not fit len");
task_fatal_error(); task_fatal_error();
} }
} }
if (offset == -1) { if (offset == 0) {
err = esp_ota_write(update_handle, buf, len); err = esp_ota_write(update_handle, buf, len);
} else { } else {
err = esp_ota_write_with_offset(update_handle, buf, len, offset); err = esp_ota_write_with_offset(update_handle, buf, len, offset);
@ -120,31 +122,18 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse
} }
} }
void common_hal_ota_finish(void) { void common_hal_dualbank_switch(void) {
if (ota_inited) { if (esp_ota_end(update_handle) == ESP_OK) {
esp_err_t err; update_handle = 0;
update_partition = NULL;
err = esp_ota_end(update_handle); }
esp_err_t err = esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL));
if (err != ESP_OK) { if (err != ESP_OK) {
if (err == ESP_ERR_OTA_VALIDATE_FAILED) { if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
ESP_LOGE(TAG, "Image validation failed, image is corrupted"); ESP_LOGE(TAG, "Image validation failed, image is corrupted");
mp_raise_RuntimeError(translate("Firmware image is invalid"));
} }
ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err));
task_fatal_error();
}
err = esp_ota_set_boot_partition(update_partition);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
task_fatal_error(); task_fatal_error();
} }
ota_reset();
}
}
void common_hal_ota_switch(void) {
if (esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)) != ESP_OK) {
mp_raise_RuntimeError(translate("Unable to switch boot partition"));
}
} }

View File

@ -24,9 +24,9 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H #ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H #define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H
extern void ota_reset(void); extern void dualbank_reset(void);
#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H #endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H

View File

@ -19,11 +19,11 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0 CIRCUITPY_AUDIOIO = 0
CIRCUITPY_CANIO = 1 CIRCUITPY_CANIO = 1
CIRCUITPY_COUNTIO = 1 CIRCUITPY_COUNTIO = 1
CIRCUITPY_DUALBANK = 1
CIRCUITPY_FREQUENCYIO = 1 CIRCUITPY_FREQUENCYIO = 1
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_ROTARYIO = 1 CIRCUITPY_ROTARYIO = 1
CIRCUITPY_NVM = 1 CIRCUITPY_NVM = 1
CIRCUITPY_OTA = 1
# We don't have enough endpoints to include MIDI. # We don't have enough endpoints to include MIDI.
CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_MIDI = 0
CIRCUITPY_WIFI = 1 CIRCUITPY_WIFI = 1

View File

@ -41,7 +41,7 @@
#include "common-hal/busio/I2C.h" #include "common-hal/busio/I2C.h"
#include "common-hal/busio/SPI.h" #include "common-hal/busio/SPI.h"
#include "common-hal/busio/UART.h" #include "common-hal/busio/UART.h"
#include "common-hal/ota/__init__.h" #include "common-hal/dualbank/__init__.h"
#include "common-hal/ps2io/Ps2.h" #include "common-hal/ps2io/Ps2.h"
#include "common-hal/pulseio/PulseIn.h" #include "common-hal/pulseio/PulseIn.h"
#include "common-hal/pwmio/PWMOut.h" #include "common-hal/pwmio/PWMOut.h"
@ -124,8 +124,8 @@ void reset_port(void) {
analogout_reset(); analogout_reset();
#endif #endif
#if CIRCUITPY_OTA #if CIRCUITPY_DUALBANK
ota_reset(); dualbank_reset();
#endif #endif
#if CIRCUITPY_PS2IO #if CIRCUITPY_PS2IO

View File

@ -205,8 +205,8 @@ endif
ifeq ($(CIRCUITPY_OS),1) ifeq ($(CIRCUITPY_OS),1)
SRC_PATTERNS += os/% SRC_PATTERNS += os/%
endif endif
ifeq ($(CIRCUITPY_OTA),1) ifeq ($(CIRCUITPY_DUALBANK),1)
SRC_PATTERNS += ota/% SRC_PATTERNS += dualbank/%
endif endif
ifeq ($(CIRCUITPY_PIXELBUF),1) ifeq ($(CIRCUITPY_PIXELBUF),1)
SRC_PATTERNS += _pixelbuf/% SRC_PATTERNS += _pixelbuf/%
@ -350,7 +350,7 @@ SRC_COMMON_HAL_ALL = \
nvm/ByteArray.c \ nvm/ByteArray.c \
nvm/__init__.c \ nvm/__init__.c \
os/__init__.c \ os/__init__.c \
ota/__init__.c \ dualbank/__init__.c \
ps2io/Ps2.c \ ps2io/Ps2.c \
ps2io/__init__.c \ ps2io/__init__.c \
pulseio/PulseIn.c \ pulseio/PulseIn.c \

View File

@ -539,11 +539,11 @@ extern const struct _mp_obj_module_t os_module;
#define OS_MODULE_ALT_NAME #define OS_MODULE_ALT_NAME
#endif #endif
#if CIRCUITPY_OTA #if CIRCUITPY_DUALBANK
extern const struct _mp_obj_module_t ota_module; extern const struct _mp_obj_module_t dualbank_module;
#define OTA_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ota), (mp_obj_t)&ota_module }, #define DUALBANK_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_dualbank), (mp_obj_t)&dualbank_module },
#else #else
#define OTA_MODULE #define DUALBANK_MODULE
#endif #endif
#if CIRCUITPY_PEW #if CIRCUITPY_PEW
@ -834,7 +834,7 @@ extern const struct _mp_obj_module_t wifi_module;
NETWORK_MODULE \ NETWORK_MODULE \
SOCKET_MODULE \ SOCKET_MODULE \
WIZNET_MODULE \ WIZNET_MODULE \
OTA_MODULE \ DUALBANK_MODULE \
PEW_MODULE \ PEW_MODULE \
PIXELBUF_MODULE \ PIXELBUF_MODULE \
PS2IO_MODULE \ PS2IO_MODULE \

View File

@ -179,8 +179,8 @@ CFLAGS += -DCIRCUITPY_NVM=$(CIRCUITPY_NVM)
CIRCUITPY_OS ?= 1 CIRCUITPY_OS ?= 1
CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS) CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS)
CIRCUITPY_OTA ?= 0 CIRCUITPY_DUALBANK ?= 0
CFLAGS += -DCIRCUITPY_OTA=$(CIRCUITPY_OTA) CFLAGS += -DCIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK)
CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF) CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF)

View File

@ -24,19 +24,20 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include "shared-bindings/ota/__init__.h" #include "shared-bindings/dualbank/__init__.h"
//| """OTA Module //| """DUALBANK Module
//| //|
//| The `ota` module implements over-the-air update. //| The `dualbank` module adds ability to update and switch
//| between the two app partitions.
//| //|
//| There are two identical ota partitions ota_0/1, these //| There are two identical partitions, these contain different
//| contain different firmware versions. //| firmware versions.
//| Having two partitions enables rollback functionality. //| Having two partitions enables rollback functionality.
//| //|
//| The two partitions are defined as boot partition and //| The two partitions are defined as boot partition and
//| next-update partition. Calling `ota.flash()` writes the //| next-update partition. Calling `dualbank.flash()` writes
//| next-update partition. //| the next-update partition.
//| //|
//| After the next-update partition is written a validation //| After the next-update partition is written a validation
//| check is performed and on a successful validation this //| check is performed and on a successful validation this
@ -47,81 +48,68 @@
//| //|
//| .. code-block:: python //| .. code-block:: python
//| //|
//| import ota //| import dualbank
//| //|
//| ota.flash(buffer, offset) //| dualbank.flash(buffer, offset)
//| ota.finish() //| dualbank.switch()
//| """ //| """
//| ... //| ...
//| //|
//| def switch() -> None:
//| """Switches the boot partition. On next reset,
//| firmware will be loaded from the partition
//| just switched over to."""
//| ...
//|
STATIC mp_obj_t ota_switch(void) {
common_hal_ota_switch();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch);
//| def finish() -> None:
//| """Validates flashed firmware, sets next boot partition.
//| **Must be called** after the firmware has been
//| completely written into the flash using `ota.flash()`.
//|
//| This is to be called only once per update."""
//| ...
//|
STATIC mp_obj_t ota_finish(void) {
common_hal_ota_finish();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish);
//| def flash(*buffer: ReadableBuffer, offset: int=0) -> None: //| def flash(*buffer: ReadableBuffer, offset: int=0) -> None:
//| """Writes one of two OTA partitions at the given offset. //| """Writes one of two app partitions at the given offset.
//|
//| The default offset is 0. It is necessary to provide the
//| offset when writing in discontinous chunks.
//| //|
//| This can be called multiple times when flashing the firmware //| This can be called multiple times when flashing the firmware
//| in small chunks.""" //| in small chunks.
//| """
//| ... //| ...
//| //|
STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t dualbank_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_offset }; enum { ARG_buffer, ARG_offset };
static const mp_arg_t allowed_args[] = { static const mp_arg_t allowed_args[] = {
{ MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
}; };
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
if (args[ARG_offset].u_int < -1) { if (args[ARG_offset].u_int < 0) {
mp_raise_ValueError(translate("offset must be >= 0")); mp_raise_ValueError(translate("offset must be >= 0"));
} }
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ);
common_hal_ota_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int); common_hal_dualbank_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 0, ota_flash); STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_flash_obj, 0, dualbank_flash);
STATIC const mp_rom_map_elem_t ota_module_globals_table[] = { //| def switch() -> None:
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, //| """Switches the boot partition.
{ MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&ota_switch_obj) }, //|
{ MP_ROM_QSTR(MP_QSTR_finish), MP_ROM_PTR(&ota_finish_obj) }, //| On next reset, firmware will be loaded from the partition
{ MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) }, //| just switched over to.
//| """
//| ...
//|
STATIC mp_obj_t dualbank_switch(void) {
common_hal_dualbank_switch();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(dualbank_switch_obj, dualbank_switch);
STATIC const mp_rom_map_elem_t dualbank_module_globals_table[] = {
// module name
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_dualbank) },
// module functions
{ MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&dualbank_flash_obj) },
{ MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&dualbank_switch_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(ota_module_globals, ota_module_globals_table); STATIC MP_DEFINE_CONST_DICT(dualbank_module_globals, dualbank_module_globals_table);
const mp_obj_module_t ota_module = { const mp_obj_module_t dualbank_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&ota_module_globals, .globals = (mp_obj_dict_t*)&dualbank_module_globals,
}; };

View File

@ -24,13 +24,12 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H #define MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H
#include "py/runtime.h" #include "py/runtime.h"
extern void common_hal_ota_switch(void); extern void common_hal_dualbank_switch(void);
extern void common_hal_ota_finish(void); extern void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t offset);
extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H