From fe0b4d347b72ada9a2f927bff53c502737d9b46e Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Thu, 16 Jun 2022 09:52:44 +0800 Subject: [PATCH] gowin: add support for GW2A GW2A has no internal flash, and it uses a yet unknown checksum algorithm. Support it by forcing external flash and skip checksum check now. Signed-off-by: Icenowy Zheng --- src/gowin.cpp | 44 ++++++++++++++++++++++++++++++-------------- src/gowin.hpp | 1 + 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/gowin.cpp b/src/gowin.cpp index a4a5413..604ff7d 100644 --- a/src/gowin.cpp +++ b/src/gowin.cpp @@ -141,6 +141,18 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, _spi_do = BSCAN_GW1NSR_4C_SPI_DO; _spi_msk = BSCAN_GW1NSR_4C_SPI_MSK; } + + /* + * GW2 series has no internal flash and uses new bitstream checksum + * algorithm that is not yet supported. + */ + switch (idcode) { + case 0x0000081b: /* GW2A(R)-18(C) */ + case 0x0000281b: /* GW2A(R)-55(C) */ + _external_flash = true; + /* FIXME: implement GW2 checksum calculation */ + skip_checksum = true; + }; } Gowin::~Gowin() @@ -193,13 +205,15 @@ void Gowin::programFlash() usleep(2*150*1000); /* check if file checksum == checksum in FPGA */ - status = readUserCode(); - int checksum = static_cast(_fs)->checksum(); - if (checksum != status) { - printError("CRC check : FAIL"); - printf("%04x %04x\n", checksum, status); - } else { - printSuccess("CRC check: Success"); + if (!skip_checksum) { + status = readUserCode(); + int checksum = static_cast(_fs)->checksum(); + if (checksum != status) { + printError("CRC check : FAIL"); + printf("%04x %04x\n", checksum, status); + } else { + printSuccess("CRC check: Success"); + } } if (_verbose) @@ -276,13 +290,15 @@ void Gowin::program(unsigned int offset, bool unprotect_flash) return; /* check if file checksum == checksum in FPGA */ - status = readUserCode(); - uint32_t checksum = static_cast(_fs)->checksum(); - if (checksum != status) { - printError("SRAM Flash: FAIL"); - printf("%04x %04x\n", checksum, status); - } else { - printSuccess("SRAM Flash: Success"); + if (!skip_checksum) { + status = readUserCode(); + uint32_t checksum = static_cast(_fs)->checksum(); + if (checksum != status) { + printError("SRAM Flash: FAIL"); + printf("%04x %04x\n", checksum, status); + } else { + printSuccess("SRAM Flash: Success"); + } } if (_verbose) displayReadReg(readStatusReg()); diff --git a/src/gowin.hpp b/src/gowin.hpp index 8523ca0..d26889e 100644 --- a/src/gowin.hpp +++ b/src/gowin.hpp @@ -54,6 +54,7 @@ class Gowin: public Device, SPIInterface { uint32_t readUserCode(); ConfigBitstreamParser *_fs; bool is_gw1n1; + bool skip_checksum; bool _external_flash; /**< select between int or ext flash */ uint8_t _spi_sck; /**< clk signal offset in bscan SPI */ uint8_t _spi_cs; /**< cs signal offset in bscan SPI */