colognechip: add bulk erase + quad enable features and simplify spi_wait overload

This commit is contained in:
Patrick Urban 2025-09-03 14:59:06 +02:00
parent 501d37e351
commit 5f0dbfc42c
2 changed files with 45 additions and 11 deletions

View File

@ -213,6 +213,45 @@ bool CologneChip::dumpFlash(uint32_t base_addr, uint32_t len)
return post_flash_access();
}
/**
* Set QE bit, if available. Works in both SPI and JTAG-SPI-bypass mode.
*/
bool CologneChip::set_quad_bit(bool set_quad)
{
/* prepare SPI access */
prepare_flash_access();
printInfo("Update Quad Enable Bit ", false);
try {
std::unique_ptr<SPIFlash> flash(_spi ?
new SPIFlash(reinterpret_cast<SPIInterface *>(_spi), false, _verbose):
new SPIFlash(this, false, _verbose));
flash->set_quad_bit(set_quad);
} catch (std::exception &e) {
printError("Fail");
printError(std::string(e.what()));
return false;
}
return post_flash_access();
}
/**
* Peform bulk erase. Works in both SPI and JTAG-SPI-bypass mode.
*/
bool CologneChip::bulk_erase_flash()
{
/* prepare SPI access */
prepare_flash_access();
printInfo("Bulk Erase ", false);
if (!SPIInterface::bulk_erase_flash()) {
return false;
}
return post_flash_access();
}
/**
* Parse bitstream from *.bit or *.cfg and program FPGA in SPI or JTAG mode
* or write configuration to external flash via SPI or JTAG-SPI-bypass.
@ -450,15 +489,10 @@ int CologneChip::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
_jtag->read_write(&tx, NULL, 8, 0);
do {
if (count == 0) {
_jtag->read_write(dummy, rx, 16, 0);
uint8_t b0 = ConfigBitstreamParser::reverseByte(rx[0]);
uint8_t b1 = ConfigBitstreamParser::reverseByte(rx[1]);
tmp = (b0 << 1) | ((b1 >> 7) & 0x01);
} else {
_jtag->read_write(dummy, rx, 8, 0);
tmp = ConfigBitstreamParser::reverseByte(rx[0]);
}
_jtag->read_write(dummy, rx, 16, 0);
uint8_t b0 = ConfigBitstreamParser::reverseByte(rx[0]);
uint8_t b1 = ConfigBitstreamParser::reverseByte(rx[1]);
tmp = (b0 << 1) | ((b1 >> 7) & 0x01);
count++;
if (count == timeout) {

View File

@ -42,8 +42,8 @@ class CologneChip: public Device, SPIInterface {
printError("protect flash not supported"); return false;}
virtual bool unprotect_flash() override {
printError("unprotect flash not supported"); return false;}
virtual bool bulk_erase_flash() override {
printError("bulk erase flash not supported"); return false;}
bool set_quad_bit(bool set_quad) override;
bool bulk_erase_flash() override;
void program(unsigned int offset, bool unprotect_flash) override;
uint32_t idCode() override {return 0;}