0001-Workaround-for-MX25-chips.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From 9d8c79eecf760e4f963a0a7f29b577cd84962a2a Mon Sep 17 00:00:00 2001
  2. From: consts <grudnevkv@gmail.com>
  3. Date: Fri, 2 Mar 2018 07:03:37 +0000
  4. Subject: [PATCH 1/1] Workaround for MX25 chips
  5. TEST: In-system programming a ThinkPad X200 using a clip and
  6. pico-serprog works now. It just doesn't without this hack.
  7. Chip: MX25L6405D
  8. Tested-by: Riku Viitanen <riku.viitanen@protonmail.com>
  9. Change-Id: I43a306b67862b59c1dcd02729e189f3bf73f481b
  10. ---
  11. cli_classic.c | 5 +++++
  12. include/programmer.h | 1 +
  13. spi.c | 11 ++++++++++-
  14. 3 files changed, 16 insertions(+), 1 deletion(-)
  15. diff --git a/cli_classic.c b/cli_classic.c
  16. index ab5f8b1..2825033 100644
  17. --- a/cli_classic.c
  18. +++ b/cli_classic.c
  19. @@ -67,6 +67,7 @@ static void cli_classic_usage(const char *name)
  20. " -o | --output <logfile> log output to <logfile>\n"
  21. " --flash-contents <ref-file> assume flash contents to be <ref-file>\n"
  22. " -L | --list-supported print supported devices\n"
  23. + " -m | --workaround-mx keep flash busy before sending command\n"
  24. #if CONFIG_PRINT_WIKI == 1
  25. " -z | --list-supported-wiki print supported devices in wiki syntax\n"
  26. #endif
  27. @@ -262,6 +263,7 @@ int main(int argc, char *argv[])
  28. {"version", 0, NULL, 'R'},
  29. {"output", 1, NULL, 'o'},
  30. {"progress", 0, NULL, OPTION_PROGRESS},
  31. + {"workaround-mx", 0, NULL, 'm'},
  32. {NULL, 0, NULL, 0},
  33. };
  34. @@ -478,6 +480,9 @@ int main(int argc, char *argv[])
  35. cli_classic_abort_usage("No log filename specified.\n");
  36. }
  37. break;
  38. + case 'm': /* --workaround-mx */
  39. + workaround_mx = 1;
  40. + break;
  41. case OPTION_PROGRESS:
  42. show_progress = true;
  43. break;
  44. diff --git a/include/programmer.h b/include/programmer.h
  45. index 873dc37..2007fd6 100644
  46. --- a/include/programmer.h
  47. +++ b/include/programmer.h
  48. @@ -364,6 +364,7 @@ enum ich_chipset {
  49. CHIPSET_GEMINI_LAKE,
  50. CHIPSET_ELKHART_LAKE,
  51. };
  52. +extern int workaround_mx; /* workaround for MX25* chips, makes flash operations more reliable, less failures */
  53. /* ichspi.c */
  54. #if CONFIG_INTERNAL == 1
  55. diff --git a/spi.c b/spi.c
  56. index 748ef99..9bbdee9 100644
  57. --- a/spi.c
  58. +++ b/spi.c
  59. @@ -27,13 +27,22 @@
  60. #include "spi_command.h"
  61. #include "spi.h"
  62. +int workaround_mx; /* Make operations with MX25* chips more reliable */
  63. +
  64. int spi_send_command(const struct flashctx *flash, unsigned int writecnt,
  65. unsigned int readcnt, const unsigned char *writearr,
  66. unsigned char *readarr)
  67. {
  68. - if (spi_current_io_mode(flash) != SINGLE_IO_1_1_1)
  69. + if (spi_current_io_mode(flash) != SINGLE_IO_1_1_1) {
  70. return default_spi_send_command(flash, writecnt, readcnt, writearr, readarr);
  71. + } else if (workaround_mx) {
  72. + const unsigned char cmd[JEDEC_READ_OUTSIZE] = {JEDEC_READ, 0, 0, 0};
  73. + unsigned char buf[256];
  74. + /* keep flash busy for some time, keep CS warm before sending actual command */
  75. + flash->mst.spi->command(flash, sizeof(cmd), sizeof(buf), cmd, buf);
  76. + }
  77. + /* actual command */
  78. return flash->mst.spi->command(flash, writecnt, readcnt, writearr,
  79. readarr);
  80. }
  81. --
  82. 2.39.2