write out firmware to correct location,
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 4 Apr 2022 17:14:46 +0000 (18:14 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 4 Apr 2022 17:14:46 +0000 (18:14 +0100)
adapt to 64/32 bit output

runsimsoc_hyperram.sh
scripts/bin2hex.py [new file with mode: 0755]

index 0fc1fe11fa4e4b6c91f2adfbe532b5a633bda088..f9ed79424a69d6f5fa6d0fde74cd23cf94579173 100755 (executable)
@@ -10,7 +10,7 @@ QSPI_DIR=./qspi_model/Cy15b104qs/model/
 FIRMWARE=./coldboot/coldboot.bin
 
 # convert firmware to 32-bit hex
-python3 scripts/bin2hex.py ${FIRMWARE} 32 > ${QSPI_DIR}/firmware.hex
+python3 scripts/bin2hex.py ${FIRMWARE} 32 > firmware.hex
 
 # create the build_simsoc/top.il file with firmware baked-in
 python3 src/ls2.py isim ./coldboot/coldboot.bin
diff --git a/scripts/bin2hex.py b/scripts/bin2hex.py
new file mode 100755 (executable)
index 0000000..09e3a14
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/python3
+
+import sys
+import subprocess
+import struct
+
+if len(sys.argv) == 3:
+    wordlen = int(sys.argv[2]) // 8
+else:
+    wordlen = 8
+
+with open(sys.argv[1], "rb") as f:
+    while True:
+        word = f.read(wordlen)
+        if len(word) == 8:
+            print("%016x" % struct.unpack('<Q', word));
+        elif len(word) == 4:
+            if wordlen == 8:
+                print("00000000%08x" % struct.unpack('<I', word));
+            else:
+                print("%08x" % struct.unpack('<I', word));
+        elif len(word) == 0:
+            exit(0);
+        else:
+            raise Exception("Bad length %d" % (len(word)))