In some boards, like Papilio, spi flash connected only to fpga. As I can understand the firmware writes to flash through fpga. How does it works? Doesnt fpga need firmware first to work? If so, how it goes through fpga before any firmware was written in flash?
First of all, the whole point of JTAG is that it allows test software to manipulate the pins of the device in order to test their external connections to other devices on the board. The ability to manipulate the internal state of the device is a secondary function. So, it should be obvious that it will be possible to cause the pins to execute the protocol required to write data to the flash.
However, that tends to be rather slow in practice, because of the large number of JTAG transactions required to perform a single flash write. Therefore, most development systems download a small, fixed design to the FPGA whose only purpose is to write to the flash, and then they transfer the configuration data to it using a more efficient protocol (still over the JTAG interface).
There are several ways the FPGA can get its configuration:
The Spartan 6 LX9 FPGA has the ability to actively read its own configuration from the EEPROM via SPI.
See dataseheet: p.4
The Master Serial Peripheral Interface (SPI) and the Master Byte-wide Peripheral Interface (BPI) are two common methods used for configuring the FPGA. The Spartan-6 FPGA configures it self from a directly attached industry-standard SPI serial flash PROM. The Spartan-6 FPGA can configure itself via BPI when connected to an industry-standard parallel NOR flash. Note that BPI configuration is not supported in the XC6SLX 4, XC6SLX25, and XC6SLX25T nor is BPI available when using Spartan-6 FPGAs in TQG144 and CPG196 packages.
Another possibility is that a µController (or USB interface IC) "feeds" the FPGA with the configuration. The µC may get the configuration data from a EEPROM or via USB from a host PC.
- The third and probably most common way during development is to program the FPGA via the JTAG interface.
Once the firmware is loaded it tells the FPGA to do what ever you want (also writing to EEPROM via SPI if you please).