Skip to content

Commit 8408f46

Browse files
Add mpos.partitions.get_next_update_partition() helper that alternates between ota_0 and ota_1 only
And use it from About and OSUpdate app.
1 parent 216b471 commit 8408f46

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Future release (next version)
44
Add changes that have been made to the code but haven't made it into a release here.
55

66
Builtin Apps:
7-
- OSUpdate: fix get_next_update() partition returning higher, non-OS partitions (only toggle between ota_0 and ota_1)
7+
- OSUpdate: restrict OTA update target to ota_0/ota_1 instead of all ota_N partitions (via shared partition helper)
8+
- About: show correct next update partition instead of always using get_next_update()
9+
10+
Framework:
11+
- Add mpos.partitions.get_next_update_partition() helper that alternates between ota_0 and ota_1 only
812

913
Frameworks:
1014
- SettingActivity: support slider UI for integer settings

internal_filesystem/builtin/apps/com.micropythonos.about/assets/about.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ def onCreate(self):
9595
# Partition info (ESP32 only)
9696
try:
9797
self._add_label(screen, f"{lv.SYMBOL.SD_CARD} Partition Info", is_header=True)
98+
from mpos.partitions import get_next_update_partition
9899
from esp32 import Partition
99100
current = Partition(Partition.RUNNING)
100101
self._add_label(screen, f"Partition.RUNNING: {current}")
101-
next_partition = current.get_next_update()
102+
next_partition = get_next_update_partition()
102103
self._add_label(screen, f"Next update partition: {next_partition}")
103104
except Exception as e:
104105
error = f"Could not find partition info because: {e}\nIt's normal to get this error on desktop."

internal_filesystem/builtin/apps/com.micropythonos.osupdate/assets/osupdate.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,10 @@ def __init__(self, partition_module=None, connectivity_manager=None, download_ma
463463
def _setup_partition(self):
464464
"""Initialize the OTA partition for writing."""
465465
if not self.simulate and self._current_partition is None:
466-
current = self.partition_module(self.partition_module.RUNNING)
467-
current_label = current.info()[4]
468-
next_label = "ota_0" if current_label == "ota_1" else "ota_1"
469-
partitions = self.partition_module.find(
470-
self.partition_module.TYPE_APP,
471-
label=next_label
466+
from mpos.partitions import get_next_update_partition
467+
self._current_partition = get_next_update_partition(
468+
partition_module=self.partition_module
472469
)
473-
if not partitions:
474-
raise Exception(f"UpdateDownloader: Could not find partition: {next_label}")
475-
self._current_partition = partitions[0]
476470
print(f"UpdateDownloader: Writing to partition: {self._current_partition}")
477471

478472
async def _process_chunk(self, chunk):
@@ -690,16 +684,10 @@ def set_boot_partition_and_restart(self):
690684
return
691685

692686
try:
693-
current = self.partition_module(self.partition_module.RUNNING)
694-
current_label = current.info()[4]
695-
next_label = "ota_0" if current_label == "ota_1" else "ota_1"
696-
partitions = self.partition_module.find(
697-
self.partition_module.TYPE_APP,
698-
label=next_label
687+
from mpos.partitions import get_next_update_partition
688+
next_partition = get_next_update_partition(
689+
partition_module=self.partition_module
699690
)
700-
if not partitions:
701-
raise Exception(f"Could not find partition: {next_label}")
702-
next_partition = partitions[0]
703691
next_partition.set_boot()
704692
print("UpdateDownloader: Boot partition set, restarting...")
705693

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def get_next_update_partition(partition_module=None):
2+
if partition_module is None:
3+
from esp32 import Partition
4+
partition_module = Partition
5+
6+
current = partition_module(partition_module.RUNNING)
7+
current_label = current.info()[4]
8+
next_label = "ota_0" if current_label == "ota_1" else "ota_1"
9+
partitions = partition_module.find(
10+
partition_module.TYPE_APP,
11+
label=next_label
12+
)
13+
if not partitions:
14+
raise Exception(f"Could not find partition: {next_label}")
15+
return partitions[0]

0 commit comments

Comments
 (0)