aboutsummaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorThorsten von Eicken2020-04-01 22:59:08 -0700
committerDamien George2020-05-03 15:00:45 +1000
commit952ff8a8ea9ae6128ff5225b180d8daaacf447e4 (patch)
treec69c41d01035ec4ee279a43f460c821cf1af04f3 /ports
parent7d97d241e861ba4cbd44d3695d4db6184974f8f9 (diff)
esp32: Improve support for OTA updates.
This commit adds several small items to improve the support for OTA updates on an esp32: - a partition table for 4MB flash modules that has two OTA partitions ready to go to do updates - a GENERIC_OTA board that uses that partition table and that enables automatic roll-back in the bootloader - a new esp32.Partition.mark_app_valid_cancel_rollback() class-method to signal that the boot is successful and should not be rolled back at the next reset - an automated test for doing an OTA update - documentation updates
Diffstat (limited to 'ports')
-rw-r--r--ports/esp32/boards/GENERIC_OTA/mpconfigboard.h2
-rw-r--r--ports/esp32/boards/GENERIC_OTA/mpconfigboard.mk4
-rw-r--r--ports/esp32/boards/GENERIC_OTA/sdkconfig.board4
-rw-r--r--ports/esp32/esp32_partition.c10
-rw-r--r--ports/esp32/partitions-ota.csv9
5 files changed, 29 insertions, 0 deletions
diff --git a/ports/esp32/boards/GENERIC_OTA/mpconfigboard.h b/ports/esp32/boards/GENERIC_OTA/mpconfigboard.h
new file mode 100644
index 000000000..ff39c4b2b
--- /dev/null
+++ b/ports/esp32/boards/GENERIC_OTA/mpconfigboard.h
@@ -0,0 +1,2 @@
+#define MICROPY_HW_BOARD_NAME "4MB/OTA module"
+#define MICROPY_HW_MCU_NAME "ESP32"
diff --git a/ports/esp32/boards/GENERIC_OTA/mpconfigboard.mk b/ports/esp32/boards/GENERIC_OTA/mpconfigboard.mk
new file mode 100644
index 000000000..db6492cac
--- /dev/null
+++ b/ports/esp32/boards/GENERIC_OTA/mpconfigboard.mk
@@ -0,0 +1,4 @@
+SDKCONFIG += boards/sdkconfig.base
+SDKCONFIG += boards/GENERIC_OTA/sdkconfig.board
+
+PART_SRC = partitions-ota.csv
diff --git a/ports/esp32/boards/GENERIC_OTA/sdkconfig.board b/ports/esp32/boards/GENERIC_OTA/sdkconfig.board
new file mode 100644
index 000000000..b0ed171d8
--- /dev/null
+++ b/ports/esp32/boards/GENERIC_OTA/sdkconfig.board
@@ -0,0 +1,4 @@
+CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
+
+# ESP-IDF v3:
+CONFIG_APP_ROLLBACK_ENABLE=y
diff --git a/ports/esp32/esp32_partition.c b/ports/esp32/esp32_partition.c
index cbb62206f..dc2bdd712 100644
--- a/ports/esp32/esp32_partition.c
+++ b/ports/esp32/esp32_partition.c
@@ -209,6 +209,15 @@ STATIC mp_obj_t esp32_partition_get_next_update(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_get_next_update_obj, esp32_partition_get_next_update);
+STATIC mp_obj_t esp32_partition_mark_app_valid_cancel_rollback(mp_obj_t cls_in) {
+ check_esp_err(esp_ota_mark_app_valid_cancel_rollback());
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_mark_app_valid_cancel_rollback_fun_obj,
+ esp32_partition_mark_app_valid_cancel_rollback);
+STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(esp32_partition_mark_app_valid_cancel_rollback_obj,
+ MP_ROM_PTR(&esp32_partition_mark_app_valid_cancel_rollback_fun_obj));
+
STATIC const mp_rom_map_elem_t esp32_partition_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_find), MP_ROM_PTR(&esp32_partition_find_obj) },
@@ -218,6 +227,7 @@ STATIC const mp_rom_map_elem_t esp32_partition_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&esp32_partition_ioctl_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_boot), MP_ROM_PTR(&esp32_partition_set_boot_obj) },
+ { MP_ROM_QSTR(MP_QSTR_mark_app_valid_cancel_rollback), MP_ROM_PTR(&esp32_partition_mark_app_valid_cancel_rollback_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_next_update), MP_ROM_PTR(&esp32_partition_get_next_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_INT(ESP32_PARTITION_BOOT) },
diff --git a/ports/esp32/partitions-ota.csv b/ports/esp32/partitions-ota.csv
new file mode 100644
index 000000000..007293015
--- /dev/null
+++ b/ports/esp32/partitions-ota.csv
@@ -0,0 +1,9 @@
+# Partition table for MicroPython with OTA support using 4MB flash
+# Name, Type, SubType, Offset, Size, Flags
+# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
+nvs, data, nvs, 0x9000, 0x4000,
+otadata, data, ota, 0xd000, 0x2000,
+phy_init, data, phy, 0xf000, 0x1000,
+ota_0, app, ota_0, 0x10000, 0x180000,
+ota_1, app, ota_1, 0x190000, 0x180000,
+vfs, data, fat, 0x310000, 0x0f0000,