Commit 77a08140 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

Merge branch 'greg-mac'

parents 3c3a66cd 594d04cd

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

[submodule "fpga-config-space"]
path = fpga-config-space
url = git://ohwr.org/hdl-core-lib/fpga-config-space.git
fpga-config-space @ 79448c11
Subproject commit 79448c1144fa9da899bf3373eafd41d886364d34
......@@ -22,6 +22,8 @@ from ConfigParser import ConfigParser, NoOptionError
from optparse import OptionParser
from sha import sha as sha160
from ptsexcept import *
sys.path.append('sdbfs')
from gen_flash_image import check_mac
default_config_file = 'ptsdefault.cfg'
default_log_pattern = 'pts_tst_{runid}_{timestamp}_{board}_{serial}_{number}.txt'
......@@ -68,8 +70,8 @@ def run_test(testname, logname, test_path, yes=False):
class Suite(object):
def __init__(self, cfgfilename=default_config_file):
self.required = [ 'board', 'serial', 'extra_serial', 'test_path',
'log_path', 'sequence' ]
self.required = [ 'board', 'serial', 'extra_serial', 'mac_addr',
'test_path', 'log_path', 'sequence' ]
for fieldname in self.required:
self.__setattr__(fieldname, None)
self.config = default_config_file
......@@ -100,6 +102,7 @@ class Suite(object):
self.board = config.get('global', 'board')
self.serial = config.get('global', 'serial')
self.extra_serial = config.get('global', 'extra_serial')
self.mac_addr = config.get('global', 'mac_addr')
self.test_path = config.get('global', 'test_path')
self.log_path = config.get('global', 'log_path')
self.sequence = config.get('global', 'sequence')
......@@ -115,6 +118,7 @@ class Suite(object):
config.set('global', 'board', self.board)
config.set('global', 'serial', self.serial)
config.set('global', 'extra_serial', self.extra_serial)
config.set('global', 'mac_addr', self.mac_addr)
config.set('global', 'test_path', self.test_path)
config.set('global', 'log_path', self.log_path)
config.set('global', 'sequence', self.sequence)
......@@ -232,10 +236,11 @@ class Suite(object):
' board = {0}\n'
' serial = {1}\n'
' optional serial = {2}\n'
' comment = {3}\n'
' timestamp = {4}\n'
' runid = {5}\n'.format(
self.board, self.serial, self.extra_serial, self.comment, ts, runid))
' MAC address = {3}\n'
' comment = {4}\n'
' timestamp = {5}\n'
' runid = {6}\n'.format(
self.board, self.serial, self.extra_serial, self.mac_addr, self.comment, ts, runid))
failures = []
for test in sequence:
try:
......@@ -402,6 +407,7 @@ class Cli(cmd.Cmd, Suite):
'board',
'serial',
'extra_serial',
'mac_addr',
'test_path',
'log_path',
'repeat',
......@@ -428,6 +434,12 @@ def validate_args(args):
if not re.match(default_test_syntax, arg) ]
return valid_args, invalid_args
def store_mac(path, mac):
filepath = os.path.join(path, 'mac.tmp')
mac_file = open(filepath, 'w')
mac_file.write(mac)
mac_file.close()
def main():
usage = ( '%prog: [options] test ...\n'
......@@ -444,6 +456,8 @@ def main():
help="board serial number", metavar="SERIAL")
parser.add_option("-e", "--extra_serial", dest="extra_serial",
help="another board serial number [Optional]", metavar="SERIAL")
parser.add_option("-m", "--mac", dest="mac_addr",
help="MAC address of the SFP port")
parser.add_option("-t", "--test-path", dest="test_path",
help="path to test files", metavar="PATH")
parser.add_option("-l", "--log-path", dest="log_path",
......@@ -481,6 +495,12 @@ def main():
print 'bad parameters:', e
return
# store MAC address if needed
if options.mac_addr:
if not check_mac(options.mac_addr):
return
store_mac(options.test_path, options.mac_addr)
# decide what to do
if options.write_config:
s.save()
......
sdbfs-eeprom/*
sdbfs-flash/*
*.bin
#!/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 :
SDBFS_MAC = "{path}sdbfs-{type}/mac-address"
SDBFS_BSTR = "{path}sdbfs-{type}/bitstream"
SDBFS_IMG = "{path}sdbfs-{type}-{mac}.bin"
GEN_SPEC_CMD = "{path}./gensdbfs -b 65536 {path}sdbfs-spec {img}"
GEN_SVEC_CMD = "{path}./gensdbfs -b 262144 {path}sdbfs-svec {img}"
###########################################################
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 address"
return 0
return 1
###########################################################
# type can be either "spec" or "svec"
def gen_sdb_image(type, mac, bstr, output=None):
if mac and 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-spec/svec 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('-')]
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, type=type) #<abs_path>/sdbfs-<type>/bitstream
if bstr:
print "Including bitstream " + bstr
shutil.copy(bstr, sdbfs_bstr)
else:
#truncate bitstream file if not given
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)
# gensdbfs for spec/svec
if type == "spec":
cmd = GEN_SPEC_CMD.format(path=abs_path, img=sdbfs_img)
else:
cmd = GEN_SVEC_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 __name__ == "__main__":
if len(sys.argv) < 3:
print "Wrong syntax"
print sys.argv[0] + " <spec/svec> <mac> [bitstream]"
sys.exit()
type = sys.argv[1]
if type != "spec" and type != "svec":
print "Wrong syntax"
print sys.argv[0] + " <spec/svec> <mac> [bitstream]"
sys.exit()
#mac = check_mac(sys.argv[2])
mac = sys.argv[2]
if len(sys.argv) > 3: