pypicoboot 1.4__py3-none-any.whl → 1.5__py3-none-any.whl

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.
picoboot/_version.py CHANGED
@@ -17,4 +17,4 @@
17
17
  */
18
18
  """
19
19
 
20
- __version__ = "1.4"
20
+ __version__ = "1.5"
picoboot/picoboot.py CHANGED
@@ -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
 
@@ -277,19 +278,30 @@ class PicoBoot:
277
278
  def has_device(self):
278
279
  return self.dev is not None
279
280
 
280
- @property
281
- def serial_number(self) -> int:
282
- s = usb.util.get_string(self.dev, self.dev.iSerialNumber)
283
- return int(s, 16)
284
-
285
281
  @property
286
282
  def serial_number_str(self) -> str:
287
283
  try:
288
- s = usb.util.get_string(self.dev, self.dev.iSerialNumber)
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)
289
294
  except Exception:
290
295
  s = "unknown"
291
296
  return s
292
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
+
293
305
  def interface_reset(self) -> None:
294
306
  logger.debug("Resetting interface...")
295
307
  self.dev.ctrl_transfer(
picoboot/utils.py CHANGED
@@ -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
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypicoboot
3
- Version: 1.4
3
+ Version: 1.5
4
4
  Summary: Pico Boot for Python
5
5
  Home-page: https://github.com/polhenarejos/pypicoboot
6
6
  Author: Pol Henarejos
@@ -1,14 +1,14 @@
1
1
  picoboot/__init__.py,sha256=c49mZU1EUgBbiMUKo7sLsZE4u1RKmBXjXHmCSgeM5vw,168
2
- picoboot/_version.py,sha256=tWPsQhFrjT59dLP64luJ8y6WZADnjkMctyD_4fue4Uk,776
3
- picoboot/picoboot.py,sha256=_4p7rWr8ck-laYc1Jh-HHsqtoNFRVqzHDP46HRcnN4c,26358
2
+ picoboot/_version.py,sha256=S-eokld2tlibADYtsq4K91uxjtIu6SYu30ozInVJoBU,776
3
+ picoboot/picoboot.py,sha256=Q1Ur-4-Dv-cepL-Qd4S6PUtrp1srD0kWJeQLHLjp_k8,26925
4
4
  picoboot/picobootmonitor.py,sha256=3msEP2S8ZS7P8QVgKpq9Z9Rcud78XygmG1_0L_OZOvs,2443
5
- picoboot/utils.py,sha256=SjpAoPZrgyD9Ws7NIFVBHt0zPOb8Lpu2_lsmfeT2rXE,1083
5
+ picoboot/utils.py,sha256=7dtF_QEXGLuJispFlrotOuTeyU5FiK26759108k_H8w,1350
6
6
  picoboot/core/__init__.py,sha256=c1kJprnljn0eP1NR3wEw-wJSCSxSRF3DA2jF5MowHXk,57
7
7
  picoboot/core/enums.py,sha256=ugXS-dbdnusLib_ge0vT1OugHVG9ZjJfpUR073MhwdQ,1353
8
8
  picoboot/core/exceptions.py,sha256=AXilq0ViaXyA6Ls9aGx6DHE9TQyPacQbwnHBXgFD3EQ,909
9
9
  picoboot/core/log.py,sha256=XWtN_hgmOtvpDMGDg-9f2BDLUe8elqUAbWti5yCJAA0,1768
10
10
  picoboot/tools/picotool.py,sha256=e2xjIxP5UZn9yfjxUWkJXq6KQHyw4YsGbuQbTauo0-Q,94
11
- pypicoboot-1.4.dist-info/METADATA,sha256=R9YQ9fgWbr5z2ITgJtM-BsRqgRQ8uSuyiyBLVcOY5Gs,41109
12
- pypicoboot-1.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
- pypicoboot-1.4.dist-info/top_level.txt,sha256=sjegZQO5-kQdFOXXJHm0P7Hg1Nw4Ri0WKHnRYDTsa4I,9
14
- pypicoboot-1.4.dist-info/RECORD,,
11
+ pypicoboot-1.5.dist-info/METADATA,sha256=-0G8dMhaIcb-IT3GY5N8_y2uDh4PYWqq0wE-AwvZLnU,41109
12
+ pypicoboot-1.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
+ pypicoboot-1.5.dist-info/top_level.txt,sha256=sjegZQO5-kQdFOXXJHm0P7Hg1Nw4Ri0WKHnRYDTsa4I,9
14
+ pypicoboot-1.5.dist-info/RECORD,,