Skip to content

Commit dee86a0

Browse files
committed
factor out esp_ota_end
1 parent 20c3184 commit dee86a0

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include "esp_log.h"
3232
#include "esp_ota_ops.h"
3333

34+
esp_ota_handle_t update_handle = 0 ;
35+
const esp_partition_t *update_partition = NULL;
36+
3437
static const char *TAG = "OTA";
3538

3639
static void __attribute__((noreturn)) task_fatal_error(void) {
@@ -41,8 +44,6 @@ static void __attribute__((noreturn)) task_fatal_error(void) {
4144
void common_hal_ota_flash(const void *buf, const size_t len) {
4245
esp_err_t err;
4346

44-
esp_ota_handle_t update_handle = 0 ;
45-
const esp_partition_t *update_partition = NULL;
4647
update_partition = esp_ota_get_next_update_partition(NULL);
4748

4849
const esp_partition_t *running = esp_ota_get_running_partition();
@@ -100,6 +101,10 @@ void common_hal_ota_flash(const void *buf, const size_t len) {
100101
ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err));
101102
task_fatal_error();
102103
}
104+
}
105+
106+
void common_hal_ota_finish(void) {
107+
esp_err_t err;
103108

104109
err = esp_ota_end(update_handle);
105110
if (err != ESP_OK) {

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_finish(void) {
34+
common_hal_ota_finish();
35+
return mp_const_none;
36+
}
37+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish);
38+
3339
STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) {
3440
mp_buffer_info_t bufinfo;
3541
mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ);
@@ -41,6 +47,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(ota_flash_obj, ota_flash);
4147

4248
STATIC const mp_rom_map_elem_t ota_module_globals_table[] = {
4349
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) },
50+
{ MP_ROM_QSTR(MP_QSTR_finish), MP_ROM_PTR(&ota_finish_obj) },
4451
{ MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) },
4552
};
4653
STATIC MP_DEFINE_CONST_DICT(ota_module_globals, ota_module_globals_table);

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_finish(void);
3233
extern void common_hal_ota_flash(const void *buf, const size_t len);
3334

3435
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H

0 commit comments

Comments
 (0)