diff --git a/uf2tool/models/context.py b/uf2tool/models/context.py index e8851e7..b938ce1 100644 --- a/uf2tool/models/context.py +++ b/uf2tool/models/context.py @@ -91,6 +91,9 @@ def get_offset(self, part: str, offs: int) -> Optional[int]: return None return start + offs + def rewind(self) -> None: + self.seq = 0 + def read_next(self, scheme: OTAScheme) -> Optional[Tuple[str, int, bytes]]: """ Read next available data block for the specified OTA scheme. @@ -152,6 +155,10 @@ def collect_data(self, scheme: OTAScheme) -> Optional[Dict[int, BytesIO]]: if not self.board_name: raise ValueError("This UF2 is not readable, since no board name is present") + # rewind to the beginning of the UF2 so collect_data can be called + # multiple times + self.rewind() + out: Dict[int, BytesIO] = {} while True: ret = self.read_next(scheme)