Configuration Bitstream Mapping with Programmable Resources on Spartan-3A FPGA using XDL and FAR

— Configuration bitstream in FPGA is specific to vendor. It is difficult to understand bitstream format and eventually impossible to know how bits are placed in LUTs, flip flop, multiplexer, input and output interconnection network in FPGA. Normally user is not interested in knowing internals of FPGA, however it is believed that by opening the internals of FPGA, development would become very fast as it is achieved by open source community. In this paper we have proposed a simplified methodology to map configuration bitstream to its programmable resources targeting Spartan-3A FPGA. A simple AND gate design implemented in VHDL under different constraints. Correlation between different locations of AND gate is established with frame address register, XDL file report, FPGA editor and device view in PlanAhead.

General structure of bitstream file Though fair amount of work is done to know bitstream format, this paper presents simple approach to understand FPGA bitstream and its mapping with resources on FPGA. Section II focused on related work done. FPGA generic architecture, design flow and bitstream format is described in section III. Preparation of background information is presented in section IV. A simple approach to analyze FPGA bitstream is elaborated in section V targeting Spartan-3A Xilinx FPGA. Results are discussed in section VI. At the end paper is concluded with conclusion in section VII.

II. RELATED WORK
FPGAs configuration bitstream is the final output of any VLSI CAD tool design methodology. In [1] database of mapping bitstream to their functional role is prepared using theoretical algorithm. This database is utilized to produce net list from any bitstream. The work shown in [1] is for Xilinx Virtex-II devices. Documentation on Xilinx Design Language (XDL) is scare. XDL provide access to almost all features of Xilinx devices. Various use cases and elaborated documentation provided in [2]. In [3], a method is presented to generate NCD from bitstream file.
Due to availability of official documents on internal architecture and configuration, it was possible for researchers to build development tools for FPGA. Alex and Clifford reversed engineered Lattice Semiconductor's iCE40 FPGA. This was first step towards the source tool chain for single FPGA [4]. "Bil" a reverse engineering tool presented in [5] retrieves netlist from bitstream for certain section of bitstream. VPR [6] performs packing, placement and routing. It maps technology mapped netlist to hypothetical FPGA specified by user. A low level bitstream manipulation tools BitMAT [7] and "BITMAN" [8] targeted Virtex-II FPGAs. A Java library named "abit" for direct manipulation of Atmel FPSLIC series bitstream and partial reconfiguration found in [9]. In [10] an open source tool based on library of micro-bitstream created for primitives and merged for creating larger design with simple merging operations. An open source tool set for reconfigurable computing presented in [11] is based on C++. Torc infrastructure can read, write, and manipulate EDIF and XDL netlist as well as Xilinx bitstream packets (but not configuration frame internals). Currently supported devices include all Virtex, VirtexE, Virtex2 pro, Virtex5, Virtex6, Virtex6L devices. PARBIT a tool in [12] extracts and relocates Virtex partial bitstream. The RapidSmith project [13] provide exclusive platform for implementing experimental idea, algorithms on Xilinx FPGAs.
Knowing bitstream format opens innovative approach for development in FPGA technology. Mostly, such type of work depends upon available documentation from vendor. But the vendor does open fair amount of information for end users and keeps certain information closed to avoid cloning of their devices. In this paper we have proposed a simple approach to map configuration bitstream to FPGA resources.
III. FPGA GENERIC ARCHITECTURE AND DESIGN FLOW FPGA means field programmable gate array. Any arbitrary digital function is implemented in FPGA. It can be programmed to implement desired hardware on it. Basic building blocks of FPGAs are configuration logic blocks (CLBs), I/O blocks, switch blocks, routing resources, memory blocks, and other dedicated functional block. The Fig. 2 gives general architecture of FPGA and Spartan -3A FPGA layout as viewed in PlanAhead design tool. A typical FPGA design flow consists of different stages like design entry, synthesis, mapping, place and route and bitstream generation. Fig. 3 depicts FPGA design flow. Three main stages of design are design entry and synthesis, design implementation and design verification [14]. Design entry is made either in schematic capture or in hardware design languages or with both. Synthesis is the process by which a given design is converted to logical design format (EDIF) or NGC file (by using Xilinx Synthesis Technology GUI). Design implementation converts the logical design format into Native Circuit Description (NCD) file. NCD file contains the physical information of FPGAs. The bitstream file generated after this stage is used to program the FPGA. In the last stage designer verifies whether the circuit meets timing and functionality requirements

IV. BACKGROUND: HDL-NCD-XDL
Listing 1 shows VHDL codes for two input AND gate. DPI1 and DIP2 are the two input ports and LED1 is the output port. Fig. 4 represents RTL schematic and Fig. 5 shows schematic of AND gate generated after VHDL codes compiled on Xilinx ISE Design Suite 14.7. Device utilization summary is given in Table 1. Other relevant information is generated by the tool. Here we gathered information necessary for mapping of FPGA configuration bitstream to its resources. "andGate.ncd" file is located in project folder directory. It is Native Circuit Description file which contains how HDL codes are mapped to physical resources like LUTs, flip flops, I/Os, routing etc. on FPGA. But it is not in human readable format. Xilinx Design Language is used to convert NCD file into human readable format. A command like "xdl -ncd2xdl andGate.ncd" converts NCD to XDL file. and Gate.xdc contains human readable information. A brief introduction of XDL is given by illustrating "andGate" example.

Xilinx Design Languages (XDL)
The NCD file contains all necessary information to implement the design on FPGA. But the NCD file format is Xilinx specific and it is not possible to analyze it. However, Xilinx has provided Xilinx Design Language in Xilinx ISE Design suite. It converts NCD file into XDL file which is human readable. Less information is available on XDL documentation.

XDL File Format
An XDL file is a text file contains information about the name of the design, intended Xilinx FPGA device and cfg attribute which allows user to configure the certain aspects of the design. It also lists logical slices, nets for routing design. The keyword "inst" is used to begin the instance statement. Instance is the instance of FPGA primitive. After the instance keyword the name of the instance is mentioned. It is followed by instance type. Placement of the slice is described by the keyword "placed" or "unplaced" after the instance type. A string beginning with "cfg" keyword used to configure the LUT contents and other functionality. Instance statement for DIP1 in case of AND gate example is given below. inst "DIP1" "IBUF", placed RIOIS_X17Y1 P78 The logic blocks are interconnected by the nets. FPGA fabric contains the static wires. The nets are used for routing purpose. A net has "outpin" as one starting point and "inpin" as endpoints (it can be multiple). The configuration in FPGAs routing structure is the connection between these nets. In Xilinx terminology these are called pips (programmable interconnect points). The inpin and outpin are connected by pip declaration. A set of pips declarations constitutes a single net. Pip is declared as "pip LOC S -> E" where pip is keyword, LOC is the location of pip, S is the starting point and E is the endpoint of the wire. Finally summary statements give statics of modules, instances and nets used in the design. Listing 2 summaries the description of XDL file format for "andGate" example compiled for XC3S50A Spartan-3A FPGA. Latter in the paper this design is named as "default" as it is compiled without any constraint.

Note:
In the above listing "cfg" keyword and its listing is not included.

Analysis of Configuration Bitstream
Bitstream files consist of a start header (Fig. 8), configuration data, bitstream final command (Fig.10) and start-up sequence. The start header contains information like design name, target device, file modification time, dummy word, synchronization word, reset CRC, device ID code, etc. The packets contain configuration commands and configuration data. The small state machine in FPGA controls configuration of programmable resources on FPGA. The command register in FPGA is either read or written by configuration information in data frames in bitstream. Always action taken by state machines is as per the command registers data. The data frames are loaded with configuration data as pointed by the frame address register (FAR). Configuration data frames can be, single frame, set of frames or full configuration space. During continuous writing of configuration data into FPGA, the FAR is automatically incremented after every FDRI write [17]. In this case frame length register (FLR) contains the length of data frame. It is written before the initiation of command to load block of data. Finally START, CRC checksum DESYNCH command are executed towards the end of bitstream file as shown in Figure 10 and Figure 11. Figure 8 and Fig. 10 shows starting and ending part of the bitstream file of AND gate example. The interpretation of each word in the frame is explained in Fig. 9 and Fig.11.

Decoding of Frame Address Register (FAR)
Frame addresses decoded for each of the design is shown in Table 3. All designs belongs to block type 0 containing CLBs, IOBs information. Major address selects major column and minor address selects memorycell address line within a major column. Column labelled with "M" indicates major address whereas "m" indicates minor address of frames. The addressing scheme gives the idea of the columns where the design lies vertically. Frame addresses and total number of frames required for implementation of design varies according to design type. Note: "M" indicates Major Address and "m" indicates minor address.

Matching and Mismatching Patterns in Configuration Bitstream
Extended Spartan-3A device, XC3S50A has 367 device frames. Result of match and mismatch pattern in configuration bitstream shown in Fig. 12.  Table 4 indicated the count of match and mismatch patterns as observed in each bitstream file. Also, it gives total count of combined pattern. The frame address for which mismatch pattern were observed are mentioned in Table 3. The mismatch pattern in bitstream file contains information about the implemented designs. Though the HDL codes are same for each design, the location of each design is different on FPGA tiles. For each of the design the mismatch patterns count is different. This is because the routing structure is different for each design. Routing of designs viewed in FPGA editor. Fig. 13 (a) depicts routing structure for default design. Three switch boxes are used for routing. Default design is located by placement and routing tool at bottom right corner of the layout. Fig. 13(b) depicts routing structure for design with const_4. This design resides in middle portion of the layout.
For the default design LUT belongs to SLICE_X23Y0 of CLB_X16Y1. This is also included in statement, "inst "LED1_OBUF" "SLICEL", placed CLB_X16Y1 SLICE_X23Y0" in XDL file generated from NCD file. Also the instance statement for instances DIP1, DIP2 and LED1 are : inst "DIP1" "IBUF", placed RIOIS_X17Y1 P78 , inst "DIP2" "IBUF", placed BIOIS_X16Y0 P72, inst "LED1" "IOB", placed RIOIS_X17Y1 P76 respectively. The instance view shown in Fig. 14  The detail view of SLICE_X23Y0 as viewed in FPGA editor is depicted Fig. 15. Likewise view for other instances generated and routing of nets related with XDL file obtained in listing 2.

VII. CONCLUSION
A simplified straight approach to map FPGAs resources to its HDL description is demonstrated in this paper. We found that information in XDL file derived from NCD file is in human readable form and helps to develop the understanding of FPGA design layout. Xilinx ISE Design suite and PlanAhead tool played vital role in analysis. Though we are able to locate FPGA design location vertically with addresses information in FAR_MAJ register, configuration information pointed by FAR_MIN address register is yet not decoded for Spartan-3A FPGA by our approach. We observed that as we move any design from bottom-left position to topleft position to top-right position to top-bottom position, the configuration information in bitstream goes away and away form starting position of bitstream file. The addition of "Match Pattern" and the "Mismatch Pattern" in configuration bitstream file equals 368 for all design under study.