Skip to content

Commit 07015ad

Browse files
committed
add ability to switch boot partition
1 parent bfa2c60 commit 07015ad

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

ports/esp32s2/common-hal/ota/__init__.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ void common_hal_ota_finish(void) {
141141
ota_reset();
142142
}
143143
}
144+
145+
void common_hal_ota_switch(void) {
146+
if (esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)) != ESP_OK) {
147+
mp_raise_RuntimeError(translate("Unable to switch partition"));
148+
}
149+
}

shared-bindings/ota/__init__.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
//|
3131
//| The `ota` module implements over-the-air update."""
3232

33+
STATIC mp_obj_t ota_switch(void) {
34+
common_hal_ota_switch();
35+
return mp_const_none;
36+
}
37+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch);
38+
3339
STATIC mp_obj_t ota_finish(void) {
3440
common_hal_ota_finish();
3541
return mp_const_none;
@@ -60,6 +66,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 1, ota_flash);
6066

6167
STATIC const mp_rom_map_elem_t ota_module_globals_table[] = {
6268
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) },
69+
{ MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&ota_switch_obj) },
6370
{ MP_ROM_QSTR(MP_QSTR_finish), MP_ROM_PTR(&ota_finish_obj) },
6471
{ MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) },
6572
};

shared-bindings/ota/__init__.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "py/runtime.h"
3131

32+
extern void common_hal_ota_switch(void);
3233
extern void common_hal_ota_finish(void);
3334
extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset);
3435

0 commit comments

Comments
 (0)