From ffa006d0ee6ae90e8757fea4c553f76324445e35 Mon Sep 17 00:00:00 2001 From: Jean THOMAS Date: Wed, 11 Dec 2024 12:01:37 +0100 Subject: [PATCH] Add 'user-flash' CLI argument --- doc/vendors/gowin.rst | 14 ++++++++++++++ src/gowin.cpp | 4 ++-- src/gowin.hpp | 3 ++- src/main.cpp | 5 ++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/vendors/gowin.rst b/doc/vendors/gowin.rst index 63f4ac1..103c3e3 100644 --- a/doc/vendors/gowin.rst +++ b/doc/vendors/gowin.rst @@ -62,3 +62,17 @@ It's possible to flash external SPI Flash (connected to MSPI) in bscan mode by u Gowin's FPGA may fails to be detected if **JTAGSEL_N** (pin 08 for *GW1N-4K*) is used as a GPIO. To recover you have to pull down this pin (before power up) to recover JTAG interface (*UG292 - JTAGSELL_N section*). + +User Flash +---------- + +.. ATTENTION:: + User Flash support is based on reverse engineering of the JTAG protocol. This functionality should be considered + experimental as it hasn't been thoroughly tested, and may in some circumstances destroy your device. + +Gowin FPGA come with extra flash space that can be read and written from the programmable logic ("User Flash"). This +flash section can also be programmed via the JTAG interface: + +.. code-block:: bash + + openFPGALoader --write-flash /path/to/bitstream.fs --user-flash /path/to/flash.bin diff --git a/src/gowin.cpp b/src/gowin.cpp index afccb56..1bf042a 100644 --- a/src/gowin.cpp +++ b/src/gowin.cpp @@ -77,8 +77,8 @@ using namespace std; Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::string mcufw, Device::prog_type_t prg_type, bool external_flash, - bool verify, int8_t verbose): Device(jtag, filename, file_type, - verify, verbose), + bool verify, int8_t verbose, const std::string& user_flash) + : Device(jtag, filename, file_type, verify, verbose), SPIInterface(filename, verbose, 0, verify, false, false), _idcode(0), is_gw1n1(false), is_gw1n4(false), is_gw1n9(false), is_gw2a(false), is_gw5a(false), diff --git a/src/gowin.hpp b/src/gowin.hpp index 0b15855..d8816d9 100644 --- a/src/gowin.hpp +++ b/src/gowin.hpp @@ -22,7 +22,8 @@ class Gowin: public Device, SPIInterface { public: Gowin(Jtag *jtag, std::string filename, const std::string &file_type, std::string mcufw, Device::prog_type_t prg_type, - bool external_flash, bool verify, int8_t verbose); + bool external_flash, bool verify, int8_t verbose, + const std::string& user_flash); uint32_t idCode() override; void reset() override; void program(unsigned int offset, bool unprotect_flash) override; diff --git a/src/main.cpp b/src/main.cpp index 9c1b138..bb17445 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,6 +97,7 @@ struct arguments { bool read_dna; bool read_xadc; string read_register; + string user_flash; }; int run_xvc_server(const struct arguments &args, const cable_t &cable, @@ -582,7 +583,7 @@ int main(int argc, char **argv) args.verify, args.verbose); } else if (fab == "Gowin") { fpga = new Gowin(jtag, args.bit_file, args.file_type, args.mcufw, - args.prg_type, args.external_flash, args.verify, args.verbose); + args.prg_type, args.external_flash, args.verify, args.verbose, args.user_flash); } else if (fab == "lattice") { fpga = new Lattice(jtag, args.bit_file, args.file_type, args.prg_type, args.flash_sector, args.verify, args.verbose, args.skip_load_bridge, args.skip_reset); @@ -871,6 +872,8 @@ int parse_opt(int argc, char **argv, struct arguments *args, cxxopts::value(args->read_xadc)) ("read-register", "Read Status Register(Xilinx FPGA only)", cxxopts::value(rd_reg)) + ("user-flash", "User flash file (Gowin LittleBee FPGA only)", + cxxopts::value(args->user_flash)) ("V,Version", "Print program version"); options.parse_positional({"bitstream"});