tcl: add SPDX tag
[fw/openocd] / tcl / cpld / xilinx-xc6s.cfg
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 # xilinx spartan6
4 # http://www.xilinx.com/support/documentation/user_guides/ug380.pdf
5
6 if { [info exists CHIPNAME] } {
7         set _CHIPNAME $CHIPNAME
8 } else {
9         set _CHIPNAME xc6s
10 }
11
12 # the 4 top bits (28:31) are the die stepping. ignore it.
13 jtag newtap $_CHIPNAME tap -irlen 6 -ignore-version \
14         -expected-id 0x04000093 \
15         -expected-id 0x04001093 \
16         -expected-id 0x04002093 \
17         -expected-id 0x04004093 \
18         -expected-id 0x04024093 \
19         -expected-id 0x04008093 \
20         -expected-id 0x04028093 \
21         -expected-id 0x0400E093 \
22         -expected-id 0x0402E093 \
23         -expected-id 0x04011093 \
24         -expected-id 0x04031093 \
25         -expected-id 0x0401D093 \
26         -expected-id 0x0403D093
27
28 pld device virtex2 $_CHIPNAME.tap
29
30 set XC6S_CFG_IN 0x05
31 set XC6S_JSHUTDOWN 0x0d
32 set XC6S_JPROGRAM 0x0b
33 set XC6S_JSTART 0x0c
34 set XC6S_BYPASS 0x3f
35
36 proc xc6s_program {tap} {
37         global XC6S_JSHUTDOWN XC6S_JPROGRAM XC6S_JSTART XC6S_BYPASS
38         irscan $tap $XC6S_JSHUTDOWN
39         irscan $tap $XC6S_JPROGRAM
40         irscan $tap $XC6S_JSTART
41         irscan $tap $XC6S_BYPASS
42 }
43
44 #xtp038 and xc3sprog approach
45 proc xc6s_program_iprog {tap} {
46         global XC6S_JSHUTDOWN XC6S_JSTART XC6S_BYPASS XC6S_CFG_IN
47         irscan $tap $XC6S_JSHUTDOWN
48         runtest 16
49         irscan $tap $XC6S_CFG_IN
50         # xtp038 IPROG 16bit flipped
51         drscan $tap 16 0xffff 16 0x9955 16 0x66aa 16 0x850c 16 0x7000 16 0x0004
52         irscan $tap $XC6S_JSTART
53         runtest 32
54         irscan $tap $XC6S_BYPASS
55         runtest 1
56 }
57
58 set XC6S_ISC_ENABLE 0x10
59 set XC6S_ISC_DISABLE 0x16
60 set XC6S_ISC_DNA 0x30
61
62 # Get the "Device DNA" from the Spartan 6.
63 # Most Xilinx FPGA devices contain an embedded, unique device identifier called
64 # the "Device DNA". The identifier is nonvolatile, permanently programmed into
65 # the FPGA, and is unchangeable providing a great serial / tracking number.
66 proc xc6s_get_dna {tap} {
67         global XC6S_ISC_ENABLE XC6S_ISC_DISABLE XC6S_ISC_DNA
68         irscan $tap $XC6S_ISC_ENABLE
69         runtest 64
70         irscan $tap $XC6S_ISC_DNA
71         # Device DNA is 57 bits long, but we can only read 32bits at a time
72         # with OpenOCD.
73         set dna [drscan $tap 16 0 16 0 16 0 9 0]
74         runtest 64
75         irscan $tap $XC6S_ISC_DISABLE
76         runtest 64
77
78         # Convert the binary data into the order impact uses
79         scan $dna "%x %x %x %x" v1 v2 v3 v4
80         set bin_dna [string reverse [concat [format "%09b" $v4][format "%016b" $v3][format "%016b" $v2][format "%016b" $v1]]]
81
82         # Return a hex version of binary
83         scan [format "0b%s" $bin_dna] "%i" hex_dna
84         return $hex_dna
85 }
86
87 # Print out the "Device DNA" in the same format that impact uses.
88 proc xc6s_print_dna {tap} {
89         set hex_dna [xc6s_get_dna $tap]
90
91         puts [format "DNA = %57b (0x%x)\n" $hex_dna $hex_dna]
92 }