OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [bin/] [config_wrapper] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wfjm
#!/usr/bin/perl -w
2 22 wfjm
# $Id: config_wrapper 534 2013-09-22 21:37:24Z mueller $
3 2 wfjm
#
4 17 wfjm
# Copyright 2010-2013 by Walter F.J. Mueller 
5 2 wfjm
#
6
# This program is free software; you may redistribute and/or modify it under
7
# the terms of the GNU General Public License as published by the Free
8
# Software Foundation, either version 2, or at your option any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for complete details.
14
#
15
#  Revision History:
16
# Date         Rev Version  Comment
17 22 wfjm
# 2013-09-21   534   1.1.8  add nexys4 support
18 17 wfjm
# 2013-01-02   467   1.1.7  jconfig: prepend '0x' to support 'jtag #2007'
19
# 2012-02-11   457   1.1.6  jconfig: use RETRO_FX2_VID/PID for USB VID/PID
20 15 wfjm
# 2011-12-03   435   1.1.5  add nexys3 support;
21 12 wfjm
# 2011-08-04   402   1.1.4  add atlys support;
22
# 2011-07-25   399   1.1.3  add nexys2-500 support; bsdl path for sp605
23
# 2011-07-18   395   1.1.2  cleanup bsdl path creation for jtag
24
# 2011-07-17   394   1.1.1  add bit->svf conversion and config with jtag
25
# 2011-07-11   393   1.1    renamed from impact_wrapper; add function parameter,
26
#                           old action with 'iconfig'
27
# 2011-07-01   386   1.0.3  support sp605/xc6slx45t
28 2 wfjm
# 2010-05-24   294   1.0.2  support nexys2/xc3s1200e
29
# 2010-04-24   282   1.0.1  proper error exit for GetOptions()
30
# 2010-04-24   281   1.0    Initial version
31
#
32
 
33
use 5.005;                                  # require Perl 5.005 or higher
34
use strict;                                 # require strict checking
35
use FileHandle;
36
 
37
use Getopt::Long;
38
 
39
my %opts = ();
40
 
41 12 wfjm
GetOptions(\%opts, "help", "dry_run", "board=s", "path=s") or exit 1;
42 2 wfjm
 
43 12 wfjm
# setup defaults for board and path
44
if (not defined $opts{board}) {
45
  $opts{board} = "s3board";
46
}
47
if (not defined $opts{path}) {
48
  $opts{path}  = "xc3s1000"  if $opts{board} eq "s3board";
49
  $opts{path}  = "xc3s1200e" if $opts{board} eq "nexys2";
50 15 wfjm
  $opts{path}  = "xc6slx16"  if $opts{board} eq "nexys3";
51 22 wfjm
  $opts{path}  = "xc7a100t"  if $opts{board} eq "nexys4";
52 12 wfjm
  $opts{path}  = "xc6slx45"  if $opts{board} eq "atlys";
53
  $opts{path}  = "xc6slx45t" if $opts{board} eq "sp605";
54
}
55 2 wfjm
 
56
sub print_help;
57 12 wfjm
sub run_command;
58 2 wfjm
 
59 12 wfjm
 
60 2 wfjm
autoflush STDOUT 1 if (-p STDOUT);          # autoflush if output into pipe
61
 
62
if (exists $opts{help}) {
63
  print_help;
64
  exit 0;
65
}
66
 
67
my $board = $opts{board};
68
my $ipath = $opts{path};
69
 
70
$ipath =~ s/-.*$//;                         # trim all after first '-'
71
 
72 12 wfjm
# now setup JTAG chain config
73 2 wfjm
 
74 12 wfjm
my @plist;
75
my $pfpga;
76 2 wfjm
 
77 12 wfjm
#
78
# Note: when new targets are added update also the blist logic below
79
#
80
if ($board eq "s3board" && $ipath eq "xc3s200") {           # S3BOARD-200
81
  @plist = ($ipath, "xcf02s");
82
  $pfpga = 1;
83
} elsif ($board eq "s3board" && $ipath eq "xc3s1000") {     # S3BOARD-1200
84
  @plist = ($ipath, "xcf04s");
85
  $pfpga = 1;
86
 
87
} elsif ($board eq "nexys2" && $ipath eq "xc3s1200e") {     # nexys2-1200
88
  @plist = ($ipath, "xcf04s");
89
  $pfpga = 1;
90
} elsif ($board eq "nexys2" && $ipath eq "xc3s500e") {      # nexys2-500
91
  @plist = ($ipath, "xcf04s");
92
  $pfpga = 1;
93
 
94 15 wfjm
} elsif ($board eq "nexys3" && $ipath eq "xc6slx16") {      # nexys3
95
  @plist = ($ipath);
96
  $pfpga = 1;
97
 
98 22 wfjm
} elsif ($board eq "nexys4" && $ipath eq "xc7a100t") {      # nexys4
99
  @plist = ($ipath);
100
  $pfpga = 1;
101
 
102 12 wfjm
} elsif ($board eq "atlys" && $ipath eq "xc6slx45") {       # atlys
103
  @plist = ($ipath);
104
  $pfpga = 1;
105
 
106
} elsif ($board eq "sp605" && $ipath eq "xc6slx45t") {      # sp605
107
  @plist = ("xccace", $ipath);
108
  $pfpga = 2;
109 2 wfjm
} else {
110 15 wfjm
  print STDERR
111
    "config_wrapper-E: only s3board/nexys2,3/atlys/sp605 supported\n";
112 2 wfjm
  exit 1;
113
}
114
 
115 12 wfjm
my @blist;
116
foreach my $part (@plist) {
117
  if    ($part =~ m/^xcf/)       { push @blist, "xcf/data" }        # proms
118
  elsif ($part =~ m/^xc3s\d*$/)  { push @blist, "spartan3/data" }   # s-3
119
  elsif ($part =~ m/^xc3s\d*e$/) { push @blist, "spartan3e/data" }  # s-3e
120
  elsif ($part =~ m/^xc6slx\d*t?$/) { push @blist, "spartan6/data" }# s-6 lx
121 22 wfjm
  elsif ($part =~ m/^xc7a\d*t?$/) { push @blist, "artix7/data" }    # 7-a
122 12 wfjm
  elsif ($part =~ m/^xccace$/)   { push @blist, "acempm/data" }     # sys-ace
123
  else {
124
    print STDERR "config_wrapper-E: no bsdl path known for $part\n";
125
    exit 1;
126
  }
127
}
128
 
129
my $cmd  = shift @ARGV;
130 2 wfjm
my $file = shift @ARGV;
131
 
132 12 wfjm
if (! defined $cmd) {
133
  print STDERR "config_wrapper-E: no command specified\n";
134
  exit 1;
135
}
136
 
137 2 wfjm
if (! defined $file) {
138 12 wfjm
  print STDERR "config_wrapper-E: no bit or svf file specified\n";
139 2 wfjm
  exit 1;
140
}
141
if (! -r $file) {
142 12 wfjm
  print STDERR "config_wrapper-E: input file not found or readable\n";
143 2 wfjm
  exit 1;
144
}
145
 
146 12 wfjm
my $xilpath = $ENV{XILINX};
147
if (! defined $xilpath) {
148
  print STDERR "config_wrapper-E: XILINX environment variable not defined\n";
149
  exit 1;
150
}
151 2 wfjm
 
152 12 wfjm
# ----- iconfig action --------------------------------------------------------
153
if ($cmd eq "iconfig") {
154 2 wfjm
 
155 12 wfjm
  my $tmpfile = "tmp_config_wrapper.cmd";
156
  open (OFILE, ">$tmpfile") or die "Couldn't open tmp cmd file: $!";
157 2 wfjm
 
158 12 wfjm
  print  OFILE "setMode -bs\n";
159
  print  OFILE "setCable -p auto\n";
160
  for (my $i = 0; $i<=$#plist; $i++) {
161
    printf OFILE "addDevice -p %d -part %s\n", $i+1, $plist[$i];
162
  }
163
  printf OFILE "assignFile -p %d -file %s\n", $pfpga, $file;
164
  printf OFILE "program -p %d -verify\n", $pfpga;
165
  print  OFILE "quit\n";
166 2 wfjm
 
167 12 wfjm
  close (OFILE) or die "Couldn't close tmp cmd file: $!";
168
 
169
  my $rc  = run_command("impact -batch", $tmpfile);
170
  exit $rc;
171
 
172
# ----- jconfig action --------------------------------------------------------
173
} elsif ($cmd eq "jconfig") {
174
 
175
  my $bpath = join ";", map "$xilpath/$_",@blist;
176
 
177
  my $tmpfile = "tmp_config_wrapper.cmd";
178
  open (OFILE, ">$tmpfile") or die "Couldn't open tmp cmd file: $!";
179
 
180
  # the UrJtag and Xilinx impact have different chain and part number schemes
181
  #   impact: 1-based, 1 is first in chain;
182
  #   UrJtag: 0-based, 0 is last in chain;
183
  # e.g. on Digilent Nexys2:
184
  #   impact: (1) FPGA  (2) PROM
185
  #   UrJtag: (1) FPGA  (0) PROM
186
 
187
  my $jtag_part = $#plist + 1 - $pfpga;
188
 
189 17 wfjm
  # handle USB VID/PID of board
190
  #  taken from RETRO_FX2_VID and RETRO_FX2_PID environment variables
191
  #  in the retro11 project the default is:
192
  #    VID: 16c0  (VOTI)
193
  #    PID: 03ef  (VOTI free for internal lab use 1007)
194
  #
195
  #   !! Important Note on Usage of this USB VID/PID !!
196
  #   This VID/PID is owned by VOTI, a small dutch company. Usage is granted
197
  #   for 'internal lab use only' by VOTI under the conditions:
198
  #     - the gadgets in which you use those PIDs do not leave your desk
199
  #     - you won't complain to VOTI if you get in trouble with duplicate PIDs
200
  #       (for instance because someone else did not follow the previous rule).
201
  #   See also http://www.voti.nl/pids/pidfaq.html
202
  #
203
 
204
  my $fx2_vid = $ENV{RETRO_FX2_VID};
205
  my $fx2_pid = $ENV{RETRO_FX2_PID};
206
  $fx2_vid = "16c0" unless defined $fx2_vid;
207
  $fx2_pid = "03ef" unless defined $fx2_pid;
208
 
209
  # give vid/pid with 0x prefix. jtag #2007 requires this, #1502 tolerates
210
  print  OFILE "cable usbblaster vid=0x$fx2_vid pid=0x$fx2_pid\n";
211 12 wfjm
  printf OFILE "bsdl path %s\n", $bpath;
212
  print  OFILE "detect\n";
213
  printf OFILE "part %d\n", $jtag_part;
214
  printf OFILE "svf %s\n", $file;
215
 
216
  close (OFILE) or die "Couldn't close tmp cmd file: $!";
217
 
218
  my $rc  = run_command("jtag", $tmpfile);
219
  exit $rc;
220
 
221
# ----- bit2svf action --------------------------------------------------------
222
} elsif ($cmd eq "bit2svf") {
223
  my $ofile = $file;
224
  $ofile =~ s/\.bit/\.svf/;
225
 
226
  my $tmpfile = "tmp_config_wrapper.cmd";
227
  open (OFILE, ">$tmpfile") or die "Couldn't open tmp cmd file: $!";
228
 
229
  print  OFILE "setMode -bs\n";
230
  printf OFILE "setCable -port svf -file %s\n", $ofile;
231
  printf OFILE "addDevice -p 1 -file %s\n", $file;
232
  print  OFILE "program -p 1\n";
233
  print  OFILE "quit\n";
234
 
235
  close (OFILE) or die "Couldn't close tmp cmd file: $!";
236
 
237
  my $rc  = run_command("impact -batch", $tmpfile);
238
  exit $rc;
239
}
240
 
241
print STDERR "config_wrapper-E: command must be bit2svf, iconfig or jconfig\n";
242
exit 1;
243
 
244
#-------------------------------------------------------------------------------
245
 
246
sub run_command {
247
 
248
  my ($cmd, $tmpfile) = @_;
249
 
250
  my $wrc;
251
  if (defined $opts{dry_run}) {
252
    print STDOUT "$cmd\n";
253
    $wrc = system "/bin/sh", "-c", "cat $tmpfile";
254 2 wfjm
  } else {
255 12 wfjm
    $wrc = system "/bin/sh", "-c", "$cmd $tmpfile";
256 2 wfjm
  }
257
 
258 12 wfjm
  my $rc  = 0;
259
  if ($wrc != 0) {
260
    my $rc = int($wrc/256);
261
    if ($rc == 0) {
262
      my $sig = $wrc % 256;
263
      print STDERR "config_wrapper-I $cmd aborted by signal $sig\n";
264
      $rc = 1;
265
    } else {
266
      print STDERR "config_wrapper-I $cmd failed (rc=$rc) $?\n";
267
    }
268
  }
269 2 wfjm
 
270 12 wfjm
  unlink $tmpfile or die "Couldn't delete tmp cmd file: $!";
271
  return $rc;
272
}
273 2 wfjm
 
274
#-------------------------------------------------------------------------------
275
 
276
sub print_help {
277 12 wfjm
  print "usage: config_wrapper [--help] [--board=b] [--path=p] cmd file\n";
278
  print "  cmd              bit2svf or iconfig or jconfig\n";
279 2 wfjm
  print "  --help           this message\n";
280 12 wfjm
  print "  --dry_run        print impact command list\n";
281 2 wfjm
  print "  --board=b        type of board\n";
282
  print "  --path=p         type of fpga\n";
283
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.