Skip to content

Commit

Permalink
2to3: fix firmware uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
laborleben committed Nov 21, 2019
1 parent bcdd066 commit 4d7672c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions SiLibUSB/siusbdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
dereferencing by assigning None and waiting for the GC to do its work
- fixing PyUSB returning iterator (instead of None) in Pythion 3 when no device is found and find_all=True
- fixing classmethod from_board_id() in Python 3
3.0.2:
- fixing loading firmware in Python 3
"""

import usb.core
Expand All @@ -92,7 +94,7 @@
from itertools import chain, islice
# import sys

__version__ = '3.0.1'
__version__ = '3.0.2'
__version_info__ = (tuple([int(num) for num in __version__.split('.')]), 'final', 0)

# set debugging options for pyUSB
Expand Down Expand Up @@ -375,28 +377,28 @@ def _read_bit_file(self, bit_file_name):
ret["File Creation Data"] = self._read_bit_file_section(f)[1]
ret["File Creation Time"] = self._read_bit_file_section(f)[1]

if f.read(1) != 'e':
if bytes(f.read(1)) != b'e':
raise ValueError('Wrong Bitstream Section')

c = array.array('B', f.read(4))
c = array.array('B', bytearray(f.read(4)))
c.byteswap()
# bitstream_len = struct.unpack("I", c)

# bitstream = f.read(bitstream_len[0])
bitstream_len = c[0] * (2 ** 24) + c[1] * (2 ** 16) + c[2] * (2 ** 8) + c[3]

bitstream = f.read(bitstream_len)
bitstream = bytearray(f.read(bitstream_len))

bs = array.array('B', bitstream)
bitstream_swap = ''

def reverse(byte):
return (b * 0x0202020202 & 0x010884422010) % 1023

for b in bs:
bitstream_swap += chr(reverse(b))
# reverse bytes
for i, b in enumerate(bs):
bitstream[i] = reverse(b)

ret["Bitstream"] = bitstream_swap
ret["Bitstream"] = bitstream
return ret

def InitXilinxConfPort(self):
Expand Down

0 comments on commit 4d7672c

Please sign in to comment.