Commit c78ba842 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

catbstream: Add support for .bit file concatenation

Signed-off-by: Theodor-Adrian Stana's avatarTheodor Stana <t.stana@cern.ch>
parent b62974bc
......@@ -7,7 +7,21 @@ bitstreams are stored on a Flash chip for applications such as MultiBoot.
The script asks the user for the bitstream file names (two input and one
output) and stores the concatenated version of the two bitstreams to the
output file. The second second bitstream starts on a sector boundary. If the
output file.
There can be two modes of running:
(1) -- Concatenate two raw .bin files to another .bin file
(2) -- Concatenate two Xilinx .bit files to an .mcs file
In both cases, you are asked for the input and output files. Note that you
have to supply the input and output file extensions, and if they are not
correct, the script warns you and exits.
(1) Two .bin files into another .bin file
-----------------------------------------
In this mode, the second second bitstream starts on a sector boundary. If the
first bitstream is smaller than the second, the script pads with zeroes until
the sector boundary.
......@@ -25,9 +39,25 @@ The output bitstream of two concatenated bitstreams would look like this:
At the time of writing of this readme, the file is designed for M25P flash
chips, which have 64kB sectors. To change the sector boundaries, all one needs
to do is change line 17 in the file for the sector boundary on his or her
to do is change line 39 in the file for the sector boundary on his or her
flash of choice:
# 0x10000 is the sector boundary in the M25P flash
lt = 0x10000 - (len(a1)%0x10000)
(2) Two .bit files into an .mcs file
------------------------------------
In this mode, the script makes use of the Xilinx PROMGEN tool. You also need
to do more work than before, in that apart from the input files, you also have
to give the flash chip size and start addresses for the bitstream.
Then, the script calls the PROMGEN tool to do all the work of concatenating
the bitstreams.
Note that apart from the needed .mcs file, some extra output files are also
generated. However, you don't need to worry about these, only the .mcs should
be interesting to you.
import sys
import subprocess
if __name__ == "__main__":
# open files
fn1 = raw_input("file 1: ")
fn2 = raw_input("file 2: ")
fn3 = raw_input("outfile: ")
f1 = open(fn1,'rb')
f2 = open(fn2,'rb')
f3 = open(fn3,'wb')
a1 = []
a2 = []
# read contents
a1 = f1.read()
a2 = f2.read()
# get sector boundary and fill with zeroes up to next sector
lt = 0x10000 - (len(a1)%0x10000)
for i in range(0, lt):
a1 += '\0'
# write output files
f3.write(a1+a2)
f1.close()
f2.close()
f3.close()
# Ask for type of output
print("How should the program run?")
print("(1) .bin + .bin -> .bin")
print("(2) .bit + .bit -> .mcs")
o = raw_input("Select (1)/(2): ")
if (o != '1') and (o != '2'):
print ("ERROR -- Please select a valid input!")
sys.exit(1)
if (o == '1'):
# open files
fn1 = raw_input("file 1 (.bin): ")
fn2 = raw_input("file 2 (.bin): ")
fn3 = raw_input("outfile (.bin): ")
fn1f = fn1.split('.')[-1]
fn2f = fn2.split('.')[-1]
fn3f = fn3.split('.')[-1]
if (fn1f != "bin") or (fn2f != "bin") or (fn3f != "bin"):
print("ERROR -- Wrong binary file format!")
print("expected : .bin/.bin/.bin")
print("got : .%s/.%s/.%s" % (fn1f, fn2f, fn3f))
sys.exit(1)
f1 = open(fn1,'rb')
f2 = open(fn2,'rb')
f3 = open(fn3,'wb')
a1 = []
a2 = []
# read contents
a1 = f1.read()
a2 = f2.read()
# get sector boundary and fill with zeroes up to next sector
lt = 0x10000 - (len(a1) % 0x10000)
for i in range(0, lt):
a1 += '\0'
# write output files
f3.write(a1+a2)
print("SUCCESS -- Output written to " + fn3)
f1.close()
f2.close()
f3.close()
elif (o == '2'):
fn1 = raw_input("file 1 (.bit): ")
fn2 = raw_input("file 2 (.bit): ")
fn3 = raw_input("outfile (.mcs): ")
fn1f = fn1.split('.')[-1]
fn2f = fn2.split('.')[-1]
fn3f = fn3.split('.')[-1]
if (fn1f != "bit") or (fn2f != "bit") or (fn3f != "mcs"):
print("ERROR -- Wrong binary file format!")
print("expected : .bit/.bit/.mcs")
print("got : .%s/.%s/.%s" % (fn1f, fn2f, fn3f))
sys.exit(1)
s = raw_input("flash size (KB): ")
a1 = raw_input("bistream 1 start address: 0x")
a2 = raw_input("bistream 2 start address: 0x")
subprocess.call("promgen -w -p mcs -spi -s " + s + " -u " + a2 + " " + fn1 + " -u " + a2 + " " + fn2 + " -o " + fn3, shell=True)
print("SUCCESS -- Output written to " + fn3)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment