pypicoboot 1.3.2__tar.gz → 1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pypicoboot-1.3.2 → pypicoboot-1.5}/PKG-INFO +1 -1
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/_version.py +1 -1
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/picoboot.py +30 -8
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/utils.py +15 -1
- {pypicoboot-1.3.2 → pypicoboot-1.5}/pypicoboot.egg-info/PKG-INFO +1 -1
- {pypicoboot-1.3.2 → pypicoboot-1.5}/LICENSE +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/README.md +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/__init__.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/core/__init__.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/core/enums.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/core/exceptions.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/core/log.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/picobootmonitor.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/picoboot/tools/picotool.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/pypicoboot.egg-info/SOURCES.txt +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/pypicoboot.egg-info/dependency_links.txt +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/pypicoboot.egg-info/requires.txt +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/pypicoboot.egg-info/top_level.txt +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/pyproject.toml +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/setup.cfg +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/setup.py +0 -0
- {pypicoboot-1.3.2 → pypicoboot-1.5}/tests/test_000_init.py +0 -0
|
@@ -23,7 +23,7 @@ import usb.core
|
|
|
23
23
|
import usb.util
|
|
24
24
|
import struct
|
|
25
25
|
import itertools
|
|
26
|
-
from .utils import uint_to_int
|
|
26
|
+
from .utils import uint_to_int, crc32_ieee
|
|
27
27
|
from .core.enums import NamedIntEnum
|
|
28
28
|
from .picobootmonitor import PicoBootMonitor, PicoBootMonitorObserver
|
|
29
29
|
from .core.log import get_logger
|
|
@@ -134,6 +134,7 @@ class Platform(NamedIntEnum):
|
|
|
134
134
|
|
|
135
135
|
class Addresses(NamedIntEnum):
|
|
136
136
|
BOOTROM_MAGIC = 0x00000010
|
|
137
|
+
PHYMARKER = 0x10100000
|
|
137
138
|
|
|
138
139
|
class PicoBoot:
|
|
139
140
|
|
|
@@ -174,7 +175,7 @@ class PicoBoot:
|
|
|
174
175
|
logger.debug("PicoBoot device initialized.")
|
|
175
176
|
|
|
176
177
|
@classmethod
|
|
177
|
-
def open(cls, vid: int = DEFAULT_VID, pid: list[int] = [DEFAULT_PID_RP2040, DEFAULT_PID_RP2350], serial: Optional[str] = None) -> "PicoBoot":
|
|
178
|
+
def open(cls, vid: int = DEFAULT_VID, pid: list[int] = [DEFAULT_PID_RP2040, DEFAULT_PID_RP2350], serial: Optional[str] = None, slot = -1) -> "PicoBoot":
|
|
178
179
|
logger.info(f"Opening PicoBoot device with VID={vid:04x} and PIDs={[f'{p:04x}' for p in pid]}...")
|
|
179
180
|
class find_vidpids(object):
|
|
180
181
|
|
|
@@ -193,6 +194,13 @@ class PicoBoot:
|
|
|
193
194
|
logger.error("No device found in PICOBOOT mode")
|
|
194
195
|
raise PicoBootNotFoundError("No device found in PICOBOOT mode")
|
|
195
196
|
|
|
197
|
+
if slot >= 0:
|
|
198
|
+
logger.info(f"Looking for device in slot {slot}...")
|
|
199
|
+
if (slot >= len(devices)):
|
|
200
|
+
logger.error("No device found in the specified slot")
|
|
201
|
+
raise PicoBootNotFoundError("No device found in the specified slot")
|
|
202
|
+
devices = [devices[slot]] if slot < len(devices) else []
|
|
203
|
+
|
|
196
204
|
dev = None
|
|
197
205
|
if serial is None:
|
|
198
206
|
logger.info("No serial number provided, using the first device found.")
|
|
@@ -270,16 +278,30 @@ class PicoBoot:
|
|
|
270
278
|
def has_device(self):
|
|
271
279
|
return self.dev is not None
|
|
272
280
|
|
|
273
|
-
@property
|
|
274
|
-
def serial_number(self) -> int:
|
|
275
|
-
s = usb.util.get_string(self.dev, self.dev.iSerialNumber)
|
|
276
|
-
return int(s, 16)
|
|
277
|
-
|
|
278
281
|
@property
|
|
279
282
|
def serial_number_str(self) -> str:
|
|
280
|
-
|
|
283
|
+
try:
|
|
284
|
+
s = None
|
|
285
|
+
if self.platform == Platform.RP2040:
|
|
286
|
+
r = self.flash_read(Addresses.PHYMARKER, 24)
|
|
287
|
+
magic = struct.unpack_from("<Q", r, 0)[0]
|
|
288
|
+
if (magic == 0x5049434F4B455953): # "PICOKEYS"
|
|
289
|
+
crc32 = crc32_ieee(r[0:20])
|
|
290
|
+
if crc32 == struct.unpack_from("<I", r, 20)[0]:
|
|
291
|
+
s = hexlify(r[12:20]).decode().upper()
|
|
292
|
+
if not s:
|
|
293
|
+
s = usb.util.get_string(self.dev, self.dev.iSerialNumber)
|
|
294
|
+
except Exception:
|
|
295
|
+
s = "unknown"
|
|
281
296
|
return s
|
|
282
297
|
|
|
298
|
+
@property
|
|
299
|
+
def serial_number(self) -> int:
|
|
300
|
+
if self.dev is None:
|
|
301
|
+
raise PicoBootInvalidStateError("Device not connected")
|
|
302
|
+
s = self.serial_number_str
|
|
303
|
+
return int(s, 16)
|
|
304
|
+
|
|
283
305
|
def interface_reset(self) -> None:
|
|
284
306
|
logger.debug("Resetting interface...")
|
|
285
307
|
self.dev.ctrl_transfer(
|
|
@@ -22,4 +22,18 @@ def uint_to_int(value: int, bits: int = 8) -> int:
|
|
|
22
22
|
mask = (1 << bits) - 1
|
|
23
23
|
value &= mask # ensure value fits in `bits`
|
|
24
24
|
sign_bit = 1 << (bits - 1)
|
|
25
|
-
return value - (1 << bits) if (value & sign_bit) else value
|
|
25
|
+
return value - (1 << bits) if (value & sign_bit) else value
|
|
26
|
+
|
|
27
|
+
def crc32_ieee(data: bytes) -> int:
|
|
28
|
+
crc = 0xFFFFFFFF
|
|
29
|
+
|
|
30
|
+
for b in data:
|
|
31
|
+
crc ^= b
|
|
32
|
+
for _ in range(8):
|
|
33
|
+
if crc & 1:
|
|
34
|
+
crc = (crc >> 1) ^ 0xEDB88320
|
|
35
|
+
else:
|
|
36
|
+
crc >>= 1
|
|
37
|
+
|
|
38
|
+
return crc ^ 0xFFFFFFFF
|
|
39
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|