xilinx/xilswap.py

26 lines
587 B
Python
Raw Normal View History

2020-09-17 17:31:24 +00:00
#!/usr/bin/env python3
import sys
import struct
WORD_BE = struct.Struct(">I")
WORD_LE = struct.Struct("<I")
if __name__ == "__main__":
if len(sys.argv) < 3:
print("usage: xilswap.py <in> <out>")
with open(sys.argv[1], "rb") as f:
data = f.read()
assert(len(data) % 4 == 0)
print("total", len(data)//4)
with open(sys.argv[2], "wb") as f:
for i in range(len(data)//4):
word = WORD_BE.unpack(data[i*4:i*4+4])[0]
f.write(WORD_LE.pack(word))
if i % 10000 == 0:
print(i, "/", len(data)//4)