From dfecda3a5fcb42fe6bc8e83621bf976032ff50c9 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Thu, 27 Oct 2022 14:16:49 +0800 Subject: [PATCH] bin2hex: handle any file length, not just 8 or 4 Treat the input as if it was padded with zeroes to a multiple of 8. This is needed if the .data in a binary changes size, it won't be a nice multiple of 4 or 8. At present the microwatt binaries all are multiples of 8, but making code alterations could make bin2hex fail unexpectedly. Signed-off-by: Matt Johnston --- litedram/gen-src/sdram_init/bin2hex.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/litedram/gen-src/sdram_init/bin2hex.py b/litedram/gen-src/sdram_init/bin2hex.py index af278bc..b53b2c9 100755 --- a/litedram/gen-src/sdram_init/bin2hex.py +++ b/litedram/gen-src/sdram_init/bin2hex.py @@ -7,11 +7,8 @@ import struct with open(sys.argv[1], "rb") as f: while True: word = f.read(8) - if len(word) == 8: - print("%016x" % struct.unpack('Q', word)); - elif len(word) == 4: - print("00000000%08x" % struct.unpack('I', word)); - elif len(word) == 0: + if len(word) == 0: exit(0); - else: - raise Exception("Bad length") + if len(word) != 8: + word = word + bytes(8 - len(word)) + print("%016x" % struct.unpack('Q', word));