Line 1... |
Line 1... |
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
# $Id: impact_wrapper 314 2010-07-09 17:38:41Z mueller $
|
# $Id: config_wrapper 402 2011-08-05 18:56:44Z mueller $
|
#
|
#
|
# Copyright 2010- by Walter F.J. Mueller
|
# Copyright 2010-2011 by Walter F.J. Mueller
|
#
|
#
|
# This program is free software; you may redistribute and/or modify it under
|
# This program is free software; you may redistribute and/or modify it under
|
# the terms of the GNU General Public License as published by the Free
|
# the terms of the GNU General Public License as published by the Free
|
# Software Foundation, either version 2, or at your option any later version.
|
# Software Foundation, either version 2, or at your option any later version.
|
#
|
#
|
Line 12... |
Line 12... |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
# for complete details.
|
# for complete details.
|
#
|
#
|
# Revision History:
|
# Revision History:
|
# Date Rev Version Comment
|
# Date Rev Version Comment
|
|
# 2011-08-04 402 1.1.4 add atlys support;
|
|
# 2011-07-25 399 1.1.3 add nexys2-500 support; bsdl path for sp605
|
|
# 2011-07-18 395 1.1.2 cleanup bsdl path creation for jtag
|
|
# 2011-07-17 394 1.1.1 add bit->svf conversion and config with jtag
|
|
# 2011-07-11 393 1.1 renamed from impact_wrapper; add function parameter,
|
|
# old action with 'iconfig'
|
|
# 2011-07-01 386 1.0.3 support sp605/xc6slx45t
|
# 2010-05-24 294 1.0.2 support nexys2/xc3s1200e
|
# 2010-05-24 294 1.0.2 support nexys2/xc3s1200e
|
# 2010-04-24 282 1.0.1 proper error exit for GetOptions()
|
# 2010-04-24 282 1.0.1 proper error exit for GetOptions()
|
# 2010-04-24 281 1.0 Initial version
|
# 2010-04-24 281 1.0 Initial version
|
#
|
#
|
|
|
Line 25... |
Line 32... |
|
|
use Getopt::Long;
|
use Getopt::Long;
|
|
|
my %opts = ();
|
my %opts = ();
|
|
|
$opts{board} = "s3board";
|
GetOptions(\%opts, "help", "dry_run", "board=s", "path=s") or exit 1;
|
$opts{path} = "xc3s1000";
|
|
|
|
GetOptions(\%opts, "help", "board=s", "path=s") or exit 1;
|
# setup defaults for board and path
|
|
if (not defined $opts{board}) {
|
|
$opts{board} = "s3board";
|
|
}
|
|
if (not defined $opts{path}) {
|
|
$opts{path} = "xc3s1000" if $opts{board} eq "s3board";
|
|
$opts{path} = "xc3s1200e" if $opts{board} eq "nexys2";
|
|
$opts{path} = "xc6slx45" if $opts{board} eq "atlys";
|
|
$opts{path} = "xc6slx45t" if $opts{board} eq "sp605";
|
|
}
|
|
|
sub print_help;
|
sub print_help;
|
|
sub run_command;
|
|
|
|
|
autoflush STDOUT 1 if (-p STDOUT); # autoflush if output into pipe
|
autoflush STDOUT 1 if (-p STDOUT); # autoflush if output into pipe
|
|
|
if (exists $opts{help}) {
|
if (exists $opts{help}) {
|
print_help;
|
print_help;
|
Line 44... |
Line 61... |
my $board = $opts{board};
|
my $board = $opts{board};
|
my $ipath = $opts{path};
|
my $ipath = $opts{path};
|
|
|
$ipath =~ s/-.*$//; # trim all after first '-'
|
$ipath =~ s/-.*$//; # trim all after first '-'
|
|
|
# at this point just support Digilent s3board with xc3s200 or xc3s1000
|
# now setup JTAG chain config
|
|
|
my $part2;
|
my @plist;
|
|
my $pfpga;
|
|
|
if ($board eq "s3board" && $ipath eq "xc3s200") {
|
#
|
$part2 = "xcf02s";
|
# Note: when new targets are added update also the blist logic below
|
} elsif ($board eq "s3board" && $ipath eq "xc3s1000") {
|
#
|
$part2 = "xcf04s";
|
if ($board eq "s3board" && $ipath eq "xc3s200") { # S3BOARD-200
|
} elsif ($board eq "nexys2" && $ipath eq "xc3s1200e") {
|
@plist = ($ipath, "xcf02s");
|
$part2 = "xcf04s";
|
$pfpga = 1;
|
|
} elsif ($board eq "s3board" && $ipath eq "xc3s1000") { # S3BOARD-1200
|
|
@plist = ($ipath, "xcf04s");
|
|
$pfpga = 1;
|
|
|
|
} elsif ($board eq "nexys2" && $ipath eq "xc3s1200e") { # nexys2-1200
|
|
@plist = ($ipath, "xcf04s");
|
|
$pfpga = 1;
|
|
} elsif ($board eq "nexys2" && $ipath eq "xc3s500e") { # nexys2-500
|
|
@plist = ($ipath, "xcf04s");
|
|
$pfpga = 1;
|
|
|
|
} elsif ($board eq "atlys" && $ipath eq "xc6slx45") { # atlys
|
|
@plist = ($ipath);
|
|
$pfpga = 1;
|
|
|
|
} elsif ($board eq "sp605" && $ipath eq "xc6slx45t") { # sp605
|
|
@plist = ("xccace", $ipath);
|
|
$pfpga = 2;
|
} else {
|
} else {
|
print STDERR "impact_wrapper-E: only s3board/nexys2 supported\n";
|
print STDERR "config_wrapper-E: only s3board/nexys2/sp605 supported\n";
|
exit 1;
|
exit 1;
|
}
|
}
|
|
|
|
my @blist;
|
|
foreach my $part (@plist) {
|
|
if ($part =~ m/^xcf/) { push @blist, "xcf/data" } # proms
|
|
elsif ($part =~ m/^xc3s\d*$/) { push @blist, "spartan3/data" } # s-3
|
|
elsif ($part =~ m/^xc3s\d*e$/) { push @blist, "spartan3e/data" } # s-3e
|
|
elsif ($part =~ m/^xc6slx\d*t?$/) { push @blist, "spartan6/data" }# s-6 lx
|
|
elsif ($part =~ m/^xccace$/) { push @blist, "acempm/data" } # sys-ace
|
|
else {
|
|
print STDERR "config_wrapper-E: no bsdl path known for $part\n";
|
|
exit 1;
|
|
}
|
|
}
|
|
|
|
my $cmd = shift @ARGV;
|
my $file = shift @ARGV;
|
my $file = shift @ARGV;
|
|
|
|
if (! defined $cmd) {
|
|
print STDERR "config_wrapper-E: no command specified\n";
|
|
exit 1;
|
|
}
|
|
|
if (! defined $file) {
|
if (! defined $file) {
|
print STDERR "impact_wrapper-E: no bit file specified\n";
|
print STDERR "config_wrapper-E: no bit or svf file specified\n";
|
exit 1;
|
exit 1;
|
}
|
}
|
if (! -r $file) {
|
if (! -r $file) {
|
print STDERR "impact_wrapper-E: input file not found or readable\n";
|
print STDERR "config_wrapper-E: input file not found or readable\n";
|
|
exit 1;
|
|
}
|
|
|
|
my $xilpath = $ENV{XILINX};
|
|
if (! defined $xilpath) {
|
|
print STDERR "config_wrapper-E: XILINX environment variable not defined\n";
|
exit 1;
|
exit 1;
|
}
|
}
|
|
|
my $tmpfile = "tmp_impact_wrapper.cmd";
|
# ----- iconfig action --------------------------------------------------------
|
|
if ($cmd eq "iconfig") {
|
|
|
|
my $tmpfile = "tmp_config_wrapper.cmd";
|
open (OFILE, ">$tmpfile") or die "Couldn't open tmp cmd file: $!";
|
open (OFILE, ">$tmpfile") or die "Couldn't open tmp cmd file: $!";
|
|
|
print OFILE "setMode -bs\n";
|
print OFILE "setMode -bs\n";
|
print OFILE "setCable -p auto\n";
|
print OFILE "setCable -p auto\n";
|
print OFILE "addDevice -p 1 -part $ipath\n";
|
for (my $i = 0; $i<=$#plist; $i++) {
|
print OFILE "addDevice -p 2 -part $part2\n";
|
printf OFILE "addDevice -p %d -part %s\n", $i+1, $plist[$i];
|
print OFILE "assignFile -p 1 -file $file\n";
|
}
|
print OFILE "program -p 1 -verify\n";
|
printf OFILE "assignFile -p %d -file %s\n", $pfpga, $file;
|
|
printf OFILE "program -p %d -verify\n", $pfpga;
|
|
print OFILE "quit\n";
|
|
|
|
close (OFILE) or die "Couldn't close tmp cmd file: $!";
|
|
|
|
my $rc = run_command("impact -batch", $tmpfile);
|
|
exit $rc;
|
|
|
|
# ----- jconfig action --------------------------------------------------------
|
|
} elsif ($cmd eq "jconfig") {
|
|
|
|
my $bpath = join ";", map "$xilpath/$_",@blist;
|
|
|
|
my $tmpfile = "tmp_config_wrapper.cmd";
|
|
open (OFILE, ">$tmpfile") or die "Couldn't open tmp cmd file: $!";
|
|
|
|
# the UrJtag and Xilinx impact have different chain and part number schemes
|
|
# impact: 1-based, 1 is first in chain;
|
|
# UrJtag: 0-based, 0 is last in chain;
|
|
# e.g. on Digilent Nexys2:
|
|
# impact: (1) FPGA (2) PROM
|
|
# UrJtag: (1) FPGA (0) PROM
|
|
|
|
my $jtag_part = $#plist + 1 - $pfpga;
|
|
|
|
print OFILE "cable usbblaster\n";
|
|
printf OFILE "bsdl path %s\n", $bpath;
|
|
print OFILE "detect\n";
|
|
printf OFILE "part %d\n", $jtag_part;
|
|
printf OFILE "svf %s\n", $file;
|
|
|
|
close (OFILE) or die "Couldn't close tmp cmd file: $!";
|
|
|
|
my $rc = run_command("jtag", $tmpfile);
|
|
exit $rc;
|
|
|
|
# ----- bit2svf action --------------------------------------------------------
|
|
} elsif ($cmd eq "bit2svf") {
|
|
my $ofile = $file;
|
|
$ofile =~ s/\.bit/\.svf/;
|
|
|
|
my $tmpfile = "tmp_config_wrapper.cmd";
|
|
open (OFILE, ">$tmpfile") or die "Couldn't open tmp cmd file: $!";
|
|
|
|
print OFILE "setMode -bs\n";
|
|
printf OFILE "setCable -port svf -file %s\n", $ofile;
|
|
printf OFILE "addDevice -p 1 -file %s\n", $file;
|
|
print OFILE "program -p 1\n";
|
print OFILE "quit\n";
|
print OFILE "quit\n";
|
|
|
close (OFILE) or die "Couldn't close tmp cmd file: $!";
|
close (OFILE) or die "Couldn't close tmp cmd file: $!";
|
|
|
my $wrc = system "/bin/sh", "-c", "impact -batch $tmpfile";
|
my $rc = run_command("impact -batch", $tmpfile);
|
|
exit $rc;
|
|
}
|
|
|
|
print STDERR "config_wrapper-E: command must be bit2svf, iconfig or jconfig\n";
|
|
exit 1;
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
sub run_command {
|
|
|
|
my ($cmd, $tmpfile) = @_;
|
|
|
|
my $wrc;
|
|
if (defined $opts{dry_run}) {
|
|
print STDOUT "$cmd\n";
|
|
$wrc = system "/bin/sh", "-c", "cat $tmpfile";
|
|
} else {
|
|
$wrc = system "/bin/sh", "-c", "$cmd $tmpfile";
|
|
}
|
|
|
my $rc = 0;
|
my $rc = 0;
|
if ($wrc != 0) {
|
if ($wrc != 0) {
|
my $rc = int($wrc/256);
|
my $rc = int($wrc/256);
|
if ($rc == 0) {
|
if ($rc == 0) {
|
my $sig = $wrc % 256;
|
my $sig = $wrc % 256;
|
print STDERR "impact_wrapper-I impact aborted by signal $sig\n";
|
print STDERR "config_wrapper-I $cmd aborted by signal $sig\n";
|
$rc = 1;
|
$rc = 1;
|
} else {
|
} else {
|
print STDERR "impact_wrapper-I impact failed (rc=$rc) $?\n";
|
print STDERR "config_wrapper-I $cmd failed (rc=$rc) $?\n";
|
}
|
}
|
}
|
}
|
|
|
unlink $tmpfile or die "Couldn't delete tmp cmd file: $!";
|
unlink $tmpfile or die "Couldn't delete tmp cmd file: $!";
|
|
return $rc;
|
exit $rc;
|
}
|
|
|
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
|
|
sub print_help {
|
sub print_help {
|
print "usage: impact_wrapper [--help] [--board=b] [--path=p] file\n";
|
print "usage: config_wrapper [--help] [--board=b] [--path=p] cmd file\n";
|
|
print " cmd bit2svf or iconfig or jconfig\n";
|
print " --help this message\n";
|
print " --help this message\n";
|
|
print " --dry_run print impact command list\n";
|
print " --board=b type of board\n";
|
print " --board=b type of board\n";
|
print " --path=p type of fpga\n";
|
print " --path=p type of fpga\n";
|
}
|
}
|