diff options
author | Pavel V. Shatov (Meister) <meisterpaul1@yandex.ru> | 2021-12-20 12:46:29 +0300 |
---|---|---|
committer | Pavel V. Shatov (Meister) <meisterpaul1@yandex.ru> | 2021-12-20 12:46:29 +0300 |
commit | e3a5752a303dff144dec71f909b5721cf2ffdb64 (patch) | |
tree | 5abfa48393aa753901085370e302e8920c0de0f5 /projects | |
parent | 1d6609566a71dee86fc1ae33175052ebbfdba24a (diff) |
Small fix to the upload script. Skip dummy text information preceeding actual
bitstream data.
Diffstat (limited to 'projects')
-rwxr-xr-x | projects/hsm/cryptech_upload | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/projects/hsm/cryptech_upload b/projects/hsm/cryptech_upload index b40427d..53d71e3 100755 --- a/projects/hsm/cryptech_upload +++ b/projects/hsm/cryptech_upload @@ -236,6 +236,24 @@ class ManagementPortSocket(ManagementPortAbstract): self.socket.close() +def find_bitstream_header(src, chunk_size): + + # this assumes, that the magic header is within the very first chunk of + # the bitstream file, which should always be the case + + xilinx_magic = b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" \ + b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" \ + b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" \ + b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" \ + b"\x00\x00\x00\xBB\x11\x22\x00\x44" \ + b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" \ + b"\xAA\x99\x55\x66" + + header = src.read(chunk_size) + + return header.find(xilinx_magic) + + def send_file(src, size, args, dst): """ Upload an image from some file-like source to the management port. @@ -260,6 +278,21 @@ def send_file(src, size, args, dst): print("Device did not accept the upload command (got {!r})".format(response)) return False + # remove garbage from beginning of bitstream + if args.fpga: + + # find magic pattern + dummy_bytes = find_bitstream_header(src, chunk_size) + if dummy_bytes < 0: + print("Can't find Xilinx magic marker in bistream") + return False + + print("Bitstream magic header found at offset {}".format(dummy_bytes)) + + # skip leading garbage + size -= dummy_bytes + src.seek(dummy_bytes) + dst.set_timeout(0.001) crc = 0 counter = 0 |