Using Xilinx iMPACT in batch mode
When using Xilinx ISE for programming CPLDs, there are two steps needed for programming:
- first implement the design (thats the process taking all the sources and translate to a SVF file)
- and then use iMPACT for program the CPLD with the SVF file
But when I started working with FPGA (with the new Numato Labs FPGA boards, I found out that there are now four steps involved until the design can be tested:
- first step is still implementing the design
- the a programming file needs to be created in ISE (thats the bit-stream file)
- then iMPACT can take the bit-stream file and creates a PROM file
- the last step is using iMPACT to transfer the PROM file into the Flash memory on the FPGA board
When checking whether a design can be translated properly, and adheres to all timing requirements, only the first step (design implementation) is needed. After that, all three steps need to be executed - every time. Thats tedious, and one even needs to have two different iMPACT projects for the last two steps (and the second one doesn’t seem to pick up changes to the PROM file, so iMPACT needs to restarted).
So it got time to automate this.
There are several ways to do this. Xilinx provides the ‘xflow’ tool which is kind of ‘make’ for its tool-set. Also, all tools can be scripted with TCL. But all of this has a steep learning curve, though the documentation is extensive. Fortunately iMPACT also provides a batch mode, which allows for easy scripting.
One of the easiest way to get started with it is to just execute the steps one needs to do, and the look for an ‘_impact.log’ file in the current folder. It contains a log of the last session, in form of iMPACT scripting command. One can just take this file and hand it over to iMPACT again.
Generating a batch file
So thats what I did. I run all the steps to be done in iMPACT, and took their recording. The resulting script file contains a lot of repeating and superfluous steps (mainly involving setting the current mode), which I removed manually. I then took the two script file (since there were two sessions involved) and combined them into one. This results in the following file (named impact_go.cmd):
setMode -pff addConfigDevice -name "main.mcs" -path "." setSubmode -pffspi setAttribute -configdevice -attr multibootBpiType -value "" addDesign -version 0 -name "0" addDeviceChain -index 0 addDeviceChain -index 0 setAttribute -configdevice -attr compressed -value "FALSE" setAttribute -configdevice -attr compressed -value "FALSE" setAttribute -configdevice -attr autoSize -value "FALSE" setAttribute -configdevice -attr fileFormat -value "mcs" setAttribute -configdevice -attr fillValue -value "FF" setAttribute -configdevice -attr swapBit -value "FALSE" setAttribute -configdevice -attr dir -value "UP" setAttribute -configdevice -attr multiboot -value "FALSE" setAttribute -configdevice -attr multiboot -value "FALSE" setAttribute -configdevice -attr spiSelected -value "TRUE" setAttribute -configdevice -attr spiSelected -value "TRUE" addPromDevice -p 1 -size 2048 -name 2M addDeviceChain -index 0 addDeviceChain -index 0 setAttribute -design -attr name -value "0000" addDevice -p 1 -file "./main.bit" generate setMode -bs setCable -port parport0 Identify -inferir identifyMPM attachflash -position 1 -spi "M25P16" assignfiletoattachedflash -position 1 -file "./main.mcs" Program -p 1 -dataWidth 1 -spionly -e -v -loadfpga exit
Running a batch file in Xilinx iMPACT
One can then execute this via
~/bin/impact.sh -batch impact_go.cmd
(impact.sh is the script I use for loading the proper libraries on Linux)
So this merges the last two steps into one, and don’t need any interaction. First, the current mode for impact is set to ‘pff’, which corresponds to a project for generating a PROM file. Then all the needed configuration for the Saturn / Mimas boards is set (both use a Spartan 6A LX9), and the same Flash memory chip. After that, the PROM device is added to the device chain (this is how iMPACT internally handles everything), and as a last step (for the first part of the script) the PROM file is generated (called ‘main.bit’).
In the next step the current mode for iMPACT is changed to ‘bs’ which is the ‘boundary scan’ mode, used for real programming. First the cable is selected (a DLC5 parallel cable for me). Then the devices connected to it are identified (so iMPACT should find the LX9 here). If this succeeds, the attached Flash is configured (with the proper chip type), and as a last step the real programming runs.
One drawback of the iMPACT batch mode is that one cannot hand over additional parameters, So the name of the bit-stream file (‘main.mcs’ above) is hard-coded inside the command file. But since it is most likely created only once, this seems OK to me.
So what about the second step - generating the bit-stream file? Fortunately when generating that in ISE, the command executed here is written to the log file. So we can extend to command above into
${ISE_124_HOME}/ISE_DS/ISE/bin/lin64/bitgen -intstyle ise -f main.ut main.ncd && ~/bin/impact.sh -batch impact_go.cmd
The ‘bitgen’ command is responsible for doing all the work - replace its path with where it is in your installation.
So now I can just implement the design in IDE, check that this runs OK, and program the FPGA with a single command. Problem solved.