Skip to content

Commit 216b471

Browse files
OSUpdate: fix get_next_update() partition returning higher, non-OS partitions (only toggle between ota_0 and ota_1)
1 parent 6120c16 commit 216b471

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Future release (next version)
33

44
Add changes that have been made to the code but haven't made it into a release here.
55

6+
Builtin Apps:
7+
- OSUpdate: fix get_next_update() partition returning higher, non-OS partitions (only toggle between ota_0 and ota_1)
8+
9+
Frameworks:
10+
- SettingActivity: support slider UI for integer settings
11+
612
Board Support:
713
- Fri3d 2026: access expander.analog as property instead of function
814

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,15 @@ def _setup_partition(self):
464464
"""Initialize the OTA partition for writing."""
465465
if not self.simulate and self._current_partition is None:
466466
current = self.partition_module(self.partition_module.RUNNING)
467-
self._current_partition = current.get_next_update()
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
472+
)
473+
if not partitions:
474+
raise Exception(f"UpdateDownloader: Could not find partition: {next_label}")
475+
self._current_partition = partitions[0]
468476
print(f"UpdateDownloader: Writing to partition: {self._current_partition}")
469477

470478
async def _process_chunk(self, chunk):
@@ -683,7 +691,15 @@ def set_boot_partition_and_restart(self):
683691

684692
try:
685693
current = self.partition_module(self.partition_module.RUNNING)
686-
next_partition = current.get_next_update()
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
699+
)
700+
if not partitions:
701+
raise Exception(f"Could not find partition: {next_label}")
702+
next_partition = partitions[0]
687703
next_partition.set_boot()
688704
print("UpdateDownloader: Boot partition set, restarting...")
689705

tests/test_osupdate.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ class MockPartition:
1717
"""Mock ESP32 Partition for testing UpdateDownloader."""
1818

1919
RUNNING = 0
20+
TYPE_APP = 0
21+
TYPE_DATA = 1
2022

21-
def __init__(self, partition_type=None):
23+
def __init__(self, partition_type=None, label="ota_0"):
2224
self.partition_type = partition_type
2325
self.blocks = {} # Store written blocks
2426
self.boot_set = False
27+
self._label = label
2528

26-
def get_next_update(self):
27-
"""Return a mock OTA partition."""
28-
return MockPartition()
29+
def info(self):
30+
"""Return mock partition info tuple: (type, subtype, addr, size, label, encrypted)."""
31+
subtype = 0x10 if self._label == "ota_0" else 0x11
32+
return (0, subtype, 0, 0x400000, self._label, False)
33+
34+
@classmethod
35+
def find(cls, type=-1, subtype=-1, label=None):
36+
"""Return a list with a mock partition matching the given label."""
37+
return [cls(label=label)]
2938

3039
def writeblocks(self, block_num, data):
3140
"""Mock writing blocks."""

0 commit comments

Comments
 (0)