Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009, 2010, 2011, 2012 Carl-Daniel Hailfinger |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 17 | #include <strings.h> |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 18 | #include <string.h> |
Felix Singer | cf6b708 | 2022-08-18 23:57:31 +0200 | [diff] [blame] | 19 | #include <stdbool.h> |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <ctype.h> |
Carl-Daniel Hailfinger | d2f007f | 2010-09-16 22:34:25 +0000 | [diff] [blame] | 22 | #include <unistd.h> |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 23 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 24 | #include "programmer.h" |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 25 | #include "spi.h" |
| 26 | |
| 27 | /* Change this to #define if you want to test without a serial implementation */ |
| 28 | #undef FAKE_COMMUNICATION |
| 29 | |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 30 | struct buspirate_speeds { |
Carl-Daniel Hailfinger | c422484 | 2011-06-09 20:06:34 +0000 | [diff] [blame] | 31 | const char *name; |
| 32 | const int speed; |
| 33 | }; |
| 34 | |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 35 | #define BP_DEFAULTBAUD 115200 |
| 36 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 37 | #ifndef FAKE_COMMUNICATION |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 38 | static int buspirate_serialport_setup(char *dev) |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 39 | { |
| 40 | /* 115200bps, 8 databits, no parity, 1 stopbit */ |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 41 | sp_fd = sp_openserport(dev, BP_DEFAULTBAUD); |
Elyes HAOUAS | 124ef38 | 2018-03-27 12:15:09 +0200 | [diff] [blame] | 42 | if (sp_fd == SER_INV_FD) |
Niklas Söderlund | 2a95e87 | 2012-07-30 19:42:33 +0000 | [diff] [blame] | 43 | return 1; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 44 | return 0; |
| 45 | } |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 46 | #else |
| 47 | #define buspirate_serialport_setup(...) 0 |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 48 | #define serialport_shutdown(...) 0 |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 49 | #define serialport_write(...) 0 |
| 50 | #define serialport_read(...) 0 |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 51 | #define sp_flush_incoming(...) 0 |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 52 | #endif |
| 53 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 54 | struct bp_spi_data { |
| 55 | unsigned char *bp_commbuf; |
| 56 | int bp_commbufsize; |
| 57 | }; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 58 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 59 | static int buspirate_commbuf_grow(int bufsize, unsigned char **bp_commbuf, int *bp_commbufsize) |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 60 | { |
| 61 | unsigned char *tmpbuf; |
| 62 | |
| 63 | /* Never shrink. realloc() calls are expensive. */ |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 64 | if (bufsize <= *bp_commbufsize) |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 65 | return 0; |
| 66 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 67 | tmpbuf = realloc(*bp_commbuf, bufsize); |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 68 | if (!tmpbuf) { |
| 69 | /* Keep the existing buffer because memory is already tight. */ |
| 70 | msg_perr("Out of memory!\n"); |
| 71 | return ERROR_OOM; |
| 72 | } |
| 73 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 74 | *bp_commbuf = tmpbuf; |
| 75 | *bp_commbufsize = bufsize; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 79 | static int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, |
| 80 | unsigned int readcnt) |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 81 | { |
Nico Huber | 519be66 | 2018-12-23 20:03:35 +0100 | [diff] [blame] | 82 | unsigned int i; |
| 83 | int ret = 0; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 84 | |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 85 | msg_pspew("%s: write %i, read %i ", __func__, writecnt, readcnt); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 86 | if (!writecnt && !readcnt) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 87 | msg_perr("Zero length command!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 88 | return 1; |
| 89 | } |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 90 | if (writecnt) |
| 91 | msg_pspew("Sending"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 92 | for (i = 0; i < writecnt; i++) |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 93 | msg_pspew(" 0x%02x", buf[i]); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 94 | #ifdef FAKE_COMMUNICATION |
| 95 | /* Placate the caller for now. */ |
| 96 | if (readcnt) { |
| 97 | buf[0] = 0x01; |
| 98 | memset(buf + 1, 0xff, readcnt - 1); |
| 99 | } |
| 100 | ret = 0; |
| 101 | #else |
| 102 | if (writecnt) |
| 103 | ret = serialport_write(buf, writecnt); |
| 104 | if (ret) |
| 105 | return ret; |
| 106 | if (readcnt) |
| 107 | ret = serialport_read(buf, readcnt); |
| 108 | if (ret) |
| 109 | return ret; |
| 110 | #endif |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 111 | if (readcnt) |
| 112 | msg_pspew(", receiving"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 113 | for (i = 0; i < readcnt; i++) |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 114 | msg_pspew(" 0x%02x", buf[i]); |
| 115 | msg_pspew("\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Jacob Garber | 4a84ec2 | 2019-07-25 19:12:31 -0600 | [diff] [blame] | 119 | static int buspirate_wait_for_string(unsigned char *buf, const char *key) |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 120 | { |
| 121 | unsigned int keylen = strlen(key); |
| 122 | int ret; |
| 123 | |
| 124 | ret = buspirate_sendrecv(buf, 0, keylen); |
| 125 | while (!ret) { |
| 126 | if (!memcmp(buf, key, keylen)) |
| 127 | return 0; |
| 128 | memmove(buf, buf + 1, keylen - 1); |
| 129 | ret = buspirate_sendrecv(buf + keylen - 1, 0, 1); |
| 130 | } |
| 131 | return ret; |
| 132 | } |
| 133 | |
Edward O'Callaghan | 5eca427 | 2020-04-12 17:27:53 +1000 | [diff] [blame] | 134 | static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 135 | const unsigned char *writearr, unsigned char *readarr); |
Edward O'Callaghan | 5eca427 | 2020-04-12 17:27:53 +1000 | [diff] [blame] | 136 | static int buspirate_spi_send_command_v2(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 137 | const unsigned char *writearr, unsigned char *readarr); |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 138 | |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 139 | static struct spi_master spi_master_buspirate = { |
Nico Huber | 1cf407b | 2017-11-10 20:18:23 +0100 | [diff] [blame] | 140 | .features = SPI_MASTER_4BA, |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 141 | .max_data_read = MAX_DATA_UNSPECIFIED, |
| 142 | .max_data_write = MAX_DATA_UNSPECIFIED, |
| 143 | .command = NULL, |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 144 | .multicommand = default_spi_send_multicommand, |
| 145 | .read = default_spi_read, |
| 146 | .write_256 = default_spi_write_256, |
Nico Huber | 7bca126 | 2012-06-15 22:28:12 +0000 | [diff] [blame] | 147 | .write_aai = default_spi_write_aai, |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 150 | static const struct buspirate_speeds spispeeds[] = { |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 151 | {"30k", 0x0}, |
| 152 | {"125k", 0x1}, |
| 153 | {"250k", 0x2}, |
| 154 | {"1M", 0x3}, |
| 155 | {"2M", 0x4}, |
| 156 | {"2.6M", 0x5}, |
| 157 | {"4M", 0x6}, |
| 158 | {"8M", 0x7}, |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 159 | {NULL, 0x0} |
| 160 | }; |
| 161 | |
| 162 | static const struct buspirate_speeds serialspeeds[] = { |
| 163 | {"115200", 115200}, |
| 164 | {"230400", 230400}, |
| 165 | {"250000", 250000}, |
| 166 | {"2000000", 2000000}, |
| 167 | {"2M", 2000000}, |
| 168 | {NULL, 0} |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 171 | static int buspirate_spi_shutdown(void *data) |
| 172 | { |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 173 | struct bp_spi_data *bp_data = data; |
| 174 | unsigned char *const bp_commbuf = bp_data->bp_commbuf; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 175 | int ret = 0, ret2 = 0; |
| 176 | /* No need to allocate a buffer here, we know that bp_commbuf is at least DEFAULT_BUFSIZE big. */ |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 177 | |
| 178 | /* Exit raw SPI mode (enter raw bitbang mode) */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 179 | bp_commbuf[0] = 0x00; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 180 | if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0))) |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 181 | goto out_shutdown; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 182 | if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO"))) |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 183 | goto out_shutdown; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 184 | if ((ret = buspirate_sendrecv(bp_commbuf, 0, 1))) |
| 185 | goto out_shutdown; |
| 186 | msg_pdbg("Raw bitbang mode version %c\n", bp_commbuf[0]); |
| 187 | if (bp_commbuf[0] != '1') { |
| 188 | msg_perr("Can't handle raw bitbang mode version %c!\n", bp_commbuf[0]); |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 189 | ret = 1; |
| 190 | goto out_shutdown; |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 191 | } |
| 192 | /* Reset Bus Pirate (return to user terminal) */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 193 | bp_commbuf[0] = 0x0f; |
| 194 | ret = buspirate_sendrecv(bp_commbuf, 1, 0); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 195 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 196 | out_shutdown: |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 197 | /* Shut down serial port communication */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 198 | ret2 = serialport_shutdown(NULL); |
| 199 | /* Keep the oldest error, it is probably the best indicator. */ |
| 200 | if (ret2 && !ret) |
| 201 | ret = ret2; |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 202 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 203 | free(bp_commbuf); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 204 | if (ret) |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 205 | msg_pdbg("Bus Pirate shutdown failed.\n"); |
| 206 | else |
| 207 | msg_pdbg("Bus Pirate shutdown completed.\n"); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 208 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 209 | free(data); |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 210 | return ret; |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 213 | #define BP_FWVERSION(a,b) ((a) << 8 | (b)) |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 214 | #define BP_HWVERSION(a,b) BP_FWVERSION(a,b) |
| 215 | |
| 216 | /** |
| 217 | * The Bus Pirate's PIC microcontroller supports custom baud rates by manually specifying a |
| 218 | * clock divisor that can be calculated with the formula (16000000 / (4 * baud)) - 1. |
| 219 | */ |
| 220 | #define BP_DIVISOR(baud) ((4000000/(baud)) - 1) |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 221 | |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 222 | static int buspirate_spi_init(void) |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 223 | { |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 224 | char *tmp; |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 225 | char *dev; |
| 226 | int i; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 227 | int cnt; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 228 | unsigned int fw_version_major = 0; |
| 229 | unsigned int fw_version_minor = 0; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 230 | unsigned int hw_version_major = 0; |
| 231 | unsigned int hw_version_minor = 0; |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 232 | int spispeed = 0x7; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 233 | int serialspeed_index = -1; |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 234 | int ret = 0; |
Felix Singer | cf6b708 | 2022-08-18 23:57:31 +0200 | [diff] [blame] | 235 | bool pullup = false; |
| 236 | bool psu = false; |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 237 | unsigned char *bp_commbuf; |
| 238 | int bp_commbufsize; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 239 | |
Carl-Daniel Hailfinger | 2b6dcb3 | 2010-07-08 10:13:37 +0000 | [diff] [blame] | 240 | dev = extract_programmer_param("dev"); |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 241 | if (dev && !strlen(dev)) { |
| 242 | free(dev); |
| 243 | dev = NULL; |
| 244 | } |
| 245 | if (!dev) { |
| 246 | msg_perr("No serial device given. Use flashrom -p buspirate_spi:dev=/dev/ttyUSB0\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 247 | return 1; |
| 248 | } |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 249 | |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 250 | tmp = extract_programmer_param("spispeed"); |
| 251 | if (tmp) { |
| 252 | for (i = 0; spispeeds[i].name; i++) { |
| 253 | if (!strncasecmp(spispeeds[i].name, tmp, strlen(spispeeds[i].name))) { |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 254 | spispeed = spispeeds[i].speed; |
| 255 | break; |
| 256 | } |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 257 | } |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 258 | if (!spispeeds[i].name) |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 259 | msg_perr("Invalid SPI speed, using default.\n"); |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 260 | } |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 261 | free(tmp); |
| 262 | |
Elyes HAOUAS | e2c90c4 | 2018-08-18 09:04:41 +0200 | [diff] [blame] | 263 | /* Extract serialspeed parameter */ |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 264 | tmp = extract_programmer_param("serialspeed"); |
| 265 | if (tmp) { |
| 266 | for (i = 0; serialspeeds[i].name; i++) { |
| 267 | if (!strncasecmp(serialspeeds[i].name, tmp, strlen(serialspeeds[i].name))) { |
| 268 | serialspeed_index = i; |
| 269 | break; |
| 270 | } |
| 271 | } |
| 272 | if (!serialspeeds[i].name) |
| 273 | msg_perr("Invalid serial speed %s, using default.\n", tmp); |
| 274 | } |
| 275 | free(tmp); |
| 276 | |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 277 | tmp = extract_programmer_param("pullups"); |
| 278 | if (tmp) { |
| 279 | if (strcasecmp("on", tmp) == 0) |
Felix Singer | cf6b708 | 2022-08-18 23:57:31 +0200 | [diff] [blame] | 280 | pullup = true; |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 281 | else if (strcasecmp("off", tmp) == 0) |
| 282 | ; // ignore |
| 283 | else |
| 284 | msg_perr("Invalid pullups state, not using them.\n"); |
| 285 | } |
| 286 | free(tmp); |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 287 | |
Jeremy Kerr | 98bdcb4 | 2021-05-23 17:58:06 +0800 | [diff] [blame] | 288 | tmp = extract_programmer_param("psus"); |
| 289 | if (tmp) { |
| 290 | if (strcasecmp("on", tmp) == 0) |
Felix Singer | cf6b708 | 2022-08-18 23:57:31 +0200 | [diff] [blame] | 291 | psu = true; |
Jeremy Kerr | 98bdcb4 | 2021-05-23 17:58:06 +0800 | [diff] [blame] | 292 | else if (strcasecmp("off", tmp) == 0) |
| 293 | ; // ignore |
| 294 | else |
| 295 | msg_perr("Invalid psus state, not enabling.\n"); |
| 296 | } |
| 297 | free(tmp); |
| 298 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 299 | /* Default buffer size is 19: 16 bytes data, 3 bytes control. */ |
| 300 | #define DEFAULT_BUFSIZE (16 + 3) |
| 301 | bp_commbuf = malloc(DEFAULT_BUFSIZE); |
| 302 | if (!bp_commbuf) { |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 303 | msg_perr("Out of memory!\n"); |
Stefan Reinauer | 1838591 | 2014-04-26 16:12:45 +0000 | [diff] [blame] | 304 | free(dev); |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 305 | return ERROR_OOM; |
| 306 | } |
| 307 | bp_commbufsize = DEFAULT_BUFSIZE; |
| 308 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 309 | ret = buspirate_serialport_setup(dev); |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 310 | free(dev); |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 311 | if (ret) { |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 312 | free(bp_commbuf); |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 313 | return ret; |
| 314 | } |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 315 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 316 | |
| 317 | struct bp_spi_data *bp_data = calloc(1, sizeof(*bp_data)); |
| 318 | if (!bp_data) { |
| 319 | msg_perr("Unable to allocate space for SPI master data\n"); |
| 320 | free(bp_commbuf); |
| 321 | return 1; |
| 322 | } |
| 323 | bp_data->bp_commbuf = bp_commbuf; |
| 324 | bp_data->bp_commbufsize = bp_commbufsize; |
| 325 | |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 326 | /* This is the brute force version, but it should work. |
| 327 | * It is likely to fail if a previous flashrom run was aborted during a write with the new SPI commands |
| 328 | * in firmware v5.5 because that firmware may wait for up to 4096 bytes of input before responding to |
| 329 | * 0x00 again. The obvious workaround (sending 4096 bytes of \0) may cause significant startup delays. |
| 330 | */ |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 331 | for (i = 0; i < 20; i++) { |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 332 | /* Enter raw bitbang mode */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 333 | bp_commbuf[0] = 0x00; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 334 | /* Send the command, don't read the response. */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 335 | ret = buspirate_sendrecv(bp_commbuf, 1, 0); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 336 | if (ret) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 337 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 338 | /* The old way to handle responses from a Bus Pirate already in BBIO mode was to flush any |
| 339 | * response which came in over serial. Unfortunately that does not work reliably on Linux |
| 340 | * with FTDI USB-serial. |
| 341 | */ |
| 342 | //sp_flush_incoming(); |
| 343 | /* The Bus Pirate can't handle UART input buffer overflow in BBIO mode, and sending a sequence |
| 344 | * of 0x00 too fast apparently triggers such an UART input buffer overflow. |
| 345 | */ |
Maksim Kuleshov | 73dc0db | 2013-04-05 08:06:10 +0000 | [diff] [blame] | 346 | internal_sleep(10000); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 347 | } |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 348 | /* We know that 20 commands of \0 should elicit at least one BBIO1 response. */ |
| 349 | if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO"))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 350 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 351 | |
| 352 | /* Reset the Bus Pirate. */ |
| 353 | bp_commbuf[0] = 0x0f; |
| 354 | /* Send the command, don't read the response. */ |
| 355 | if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 356 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 357 | if ((ret = buspirate_wait_for_string(bp_commbuf, "irate "))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 358 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 359 | /* Read the hardware version string. Last byte of the buffer is reserved for \0. */ |
| 360 | for (i = 0; i < DEFAULT_BUFSIZE - 1; i++) { |
| 361 | if ((ret = buspirate_sendrecv(bp_commbuf + i, 0, 1))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 362 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 363 | if (strchr("\r\n\t ", bp_commbuf[i])) |
| 364 | break; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 365 | } |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 366 | bp_commbuf[i] = '\0'; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 367 | msg_pdbg("Detected Bus Pirate hardware "); |
| 368 | if (bp_commbuf[0] != 'v') |
| 369 | msg_pdbg("(unknown version number format)"); |
| 370 | else if (!strchr("0123456789", bp_commbuf[1])) |
| 371 | msg_pdbg("(unknown version number format)"); |
| 372 | else { |
| 373 | hw_version_major = strtoul((char *)bp_commbuf + 1, &tmp, 10); |
| 374 | while ((*tmp != '\0') && !strchr("0123456789", *tmp)) |
| 375 | tmp++; |
| 376 | hw_version_minor = strtoul(tmp, NULL, 10); |
| 377 | msg_pdbg("%u.%u", hw_version_major, hw_version_minor); |
| 378 | } |
| 379 | msg_pdbg2(" (\"%s\")", bp_commbuf); |
| 380 | msg_pdbg("\n"); |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 381 | |
| 382 | if ((ret = buspirate_wait_for_string(bp_commbuf, "irmware "))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 383 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 384 | /* Read the firmware version string. Last byte of the buffer is reserved for \0. */ |
| 385 | for (i = 0; i < DEFAULT_BUFSIZE - 1; i++) { |
| 386 | if ((ret = buspirate_sendrecv(bp_commbuf + i, 0, 1))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 387 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 388 | if (strchr("\r\n\t ", bp_commbuf[i])) |
| 389 | break; |
| 390 | } |
| 391 | bp_commbuf[i] = '\0'; |
| 392 | msg_pdbg("Detected Bus Pirate firmware "); |
| 393 | if (bp_commbuf[0] != 'v') |
| 394 | msg_pdbg("(unknown version number format)"); |
| 395 | else if (!strchr("0123456789", bp_commbuf[1])) |
| 396 | msg_pdbg("(unknown version number format)"); |
| 397 | else { |
| 398 | fw_version_major = strtoul((char *)bp_commbuf + 1, &tmp, 10); |
| 399 | while ((*tmp != '\0') && !strchr("0123456789", *tmp)) |
| 400 | tmp++; |
| 401 | fw_version_minor = strtoul(tmp, NULL, 10); |
| 402 | msg_pdbg("%u.%u", fw_version_major, fw_version_minor); |
| 403 | } |
| 404 | msg_pdbg2(" (\"%s\")", bp_commbuf); |
| 405 | msg_pdbg("\n"); |
| 406 | |
| 407 | if ((ret = buspirate_wait_for_string(bp_commbuf, "HiZ>"))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 408 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 409 | |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 410 | /* Tell the user about missing SPI binary mode in firmware 2.3 and older. */ |
| 411 | if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(2, 4)) { |
| 412 | msg_pinfo("Bus Pirate firmware 2.3 and older does not support binary SPI access.\n"); |
| 413 | msg_pinfo("Please upgrade to the latest firmware (at least 2.4).\n"); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 414 | ret = SPI_PROGRAMMER_ERROR; |
| 415 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 418 | /* Use fast SPI mode in firmware 5.5 and newer. */ |
| 419 | if (BP_FWVERSION(fw_version_major, fw_version_minor) >= BP_FWVERSION(5, 5)) { |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 420 | msg_pdbg("Using SPI command set v2.\n"); |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 421 | /* Sensible default buffer size. */ |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 422 | if (buspirate_commbuf_grow(260 + 5, &bp_commbuf, &bp_commbufsize)) { |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 423 | ret = ERROR_OOM; |
| 424 | goto init_err_cleanup_exit; |
| 425 | } |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 426 | bp_data->bp_commbuf = bp_commbuf; |
| 427 | bp_data->bp_commbufsize = bp_commbufsize; |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 428 | spi_master_buspirate.max_data_read = 2048; |
| 429 | spi_master_buspirate.max_data_write = 256; |
| 430 | spi_master_buspirate.command = buspirate_spi_send_command_v2; |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 431 | } else { |
| 432 | msg_pinfo("Bus Pirate firmware 5.4 and older does not support fast SPI access.\n"); |
| 433 | msg_pinfo("Reading/writing a flash chip may take hours.\n"); |
| 434 | msg_pinfo("It is recommended to upgrade to firmware 5.5 or newer.\n"); |
| 435 | /* Sensible default buffer size. */ |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 436 | if (buspirate_commbuf_grow(16 + 3, &bp_commbuf, &bp_commbufsize)) { |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 437 | ret = ERROR_OOM; |
| 438 | goto init_err_cleanup_exit; |
| 439 | } |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 440 | bp_data->bp_commbuf = bp_commbuf; |
| 441 | bp_data->bp_commbufsize = bp_commbufsize; |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 442 | spi_master_buspirate.max_data_read = 12; |
| 443 | spi_master_buspirate.max_data_write = 12; |
| 444 | spi_master_buspirate.command = buspirate_spi_send_command_v1; |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 447 | /* Workaround for broken speed settings in firmware 6.1 and older. */ |
| 448 | if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(6, 2)) |
| 449 | if (spispeed > 0x4) { |
| 450 | msg_perr("Bus Pirate firmware 6.1 and older does not support SPI speeds above 2 MHz. " |
| 451 | "Limiting speed to 2 MHz.\n"); |
| 452 | msg_pinfo("It is recommended to upgrade to firmware 6.2 or newer.\n"); |
| 453 | spispeed = 0x4; |
| 454 | } |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 455 | |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 456 | /* This works because speeds numbering starts at 0 and is contiguous. */ |
| 457 | msg_pdbg("SPI speed is %sHz\n", spispeeds[spispeed].name); |
| 458 | |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 459 | /* Set 2M baud serial speed by default on hardware 3.0 and newer if a custom speed was not set */ |
| 460 | if (serialspeed_index == -1 && BP_HWVERSION(hw_version_major, hw_version_minor) >= BP_HWVERSION(3, 0)) { |
| 461 | serialspeed_index = ARRAY_SIZE(serialspeeds) - 2; |
| 462 | msg_pdbg("Bus Pirate v3 or newer detected. Set serial speed to 2M baud.\n"); |
| 463 | } |
| 464 | |
| 465 | /* Set custom serial speed if specified */ |
| 466 | if (serialspeed_index != -1) { |
| 467 | if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(5, 5)) { |
| 468 | /* This feature requires firmware 5.5 or newer */ |
| 469 | msg_perr("Bus Pirate firmware 5.4 and older does not support custom serial speeds." |
| 470 | "Using default speed of 115200 baud.\n"); |
| 471 | } else if (serialspeeds[serialspeed_index].speed != BP_DEFAULTBAUD) { |
| 472 | /* Set the serial speed to match the user's choice if it doesn't already */ |
| 473 | |
| 474 | if (BP_HWVERSION(hw_version_major, hw_version_minor) < BP_HWVERSION(3, 0)) |
| 475 | msg_pwarn("Increased serial speeds may not work on older (<3.0) Bus Pirates." |
| 476 | " Continue at your own risk.\n"); |
| 477 | |
| 478 | /* Enter baud rate configuration mode */ |
| 479 | cnt = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "b\n"); |
| 480 | if ((ret = buspirate_sendrecv(bp_commbuf, cnt, 0))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 481 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 482 | if ((ret = buspirate_wait_for_string(bp_commbuf, ">"))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 483 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 484 | |
| 485 | /* Enter manual clock divisor entry mode */ |
| 486 | cnt = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "10\n"); |
| 487 | if ((ret = buspirate_sendrecv(bp_commbuf, cnt, 0))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 488 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 489 | if ((ret = buspirate_wait_for_string(bp_commbuf, ">"))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 490 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 491 | |
| 492 | /* Set the clock divisor to the value calculated from the user's input */ |
| 493 | cnt = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "%d\n", |
| 494 | BP_DIVISOR(serialspeeds[serialspeed_index].speed)); |
| 495 | |
| 496 | if ((ret = buspirate_sendrecv(bp_commbuf, cnt, 0))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 497 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 498 | sleep(1); |
| 499 | |
| 500 | /* Reconfigure the host's serial baud rate to the new value */ |
| 501 | if ((ret = serialport_config(sp_fd, serialspeeds[serialspeed_index].speed))) { |
| 502 | msg_perr("Unable to configure system baud rate to specified value."); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 503 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* Return to the main prompt */ |
| 507 | bp_commbuf[0] = ' '; |
| 508 | if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 509 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 510 | if ((ret = buspirate_wait_for_string(bp_commbuf, "HiZ>"))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 511 | goto init_err_cleanup_exit; |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 512 | |
| 513 | msg_pdbg("Serial speed is %d baud\n", serialspeeds[serialspeed_index].speed); |
| 514 | } |
| 515 | |
| 516 | } |
| 517 | |
| 518 | |
| 519 | |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 520 | /* Enter raw bitbang mode */ |
| 521 | for (i = 0; i < 20; i++) { |
| 522 | bp_commbuf[0] = 0x00; |
| 523 | if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 524 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 525 | } |
| 526 | if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO"))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 527 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 528 | if ((ret = buspirate_sendrecv(bp_commbuf, 0, 1))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 529 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 530 | msg_pdbg("Raw bitbang mode version %c\n", bp_commbuf[0]); |
| 531 | if (bp_commbuf[0] != '1') { |
| 532 | msg_perr("Can't handle raw bitbang mode version %c!\n", bp_commbuf[0]); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 533 | ret = 1; |
| 534 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 535 | } |
| 536 | /* Enter raw SPI mode */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 537 | bp_commbuf[0] = 0x01; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 538 | ret = buspirate_sendrecv(bp_commbuf, 1, 0); |
Anastasia Klimchuk | ee6d548 | 2021-06-24 16:25:43 +1000 | [diff] [blame] | 539 | if (ret) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 540 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 541 | if ((ret = buspirate_wait_for_string(bp_commbuf, "SPI"))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 542 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 543 | if ((ret = buspirate_sendrecv(bp_commbuf, 0, 1))) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 544 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | a16a892 | 2012-08-17 17:30:43 +0000 | [diff] [blame] | 545 | msg_pdbg("Raw SPI mode version %c\n", bp_commbuf[0]); |
| 546 | if (bp_commbuf[0] != '1') { |
| 547 | msg_perr("Can't handle raw SPI mode version %c!\n", bp_commbuf[0]); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 548 | ret = 1; |
| 549 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /* Initial setup (SPI peripherals config): Enable power, CS high, AUX */ |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 553 | bp_commbuf[0] = 0x40 | 0x0b; |
Felix Singer | cf6b708 | 2022-08-18 23:57:31 +0200 | [diff] [blame] | 554 | if (pullup) { |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 555 | bp_commbuf[0] |= (1 << 2); |
| 556 | msg_pdbg("Enabling pull-up resistors.\n"); |
| 557 | } |
Felix Singer | cf6b708 | 2022-08-18 23:57:31 +0200 | [diff] [blame] | 558 | if (psu) { |
Jeremy Kerr | 98bdcb4 | 2021-05-23 17:58:06 +0800 | [diff] [blame] | 559 | bp_commbuf[0] |= (1 << 3); |
| 560 | msg_pdbg("Enabling PSUs.\n"); |
| 561 | } |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 562 | ret = buspirate_sendrecv(bp_commbuf, 1, 1); |
Anastasia Klimchuk | ee6d548 | 2021-06-24 16:25:43 +1000 | [diff] [blame] | 563 | if (ret) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 564 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 565 | if (bp_commbuf[0] != 0x01) { |
Brian Salcedo | 30dfdba | 2013-01-03 20:44:30 +0000 | [diff] [blame] | 566 | msg_perr("Protocol error while setting power/CS/AUX(/Pull-up resistors)!\n"); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 567 | ret = 1; |
| 568 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 571 | /* Set SPI speed */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 572 | bp_commbuf[0] = 0x60 | spispeed; |
| 573 | ret = buspirate_sendrecv(bp_commbuf, 1, 1); |
Anastasia Klimchuk | ee6d548 | 2021-06-24 16:25:43 +1000 | [diff] [blame] | 574 | if (ret) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 575 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 576 | if (bp_commbuf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 577 | msg_perr("Protocol error while setting SPI speed!\n"); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 578 | ret = 1; |
| 579 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 580 | } |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 581 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 582 | /* Set SPI config: output type, idle, clock edge, sample */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 583 | bp_commbuf[0] = 0x80 | 0xa; |
Felix Singer | cf6b708 | 2022-08-18 23:57:31 +0200 | [diff] [blame] | 584 | if (pullup) { |
Maxime Vincent | 2099c64 | 2017-11-24 13:04:08 +0100 | [diff] [blame] | 585 | bp_commbuf[0] &= ~(1 << 3); |
| 586 | msg_pdbg("Pull-ups enabled, so using HiZ pin output! (Open-Drain mode)\n"); |
| 587 | } |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 588 | ret = buspirate_sendrecv(bp_commbuf, 1, 1); |
Anastasia Klimchuk | ee6d548 | 2021-06-24 16:25:43 +1000 | [diff] [blame] | 589 | if (ret) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 590 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 591 | if (bp_commbuf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 592 | msg_perr("Protocol error while setting SPI config!\n"); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 593 | ret = 1; |
| 594 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* De-assert CS# */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 598 | bp_commbuf[0] = 0x03; |
| 599 | ret = buspirate_sendrecv(bp_commbuf, 1, 1); |
Anastasia Klimchuk | ee6d548 | 2021-06-24 16:25:43 +1000 | [diff] [blame] | 600 | if (ret) |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 601 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 602 | if (bp_commbuf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 603 | msg_perr("Protocol error while raising CS#!\n"); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 604 | ret = 1; |
| 605 | goto init_err_cleanup_exit; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 608 | if (register_shutdown(buspirate_spi_shutdown, bp_data) != 0) { |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 609 | ret = 1; |
| 610 | goto init_err_cleanup_exit; |
| 611 | } |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 612 | register_spi_master(&spi_master_buspirate, bp_data); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 613 | |
| 614 | return 0; |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 615 | |
| 616 | init_err_cleanup_exit: |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 617 | buspirate_spi_shutdown(bp_data); |
Anastasia Klimchuk | 7dcb6f3 | 2021-05-24 15:12:10 +1000 | [diff] [blame] | 618 | return ret; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Edward O'Callaghan | 5eca427 | 2020-04-12 17:27:53 +1000 | [diff] [blame] | 621 | static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 622 | const unsigned char *writearr, unsigned char *readarr) |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 623 | { |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 624 | struct bp_spi_data *bp_data = flash->mst->spi.data; |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 625 | unsigned int i = 0; |
| 626 | int ret = 0; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 627 | |
| 628 | if (writecnt > 16 || readcnt > 16 || (readcnt + writecnt) > 16) |
| 629 | return SPI_INVALID_LENGTH; |
| 630 | |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 631 | /* 3 bytes extra for CS#, len, CS#. */ |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 632 | if (buspirate_commbuf_grow(writecnt + readcnt + 3, &bp_data->bp_commbuf, &bp_data->bp_commbufsize)) |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 633 | return ERROR_OOM; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 634 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 635 | unsigned char *const bp_commbuf = bp_data->bp_commbuf; |
| 636 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 637 | /* Assert CS# */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 638 | bp_commbuf[i++] = 0x02; |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 639 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 640 | bp_commbuf[i++] = 0x10 | (writecnt + readcnt - 1); |
| 641 | memcpy(bp_commbuf + i, writearr, writecnt); |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 642 | i += writecnt; |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 643 | memset(bp_commbuf + i, 0, readcnt); |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 644 | |
| 645 | i += readcnt; |
| 646 | /* De-assert CS# */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 647 | bp_commbuf[i++] = 0x03; |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 648 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 649 | ret = buspirate_sendrecv(bp_commbuf, i, i); |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 650 | |
| 651 | if (ret) { |
| 652 | msg_perr("Bus Pirate communication error!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 653 | return SPI_GENERIC_ERROR; |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 656 | if (bp_commbuf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 657 | msg_perr("Protocol error while lowering CS#!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 658 | return SPI_GENERIC_ERROR; |
| 659 | } |
| 660 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 661 | if (bp_commbuf[1] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 662 | msg_perr("Protocol error while reading/writing SPI!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 663 | return SPI_GENERIC_ERROR; |
| 664 | } |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 665 | |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 666 | if (bp_commbuf[i - 1] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 667 | msg_perr("Protocol error while raising CS#!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 668 | return SPI_GENERIC_ERROR; |
| 669 | } |
| 670 | |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 671 | /* Skip CS#, length, writearr. */ |
Carl-Daniel Hailfinger | 316fdfb | 2012-06-08 15:27:47 +0000 | [diff] [blame] | 672 | memcpy(readarr, bp_commbuf + 2 + writecnt, readcnt); |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 673 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 674 | return ret; |
| 675 | } |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 676 | |
Edward O'Callaghan | 5eca427 | 2020-04-12 17:27:53 +1000 | [diff] [blame] | 677 | static int buspirate_spi_send_command_v2(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 678 | const unsigned char *writearr, unsigned char *readarr) |
| 679 | { |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 680 | struct bp_spi_data *bp_data = flash->mst->spi.data; |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 681 | int i = 0, ret = 0; |
| 682 | |
| 683 | if (writecnt > 4096 || readcnt > 4096 || (readcnt + writecnt) > 4096) |
| 684 | return SPI_INVALID_LENGTH; |
| 685 | |
| 686 | /* 5 bytes extra for command, writelen, readlen. |
| 687 | * 1 byte extra for Ack/Nack. |
| 688 | */ |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 689 | if (buspirate_commbuf_grow(max(writecnt + 5, readcnt + 1), &bp_data->bp_commbuf, &bp_data->bp_commbufsize)) |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 690 | return ERROR_OOM; |
| 691 | |
Anastasia Klimchuk | d8f8c99 | 2021-05-06 07:47:04 +1000 | [diff] [blame^] | 692 | unsigned char *const bp_commbuf = bp_data->bp_commbuf; |
| 693 | |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 694 | /* Combined SPI write/read. */ |
| 695 | bp_commbuf[i++] = 0x04; |
| 696 | bp_commbuf[i++] = (writecnt >> 8) & 0xff; |
| 697 | bp_commbuf[i++] = writecnt & 0xff; |
| 698 | bp_commbuf[i++] = (readcnt >> 8) & 0xff; |
| 699 | bp_commbuf[i++] = readcnt & 0xff; |
| 700 | memcpy(bp_commbuf + i, writearr, writecnt); |
Shawn Anastasio | 2b5adfb | 2017-12-31 00:17:15 -0600 | [diff] [blame] | 701 | |
Carl-Daniel Hailfinger | 64263c7 | 2012-11-01 23:38:51 +0000 | [diff] [blame] | 702 | ret = buspirate_sendrecv(bp_commbuf, i + writecnt, 1 + readcnt); |
| 703 | |
| 704 | if (ret) { |
| 705 | msg_perr("Bus Pirate communication error!\n"); |
| 706 | return SPI_GENERIC_ERROR; |
| 707 | } |
| 708 | |
| 709 | if (bp_commbuf[0] != 0x01) { |
| 710 | msg_perr("Protocol error while sending SPI write/read!\n"); |
| 711 | return SPI_GENERIC_ERROR; |
| 712 | } |
| 713 | |
| 714 | /* Skip Ack. */ |
| 715 | memcpy(readarr, bp_commbuf + 1, readcnt); |
| 716 | |
| 717 | return ret; |
Nico Huber | deeac7e | 2017-04-22 00:09:42 +0200 | [diff] [blame] | 718 | } |
Thomas Heijligen | cc853d8 | 2021-05-04 15:32:17 +0200 | [diff] [blame] | 719 | |
| 720 | const struct programmer_entry programmer_buspirate_spi = { |
| 721 | .name = "buspirate_spi", |
| 722 | .type = OTHER, |
| 723 | /* FIXME */ |
| 724 | .devs.note = "Dangerous Prototypes Bus Pirate\n", |
| 725 | .init = buspirate_spi_init, |
| 726 | .map_flash_region = fallback_map, |
| 727 | .unmap_flash_region = fallback_unmap, |
| 728 | .delay = internal_delay, |
| 729 | }; |