summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authormicroDev <70126934+microDev1@users.noreply.github.com>2020-12-10 15:45:25 +0530
committermicroDev <70126934+microDev1@users.noreply.github.com>2020-12-10 15:45:25 +0530
commitbfa2c604efa213628bb33ad870b851a43f21c877 (patch)
tree9539f191fc32224c31bd379c4fbf066528ee6626 /shared-bindings
parented5add37f6c6f6ed8e1acb6c14bd47df0fdfb0fb (diff)
add ability to flash in discontinuous chunks
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/ota/__init__.c21
-rw-r--r--shared-bindings/ota/__init__.h2
2 files changed, 18 insertions, 5 deletions
diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c
index 55858a80e..84a46c83a 100644
--- a/shared-bindings/ota/__init__.c
+++ b/shared-bindings/ota/__init__.c
@@ -36,14 +36,27 @@ STATIC mp_obj_t ota_finish(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish);
-STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) {
+STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ enum { ARG_binary, ARG_offset };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_binary, MP_ARG_OBJ | MP_ARG_REQUIRED },
+ { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
+ };
+
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ if (args[ARG_offset].u_int < -1) {
+ mp_raise_ValueError(translate("offset must be >= 0"));
+ }
+
mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ);
+ mp_get_buffer_raise(args[ARG_binary].u_obj, &bufinfo, MP_BUFFER_READ);
- common_hal_ota_flash(bufinfo.buf, bufinfo.len);
+ common_hal_ota_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int);
return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(ota_flash_obj, ota_flash);
+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) },
diff --git a/shared-bindings/ota/__init__.h b/shared-bindings/ota/__init__.h
index 1765c21ad..9eec604e0 100644
--- a/shared-bindings/ota/__init__.h
+++ b/shared-bindings/ota/__init__.h
@@ -30,6 +30,6 @@
#include "py/runtime.h"
extern void common_hal_ota_finish(void);
-extern void common_hal_ota_flash(const void *buf, const size_t len);
+extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H