wip
This commit is contained in:
parent
3e3aea8357
commit
df2fb3a5aa
|
|
@ -208,6 +208,8 @@ add_executable(openFPGALoader
|
||||||
${OPENFPGALOADER_HEADERS}
|
${OPENFPGALOADER_HEADERS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(fsread src/fsread.cpp src/configBitstreamParser.cpp src/fsparser.cpp src/display.cpp)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${LIBUSB_INCLUDE_DIRS}
|
${LIBUSB_INCLUDE_DIRS}
|
||||||
${LIBFTDI_INCLUDE_DIRS}
|
${LIBFTDI_INCLUDE_DIRS}
|
||||||
|
|
@ -300,6 +302,7 @@ endif()
|
||||||
if (ZLIB_FOUND)
|
if (ZLIB_FOUND)
|
||||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||||
target_link_libraries(openFPGALoader ${ZLIB_LIBRARIES})
|
target_link_libraries(openFPGALoader ${ZLIB_LIBRARIES})
|
||||||
|
target_link_libraries(fsread ${ZLIB_LIBRARIES})
|
||||||
add_definitions(-DHAS_ZLIB=1)
|
add_definitions(-DHAS_ZLIB=1)
|
||||||
else()
|
else()
|
||||||
message("zlib library not found: can't flash intel/altera devices")
|
message("zlib library not found: can't flash intel/altera devices")
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,24 @@ int FsParser::parseHeader()
|
||||||
case 0x0B: /* only present when bit_security is set */
|
case 0x0B: /* only present when bit_security is set */
|
||||||
_hdr["SecurityBit"] = "ON";
|
_hdr["SecurityBit"] = "ON";
|
||||||
break;
|
break;
|
||||||
case 0x10:
|
case 0x10: {
|
||||||
/* unknown conversion */
|
/* unknown conversion */
|
||||||
_hdr["loading_rate"] = to_string(0xff & (val >> 16));
|
unsigned rate = (val >> 16) & 0xff;
|
||||||
_compressed = 0x01 & (val >> 13);
|
if (rate) {
|
||||||
|
rate &= 0x7f;
|
||||||
|
rate ^= 0x44;
|
||||||
|
rate = (rate >> 2) + 1;
|
||||||
|
rate = 125000000/rate;
|
||||||
|
} else {
|
||||||
|
rate = 2500000; // default
|
||||||
|
}
|
||||||
|
_hdr["LoadingRate"] = to_string(rate);
|
||||||
|
_compressed = (val >> 13) & 1;
|
||||||
_hdr["Compress"] = (_compressed) ? "ON" : "OFF";
|
_hdr["Compress"] = (_compressed) ? "ON" : "OFF";
|
||||||
_hdr["ProgramDoneBypass"] = (0x01 & (val >> 12))?"ON":"OFF";
|
_hdr["ProgramDoneBypass"] = ((val >> 12) & 1) ? "ON" : "OFF";
|
||||||
|
printf("Loading Rate: %f MHz\n", rate*1e-6);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 0x12: /* unknown */
|
case 0x12: /* unknown */
|
||||||
break;
|
break;
|
||||||
case 0x51:
|
case 0x51:
|
||||||
|
|
@ -245,9 +256,10 @@ int FsParser::parse()
|
||||||
_checksum = 0;
|
_checksum = 0;
|
||||||
for (uint32_t pos = 0; pos < tmp.size(); pos+=16)
|
for (uint32_t pos = 0; pos < tmp.size(); pos+=16)
|
||||||
_checksum += (uint16_t)bitToVal(&tmp[pos], 16);
|
_checksum += (uint16_t)bitToVal(&tmp[pos], 16);
|
||||||
|
|
||||||
if (_verbose)
|
if (_verbose) {
|
||||||
printf("checksum 0x%04x\n", _checksum);
|
printf("checksum 0x%04x\n", _checksum);
|
||||||
|
}
|
||||||
|
|
||||||
printSuccess("Done");
|
printSuccess("Done");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "fsparser.hpp"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
FsParser fs(argv[1], true, 1);
|
||||||
|
fs.parse();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -200,8 +200,9 @@ Gowin::~Gowin()
|
||||||
bool Gowin::send_command(uint8_t cmd)
|
bool Gowin::send_command(uint8_t cmd)
|
||||||
{
|
{
|
||||||
_jtag->shiftIR(&cmd, nullptr, 8);
|
_jtag->shiftIR(&cmd, nullptr, 8);
|
||||||
_jtag->toggleClk(8);
|
_jtag->toggleClk(6);
|
||||||
|
_jtag->flush();
|
||||||
|
usleep(250);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,9 +225,11 @@ bool Gowin::send_command(uint8_t cmd)
|
||||||
|
|
||||||
uint32_t Gowin::readReg32(uint8_t cmd)
|
uint32_t Gowin::readReg32(uint8_t cmd)
|
||||||
{
|
{
|
||||||
uint32_t reg = 0, tmp = 0xff;
|
uint32_t reg = 0, tmp = 0xffffffffU;
|
||||||
send_command(cmd);
|
send_command(cmd);
|
||||||
_jtag->shiftDR((uint8_t *)&tmp, (uint8_t *)®, 32);
|
_jtag->shiftDR((uint8_t *)&tmp, (uint8_t *)®, 32);
|
||||||
|
_jtag->flush();
|
||||||
|
usleep(200);
|
||||||
return le32toh(reg);
|
return le32toh(reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,15 +244,15 @@ void Gowin::programFlash()
|
||||||
const uint8_t *data = _fs->getData();
|
const uint8_t *data = _fs->getData();
|
||||||
int length = _fs->getLength();
|
int length = _fs->getLength();
|
||||||
|
|
||||||
_jtag->setClkFreq(2500000);
|
_jtag->setClkFreq(3000000);
|
||||||
|
|
||||||
send_command(CONFIG_DISABLE);
|
send_command(CONFIG_DISABLE);
|
||||||
send_command(NOOP);
|
send_command(0);
|
||||||
_jtag->go_test_logic_reset();
|
_jtag->go_test_logic_reset();
|
||||||
_jtag->flush();
|
//_jtag->flush();
|
||||||
usleep(500*1000);
|
//usleep(500*1000);
|
||||||
|
|
||||||
eraseSRAM();
|
//eraseSRAM();
|
||||||
if (!eraseFLASH())
|
if (!eraseFLASH())
|
||||||
return;
|
return;
|
||||||
/* test status a faire */
|
/* test status a faire */
|
||||||
|
|
@ -481,6 +484,7 @@ inline uint32_t bswap_32(uint32_t x)
|
||||||
bool Gowin::writeFLASH(uint32_t page, const uint8_t *data, int length)
|
bool Gowin::writeFLASH(uint32_t page, const uint8_t *data, int length)
|
||||||
{
|
{
|
||||||
printInfo("Write FLASH ", false);
|
printInfo("Write FLASH ", false);
|
||||||
|
//return true;
|
||||||
uint8_t xpage[256];
|
uint8_t xpage[256];
|
||||||
length /= 8;
|
length /= 8;
|
||||||
for (int off = 0; off < length; off += 256) {
|
for (int off = 0; off < length; off += 256) {
|
||||||
|
|
@ -565,6 +569,15 @@ bool Gowin::writeSRAM(const uint8_t *data, int length)
|
||||||
bool Gowin::eraseFLASH()
|
bool Gowin::eraseFLASH()
|
||||||
{
|
{
|
||||||
printInfo("Erase Flash ", false);
|
printInfo("Erase Flash ", false);
|
||||||
|
send_command(CONFIG_DISABLE);
|
||||||
|
send_command(0);
|
||||||
|
send_command(CONFIG_DISABLE);
|
||||||
|
send_command(0);
|
||||||
|
readStatusReg();
|
||||||
|
readStatusReg();
|
||||||
|
readStatusReg();
|
||||||
|
readReg32(0x11);
|
||||||
|
usleep(500);
|
||||||
send_command(CONFIG_ENABLE);
|
send_command(CONFIG_ENABLE);
|
||||||
send_command(EFLASH_ERASE);
|
send_command(EFLASH_ERASE);
|
||||||
uint32_t tx = 0;
|
uint32_t tx = 0;
|
||||||
|
|
@ -574,20 +587,20 @@ bool Gowin::eraseFLASH()
|
||||||
_jtag->shiftDR((uint8_t *)&tx, NULL, 32);
|
_jtag->shiftDR((uint8_t *)&tx, NULL, 32);
|
||||||
}
|
}
|
||||||
sendClkUs(150*1000);
|
sendClkUs(150*1000);
|
||||||
if (_verbose)
|
|
||||||
displayReadReg(readStatusReg());
|
|
||||||
send_command(CONFIG_DISABLE);
|
send_command(CONFIG_DISABLE);
|
||||||
send_command(NOOP);
|
send_command(NOOP);
|
||||||
|
send_command(0x11);
|
||||||
send_command(CONFIG_DISABLE);
|
send_command(CONFIG_DISABLE);
|
||||||
send_command(NOOP);
|
send_command(NOOP);
|
||||||
send_command(RELOAD);
|
send_command(RELOAD);
|
||||||
send_command(NOOP);
|
send_command(NOOP);
|
||||||
|
_jtag->flush();
|
||||||
|
usleep(500*1000);
|
||||||
|
readReg32(0x11);
|
||||||
|
readReg32(0x11);
|
||||||
if (_verbose)
|
if (_verbose)
|
||||||
displayReadReg(readStatusReg());
|
displayReadReg(readStatusReg());
|
||||||
_jtag->flush();
|
_jtag->flush();
|
||||||
usleep(500*1000);
|
|
||||||
if (_verbose)
|
|
||||||
displayReadReg(readStatusReg());
|
|
||||||
printSuccess("Done");
|
printSuccess("Done");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -606,6 +619,19 @@ void Gowin::sendClkUs(unsigned us)
|
||||||
bool Gowin::eraseSRAM()
|
bool Gowin::eraseSRAM()
|
||||||
{
|
{
|
||||||
printInfo("Erase SRAM ", false);
|
printInfo("Erase SRAM ", false);
|
||||||
|
|
||||||
|
send_command(CONFIG_DISABLE);
|
||||||
|
send_command(0);
|
||||||
|
_jtag->go_test_logic_reset();
|
||||||
|
readReg32(0x11);
|
||||||
|
readReg32(0x41);
|
||||||
|
_jtag->go_test_logic_reset();
|
||||||
|
send_command(CONFIG_DISABLE);
|
||||||
|
send_command(0);
|
||||||
|
_jtag->go_test_logic_reset();
|
||||||
|
readReg32(0x41);
|
||||||
|
readReg32(0x11);
|
||||||
|
|
||||||
send_command(CONFIG_ENABLE);
|
send_command(CONFIG_ENABLE);
|
||||||
send_command(ERASE_SRAM);
|
send_command(ERASE_SRAM);
|
||||||
send_command(NOOP);
|
send_command(NOOP);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue