Commit 76c5a50d authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

svec pts: add an exportable patch adding MAC address assignment to existing PTSes

parent 98f1c44c
This folder contains patches to the original SVEC PTS that is used by the
companies producing boards. To export one of these patches, please go into the
appropriate directory for the patch and create an archive of _ubuntu_ directory,
e.g.:
# cd macaddr
# tar czf svecpts_macaddr.tar.gz ubuntu
Before applying the patch on a working PTS, please create a backup archive of the
main PTS directory, This archive caould be then used to restore the original PTS
if something goes wrong with applying the patches:
# cd ~
# tar czf pts_backup.tar.gz ubuntu
To apply the patch on a working PTS, the content has to be extracted in the home
directory of the _pts_ user, on the SVEC PTS laptop:
# cd ~
# tar xzf svecpts_macaddr.tar.gz
#!/bin/bash
xc3sprog -p 0 -c xpc svec_app.bit
xc3sprog -p 1 -c xpc svec_sys.bit
if [ "$1" == "sdbfs" ]; then
echo "Flashing SDBFS, this takes a while..."
xc3sprog -p 0 -c xpc -I sdbfs-svec.bin:W:0:BIN
else
echo "Flashing only bootloader"
xc3sprog -p 0 -c xpc -I svec-bootloader-v3-20140815.bin:W:0:BIN
fi
xc3sprog -p 1 -c xpc svec-bootloader-v3-20140815.bin:w:0:BIN
#! /usr/bin/python
# coding: utf8
import sys
import time
import traceback
import os
import subprocess
import re
sys.path.append('sdbfs')
sys.path.append('/home/pts/ubuntu/pts/sdbfs')
import gen_flash_image
sys.path.append('.')
def men_is_on():
on = 0
subprocess.call("/home/pts/ubuntu/pts/get-fan-speeds", shell=True, stdout=fnull, stderr=fnull)
btxt = tuple(open("/home/pts/ubuntu/pts/log/fan-speeds","r"))
for i in range(1,len(btxt)):
if btxt[i].find("INTEGER: 0") == -1:
on = on + 1
return on
def men_on():
tmo = 1
while men_is_on() == 0:
print "Try:%d Switching ON the VME Crate" % (tmo)
subprocess.call("/home/pts/ubuntu/pts/men-on", shell=True, stdout=fnull, stderr=fnull)
tmo = tmo + 1
if tmo > 10:
print "FATAL ERROR: VME Crate: Unable to switch ON"
sys.exit(1)
time.sleep(1)
def men_off():
tmo = 1
while men_is_on() != 0:
print "Try:%d Switching OFF the VME Crate" % (tmo)
subprocess.call("/home/pts/ubuntu/pts/men-off", shell=True, stdout=fnull, stderr=fnull)
tmo = tmo + 1
if tmo > 10:
print "FATAL ERROR: VME Crate: Unable to switch OFF"
sys.exit(1)
time.sleep(10)
if __name__ == '__main__':
print "\nHello and Welcome to the SVEC PTS!\n"
fnull = open(os.devnull, "w")
men_off()
while True:
sn1 = raw_input("--> Scan the 1st barcode: ")
m = re.search(r"[^a-z\-A-Z0-9_]+",sn1)
if m:
print "Bad character in barcode"
else:
break
while True:
sn2 = raw_input("--> Scan the 2nd barcode: ")
if len(sn2) > 2:
m = re.search(r"[^a-z\-A-Z0-9_]+",sn2)
if m:
print "Bad character in barcode"
else:
break
else:
sn2 = "0"
break
while True:
mac = raw_input("--> Type the MAC address: ")
if len(mac) > 1:
if gen_flash_image.check_mac(mac):
break
else:
mac = ""
break
msg = "\n--> Plug the SVEC board '%s-%s' into the VME crate.\n Then type 'ok': " % (sn1, sn2)
ok = raw_input(msg)
while True:
if ok.find("ok") != -1 or ok.find("OK") != -1:
break
else:
ok = raw_input("--> Please type 'ok' to continue: ")
print "\n"
print "Initializing the test environment"
men_on()
# give some time for the things to settle before flashing
time.sleep(10)
# generate SDBFS image for a given MAC (if no MAC was given, function
# returns immediatelly
if mac:
gen_flash_image.gen_sdb_image("svec", mac, "",
"/home/pts/ubuntu/pts/boot/Flasher/production_flasher/sdbfs-svec.bin")
# Programming Flash
cmd = "cd /home/pts/ubuntu/pts/boot/Flasher/production_flasher; ./flash_svec.sh"
if mac:
print "Programming SDBFS with MAC address and bootloader, this will take ~8 minutes..."
cmd += " sdbfs"
else:
print "Programming the bootloader..."
subprocess.call(cmd, shell=True, stdout=fnull, stderr=fnull)
print "Programming complete"
print "VME Crate power cycle"
men_off()
time.sleep(2)
men_on()
print "VME Crate booting...this will take 1 min"
time.sleep(60)
subprocess.call("cd /home/pts/ubuntu/pts; rm -rf ./log; mkdir log; chmod 777 log", shell=True, stdout=fnull, stderr=fnull)
subprocess.call("cd /home/pts/ubuntu/pts; ./allow_tty", shell=True, stdout=fnull, stderr=fnull)
time.sleep(10)
print "\nRunning tests!\n"
subprocess.call("/home/pts/ubuntu/pts/query-bootloader", shell=True, stdout=fnull, stderr=fnull)
time.sleep(2)
sinfo = os.stat("/home/pts/ubuntu/pts/log/flash_result.txt")
if sinfo.st_size == 0:
print "FAIL: test00: Bootloader NOT Found"
print "ERROR: Flash IC14: Flash found empty after power cycle"
sys.exit(1)
else:
print "PASS: test00"
subprocess.call("/home/pts/ubuntu/pts/load-uart-test", shell=True, stdout=fnull, stderr=fnull)
subprocess.call("/home/pts/ubuntu/pts/run-uart-test", shell=True, stdout=fnull, stderr=fnull)
cmd = "ssh -X pts@men /home/pts/ubuntu/pts/jpts-men-root %s %s" % (sn1, sn2)
subprocess.call(cmd, shell=True, stdout=fnull, stderr=fnull)
subprocess.call("grep PASS /home/pts/ubuntu/pts/log/*.log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
subprocess.call("grep FAIL /home/pts/ubuntu/pts/log/*.log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
print "\nSaving test results on USB key"
try:
subprocess.call("mkdir -p /media/pts/log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
subprocess.call("cp /home/pts/ubuntu/pts/log/*.log /media/pts/log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
subprocess.call("cp /home/pts/ubuntu/pts/log/*.inf /media/pts/log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
except e:
print "ERROR: No access to USB key at /media/pts"
print e
print "\nTesting completed!"
men_off()
msg = "\n--> To see all the PTS errors, type 'ok': "
ok = raw_input(msg)
if ok.find("ok") != -1:
subprocess.call("grep ERROR /home/pts/ubuntu/pts/log/*.inf", shell=True, stdout=sys.stdout, stderr=sys.stderr)
subprocess.call("grep WARNING /home/pts/ubuntu/pts/log/*.inf", shell=True, stdout=sys.stdout, stderr=sys.stderr)
print ""
print "--> You may now unplug the SVEC board %s-%s\n" % (sn1, sn2)
msg = "--> To exit PTS, type 'ok': "
ok = raw_input(msg)
while True:
if ok.find("ok") != -1 or ok.find("OK") != -1:
print "Exited PTS"
time.sleep(1)
sys.exit(1)
else:
ok = raw_input("--> To exit PTS, type 'ok': ")
#!/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:
bitstream = sys.argv[3]
else:
bitstream = ""
gen_sdb_image(type, mac, bitstream)
#
# We want to store WRPC parameters but also the FPGA bitstream in the same
# FLASH. That is why our default position for various parameters is right after
# the bitstream.
.
position = 1507328
# Allocation granularity is 64 bytes
# We start with bitstream file at position 0, later the same set of files as for
# EEPROM image is used.
bitstream
write = 1
position = 0
maxsize = 1507328
mac-address
write = 1
maxsize = 6
wr-init
write = 1
maxsize = 256
# each sfp takes 29 bytes, 4 of them fit in 128 bytes
sfp-database
write = 1
maxsize = 128
calibration
write = 1
maxsize = 128
# This is an example config file, that can be used to build a filesystem
# from this very directory. Please note that gensdbfs doesn't look for
# config files in subdirectories but only in the tol-level one.
.
vendor = 0xce42
device = 0x5fec
position = 0x600000
# System FPGA bitstream
svec-bootloader.bin
position = 0
# Application FPGA bitstream
bitstream
position = 0x100000
mac-address
write = 1
maxsize = 6
wr-init
write = 1
maxsize = 256
# each sfp takes 29 bytes, 4 of them fit in 128 bytes
sfp-database
write = 1
maxsize = 128
calibration
write = 1
maxsize = 128
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