Commit 4eb3b3f4 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

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

parent 5364f76f
This folder contains patches to the original SPEC 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 specpts_macaddr.tar.gz *
Before applying the patch on a working PTS, please create a backup archive of the
main PTS directory, where files like pts.py and spec.sh are located. This
archive caould be then used to restore the original PTS if something goes wrong
with applying the patches:
# tar czf pts_backup.tar.gz pts
To apply the patch on a working PTS, the content has to be extracted in the main
PTS directory, where files like pts.py and spec.sh are located:
# cd pts
# tar xzf specpts_macaddr.tar.gz
This diff is collapsed.
#!/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
#!/bin/sh
LOGDIR=./log
mkdir -p $LOGDIR
sudo rm -fr $LOGDIR/pts*
serial=$1
if [ x$1 = x"" ]; then
echo -n "Please, input SERIAL number: "
read serial
fi
extra_serial=$2
if [ x$2 = x"" ]; then
echo -n "Please, input extra SERIAL number: "
read extra_serial
fi
if [ x$extra_serial = x"" ]; then
extra_serial=0000
fi
# MAC address for the board
echo -n "Please, input MAC addres (use XX:XX:XX:XX:XX:XX format): "
read mac_addr
tmp=""
echo -n "--------------------------------------------------------------\n"
echo -n "Remove the jumper from the board!\n"
echo -n "Press enter to continue...\n"
read tmp
echo -n "--------------------------------------------------------------\n"
# Assemble pts.py call with parameters for SPEC
cmd="sudo ./pts.py -b SPEC -s "$serial" -e "$extra_serial
if [ ! x$mac_addr = x"" ]; then
cmd=$cmd" -m "$mac_addr
fi
cmd=$cmd" -t./test/spec/python -l "$LOGDIR" 00 01 02 03 04 05 06 07 08 09 10 12"
# Execute pts.py
$cmd
echo -n "Press enter to exit... "
read tmp
#! /usr/bin/env python
# coding: utf8
# Copyright CERN, 2011
# Author: Samuel Iglesias Gonsalvez <siglesia@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
import sys
import rr
import time
import os
import os.path
from ctypes import *
from ptsexcept import *
sys.path.append('sdbfs')
import gen_flash_image
"""
test03: loads a firmware file to Flash memory and boots from it. The FW just blinks the leds.
"""
mac_filename = 'mac.tmp'
class CGennumFlash :
GENNUM_FLASH = 1;
GENNUM_FPGA = 2;
FPGA_FLASH = 3;
def __init__ (self, bus, path):
self.bus = bus;
library = os.path.join(path,"libfpga_loader.so");
self.lib = cdll.LoadLibrary(library);
self.lib.rr_init();
self.lib.gpio_init();
def main (default_directory='.'):
fpga_firmware = "/test_flash.bin"
# first try to read MAC address form file
filename = os.path.join(default_directory, mac_filename)
print "Trying to open " + filename
try:
macfile = open(filename, 'r')
except IOError:
print "MAC address not assigned..."
mac = ""
else:
mac = macfile.read()
macfile.close()
os.remove(filename)
print "MAC: " + mac
gen_flash_image.gen_sdb_image("spec", mac,
default_directory+"/test_flash.bin",
default_directory+"/test_flash_mac.bin")
fpga_firmware = "/test_flash_mac.bin"
gennum = rr.Gennum();
flash = CGennumFlash(gennum, default_directory);
start = time.time();
flash.lib.gpio_bootselect(flash.GENNUM_FLASH);
version = hex(flash.lib.flash_read_id());
if (version != "0x202016"):
raise PtsError('Error: version of the flash is not correct: ' + version);
# Load a new firmware to the Flash memory.
print "Starting the process to load a FW ("+default_directory+fpga_firmware+" into Flash memory"
flash.lib.load_mcs_to_flash(default_directory + fpga_firmware);
time.sleep(1);
print "Forcing to load FW from Flash memory to FPGA"
# Force the FPGA to load the FW from the Flash memory
flash.lib.force_load_fpga_from_flash();
finish = time.time();
print "Time elapsed: " + str(finish - start) + " seconds"
time.sleep(5)
ask = "";
tmp_stdout = sys.stdout;
sys.stdout = sys.__stdout__;
tmp_stdin = sys.stdin;
sys.stdin = sys.__stdin__;
while ((ask != "Y") and (ask != "N")) :
print "-------------------------------------------------------------"
print "\t PRESS THE BUTTONS IN THE SPEC BOARD "
ask = raw_input("Are the LEDs blinking when you press the buttons? [Y/N]")
ask = ask.upper()
print "-------------------------------------------------------------"
sys.stdout = tmp_stdout;
sys.stdin = tmp_stdin;
if (ask == "N") :
raise PtsError("Error loading FW through the Flash memory or there is a problem with the LEDs");
if __name__ == '__main__' :
main();
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