Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Production Test Suite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
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
Production Test Suite
Commits
2d4337bc
Commit
2d4337bc
authored
Jan 09, 2017
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sdbfs: python script to generate sdbfs image with MAC and bitstream
parent
0c65999f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
gen_flash_image.py
sdbfs/gen_flash_image.py
+103
-0
No files found.
sdbfs/gen_flash_image.py
0 → 100755
View file @
2d4337bc
#!/usr/bin/python
################################################################################
##
## The script is part of the SPEC and SVEC PTS. It is used to generate SDBFS
## image that is then stored in Flash or EEPROM memory. The image contains MAC
## address and optionally also an FPGA bitstream. The main purpose of including
## it to the PTS is to allow manufacturers assigning official MAC addresses to
## SPEC and SVEC boards.
##
## Copyright (C) 2017 CERN (www.cern.ch)
## Author: Grzegorz Daniluk <grzegorz.daniluk@cern.ch>
##
################################################################################
import
sys
import
re
import
subprocess
import
os
import
shutil
#class CSDBGenerator :
MAC_FILE
=
"sdbfs-<type>/mac-address"
BSTR_FILE
=
"sdbfs-flash/bitstream"
BSTR_CMD
=
"cp <bstr> <path>sdbfs-flash/bitstream"
BSTR_TRUNC
=
"> <path>sdbfs-flash/bitstream"
GEN_FLASH_CMD
=
"<path>./gensdbfs -b 65536 <path>sdbfs-flash <path>sdbfs-flash-<mac>.bin"
GEN_EEPROM_CMD
=
"<path>./gensdbfs <path>sdbfs-eeprom <path>sdbfs-eeprom-<mac>.bin"
###########################################################
def
check_mac
(
mac
):
if
not
re
.
match
(
"[0-9a-f]{2}([-:])[0-9a-f]{2}(
\\
1[0-9a-f]{2}){4}$"
,
mac
.
lower
()):
print
"Not a valid MAC"
return
0
return
1
###########################################################
# type can be either "flash" or "eeprom"
def
gen_sdb_image
(
type
,
mac
,
bstr
,
output
):
if
not
check_mac
(
mac
):
return
mac
=
mac
.
replace
(
':'
,
'-'
)
abs_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
'/'
# 1. write MAC address to the file in SDBFS
mac_bytes
=
[
int
(
i
,
16
)
for
i
in
mac
.
split
(
'-'
)]
fname
=
MAC_FILE
.
replace
(
"<type>"
,
type
)
f
=
open
(
os
.
path
.
join
(
abs_path
,
fname
),
'wb'
)
f
.
truncate
()
for
byte
in
mac_bytes
:
f
.
write
(
chr
(
byte
))
f
.
close
()
# 2. copy bitstream to SDBFS, if needed
if
type
==
"flash"
and
bstr
:
print
"Including bitstream "
+
bstr
fname
=
os
.
path
.
join
(
abs_path
,
BSTR_FILE
)
subprocess
.
Popen
(
"cp "
+
bstr
+
" "
+
fname
,
shell
=
True
)
.
wait
()
elif
type
==
"flash"
:
#truncate bitstream file if not given for flash
print
"No bitstream given for flash, truncating"
fname
=
os
.
path
.
join
(
abs_path
,
BSTR_FILE
)
subprocess
.
Popen
(
"> "
+
fname
,
shell
=
True
)
.
wait
()
# 3. generate SDBFS image
if
type
==
"flash"
:
# gensdbfs for flash
fname
=
GEN_FLASH_CMD
.
replace
(
"<mac>"
,
mac
)
cmd
=
fname
.
replace
(
"<path>"
,
abs_path
)
subprocess
.
Popen
(
cmd
,
shell
=
True
)
.
wait
()
shutil
.
copy
(
abs_path
+
"sdbfs-flash-"
+
mac
+
".bin"
,
output
)
print
"Generated sdbfs-flash-"
+
mac
elif
type
==
"eeprom"
:
fname
=
GEN_EEPROM_CMD
.
replace
(
"<mac>"
,
mac
)
path
=
os
.
path
.
join
(
abs_path
,
fname
)
subprocess
.
Popen
(
path
,
shell
=
True
)
.
wait
()
print
"Generated sdbfs-eeprom-"
+
mac
###########################################################
#if len(sys.argv) < 3:
# print "Wrong syntax"
# print sys.argv[0] + " <flash/eeprom> <mac> [bitstream]"
# sys.exit()
#
#type = sys.argv[1]
#if type != "flash" and type != "eeprom":
# print "Wrong syntax"
# print sys.argv[0] + " <flash/eeprom> <mac> [bitstream]"
# sys.exit()
#
#mac = check_mac(sys.argv[2])
#
#if len(sys.argv) > 3:
# bitstream = sys.argv[3]
#else:
# bitstream = ""
#
#gen_sdb_image(type, mac, bitstream)
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