openocd: revert to lambdaconcept patch

This commit is contained in:
Sebastien Bourdeauducq 2021-07-29 15:30:09 +08:00
parent 8d8ea8b377
commit bb1585fbbd
3 changed files with 26 additions and 117 deletions

View File

@ -0,0 +1,24 @@
diff --git a/src/flash/nor/spi.c b/src/flash/nor/spi.c
index af72ffc4..e5c9a9bd 100644
--- a/src/flash/nor/spi.c
+++ b/src/flash/nor/spi.c
@@ -90,8 +90,8 @@ const struct flash_device flash_devices[] = {
FLASH_ID("mac 25r6435f", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001728c2, 0x100, 0x10000, 0x800000),
FLASH_ID("micron n25q064", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0017ba20, 0x100, 0x10000, 0x800000),
FLASH_ID("micron n25q128", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0018ba20, 0x100, 0x10000, 0x1000000),
- FLASH_ID("micron n25q256 3v", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0019ba20, 0x100, 0x10000, 0x2000000),
- FLASH_ID("micron n25q256 1.8v", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0019bb20, 0x100, 0x10000, 0x2000000),
+ FLASH_ID("micron n25q256 3v", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0019ba20, 0x100, 0x10000, 0x2000000),
+ FLASH_ID("micron n25q256 1.8v", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0019bb20, 0x100, 0x10000, 0x2000000),
FLASH_ID("micron mt25ql512", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0020ba20, 0x100, 0x10000, 0x4000000),
FLASH_ID("micron mt25ql01", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0021ba20, 0x100, 0x10000, 0x8000000),
FLASH_ID("micron mt25ql02", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0022ba20, 0x100, 0x10000, 0x10000000),
@@ -124,7 +124,7 @@ const struct flash_device flash_devices[] = {
FLASH_ID("issi is25lp064", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x0017609d, 0x100, 0x10000, 0x800000),
FLASH_ID("issi is25lp128d", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0018609d, 0x100, 0x10000, 0x1000000),
FLASH_ID("issi is25wp128d", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0018709d, 0x100, 0x10000, 0x1000000),
- FLASH_ID("issi is25lp256d", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0019609d, 0x100, 0x10000, 0x2000000),
+ FLASH_ID("issi is25lp256d", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0019609d, 0x100, 0x10000, 0x2000000),
FLASH_ID("issi is25wp256d", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0019709d, 0x100, 0x10000, 0x2000000),
FLASH_ID("issi is25lp512m", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x001a609d, 0x100, 0x10000, 0x4000000),
FLASH_ID("issi is25wp512m", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x001a709d, 0x100, 0x10000, 0x4000000),

View File

@ -1,115 +0,0 @@
diff '--color=auto' -Naur openocd-0.11.0/src/flash/nor/jtagspi.c openocd-0.11.0.new/src/flash/nor/jtagspi.c
--- openocd-0.11.0/src/flash/nor/jtagspi.c 2020-12-10 03:43:09.000000000 +0800
+++ openocd-0.11.0.new/src/flash/nor/jtagspi.c 2021-07-27 18:31:32.179205804 +0800
@@ -82,7 +82,7 @@
struct scan_field fields[6];
uint8_t marker = 1;
uint8_t xfer_bits_buf[4];
- uint8_t addr_buf[3];
+ uint8_t addr_buf[4];
uint8_t *data_buf;
uint32_t xfer_bits;
int is_read, lenb, n;
@@ -102,9 +102,12 @@
xfer_bits = 8 + len - 1;
/* cmd + read/write - 1 due to the counter implementation */
- if (addr)
- xfer_bits += 24;
- h_u32_to_be(xfer_bits_buf, xfer_bits);
+ if (addr) {
+ if (bank->size > (1 << 24))
+ xfer_bits += 32;
+ else
+ xfer_bits += 24;
+ }
flip_u8(xfer_bits_buf, xfer_bits_buf, 4);
fields[n].num_bits = 32;
fields[n].out_value = xfer_bits_buf;
@@ -118,9 +121,15 @@
n++;
if (addr) {
- h_u24_to_be(addr_buf, *addr);
- flip_u8(addr_buf, addr_buf, 3);
- fields[n].num_bits = 24;
+ if (bank->size > (1 << 24)) {
+ h_u32_to_be(addr_buf, *addr);
+ flip_u8(addr_buf, addr_buf, 4);
+ fields[n].num_bits = 32;
+ } else {
+ h_u24_to_be(addr_buf, *addr);
+ flip_u8(addr_buf, addr_buf, 3);
+ fields[n].num_bits = 24;
+ }
fields[n].out_value = addr_buf;
fields[n].in_value = NULL;
n++;
@@ -304,11 +313,14 @@
struct jtagspi_flash_bank *info = bank->driver_priv;
int retval;
int64_t t0 = timeval_ms();
+ uint8_t erase_cmd = info->dev->erase_cmd;
retval = jtagspi_write_enable(bank);
if (retval != ERROR_OK)
return retval;
- jtagspi_cmd(bank, info->dev->erase_cmd, &bank->sectors[sector].offset, NULL, 0);
+ if (bank->size > (1 << 24))
+ erase_cmd = SPIFLASH_4BYTE_SECTOR_ERASE;
+ jtagspi_cmd(bank, erase_cmd, &bank->sectors[sector].offset, NULL, 0);
retval = jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
LOG_INFO("sector %u took %" PRId64 " ms", sector, timeval_ms() - t0);
return retval;
@@ -374,24 +386,36 @@
static int jtagspi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
{
struct jtagspi_flash_bank *info = bank->driver_priv;
+ uint8_t read_cmd = SPIFLASH_READ;
if (!(info->probed)) {
LOG_ERROR("Flash bank not yet probed.");
return ERROR_FLASH_BANK_NOT_PROBED;
}
+ if (count >= (1 << 28)) {
+ LOG_ERROR("Read too large.");
+ return ERROR_FAIL;
+ }
- jtagspi_cmd(bank, SPIFLASH_READ, &offset, buffer, -count*8);
+ if (bank->size > (1 << 24))
+ read_cmd = SPIFLASH_4BYTE_READ;
+ jtagspi_cmd(bank, read_cmd, &offset, buffer, -count*8);
return ERROR_OK;
}
static int jtagspi_page_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
{
int retval;
+ uint8_t program_cmd = SPIFLASH_PAGE_PROGRAM;
retval = jtagspi_write_enable(bank);
if (retval != ERROR_OK)
return retval;
- jtagspi_cmd(bank, SPIFLASH_PAGE_PROGRAM, &offset, (uint8_t *) buffer, count*8);
+
+ if (bank->size > (1 << 24))
+ program_cmd = SPIFLASH_4BYTE_PAGE_PROGRAM;
+
+ jtagspi_cmd(bank, program_cmd, &offset, (uint8_t *) buffer, count*8);
return jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
}
diff '--color=auto' -Naur openocd-0.11.0/src/flash/nor/spi.h openocd-0.11.0.new/src/flash/nor/spi.h
--- openocd-0.11.0/src/flash/nor/spi.h 2020-12-10 03:43:09.000000000 +0800
+++ openocd-0.11.0.new/src/flash/nor/spi.h 2021-07-27 18:32:08.106935700 +0800
@@ -87,6 +87,9 @@
#define SPIFLASH_PAGE_PROGRAM 0x02 /* Page Program */
#define SPIFLASH_FAST_READ 0x0B /* Fast Read */
#define SPIFLASH_READ 0x03 /* Normal Read */
+#define SPIFLASH_4BYTE_READ 0x13 /* Read with 4 byte address */
+#define SPIFLASH_4BYTE_SECTOR_ERASE 0xDC /* Sector Erase with 4 byte address */
+#define SPIFLASH_4BYTE_PAGE_PROGRAM 0x12 /* Page Program with 4 byte address */
#define SPIFLASH_MASS_ERASE 0xC7 /* Mass Erase */
#define SPIFLASH_READ_SFDP 0x5A /* Read Serial Flash Discoverable Parameters */

View File

@ -15,9 +15,9 @@ let
cp $src/*.bit $out/share/bscan-spi-bitstreams cp $src/*.bit $out/share/bscan-spi-bitstreams
''; '';
}; };
# based on https://github.com/m-labs/openocd/commit/17395320816c0bcc4f3401633197a851aeda20ce # https://docs.lambdaconcept.com/screamer/troubleshooting.html#error-contents-differ
openocd-fixed = openocd.overrideAttrs(oa: { openocd-fixed = openocd.overrideAttrs(oa: {
patches = oa.patches or [] ++ [ ./openocd-jtagspi.nix ]; patches = oa.patches or [] ++ [ ./openocd-jtagspi.diff ];
}); });
in in
buildEnv { buildEnv {