|
30 | 30 | //|
|
31 | 31 | //| The `ota` module implements over-the-air update."""
|
32 | 32 |
|
| 33 | +//| def switch() -> None: |
| 34 | +//| """Switches the boot partition. |
| 35 | +//| ... |
| 36 | +//| |
33 | 37 | STATIC mp_obj_t ota_switch(void) {
|
34 | 38 | common_hal_ota_switch();
|
35 | 39 | return mp_const_none;
|
36 | 40 | }
|
37 | 41 | STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch);
|
38 | 42 |
|
| 43 | +//| def finish() -> None: |
| 44 | +//| """Validates flashed firmware, sets next boot partition. |
| 45 | +//| **Must be called after** `ota.flash()` |
| 46 | +//| ... |
| 47 | +//| |
39 | 48 | STATIC mp_obj_t ota_finish(void) {
|
40 | 49 | common_hal_ota_finish();
|
41 | 50 | return mp_const_none;
|
42 | 51 | }
|
43 | 52 | STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish);
|
44 | 53 |
|
| 54 | +//| def flash(*buffer: WriteableBuffer, offset: int=0) -> None: |
| 55 | +//| """Writes one of two OTA partition at the given offset. |
| 56 | +//| ... |
| 57 | +//| |
45 | 58 | STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
46 |
| - enum { ARG_binary, ARG_offset }; |
| 59 | + enum { ARG_buffer, ARG_offset }; |
47 | 60 | static const mp_arg_t allowed_args[] = {
|
48 |
| - { MP_QSTR_binary, MP_ARG_OBJ | MP_ARG_REQUIRED }, |
| 61 | + { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, |
49 | 62 | { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
|
50 | 63 | };
|
51 | 64 |
|
52 | 65 | mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
53 |
| - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
| 66 | + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
54 | 67 |
|
55 | 68 | if (args[ARG_offset].u_int < -1) {
|
56 | 69 | mp_raise_ValueError(translate("offset must be >= 0"));
|
57 | 70 | }
|
58 | 71 |
|
59 | 72 | mp_buffer_info_t bufinfo;
|
60 |
| - mp_get_buffer_raise(args[ARG_binary].u_obj, &bufinfo, MP_BUFFER_READ); |
| 73 | + mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); |
61 | 74 |
|
62 | 75 | common_hal_ota_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int);
|
63 | 76 | return mp_const_none;
|
64 | 77 | }
|
65 |
| -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 1, ota_flash); |
| 78 | +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 0, ota_flash); |
66 | 79 |
|
67 | 80 | STATIC const mp_rom_map_elem_t ota_module_globals_table[] = {
|
68 | 81 | { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) },
|
|
0 commit comments