factor out esp_ota_end

This commit is contained in:
microDev 2020-12-10 14:04:24 +05:30
parent 20c3184c87
commit dee86a014b
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
3 changed files with 15 additions and 2 deletions

View File

@ -31,6 +31,9 @@
#include "esp_log.h"
#include "esp_ota_ops.h"
esp_ota_handle_t update_handle = 0 ;
const esp_partition_t *update_partition = NULL;
static const char *TAG = "OTA";
static void __attribute__((noreturn)) task_fatal_error(void) {
@ -41,8 +44,6 @@ static void __attribute__((noreturn)) task_fatal_error(void) {
void common_hal_ota_flash(const void *buf, const size_t len) {
esp_err_t err;
esp_ota_handle_t update_handle = 0 ;
const esp_partition_t *update_partition = NULL;
update_partition = esp_ota_get_next_update_partition(NULL);
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) {
ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err));
task_fatal_error();
}
}
void common_hal_ota_finish(void) {
esp_err_t err;
err = esp_ota_end(update_handle);
if (err != ESP_OK) {

View File

@ -30,6 +30,12 @@
//|
//| The `ota` module implements over-the-air 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);
STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) {
mp_buffer_info_t bufinfo;
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);
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_finish), MP_ROM_PTR(&ota_finish_obj) },
{ MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) },
};
STATIC MP_DEFINE_CONST_DICT(ota_module_globals, ota_module_globals_table);

View File

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