add ability to switch boot partition

This commit is contained in:
microDev 2020-12-10 16:42:45 +05:30
parent bfa2c604ef
commit 07015ad527
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
3 changed files with 14 additions and 0 deletions

View File

@ -141,3 +141,9 @@ void common_hal_ota_finish(void) {
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 partition"));
}
}

View File

@ -30,6 +30,12 @@
//|
//| The `ota` module implements over-the-air update."""
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);
STATIC mp_obj_t ota_finish(void) {
common_hal_ota_finish();
return mp_const_none;
@ -60,6 +66,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 1, ota_flash);
STATIC const mp_rom_map_elem_t ota_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) },
{ MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&ota_switch_obj) },
{ MP_ROM_QSTR(MP_QSTR_finish), MP_ROM_PTR(&ota_finish_obj) },
{ MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) },
};

View File

@ -29,6 +29,7 @@
#include "py/runtime.h"
extern void common_hal_ota_switch(void);
extern void common_hal_ota_finish(void);
extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset);