Skip to content

Commit 3cf558e

Browse files
committed
colognechip: added a workaround to drive reset pin with DirtyJTAG cable
(requires a recent DirtyJTAG firmware)
1 parent 3c7324d commit 3cf558e

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

src/colognechip.cpp

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ CologneChip::CologneChip(Jtag* jtag, const std::string &filename,
4646
ftdi_board_name = std::regex_replace(board_name, std::regex("jtag"), "spi");
4747
} else if (cable_name == "gatemate_pgm") {
4848
ftdi_board_name = "gatemate_pgm_spi";
49+
} else if (cable_name == "dirtyJtag") {
50+
_dirtyjtag = reinterpret_cast<DirtyJtag *>(_jtag->_jtag);
51+
_rstn_pin = (1 << 6);
52+
_done_pin = 0;
53+
_fail_pin = 0;
54+
_oen_pin = 0;
4955
}
5056

5157
if (ftdi_board_name != "") {
@@ -84,6 +90,10 @@ void CologneChip::reset()
8490
_ftdi_jtag->gpio_clear(_rstn_pin | _oen_pin);
8591
usleep(SLEEP_US);
8692
_ftdi_jtag->gpio_set(_rstn_pin);
93+
} else if (_dirtyjtag) {
94+
_dirtyjtag->gpio_clear(_rstn_pin);
95+
_dirtyjtag->gpio_set(_rstn_pin);
96+
usleep(SLEEP_US);
8797
}
8898
}
8999

@@ -123,10 +133,7 @@ void CologneChip::waitCfgDone()
123133
}
124134
}
125135

126-
/**
127-
* Dump flash contents to file. Works in both SPI and JTAG-SPI-bypass mode.
128-
*/
129-
bool CologneChip::detect_flash()
136+
bool CologneChip::prepare_flash_access()
130137
{
131138
if (_spi) {
132139
/* enable output and hold reset */
@@ -135,9 +142,37 @@ bool CologneChip::detect_flash()
135142
/* enable output and disable reset */
136143
_ftdi_jtag->gpio_clear(_oen_pin);
137144
_ftdi_jtag->gpio_set(_rstn_pin);
145+
} else if (_dirtyjtag) {
146+
_dirtyjtag->gpio_clear(_rstn_pin);
147+
_dirtyjtag->gpio_set(_rstn_pin);
148+
usleep(SLEEP_US);
138149
}
139150

151+
return true;
152+
}
153+
154+
bool CologneChip::post_flash_access()
155+
{
156+
if (_spi) {
157+
/* disable output and release reset */
158+
_spi->gpio_set(_rstn_pin | _oen_pin);
159+
} else if (_ftdi_jtag) {
160+
/* disable output */
161+
_ftdi_jtag->gpio_set(_oen_pin);
162+
}
163+
usleep(SLEEP_US);
164+
165+
return true;
166+
}
167+
168+
/**
169+
* Dump flash contents to file. Works in both SPI and JTAG-SPI-bypass mode.
170+
*/
171+
bool CologneChip::detect_flash()
172+
{
140173
/* prepare SPI access */
174+
prepare_flash_access();
175+
141176
printInfo("Read Flash ", false);
142177
try {
143178
std::unique_ptr<SPIFlash> flash(_spi ?
@@ -151,33 +186,17 @@ bool CologneChip::detect_flash()
151186
return false;
152187
}
153188

154-
if (_spi) {
155-
/* disable output and release reset */
156-
_spi->gpio_set(_rstn_pin | _oen_pin);
157-
} else if (_ftdi_jtag) {
158-
/* disable output */
159-
_ftdi_jtag->gpio_set(_oen_pin);
160-
}
161-
usleep(SLEEP_US);
162-
163-
return true;
189+
return post_flash_access();
164190
}
165191

166192
/**
167193
* Dump flash contents to file. Works in both SPI and JTAG-SPI-bypass mode.
168194
*/
169195
bool CologneChip::dumpFlash(uint32_t base_addr, uint32_t len)
170196
{
171-
if (_spi) {
172-
/* enable output and hold reset */
173-
_spi->gpio_clear(_rstn_pin | _oen_pin);
174-
} else if (_ftdi_jtag) {
175-
/* enable output and disable reset */
176-
_ftdi_jtag->gpio_clear(_oen_pin);
177-
_ftdi_jtag->gpio_set(_rstn_pin);
178-
}
179-
180197
/* prepare SPI access */
198+
prepare_flash_access();
199+
181200
printInfo("Read Flash ", false);
182201
try {
183202
std::unique_ptr<SPIFlash> flash(_spi ?
@@ -190,16 +209,7 @@ bool CologneChip::dumpFlash(uint32_t base_addr, uint32_t len)
190209
return false;
191210
}
192211

193-
if (_spi) {
194-
/* disable output and release reset */
195-
_spi->gpio_set(_rstn_pin | _oen_pin);
196-
} else if (_ftdi_jtag) {
197-
/* disable output */
198-
_ftdi_jtag->gpio_set(_oen_pin);
199-
}
200-
usleep(SLEEP_US);
201-
202-
return true;
212+
return post_flash_access();
203213
}
204214

205215
/**

src/colognechip.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313

1414
#include "device.hpp"
15+
#include "dirtyJtag.hpp"
1516
#include "jtag.hpp"
1617
#include "ftdispi.hpp"
1718
#include "ftdiJtagMPSSE.hpp"
@@ -48,6 +49,10 @@ class CologneChip: public Device, SPIInterface {
4849
uint32_t idCode() override {return 0;}
4950
void reset() override;
5051

52+
protected:
53+
bool prepare_flash_access() override;
54+
bool post_flash_access() override;
55+
5156
private:
5257
void programSPI_sram(const uint8_t *data, int length);
5358
void programSPI_flash(unsigned int offset, const uint8_t *data, int length,
@@ -65,6 +70,7 @@ class CologneChip: public Device, SPIInterface {
6570

6671
FtdiSpi *_spi = NULL;
6772
FtdiJtagMPSSE *_ftdi_jtag = NULL;
73+
DirtyJtag *_dirtyjtag = NULL;
6874
uint16_t _rstn_pin;
6975
uint16_t _done_pin;
7076
uint16_t _fail_pin;

0 commit comments

Comments
 (0)