use RawParser for gowin mcu flashing
This commit is contained in:
parent
c3d13e8b75
commit
e44af80776
|
|
@ -83,7 +83,9 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
||||||
_spi_msk(BSCAN_SPI_MSK)
|
_spi_msk(BSCAN_SPI_MSK)
|
||||||
{
|
{
|
||||||
_fs = NULL;
|
_fs = NULL;
|
||||||
uint32_t idcode = _jtag->get_target_device_id();;
|
_mcufw = NULL;
|
||||||
|
|
||||||
|
uint32_t idcode = _jtag->get_target_device_id();
|
||||||
|
|
||||||
if (prg_type == Device::WR_FLASH)
|
if (prg_type == Device::WR_FLASH)
|
||||||
_mode = Device::FLASH_MODE;
|
_mode = Device::FLASH_MODE;
|
||||||
|
|
@ -159,23 +161,16 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
||||||
if (idcode != 0x0100981b)
|
if (idcode != 0x0100981b)
|
||||||
throw std::runtime_error("Microcontroller firmware flashing only supported on GW1NSR-4C");
|
throw std::runtime_error("Microcontroller firmware flashing only supported on GW1NSR-4C");
|
||||||
|
|
||||||
|
_mcufw = new RawParser(mcufw, false);
|
||||||
FILE *fd = fopen(mcufw.c_str(), "rb");
|
|
||||||
if (!fd)
|
|
||||||
throw std::runtime_error("Error: fail to open " + filename);
|
|
||||||
|
|
||||||
fseek(fd, 0, SEEK_END);
|
|
||||||
int file_size = ftell(fd);
|
|
||||||
fseek(fd, 0, SEEK_SET);
|
|
||||||
|
|
||||||
mcufwdata.resize(file_size);
|
if (_mcufw->parse() == EXIT_FAILURE) {
|
||||||
|
printError("FAIL");
|
||||||
|
delete _mcufw;
|
||||||
|
throw std::runtime_error("can't parse file");
|
||||||
|
} else {
|
||||||
|
printSuccess("DONE");
|
||||||
|
}
|
||||||
|
|
||||||
int ret = fread((char *) mcufwdata.data(), sizeof(char), file_size, fd);
|
|
||||||
fclose(fd);
|
|
||||||
if (ret != file_size)
|
|
||||||
throw std::runtime_error("Error: fail to read " + mcufw);
|
|
||||||
|
|
||||||
/* FIXME: implement checksum calculation */
|
|
||||||
skip_checksum = true;
|
skip_checksum = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -184,6 +179,8 @@ Gowin::~Gowin()
|
||||||
{
|
{
|
||||||
if (_fs)
|
if (_fs)
|
||||||
delete _fs;
|
delete _fs;
|
||||||
|
if (_mcufw)
|
||||||
|
delete _mcufw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gowin::reset()
|
void Gowin::reset()
|
||||||
|
|
@ -195,20 +192,16 @@ void Gowin::reset()
|
||||||
void Gowin::programFlash()
|
void Gowin::programFlash()
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
uint8_t *data;
|
|
||||||
int length;
|
|
||||||
uint8_t *mcu_data;
|
|
||||||
int mcu_length;
|
|
||||||
|
|
||||||
data = _fs->getData();
|
uint8_t *data = _fs->getData();
|
||||||
length = _fs->getLength();
|
int length = _fs->getLength();
|
||||||
|
|
||||||
if (mcufwdata.size() == 0) {
|
uint8_t *mcu_data = nullptr;
|
||||||
mcu_data = nullptr;
|
int mcu_length = 0;
|
||||||
mcu_length = 0;
|
|
||||||
} else {
|
if (_mcufw) {
|
||||||
mcu_data = (uint8_t *) mcufwdata.data();
|
mcu_data = _mcufw->getData();
|
||||||
mcu_length = mcufwdata.size() * 8;
|
mcu_length = _mcufw->getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* erase SRAM */
|
/* erase SRAM */
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,6 @@ class Gowin: public Device, SPIInterface {
|
||||||
uint8_t _spi_di; /**< di signal (mosi) offset in bscan SPI */
|
uint8_t _spi_di; /**< di signal (mosi) offset in bscan SPI */
|
||||||
uint8_t _spi_do; /**< do signal (miso) offset in bscan SPI */
|
uint8_t _spi_do; /**< do signal (miso) offset in bscan SPI */
|
||||||
uint8_t _spi_msk; /** default spi msk with only do out */
|
uint8_t _spi_msk; /** default spi msk with only do out */
|
||||||
std::string mcufwdata;
|
ConfigBitstreamParser *_mcufw;
|
||||||
};
|
};
|
||||||
#endif // GOWIN_HPP_
|
#endif // GOWIN_HPP_
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue