A modified version of this code which I found on github

Original source: https://github.com/XenoKrelian/RpiJtag

-- removed almost all of jtag state machine infrastructure.
-- changed lots of loops and if clauses to be a little faster.
-- removed any attempt to support multiple device jtag chains (see original code
to potentially add it back in at some point.
-- removed bsd file reading (which didn't work out the box)
-- removed delays in command writing loops.
-- sped up bitstream writing by
  -- loading entire file into memory rather than bytewise in the programming loop
  -- only touch the TMS signal on the last byte, don't call GPIO_CLR on it
     for every intermediate byte
  -- track the current state of TDI, only call GPIO_CLR/SET when the value has changed

Currently can write a Kintex 7 325T bitstream (91Mb) in ~13 seconds. Tested with a KC705
Xilinx dev board. Mostly reliable. Currently running with ~nF caps on TDI/TCK/TMS. Programmed
OK the last ~8 times, provided PROG_B is manually toggled (push switch) between programming cycles.
Caps seem to have improved things, though I've made no effort to scope any signals yet.
After a failed programming run, reprogramming doesn't help unless PROG_B is toggled.

TODO:
- diagnose occasional programming failure.
- work out how to recover from failure without manual intervention
- refactoring.
- adapt for .bin (rather than .bit) files (aka .bof files)
- re-parameterise the delays so they can be put back in for debugging when necessary