Skip to content

Commit 4863413

Browse files
committed
rename ota to dualbank
1 parent 37ee5e6 commit 4863413

File tree

10 files changed

+102
-126
lines changed

10 files changed

+102
-126
lines changed

locale/circuitpython.pot

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-12-10 16:56+0530\n"
11+
"POT-Creation-Date: 2020-12-17 19:42+0530\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -936,6 +936,10 @@ msgstr ""
936936
msgid "Filters too complex"
937937
msgstr ""
938938

939+
#: ports/esp32s2/common-hal/dualbank/__init__.c
940+
msgid "Firmware image is invalid"
941+
msgstr ""
942+
939943
#: ports/cxd56/common-hal/camera/Camera.c
940944
msgid "Format not supported"
941945
msgstr ""
@@ -1420,10 +1424,6 @@ msgstr ""
14201424
msgid "Not settable"
14211425
msgstr ""
14221426

1423-
#: ports/esp32s2/common-hal/ota/__init__.c
1424-
msgid "OTA Update Failed"
1425-
msgstr ""
1426-
14271427
#: shared-bindings/util.c
14281428
msgid ""
14291429
"Object has been deinitialized and can no longer be used. Create a new object."
@@ -1911,10 +1911,6 @@ msgstr ""
19111911
msgid "Unable to read color palette data"
19121912
msgstr ""
19131913

1914-
#: ports/esp32s2/common-hal/ota/__init__.c
1915-
msgid "Unable to switch boot partition"
1916-
msgstr ""
1917-
19181914
#: shared-bindings/nvm/ByteArray.c
19191915
msgid "Unable to write to nvm."
19201916
msgstr ""
@@ -1983,6 +1979,10 @@ msgstr ""
19831979
msgid "Unsupported pull value."
19841980
msgstr ""
19851981

1982+
#: ports/esp32s2/common-hal/dualbank/__init__.c
1983+
msgid "Update Failed"
1984+
msgstr ""
1985+
19861986
#: ports/nrf/common-hal/_bleio/Characteristic.c
19871987
#: ports/nrf/common-hal/_bleio/Descriptor.c
19881988
msgid "Value length != required fixed length"
@@ -3210,7 +3210,7 @@ msgstr ""
32103210
msgid "offset is too large"
32113211
msgstr ""
32123212

3213-
#: shared-bindings/ota/__init__.c
3213+
#: shared-bindings/dualbank/__init__.c
32143214
msgid "offset must be >= 0"
32153215
msgstr ""
32163216

ports/esp32s2/common-hal/ota/__init__.c renamed to ports/esp32s2/common-hal/dualbank/__init__.c

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "common-hal/ota/__init__.h"
28-
#include "shared-bindings/ota/__init__.h"
27+
#include "common-hal/dualbank/__init__.h"
28+
#include "shared-bindings/dualbank/__init__.h"
2929

3030
#include <string.h>
3131

@@ -35,21 +35,24 @@
3535
static const esp_partition_t *update_partition = NULL;
3636
static esp_ota_handle_t update_handle = 0;
3737

38-
static bool ota_inited = false;
39-
static const char *TAG = "OTA";
38+
static const char *TAG = "dualbank";
4039

41-
void ota_reset(void) {
42-
update_handle = 0;
43-
update_partition = NULL;
44-
ota_inited = false;
40+
void dualbank_reset(void) {
41+
// should use `abort` instead of `end`
42+
// but not in idf v4.2
43+
// esp_ota_abort(update_handle);
44+
if (esp_ota_end(update_handle) == ESP_OK) {
45+
update_handle = 0;
46+
update_partition = NULL;
47+
}
4548
}
4649

4750
static void __attribute__((noreturn)) task_fatal_error(void) {
4851
ESP_LOGE(TAG, "Exiting task due to fatal error...");
49-
mp_raise_RuntimeError(translate("OTA Update Failed"));
52+
mp_raise_RuntimeError(translate("Update Failed"));
5053
}
5154

52-
void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset) {
55+
void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t offset) {
5356
esp_err_t err;
5457

5558
const esp_partition_t *running = esp_ota_get_running_partition();
@@ -67,7 +70,7 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse
6770
assert(update_partition != NULL);
6871
}
6972

70-
if (!ota_inited) {
73+
if (update_handle == 0) {
7174
if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) {
7275
esp_app_desc_t new_app_info;
7376
memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t));
@@ -102,14 +105,13 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse
102105
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
103106
task_fatal_error();
104107
}
105-
ota_inited = true;
106108
} else {
107109
ESP_LOGE(TAG, "received package is not fit len");
108110
task_fatal_error();
109111
}
110112
}
111113

112-
if (offset == -1) {
114+
if (offset == 0) {
113115
err = esp_ota_write(update_handle, buf, len);
114116
} else {
115117
err = esp_ota_write_with_offset(update_handle, buf, len, offset);
@@ -120,31 +122,18 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse
120122
}
121123
}
122124

123-
void common_hal_ota_finish(void) {
124-
if (ota_inited) {
125-
esp_err_t err;
126-
127-
err = esp_ota_end(update_handle);
128-
if (err != ESP_OK) {
129-
if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
130-
ESP_LOGE(TAG, "Image validation failed, image is corrupted");
131-
}
132-
ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err));
133-
task_fatal_error();
134-
}
135-
136-
err = esp_ota_set_boot_partition(update_partition);
137-
if (err != ESP_OK) {
138-
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
139-
task_fatal_error();
140-
}
141-
142-
ota_reset();
125+
void common_hal_dualbank_switch(void) {
126+
if (esp_ota_end(update_handle) == ESP_OK) {
127+
update_handle = 0;
128+
update_partition = NULL;
143129
}
144-
}
145-
146-
void common_hal_ota_switch(void) {
147-
if (esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)) != ESP_OK) {
148-
mp_raise_RuntimeError(translate("Unable to switch boot partition"));
130+
esp_err_t err = esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL));
131+
if (err != ESP_OK) {
132+
if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
133+
ESP_LOGE(TAG, "Image validation failed, image is corrupted");
134+
mp_raise_RuntimeError(translate("Firmware image is invalid"));
135+
}
136+
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
137+
task_fatal_error();
149138
}
150139
}

ports/esp32s2/common-hal/ota/__init__.h renamed to ports/esp32s2/common-hal/dualbank/__init__.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H
28-
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H
27+
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H
28+
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H
2929

30-
extern void ota_reset(void);
30+
extern void dualbank_reset(void);
3131

32-
#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H
32+
#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H

ports/esp32s2/mpconfigport.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ CIRCUITPY_AUDIOBUSIO = 0
1919
CIRCUITPY_AUDIOIO = 0
2020
CIRCUITPY_CANIO = 1
2121
CIRCUITPY_COUNTIO = 1
22+
CIRCUITPY_DUALBANK = 1
2223
CIRCUITPY_FREQUENCYIO = 1
2324
CIRCUITPY_I2CPERIPHERAL = 0
2425
CIRCUITPY_ROTARYIO = 1
2526
CIRCUITPY_NVM = 1
26-
CIRCUITPY_OTA = 1
2727
# We don't have enough endpoints to include MIDI.
2828
CIRCUITPY_USB_MIDI = 0
2929
CIRCUITPY_WIFI = 1

ports/esp32s2/supervisor/port.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "common-hal/busio/I2C.h"
4242
#include "common-hal/busio/SPI.h"
4343
#include "common-hal/busio/UART.h"
44-
#include "common-hal/ota/__init__.h"
44+
#include "common-hal/dualbank/__init__.h"
4545
#include "common-hal/ps2io/Ps2.h"
4646
#include "common-hal/pulseio/PulseIn.h"
4747
#include "common-hal/pwmio/PWMOut.h"
@@ -124,8 +124,8 @@ void reset_port(void) {
124124
analogout_reset();
125125
#endif
126126

127-
#if CIRCUITPY_OTA
128-
ota_reset();
127+
#if CIRCUITPY_DUALBANK
128+
dualbank_reset();
129129
#endif
130130

131131
#if CIRCUITPY_PS2IO

py/circuitpy_defns.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ endif
205205
ifeq ($(CIRCUITPY_OS),1)
206206
SRC_PATTERNS += os/%
207207
endif
208-
ifeq ($(CIRCUITPY_OTA),1)
209-
SRC_PATTERNS += ota/%
208+
ifeq ($(CIRCUITPY_DUALBANK),1)
209+
SRC_PATTERNS += dualbank/%
210210
endif
211211
ifeq ($(CIRCUITPY_PIXELBUF),1)
212212
SRC_PATTERNS += _pixelbuf/%
@@ -350,7 +350,7 @@ SRC_COMMON_HAL_ALL = \
350350
nvm/ByteArray.c \
351351
nvm/__init__.c \
352352
os/__init__.c \
353-
ota/__init__.c \
353+
dualbank/__init__.c \
354354
ps2io/Ps2.c \
355355
ps2io/__init__.c \
356356
pulseio/PulseIn.c \

py/circuitpy_mpconfig.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,11 @@ extern const struct _mp_obj_module_t os_module;
539539
#define OS_MODULE_ALT_NAME
540540
#endif
541541

542-
#if CIRCUITPY_OTA
543-
extern const struct _mp_obj_module_t ota_module;
544-
#define OTA_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ota), (mp_obj_t)&ota_module },
542+
#if CIRCUITPY_DUALBANK
543+
extern const struct _mp_obj_module_t dualbank_module;
544+
#define DUALBANK_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_dualbank), (mp_obj_t)&dualbank_module },
545545
#else
546-
#define OTA_MODULE
546+
#define DUALBANK_MODULE
547547
#endif
548548

549549
#if CIRCUITPY_PEW
@@ -834,7 +834,7 @@ extern const struct _mp_obj_module_t wifi_module;
834834
NETWORK_MODULE \
835835
SOCKET_MODULE \
836836
WIZNET_MODULE \
837-
OTA_MODULE \
837+
DUALBANK_MODULE \
838838
PEW_MODULE \
839839
PIXELBUF_MODULE \
840840
PS2IO_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ CFLAGS += -DCIRCUITPY_NVM=$(CIRCUITPY_NVM)
179179
CIRCUITPY_OS ?= 1
180180
CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS)
181181

182-
CIRCUITPY_OTA ?= 0
183-
CFLAGS += -DCIRCUITPY_OTA=$(CIRCUITPY_OTA)
182+
CIRCUITPY_DUALBANK ?= 0
183+
CFLAGS += -DCIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK)
184184

185185
CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD)
186186
CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF)

0 commit comments

Comments
 (0)