Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
Conv TTL Blocking
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Conv TTL Blocking
Commits
c78ba842
Commit
c78ba842
authored
Mar 12, 2014
by
Theodor-Adrian Stana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catbstream: Add support for .bit file concatenation
Signed-off-by:
Theodor Stana
<
t.stana@cern.ch
>
parent
b62974bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
27 deletions
+100
-27
README.txt
software/catbstream/README.txt
+32
-2
catbstream.py
software/catbstream/catbstream.py
+68
-25
No files found.
software/catbstream/README.txt
View file @
c78ba842
...
...
@@ -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.
software/catbstream/catbstream.py
View file @
c78ba842
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment