litex: reorganize things, first work working version
[litex.git] / litex / build / lattice / programmer.py
1 import os
2 import subprocess
3
4 from litex.build.generic_programmer import GenericProgrammer
5 from litex.build import tools
6
7
8 # XXX Lattice programmer need an .xcf file, will need clean up and support for more parameters
9 _xcf_template = """
10 <?xml version='1.0' encoding='utf-8' ?>
11 <!DOCTYPE ispXCF SYSTEM "IspXCF.dtd" >
12 <ispXCF version="3.4.1">
13 <Comment></Comment>
14 <Chain>
15 <Comm>JTAG</Comm>
16 <Device>
17 <SelectedProg value="TRUE"/>
18 <Pos>1</Pos>
19 <Vendor>Lattice</Vendor>
20 <Family>LatticeECP3</Family>
21 <Name>LFE3-35EA</Name>
22 <File>{bitstream_file}</File>
23 <Operation>Fast Program</Operation>
24 </Device>
25 </Chain>
26 <ProjectOptions>
27 <Program>SEQUENTIAL</Program>
28 <Process>ENTIRED CHAIN</Process>
29 <OperationOverride>No Override</OperationOverride>
30 <StartTAP>TLR</StartTAP>
31 <EndTAP>TLR</EndTAP>
32 <VerifyUsercode value="FALSE"/>
33 </ProjectOptions>
34 <CableOptions>
35 <CableName>USB2</CableName>
36 <PortAdd>FTUSB-0</PortAdd>
37 <USBID>Dual RS232-HS A Location 0000 Serial A</USBID>
38 <JTAGPinSetting>
39 TRST ABSENT;
40 ISPEN ABSENT;
41 </JTAGPinSetting>
42 </CableOptions>
43 </ispXCF>
44 """
45
46
47 class LatticeProgrammer(GenericProgrammer):
48 needs_bitreverse = False
49
50 def load_bitstream(self, bitstream_file):
51 xcf_file = bitstream_file.replace(".bit", ".xcf")
52 xcf_content = _xcf_template.format(bitstream_file=bitstream_file)
53 tools.write_to_file(xcf_file, xcf_content)
54 subprocess.call(["pgrcmd", "-infile", xcf_file])