diff options
Diffstat (limited to 'projects/hsm')
-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 |