You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.8 KiB

  1. diff '--color=auto' -Naur openocd-0.11.0/src/flash/nor/jtagspi.c openocd-0.11.0.new/src/flash/nor/jtagspi.c
  2. --- openocd-0.11.0/src/flash/nor/jtagspi.c 2020-12-10 03:43:09.000000000 +0800
  3. +++ openocd-0.11.0.new/src/flash/nor/jtagspi.c 2021-07-27 18:31:32.179205804 +0800
  4. @@ -82,7 +82,7 @@
  5. struct scan_field fields[6];
  6. uint8_t marker = 1;
  7. uint8_t xfer_bits_buf[4];
  8. - uint8_t addr_buf[3];
  9. + uint8_t addr_buf[4];
  10. uint8_t *data_buf;
  11. uint32_t xfer_bits;
  12. int is_read, lenb, n;
  13. @@ -102,9 +102,12 @@
  14. xfer_bits = 8 + len - 1;
  15. /* cmd + read/write - 1 due to the counter implementation */
  16. - if (addr)
  17. - xfer_bits += 24;
  18. - h_u32_to_be(xfer_bits_buf, xfer_bits);
  19. + if (addr) {
  20. + if (bank->size > (1 << 24))
  21. + xfer_bits += 32;
  22. + else
  23. + xfer_bits += 24;
  24. + }
  25. flip_u8(xfer_bits_buf, xfer_bits_buf, 4);
  26. fields[n].num_bits = 32;
  27. fields[n].out_value = xfer_bits_buf;
  28. @@ -118,9 +121,15 @@
  29. n++;
  30. if (addr) {
  31. - h_u24_to_be(addr_buf, *addr);
  32. - flip_u8(addr_buf, addr_buf, 3);
  33. - fields[n].num_bits = 24;
  34. + if (bank->size > (1 << 24)) {
  35. + h_u32_to_be(addr_buf, *addr);
  36. + flip_u8(addr_buf, addr_buf, 4);
  37. + fields[n].num_bits = 32;
  38. + } else {
  39. + h_u24_to_be(addr_buf, *addr);
  40. + flip_u8(addr_buf, addr_buf, 3);
  41. + fields[n].num_bits = 24;
  42. + }
  43. fields[n].out_value = addr_buf;
  44. fields[n].in_value = NULL;
  45. n++;
  46. @@ -304,11 +313,14 @@
  47. struct jtagspi_flash_bank *info = bank->driver_priv;
  48. int retval;
  49. int64_t t0 = timeval_ms();
  50. + uint8_t erase_cmd = info->dev->erase_cmd;
  51. retval = jtagspi_write_enable(bank);
  52. if (retval != ERROR_OK)
  53. return retval;
  54. - jtagspi_cmd(bank, info->dev->erase_cmd, &bank->sectors[sector].offset, NULL, 0);
  55. + if (bank->size > (1 << 24))
  56. + erase_cmd = SPIFLASH_4BYTE_SECTOR_ERASE;
  57. + jtagspi_cmd(bank, erase_cmd, &bank->sectors[sector].offset, NULL, 0);
  58. retval = jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
  59. LOG_INFO("sector %u took %" PRId64 " ms", sector, timeval_ms() - t0);
  60. return retval;
  61. @@ -374,24 +386,36 @@
  62. static int jtagspi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
  63. {
  64. struct jtagspi_flash_bank *info = bank->driver_priv;
  65. + uint8_t read_cmd = SPIFLASH_READ;
  66. if (!(info->probed)) {
  67. LOG_ERROR("Flash bank not yet probed.");
  68. return ERROR_FLASH_BANK_NOT_PROBED;
  69. }
  70. + if (count >= (1 << 28)) {
  71. + LOG_ERROR("Read too large.");
  72. + return ERROR_FAIL;
  73. + }
  74. - jtagspi_cmd(bank, SPIFLASH_READ, &offset, buffer, -count*8);
  75. + if (bank->size > (1 << 24))
  76. + read_cmd = SPIFLASH_4BYTE_READ;
  77. + jtagspi_cmd(bank, read_cmd, &offset, buffer, -count*8);
  78. return ERROR_OK;
  79. }
  80. static int jtagspi_page_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
  81. {
  82. int retval;
  83. + uint8_t program_cmd = SPIFLASH_PAGE_PROGRAM;
  84. retval = jtagspi_write_enable(bank);
  85. if (retval != ERROR_OK)
  86. return retval;
  87. - jtagspi_cmd(bank, SPIFLASH_PAGE_PROGRAM, &offset, (uint8_t *) buffer, count*8);
  88. +
  89. + if (bank->size > (1 << 24))
  90. + program_cmd = SPIFLASH_4BYTE_PAGE_PROGRAM;
  91. +
  92. + jtagspi_cmd(bank, program_cmd, &offset, (uint8_t *) buffer, count*8);
  93. return jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
  94. }
  95. diff '--color=auto' -Naur openocd-0.11.0/src/flash/nor/spi.h openocd-0.11.0.new/src/flash/nor/spi.h
  96. --- openocd-0.11.0/src/flash/nor/spi.h 2020-12-10 03:43:09.000000000 +0800
  97. +++ openocd-0.11.0.new/src/flash/nor/spi.h 2021-07-27 18:32:08.106935700 +0800
  98. @@ -87,6 +87,9 @@
  99. #define SPIFLASH_PAGE_PROGRAM 0x02 /* Page Program */
  100. #define SPIFLASH_FAST_READ 0x0B /* Fast Read */
  101. #define SPIFLASH_READ 0x03 /* Normal Read */
  102. +#define SPIFLASH_4BYTE_READ 0x13 /* Read with 4 byte address */
  103. +#define SPIFLASH_4BYTE_SECTOR_ERASE 0xDC /* Sector Erase with 4 byte address */
  104. +#define SPIFLASH_4BYTE_PAGE_PROGRAM 0x12 /* Page Program with 4 byte address */
  105. #define SPIFLASH_MASS_ERASE 0xC7 /* Mass Erase */
  106. #define SPIFLASH_READ_SFDP 0x5A /* Read Serial Flash Discoverable Parameters */