gowin: mcufw may be written without fs (but this erase all memory)

This commit is contained in:
Gwenhael Goavec-Merou 2023-12-14 13:13:29 +01:00
parent 2093ce7520
commit 22f33618b0
1 changed files with 15 additions and 6 deletions

View File

@ -260,8 +260,12 @@ void Gowin::reset()
void Gowin::programFlash() void Gowin::programFlash()
{ {
const uint8_t *data = _fs->getData(); const uint8_t *data = NULL;
int length = _fs->getLength(); int length = 0;
if (_fs) {
data = _fs->getData();
length = _fs->getLength();
}
_jtag->setClkFreq(2500000); // default for GOWIN, should use LoadingRate from file header _jtag->setClkFreq(2500000); // default for GOWIN, should use LoadingRate from file header
@ -281,14 +285,18 @@ void Gowin::programFlash()
if (!disableCfg()) if (!disableCfg())
return; return;
/* test status a faire */ /* test status a faire */
if (!writeFLASH(0, data, length)) if (data) {
return; if (!writeFLASH(0, data, length))
return;
}
if (_mcufw) { if (_mcufw) {
const uint8_t *mcu_data = _mcufw->getData(); const uint8_t *mcu_data = _mcufw->getData();
int mcu_length = _mcufw->getLength(); int mcu_length = _mcufw->getLength();
if (!writeFLASH(0x380, mcu_data, mcu_length)) if (!writeFLASH(0x380, mcu_data, mcu_length))
return; return;
} }
if (_verify) if (_verify)
printWarn("writing verification not supported"); printWarn("writing verification not supported");
@ -301,7 +309,8 @@ void Gowin::programFlash()
usleep(2*150*1000); usleep(2*150*1000);
/* check if file checksum == checksum in FPGA */ /* check if file checksum == checksum in FPGA */
if (!skip_checksum) /* don't try to read checksum in mcufw mode only */
if (!skip_checksum && data)
checkCRC(); checkCRC();
if (_verbose) if (_verbose)
@ -385,7 +394,7 @@ void Gowin::programSRAM()
void Gowin::program(unsigned int offset, bool unprotect_flash) void Gowin::program(unsigned int offset, bool unprotect_flash)
{ {
if (!_fs) if (!_fs && !_mcufw)
return; return;
if (_mode == FLASH_MODE) { if (_mode == FLASH_MODE) {