Skip to content

Commit bfa2c60

Browse files
committed
add ability to flash in discontinuous chunks
1 parent ed5add3 commit bfa2c60

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void __attribute__((noreturn)) task_fatal_error(void) {
4848
mp_raise_RuntimeError(translate("OTA Update Failed"));
4949
}
5050

51-
void common_hal_ota_flash(const void *buf, const size_t len) {
51+
void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset) {
5252
esp_err_t err;
5353

5454
const esp_partition_t *running = esp_ota_get_running_partition();
@@ -108,7 +108,11 @@ void common_hal_ota_flash(const void *buf, const size_t len) {
108108
}
109109
}
110110

111-
err = esp_ota_write( update_handle, buf, len);
111+
if (offset == -1) {
112+
err = esp_ota_write(update_handle, buf, len);
113+
} else {
114+
err = esp_ota_write_with_offset(update_handle, buf, len, offset);
115+
}
112116
if (err != ESP_OK) {
113117
ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err));
114118
task_fatal_error();

shared-bindings/ota/__init__.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,27 @@ STATIC mp_obj_t ota_finish(void) {
3636
}
3737
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish);
3838

39-
STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) {
39+
STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
40+
enum { ARG_binary, ARG_offset };
41+
static const mp_arg_t allowed_args[] = {
42+
{ MP_QSTR_binary, MP_ARG_OBJ | MP_ARG_REQUIRED },
43+
{ MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
44+
};
45+
46+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
47+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
48+
49+
if (args[ARG_offset].u_int < -1) {
50+
mp_raise_ValueError(translate("offset must be >= 0"));
51+
}
52+
4053
mp_buffer_info_t bufinfo;
41-
mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ);
54+
mp_get_buffer_raise(args[ARG_binary].u_obj, &bufinfo, MP_BUFFER_READ);
4255

43-
common_hal_ota_flash(bufinfo.buf, bufinfo.len);
56+
common_hal_ota_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int);
4457
return mp_const_none;
4558
}
46-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ota_flash_obj, ota_flash);
59+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 1, ota_flash);
4760

4861
STATIC const mp_rom_map_elem_t ota_module_globals_table[] = {
4962
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) },

shared-bindings/ota/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
#include "py/runtime.h"
3131

3232
extern void common_hal_ota_finish(void);
33-
extern void common_hal_ota_flash(const void *buf, const size_t len);
33+
extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset);
3434

3535
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H

0 commit comments

Comments
 (0)