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
42a97e15
Commit
42a97e15
authored
Jan 09, 2017
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sdbfs/gen_flash_image.py: code cleanup
parent
2d4337bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
23 deletions
+28
-23
gen_flash_image.py
sdbfs/gen_flash_image.py
+28
-23
No files found.
sdbfs/gen_flash_image.py
View file @
42a97e15
...
...
@@ -20,12 +20,11 @@ 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"
SDBFS_MAC
=
"{path}sdbfs-{type}/mac-address"
SDBFS_BSTR
=
"{path}sdbfs-flash/bitstream"
SDBFS_IMG
=
"{path}sdbfs-{type}-{mac}.bin"
GEN_FLASH_CMD
=
"{path}./gensdbfs -b 65536 {path}sdbfs-flash {img}"
GEN_EEPROM_CMD
=
"{path}./gensdbfs {path}sdbfs-eeprom {img}"
###########################################################
...
...
@@ -39,47 +38,53 @@ def check_mac(mac):
###########################################################
# type can be either "flash" or "eeprom"
def
gen_sdb_image
(
type
,
mac
,
bstr
,
output
):
def
gen_sdb_image
(
type
,
mac
,
bstr
,
output
=
None
):
if
not
check_mac
(
mac
):
return
# Translate MAC to be always in XX-XX-XX-XX-XX-XX format
mac
=
mac
.
replace
(
':'
,
'-'
)
# Get the absolute path where this script resides. This lets us have always
# access to the sdbfs-flash/eeprom structure, no matter where this script is
# called.
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'
)
sdbfs_mac
=
SDBFS_MAC
.
format
(
path
=
abs_path
,
type
=
type
)
f
=
open
(
sdbfs_mac
,
'wb'
)
f
.
truncate
()
for
byte
in
mac_bytes
:
f
.
write
(
chr
(
byte
))
f
.
close
()
# 2. copy bitstream to SDBFS, if needed
sdbfs_bstr
=
SDBFS_BSTR
.
format
(
path
=
abs_path
)
#<abs_path>/sdbfs-flash/bitstream
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
()
shutil
.
copy
(
bstr
,
sdbfs_bstr
)
elif
type
==
"flash"
:
#truncate bitstream file if not given for flash
print
"No bitstream given for flash, truncating"
f
name
=
os
.
path
.
join
(
abs_path
,
BSTR_FILE
)
subprocess
.
Popen
(
"> "
+
fname
,
shell
=
True
)
.
wait
()
f
=
open
(
sdbfs_bstr
,
'wb'
)
f
.
truncate
(
)
f
.
close
()
# 3. generate SDBFS image
sdbfs_img
=
SDBFS_IMG
.
format
(
path
=
abs_path
,
type
=
type
,
mac
=
mac
)
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
cmd
=
GEN_FLASH_CMD
.
format
(
path
=
abs_path
,
img
=
sdbfs_img
)
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
# gensdbfs for eeprom
cmd
=
GEN_EEPROM_CMD
.
format
(
path
=
abs_path
,
img
=
sdbfs_img
)
subprocess
.
Popen
(
cmd
,
shell
=
True
)
.
wait
()
print
"Generated "
+
sdbfs_img
# 4. Copy generated SDBFS image to <output>
if
output
:
shutil
.
copy
(
sdbfs_img
,
output
)
print
"Generated image ("
+
sdbfs_img
+
") copied to "
+
output
###########################################################
#if len(sys.argv) < 3:
...
...
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