[Cryptech-Commits] [sw/stm32] branch ice40mkm updated: Small fix to the upload script. Skip dummy text information preceeding actual bitstream data.

git at cryptech.is git at cryptech.is
Mon Dec 20 09:48:47 UTC 2021


This is an automated email from the git hooks/post-receive script.

meisterpaul1 at yandex.ru pushed a commit to branch ice40mkm
in repository sw/stm32.

The following commit(s) were added to refs/heads/ice40mkm by this push:
     new e3a5752  Small fix to the upload script. Skip dummy text information preceeding actual bitstream data.
e3a5752 is described below

commit e3a5752a303dff144dec71f909b5721cf2ffdb64
Author: Pavel V. Shatov (Meister) <meisterpaul1 at yandex.ru>
AuthorDate: Mon Dec 20 12:46:29 2021 +0300

    Small fix to the upload script. Skip dummy text information preceeding actual
    bitstream data.
---
 projects/hsm/cryptech_upload | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

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

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Commits mailing list