import binascii
-def CRC32(buf):
- return binascii.crc32(buf).to_bytes(4, byteorder='big')
-
-def LENGTH(buf):
- return len(buf).to_bytes(4, byteorder='big')
-
-def insert_crc(i_filename, o_filename=None):
- f = open(i_filename, 'rb+')
- fdata = f.read()
- fcrc = CRC32(fdata)
- flength = LENGTH(fdata)
- f.close()
-
- # Write the CRC32 in big endian at the end of the file
+def insert_crc(i_filename, fbi_mode=False, o_filename=None):
if o_filename is None:
- f = open(i_filename, 'wb')
- f.write(fdata)
- f.write(fcrc)
- f.close()
+ o_filename = i_filename
+
+ with open(i_filename, 'rb') as f:
+ fdata = f.read()
+ fcrc = binascii.crc32(fdata).to_bytes(4, byteorder="big")
+ flength = len(fdata).to_bytes(4, byteorder="big")
- # Write a new file prepended with the size and CRC
- else:
- f = open(o_filename, 'wb')
- f.write(flength)
- f.write(fcrc)
- f.write(fdata)
- f.close()
+ with open(o_filename, 'wb') as f:
+ if fbi_mode:
+ f.write(flength)
+ f.write(fcrc)
+ f.write(fdata)
+ else:
+ f.write(fdata)
+ f.write(fcrc)
#!/usr/bin/env python3
-import sys, argparse
+import argparse
import crc
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="CRC32 computation tool and MiSoC image file writer.")
- parser.add_argument("-i", default=None, help="input file")
- parser.add_argument("-o", default=None, help="output file (if not specified = input file)")
+ parser.add_argument("input", help="input file")
+ parser.add_argument("-o", "--output", default=None, help="output file (if not specified, use input file)")
+ parser.add_argument("-f", "--fbi", default=False, action="store_true", help="build flash boot image (FBI) file")
args = parser.parse_args()
-
- i_filename = args.i
- o_filename = args.o
-
- crc.insert_crc(i_filename, o_filename)
+ crc.insert_crc(args.input, args.fbi, args.output)
MSCDIR=../..
include $(MSCDIR)/software/common.mak
-PYTHON = python3
OBJECTS=isr.o sdram.o main.o boot-helper.o boot.o dataflow.o
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
chmod -x $@
- $(PYTHON) $(MSCDIR)/mkmscimg.py -i $@
+ $(MSCDIR)/mkmscimg.py $@
bios.elf: linker.ld $(OBJECTS) libs
MSCDIR=../..
include $(MSCDIR)/software/common.mak
-PYTHON = python3
OBJECTS=isr.o processor.o dvisampler0.o dvisampler1.o edid.o pll.o ci.o config.o main.o
chmod -x $@
%.fbi: %.bin
- $(PYTHON) $(MSCDIR)/mkmscimg.py -i $< -o $@
+ $(MSCDIR)/mkmscimg.py -f -o $@ $<
videomixer.elf: $(OBJECTS) libs