aboutsummaryrefslogtreecommitdiff
path: root/tcl/cpld/xilinx-xc6s.cfg
blob: 9ce7ad4918d43924bc0aa6316faf8bd53ab221cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# xilinx spartan6
# http://www.xilinx.com/support/documentation/user_guides/ug380.pdf

if { [info exists CHIPNAME] } {
	set _CHIPNAME $CHIPNAME
} else {
	set _CHIPNAME xc6s
}

# the 4 top bits (28:31) are the die stepping. ignore it.
jtag newtap $_CHIPNAME tap -irlen 6 -ignore-version \
	-expected-id 0x04000093 \
	-expected-id 0x04001093 \
	-expected-id 0x04002093 \
	-expected-id 0x04004093 \
	-expected-id 0x04024093 \
	-expected-id 0x04008093 \
	-expected-id 0x04028093 \
	-expected-id 0x0400E093 \
	-expected-id 0x0402E093 \
	-expected-id 0x04011093 \
	-expected-id 0x04031093 \
	-expected-id 0x0401D093 \
	-expected-id 0x0403D093

pld device virtex2 $_CHIPNAME.tap

set XC6S_CFG_IN 0x05
set XC6S_JSHUTDOWN 0x0d
set XC6S_JPROGRAM 0x0b
set XC6S_JSTART 0x0c
set XC6S_BYPASS 0x3f

proc xc6s_program {tap} {
	global XC6S_JSHUTDOWN XC6S_JPROGRAM XC6S_JSTART XC6S_BYPASS
	irscan $tap $XC6S_JSHUTDOWN
	irscan $tap $XC6S_JPROGRAM
	irscan $tap $XC6S_JSTART
	irscan $tap $XC6S_BYPASS
}

#xtp038 and xc3sprog approach
proc xc6s_program_iprog {tap} {
	global XC6S_JSHUTDOWN XC6S_JSTART XC6S_BYPASS XC6S_CFG_IN
	irscan $tap $XC6S_JSHUTDOWN
	runtest 16
	irscan $tap $XC6S_CFG_IN
	# xtp038 IPROG 16bit flipped
	drscan $tap 16 0xffff 16 0x9955 16 0x66aa 16 0x850c 16 0x7000 16 0x0004
	irscan $tap $XC6S_JSTART
	runtest 32
	irscan $tap $XC6S_BYPASS
	runtest 1
}

set XC6S_ISC_ENABLE 0x10
set XC6S_ISC_DISABLE 0x16
set XC6S_ISC_DNA 0x30

# Get the "Device DNA" from the Spartan 6.
# Most Xilinx FPGA devices contain an embedded, unique device identifier called
# the "Device DNA". The identifier is nonvolatile, permanently programmed into
# the FPGA, and is unchangeable providing a great serial / tracking number.
proc xc6s_get_dna {tap} {
	global XC6S_ISC_ENABLE XC6S_ISC_DISABLE XC6S_ISC_DNA
	irscan $tap $XC6S_ISC_ENABLE
	runtest 64
	irscan $tap $XC6S_ISC_DNA
	# Device DNA is 57 bits long, but we can only read 32bits at a time
	# with OpenOCD.
	set dna [drscan $tap 16 0 16 0 16 0 9 0]
	runtest 64
	irscan $tap $XC6S_ISC_DISABLE
	runtest 64

	# Convert the binary data into the order impact uses
	scan $dna "%x %x %x %x" v1 v2 v3 v4
	set bin_dna [string reverse [concat [format "%09b" $v4][format "%016b" $v3][format "%016b" $v2][format "%016b" $v1]]]

	# Return a hex version of binary
	scan [format "0b%s" $bin_dna] "%i" hex_dna
	return $hex_dna
}

# Print out the "Device DNA" in the same format that impact uses.
proc xc6s_print_dna {tap} {
	set hex_dna [xc6s_get_dna $tap]

	puts [format "DNA = %57b (0x%x)\n" $hex_dna $hex_dna]
}