openocd/tcl/fpga/xilinx-dna.cfg
Antonio Borneo f5657aa76e tcl: [1/3] prepare for jimtcl 0.81 'expr' syntax change
Jimtcl commit 1843b79a03dd ("expr: TIP 526, only support a single
arg") drops the support for multi-argument syntax for the TCL
command 'expr'.

In the TCL scripts distributed with OpenOCD there are 1700+ lines
that should be modified before switching to jimtcl 0.81.

Apply the script below on every script in tcl folder. It fixes
more than 92% of the lines

%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---
 #!/usr/bin/perl -Wpi

 my $re_sym = qr{[a-z_][a-z0-9_]*}i;
 my $re_var = qr{(?:\$|\$::)$re_sym};
 my $re_const = qr{0x[0-9a-f]+|[0-9]+|[0-9]*\.[0-9]*}i;
 my $re_item = qr{(?:~\s*)?(?:$re_var|$re_const)};
 my $re_op = qr{<<|>>|[+\-*/&|]};
 my $re_expr = qr{(
     (?:\(\s*(?:$re_item|(?-1))\s*\)|$re_item)
     \s*$re_op\s*
     (?:$re_item|(?-1)|\(\s*(?:$re_item|(?-1))\s*\))
 )}x;

 # [expr [dict get $regsC100 SYM] + HEXNUM]
 s/\[expr (\[dict get $re_var $re_sym\s*\] \+ *$re_const)\]/\[expr \{$1\}\]/;

 # [ expr (EXPR) ]
 # [ expr EXPR ]
 # note: $re_expr captures '$3'
 s/\[(\s*expr\s*)\((\s*$re_expr\s*)\)(\s*)\]/\[$1\{$2\}$4\]/;
 s/\[(\s*expr\s*)($re_expr)(\s*)\]/\[$1\{$2\}$4\]/;
%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---%<---

Change-Id: I0d6bddc6abf6dd29062f2b4e72b5a2b5080293b9
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6159
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2021-05-08 09:48:44 +01:00

44 lines
1.2 KiB
INI

proc xilinx_dna_addr {chip} {
array set addrs {
Spartan6 0x30
Series7 0x17
}
return $addrs($chip)
}
# Get the "Device DNA".
# Most Xilinx FPGA devices contain an embedded, unique device identifier.
# The identifier is nonvolatile, permanently programmed into
# the FPGA, and is unchangeable providing a great serial / tracking number.
# This function returns the DNA as a 64 bit integer with the 7 LSBs zeroed.
# This is compatible with the FUSE DNA which contains all 64 bits.
proc xilinx_get_dna {tap chip} {
set XC7_ISC_ENABLE 0x10
set XC7_ISC_DISABLE 0x16
set XC7_ISC_DNA [xilinx_dna_addr $chip]
irscan $tap $XC7_ISC_ENABLE
runtest 64
irscan $tap $XC7_ISC_DNA
scan [drscan $tap 32 0 32 0] "%08x %08x" hi lo
runtest 64
irscan $tap $XC7_ISC_DISABLE
runtest 64
# openocd interprets DR scans as LSB first, bit-reverse it
return [scan [string reverse [format "%032b%032bb0" $lo $hi]] "%i"]
}
# Print out the "Device DNA" in the same format that impact uses.
proc xilinx_print_dna {dna} {
set dna [expr {$dna >> 64 - 57}]
echo [format "DNA = %057b (0x%016x)" $dna $dna]
}
proc xc7_get_dna {tap} {
return [xilinx_get_dna $tap Series7]
}
proc xc6s_get_dna {tap} {
return [xilinx_get_dna $tap Spartan6]
}