blob: ae939e346d0652aecf59b5c37186a1e91b325677 [file] [log] [blame]
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +00001/*
2 * This file is part of the flashrom project.
3 *
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +00004 * Copyright (C) 2009, 2010, 2011, 2012 Carl-Daniel Hailfinger
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +00005 *
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 Hailfinger5cca01f2009-11-24 00:20:03 +000014 */
15
16#include <stdio.h>
Carl-Daniel Hailfinger1c6d2ff2012-08-27 00:44:42 +000017#include <strings.h>
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000018#include <string.h>
19#include <stdlib.h>
20#include <ctype.h>
Carl-Daniel Hailfingerd2f007f2010-09-16 22:34:25 +000021#include <unistd.h>
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000022#include "flash.h"
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000023#include "programmer.h"
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000024#include "spi.h"
25
26/* Change this to #define if you want to test without a serial implementation */
27#undef FAKE_COMMUNICATION
28
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -060029struct buspirate_speeds {
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +000030 const char *name;
31 const int speed;
32};
33
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -060034#define BP_DEFAULTBAUD 115200
35
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000036#ifndef FAKE_COMMUNICATION
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000037static int buspirate_serialport_setup(char *dev)
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000038{
39 /* 115200bps, 8 databits, no parity, 1 stopbit */
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -060040 sp_fd = sp_openserport(dev, BP_DEFAULTBAUD);
Elyes HAOUAS124ef382018-03-27 12:15:09 +020041 if (sp_fd == SER_INV_FD)
Niklas Söderlund2a95e872012-07-30 19:42:33 +000042 return 1;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000043 return 0;
44}
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000045#else
46#define buspirate_serialport_setup(...) 0
Carl-Daniel Hailfingerefa151e2010-01-06 16:09:10 +000047#define serialport_shutdown(...) 0
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000048#define serialport_write(...) 0
49#define serialport_read(...) 0
Patrick Georgi3b6237d2010-01-06 19:09:40 +000050#define sp_flush_incoming(...) 0
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000051#endif
52
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +000053static unsigned char *bp_commbuf = NULL;
54static int bp_commbufsize = 0;
55
56static int buspirate_commbuf_grow(int bufsize)
57{
58 unsigned char *tmpbuf;
59
60 /* Never shrink. realloc() calls are expensive. */
61 if (bufsize <= bp_commbufsize)
62 return 0;
63
64 tmpbuf = realloc(bp_commbuf, bufsize);
65 if (!tmpbuf) {
66 /* Keep the existing buffer because memory is already tight. */
67 msg_perr("Out of memory!\n");
68 return ERROR_OOM;
69 }
70
71 bp_commbuf = tmpbuf;
72 bp_commbufsize = bufsize;
73 return 0;
74}
75
Uwe Hermann91f4afa2011-07-28 08:13:25 +000076static int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt,
77 unsigned int readcnt)
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000078{
Nico Huber519be662018-12-23 20:03:35 +010079 unsigned int i;
80 int ret = 0;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000081
Sean Nelson84f7bce2010-01-09 23:56:41 +000082 msg_pspew("%s: write %i, read %i ", __func__, writecnt, readcnt);
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000083 if (!writecnt && !readcnt) {
Sean Nelson84f7bce2010-01-09 23:56:41 +000084 msg_perr("Zero length command!\n");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000085 return 1;
86 }
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +000087 if (writecnt)
88 msg_pspew("Sending");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000089 for (i = 0; i < writecnt; i++)
Sean Nelson84f7bce2010-01-09 23:56:41 +000090 msg_pspew(" 0x%02x", buf[i]);
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +000091#ifdef FAKE_COMMUNICATION
92 /* Placate the caller for now. */
93 if (readcnt) {
94 buf[0] = 0x01;
95 memset(buf + 1, 0xff, readcnt - 1);
96 }
97 ret = 0;
98#else
99 if (writecnt)
100 ret = serialport_write(buf, writecnt);
101 if (ret)
102 return ret;
103 if (readcnt)
104 ret = serialport_read(buf, readcnt);
105 if (ret)
106 return ret;
107#endif
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000108 if (readcnt)
109 msg_pspew(", receiving");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000110 for (i = 0; i < readcnt; i++)
Sean Nelson84f7bce2010-01-09 23:56:41 +0000111 msg_pspew(" 0x%02x", buf[i]);
112 msg_pspew("\n");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000113 return 0;
114}
115
Jacob Garber4a84ec22019-07-25 19:12:31 -0600116static int buspirate_wait_for_string(unsigned char *buf, const char *key)
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000117{
118 unsigned int keylen = strlen(key);
119 int ret;
120
121 ret = buspirate_sendrecv(buf, 0, keylen);
122 while (!ret) {
123 if (!memcmp(buf, key, keylen))
124 return 0;
125 memmove(buf, buf + 1, keylen - 1);
126 ret = buspirate_sendrecv(buf + keylen - 1, 0, 1);
127 }
128 return ret;
129}
130
Edward O'Callaghan5eca4272020-04-12 17:27:53 +1000131static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000132 const unsigned char *writearr, unsigned char *readarr);
Edward O'Callaghan5eca4272020-04-12 17:27:53 +1000133static int buspirate_spi_send_command_v2(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000134 const unsigned char *writearr, unsigned char *readarr);
Michael Karcherb9dbe482011-05-11 17:07:07 +0000135
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000136static struct spi_master spi_master_buspirate = {
Nico Huber1cf407b2017-11-10 20:18:23 +0100137 .features = SPI_MASTER_4BA,
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000138 .max_data_read = MAX_DATA_UNSPECIFIED,
139 .max_data_write = MAX_DATA_UNSPECIFIED,
140 .command = NULL,
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000141 .multicommand = default_spi_send_multicommand,
142 .read = default_spi_read,
143 .write_256 = default_spi_write_256,
Nico Huber7bca1262012-06-15 22:28:12 +0000144 .write_aai = default_spi_write_aai,
Michael Karcherb9dbe482011-05-11 17:07:07 +0000145};
146
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600147static const struct buspirate_speeds spispeeds[] = {
Carl-Daniel Hailfingerd5b28fa2009-11-24 18:27:10 +0000148 {"30k", 0x0},
149 {"125k", 0x1},
150 {"250k", 0x2},
151 {"1M", 0x3},
152 {"2M", 0x4},
153 {"2.6M", 0x5},
154 {"4M", 0x6},
155 {"8M", 0x7},
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600156 {NULL, 0x0}
157};
158
159static const struct buspirate_speeds serialspeeds[] = {
160 {"115200", 115200},
161 {"230400", 230400},
162 {"250000", 250000},
163 {"2000000", 2000000},
164 {"2M", 2000000},
165 {NULL, 0}
Carl-Daniel Hailfingerd5b28fa2009-11-24 18:27:10 +0000166};
167
David Hendricks8bb20212011-06-14 01:35:36 +0000168static int buspirate_spi_shutdown(void *data)
169{
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000170 int ret = 0, ret2 = 0;
171 /* No need to allocate a buffer here, we know that bp_commbuf is at least DEFAULT_BUFSIZE big. */
David Hendricks8bb20212011-06-14 01:35:36 +0000172
173 /* Exit raw SPI mode (enter raw bitbang mode) */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000174 bp_commbuf[0] = 0x00;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000175 if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000176 goto out_shutdown;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000177 if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO")))
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000178 goto out_shutdown;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000179 if ((ret = buspirate_sendrecv(bp_commbuf, 0, 1)))
180 goto out_shutdown;
181 msg_pdbg("Raw bitbang mode version %c\n", bp_commbuf[0]);
182 if (bp_commbuf[0] != '1') {
183 msg_perr("Can't handle raw bitbang mode version %c!\n", bp_commbuf[0]);
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000184 ret = 1;
185 goto out_shutdown;
David Hendricks8bb20212011-06-14 01:35:36 +0000186 }
187 /* Reset Bus Pirate (return to user terminal) */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000188 bp_commbuf[0] = 0x0f;
189 ret = buspirate_sendrecv(bp_commbuf, 1, 0);
David Hendricks8bb20212011-06-14 01:35:36 +0000190
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000191out_shutdown:
David Hendricks8bb20212011-06-14 01:35:36 +0000192 /* Shut down serial port communication */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000193 ret2 = serialport_shutdown(NULL);
194 /* Keep the oldest error, it is probably the best indicator. */
195 if (ret2 && !ret)
196 ret = ret2;
197 bp_commbufsize = 0;
198 free(bp_commbuf);
199 bp_commbuf = NULL;
David Hendricks8bb20212011-06-14 01:35:36 +0000200 if (ret)
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000201 msg_pdbg("Bus Pirate shutdown failed.\n");
202 else
203 msg_pdbg("Bus Pirate shutdown completed.\n");
David Hendricks8bb20212011-06-14 01:35:36 +0000204
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000205 return ret;
David Hendricks8bb20212011-06-14 01:35:36 +0000206}
207
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000208#define BP_FWVERSION(a,b) ((a) << 8 | (b))
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600209#define BP_HWVERSION(a,b) BP_FWVERSION(a,b)
210
211/**
212 * The Bus Pirate's PIC microcontroller supports custom baud rates by manually specifying a
213 * clock divisor that can be calculated with the formula (16000000 / (4 * baud)) - 1.
214 */
215#define BP_DIVISOR(baud) ((4000000/(baud)) - 1)
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000216
Thomas Heijligencc853d82021-05-04 15:32:17 +0200217static int buspirate_spi_init(void)
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000218{
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000219 char *tmp;
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000220 char *dev;
221 int i;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600222 int cnt;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000223 unsigned int fw_version_major = 0;
224 unsigned int fw_version_minor = 0;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600225 unsigned int hw_version_major = 0;
226 unsigned int hw_version_minor = 0;
Carl-Daniel Hailfinger082c8b52011-08-15 19:54:20 +0000227 int spispeed = 0x7;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600228 int serialspeed_index = -1;
Carl-Daniel Hailfinger082c8b52011-08-15 19:54:20 +0000229 int ret = 0;
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000230 int pullup = 0;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000231
Carl-Daniel Hailfinger2b6dcb32010-07-08 10:13:37 +0000232 dev = extract_programmer_param("dev");
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000233 if (dev && !strlen(dev)) {
234 free(dev);
235 dev = NULL;
236 }
237 if (!dev) {
238 msg_perr("No serial device given. Use flashrom -p buspirate_spi:dev=/dev/ttyUSB0\n");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000239 return 1;
240 }
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000241
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000242 tmp = extract_programmer_param("spispeed");
243 if (tmp) {
244 for (i = 0; spispeeds[i].name; i++) {
245 if (!strncasecmp(spispeeds[i].name, tmp, strlen(spispeeds[i].name))) {
Carl-Daniel Hailfingerd5b28fa2009-11-24 18:27:10 +0000246 spispeed = spispeeds[i].speed;
247 break;
248 }
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000249 }
Carl-Daniel Hailfingerd5b28fa2009-11-24 18:27:10 +0000250 if (!spispeeds[i].name)
Sean Nelson84f7bce2010-01-09 23:56:41 +0000251 msg_perr("Invalid SPI speed, using default.\n");
Carl-Daniel Hailfingerd5b28fa2009-11-24 18:27:10 +0000252 }
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000253 free(tmp);
254
Elyes HAOUASe2c90c42018-08-18 09:04:41 +0200255 /* Extract serialspeed parameter */
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600256 tmp = extract_programmer_param("serialspeed");
257 if (tmp) {
258 for (i = 0; serialspeeds[i].name; i++) {
259 if (!strncasecmp(serialspeeds[i].name, tmp, strlen(serialspeeds[i].name))) {
260 serialspeed_index = i;
261 break;
262 }
263 }
264 if (!serialspeeds[i].name)
265 msg_perr("Invalid serial speed %s, using default.\n", tmp);
266 }
267 free(tmp);
268
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000269 tmp = extract_programmer_param("pullups");
270 if (tmp) {
271 if (strcasecmp("on", tmp) == 0)
272 pullup = 1;
273 else if (strcasecmp("off", tmp) == 0)
274 ; // ignore
275 else
276 msg_perr("Invalid pullups state, not using them.\n");
277 }
278 free(tmp);
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000279
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000280 /* Default buffer size is 19: 16 bytes data, 3 bytes control. */
281#define DEFAULT_BUFSIZE (16 + 3)
282 bp_commbuf = malloc(DEFAULT_BUFSIZE);
283 if (!bp_commbuf) {
284 bp_commbufsize = 0;
285 msg_perr("Out of memory!\n");
Stefan Reinauer18385912014-04-26 16:12:45 +0000286 free(dev);
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000287 return ERROR_OOM;
288 }
289 bp_commbufsize = DEFAULT_BUFSIZE;
290
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000291 ret = buspirate_serialport_setup(dev);
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000292 free(dev);
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000293 if (ret) {
294 bp_commbufsize = 0;
295 free(bp_commbuf);
296 bp_commbuf = NULL;
297 return ret;
298 }
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000299
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000300 /* This is the brute force version, but it should work.
301 * It is likely to fail if a previous flashrom run was aborted during a write with the new SPI commands
302 * in firmware v5.5 because that firmware may wait for up to 4096 bytes of input before responding to
303 * 0x00 again. The obvious workaround (sending 4096 bytes of \0) may cause significant startup delays.
304 */
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000305 for (i = 0; i < 20; i++) {
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000306 /* Enter raw bitbang mode */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000307 bp_commbuf[0] = 0x00;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000308 /* Send the command, don't read the response. */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000309 ret = buspirate_sendrecv(bp_commbuf, 1, 0);
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000310 if (ret)
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000311 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000312 /* The old way to handle responses from a Bus Pirate already in BBIO mode was to flush any
313 * response which came in over serial. Unfortunately that does not work reliably on Linux
314 * with FTDI USB-serial.
315 */
316 //sp_flush_incoming();
317 /* The Bus Pirate can't handle UART input buffer overflow in BBIO mode, and sending a sequence
318 * of 0x00 too fast apparently triggers such an UART input buffer overflow.
319 */
Maksim Kuleshov73dc0db2013-04-05 08:06:10 +0000320 internal_sleep(10000);
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000321 }
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000322 /* We know that 20 commands of \0 should elicit at least one BBIO1 response. */
323 if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000324 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000325
326 /* Reset the Bus Pirate. */
327 bp_commbuf[0] = 0x0f;
328 /* Send the command, don't read the response. */
329 if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000330 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000331 if ((ret = buspirate_wait_for_string(bp_commbuf, "irate ")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000332 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000333 /* Read the hardware version string. Last byte of the buffer is reserved for \0. */
334 for (i = 0; i < DEFAULT_BUFSIZE - 1; i++) {
335 if ((ret = buspirate_sendrecv(bp_commbuf + i, 0, 1)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000336 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000337 if (strchr("\r\n\t ", bp_commbuf[i]))
338 break;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000339 }
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000340 bp_commbuf[i] = '\0';
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600341 msg_pdbg("Detected Bus Pirate hardware ");
342 if (bp_commbuf[0] != 'v')
343 msg_pdbg("(unknown version number format)");
344 else if (!strchr("0123456789", bp_commbuf[1]))
345 msg_pdbg("(unknown version number format)");
346 else {
347 hw_version_major = strtoul((char *)bp_commbuf + 1, &tmp, 10);
348 while ((*tmp != '\0') && !strchr("0123456789", *tmp))
349 tmp++;
350 hw_version_minor = strtoul(tmp, NULL, 10);
351 msg_pdbg("%u.%u", hw_version_major, hw_version_minor);
352 }
353 msg_pdbg2(" (\"%s\")", bp_commbuf);
354 msg_pdbg("\n");
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000355
356 if ((ret = buspirate_wait_for_string(bp_commbuf, "irmware ")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000357 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000358 /* Read the firmware version string. Last byte of the buffer is reserved for \0. */
359 for (i = 0; i < DEFAULT_BUFSIZE - 1; i++) {
360 if ((ret = buspirate_sendrecv(bp_commbuf + i, 0, 1)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000361 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000362 if (strchr("\r\n\t ", bp_commbuf[i]))
363 break;
364 }
365 bp_commbuf[i] = '\0';
366 msg_pdbg("Detected Bus Pirate firmware ");
367 if (bp_commbuf[0] != 'v')
368 msg_pdbg("(unknown version number format)");
369 else if (!strchr("0123456789", bp_commbuf[1]))
370 msg_pdbg("(unknown version number format)");
371 else {
372 fw_version_major = strtoul((char *)bp_commbuf + 1, &tmp, 10);
373 while ((*tmp != '\0') && !strchr("0123456789", *tmp))
374 tmp++;
375 fw_version_minor = strtoul(tmp, NULL, 10);
376 msg_pdbg("%u.%u", fw_version_major, fw_version_minor);
377 }
378 msg_pdbg2(" (\"%s\")", bp_commbuf);
379 msg_pdbg("\n");
380
381 if ((ret = buspirate_wait_for_string(bp_commbuf, "HiZ>")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000382 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600383
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000384 /* Tell the user about missing SPI binary mode in firmware 2.3 and older. */
385 if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(2, 4)) {
386 msg_pinfo("Bus Pirate firmware 2.3 and older does not support binary SPI access.\n");
387 msg_pinfo("Please upgrade to the latest firmware (at least 2.4).\n");
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000388 ret = SPI_PROGRAMMER_ERROR;
389 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000390 }
391
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000392 /* Use fast SPI mode in firmware 5.5 and newer. */
393 if (BP_FWVERSION(fw_version_major, fw_version_minor) >= BP_FWVERSION(5, 5)) {
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600394 msg_pdbg("Using SPI command set v2.\n");
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000395 /* Sensible default buffer size. */
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000396 if (buspirate_commbuf_grow(260 + 5)) {
397 ret = ERROR_OOM;
398 goto init_err_cleanup_exit;
399 }
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000400 spi_master_buspirate.max_data_read = 2048;
401 spi_master_buspirate.max_data_write = 256;
402 spi_master_buspirate.command = buspirate_spi_send_command_v2;
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000403 } else {
404 msg_pinfo("Bus Pirate firmware 5.4 and older does not support fast SPI access.\n");
405 msg_pinfo("Reading/writing a flash chip may take hours.\n");
406 msg_pinfo("It is recommended to upgrade to firmware 5.5 or newer.\n");
407 /* Sensible default buffer size. */
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000408 if (buspirate_commbuf_grow(16 + 3)) {
409 ret = ERROR_OOM;
410 goto init_err_cleanup_exit;
411 }
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000412 spi_master_buspirate.max_data_read = 12;
413 spi_master_buspirate.max_data_write = 12;
414 spi_master_buspirate.command = buspirate_spi_send_command_v1;
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000415 }
416
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000417 /* Workaround for broken speed settings in firmware 6.1 and older. */
418 if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(6, 2))
419 if (spispeed > 0x4) {
420 msg_perr("Bus Pirate firmware 6.1 and older does not support SPI speeds above 2 MHz. "
421 "Limiting speed to 2 MHz.\n");
422 msg_pinfo("It is recommended to upgrade to firmware 6.2 or newer.\n");
423 spispeed = 0x4;
424 }
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600425
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000426 /* This works because speeds numbering starts at 0 and is contiguous. */
427 msg_pdbg("SPI speed is %sHz\n", spispeeds[spispeed].name);
428
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600429 /* Set 2M baud serial speed by default on hardware 3.0 and newer if a custom speed was not set */
430 if (serialspeed_index == -1 && BP_HWVERSION(hw_version_major, hw_version_minor) >= BP_HWVERSION(3, 0)) {
431 serialspeed_index = ARRAY_SIZE(serialspeeds) - 2;
432 msg_pdbg("Bus Pirate v3 or newer detected. Set serial speed to 2M baud.\n");
433 }
434
435 /* Set custom serial speed if specified */
436 if (serialspeed_index != -1) {
437 if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(5, 5)) {
438 /* This feature requires firmware 5.5 or newer */
439 msg_perr("Bus Pirate firmware 5.4 and older does not support custom serial speeds."
440 "Using default speed of 115200 baud.\n");
441 } else if (serialspeeds[serialspeed_index].speed != BP_DEFAULTBAUD) {
442 /* Set the serial speed to match the user's choice if it doesn't already */
443
444 if (BP_HWVERSION(hw_version_major, hw_version_minor) < BP_HWVERSION(3, 0))
445 msg_pwarn("Increased serial speeds may not work on older (<3.0) Bus Pirates."
446 " Continue at your own risk.\n");
447
448 /* Enter baud rate configuration mode */
449 cnt = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "b\n");
450 if ((ret = buspirate_sendrecv(bp_commbuf, cnt, 0)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000451 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600452 if ((ret = buspirate_wait_for_string(bp_commbuf, ">")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000453 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600454
455 /* Enter manual clock divisor entry mode */
456 cnt = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "10\n");
457 if ((ret = buspirate_sendrecv(bp_commbuf, cnt, 0)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000458 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600459 if ((ret = buspirate_wait_for_string(bp_commbuf, ">")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000460 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600461
462 /* Set the clock divisor to the value calculated from the user's input */
463 cnt = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "%d\n",
464 BP_DIVISOR(serialspeeds[serialspeed_index].speed));
465
466 if ((ret = buspirate_sendrecv(bp_commbuf, cnt, 0)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000467 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600468 sleep(1);
469
470 /* Reconfigure the host's serial baud rate to the new value */
471 if ((ret = serialport_config(sp_fd, serialspeeds[serialspeed_index].speed))) {
472 msg_perr("Unable to configure system baud rate to specified value.");
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000473 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600474 }
475
476 /* Return to the main prompt */
477 bp_commbuf[0] = ' ';
478 if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000479 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600480 if ((ret = buspirate_wait_for_string(bp_commbuf, "HiZ>")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000481 goto init_err_cleanup_exit;
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600482
483 msg_pdbg("Serial speed is %d baud\n", serialspeeds[serialspeed_index].speed);
484 }
485
486 }
487
488
489
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000490 /* Enter raw bitbang mode */
491 for (i = 0; i < 20; i++) {
492 bp_commbuf[0] = 0x00;
493 if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000494 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000495 }
496 if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000497 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000498 if ((ret = buspirate_sendrecv(bp_commbuf, 0, 1)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000499 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000500 msg_pdbg("Raw bitbang mode version %c\n", bp_commbuf[0]);
501 if (bp_commbuf[0] != '1') {
502 msg_perr("Can't handle raw bitbang mode version %c!\n", bp_commbuf[0]);
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000503 ret = 1;
504 goto init_err_cleanup_exit;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000505 }
506 /* Enter raw SPI mode */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000507 bp_commbuf[0] = 0x01;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000508 ret = buspirate_sendrecv(bp_commbuf, 1, 0);
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000509 if (ret) {
510 ret = 1;
511 goto init_err_cleanup_exit;
512 }
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000513 if ((ret = buspirate_wait_for_string(bp_commbuf, "SPI")))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000514 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000515 if ((ret = buspirate_sendrecv(bp_commbuf, 0, 1)))
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000516 goto init_err_cleanup_exit;
Carl-Daniel Hailfingera16a8922012-08-17 17:30:43 +0000517 msg_pdbg("Raw SPI mode version %c\n", bp_commbuf[0]);
518 if (bp_commbuf[0] != '1') {
519 msg_perr("Can't handle raw SPI mode version %c!\n", bp_commbuf[0]);
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000520 ret = 1;
521 goto init_err_cleanup_exit;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000522 }
523
524 /* Initial setup (SPI peripherals config): Enable power, CS high, AUX */
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000525 bp_commbuf[0] = 0x40 | 0x0b;
526 if (pullup == 1) {
527 bp_commbuf[0] |= (1 << 2);
528 msg_pdbg("Enabling pull-up resistors.\n");
529 }
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000530 ret = buspirate_sendrecv(bp_commbuf, 1, 1);
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000531 if (ret) {
532 ret = 1;
533 goto init_err_cleanup_exit;
534 }
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000535 if (bp_commbuf[0] != 0x01) {
Brian Salcedo30dfdba2013-01-03 20:44:30 +0000536 msg_perr("Protocol error while setting power/CS/AUX(/Pull-up resistors)!\n");
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000537 ret = 1;
538 goto init_err_cleanup_exit;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000539 }
540
Carl-Daniel Hailfingerd5b28fa2009-11-24 18:27:10 +0000541 /* Set SPI speed */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000542 bp_commbuf[0] = 0x60 | spispeed;
543 ret = buspirate_sendrecv(bp_commbuf, 1, 1);
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000544 if (ret) {
545 ret = 1;
546 goto init_err_cleanup_exit;
547 }
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000548 if (bp_commbuf[0] != 0x01) {
Sean Nelson84f7bce2010-01-09 23:56:41 +0000549 msg_perr("Protocol error while setting SPI speed!\n");
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000550 ret = 1;
551 goto init_err_cleanup_exit;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000552 }
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600553
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000554 /* Set SPI config: output type, idle, clock edge, sample */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000555 bp_commbuf[0] = 0x80 | 0xa;
Maxime Vincent2099c642017-11-24 13:04:08 +0100556 if (pullup == 1) {
557 bp_commbuf[0] &= ~(1 << 3);
558 msg_pdbg("Pull-ups enabled, so using HiZ pin output! (Open-Drain mode)\n");
559 }
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000560 ret = buspirate_sendrecv(bp_commbuf, 1, 1);
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000561 if (ret) {
562 ret = 1;
563 goto init_err_cleanup_exit;
564 }
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000565 if (bp_commbuf[0] != 0x01) {
Sean Nelson84f7bce2010-01-09 23:56:41 +0000566 msg_perr("Protocol error while setting SPI config!\n");
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000567 ret = 1;
568 goto init_err_cleanup_exit;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000569 }
570
571 /* De-assert CS# */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000572 bp_commbuf[0] = 0x03;
573 ret = buspirate_sendrecv(bp_commbuf, 1, 1);
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000574 if (ret) {
575 ret = 1;
576 goto init_err_cleanup_exit;
577 }
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000578 if (bp_commbuf[0] != 0x01) {
Sean Nelson84f7bce2010-01-09 23:56:41 +0000579 msg_perr("Protocol error while raising CS#!\n");
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000580 ret = 1;
581 goto init_err_cleanup_exit;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000582 }
583
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000584 if (register_shutdown(buspirate_spi_shutdown, NULL) != 0) {
585 ret = 1;
586 goto init_err_cleanup_exit;
587 }
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000588 register_spi_master(&spi_master_buspirate);
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000589
590 return 0;
Anastasia Klimchuk7dcb6f32021-05-24 15:12:10 +1000591
592init_err_cleanup_exit:
593 buspirate_spi_shutdown(NULL);
594 return ret;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000595}
596
Edward O'Callaghan5eca4272020-04-12 17:27:53 +1000597static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000598 const unsigned char *writearr, unsigned char *readarr)
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000599{
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000600 unsigned int i = 0;
601 int ret = 0;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000602
603 if (writecnt > 16 || readcnt > 16 || (readcnt + writecnt) > 16)
604 return SPI_INVALID_LENGTH;
605
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000606 /* 3 bytes extra for CS#, len, CS#. */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000607 if (buspirate_commbuf_grow(writecnt + readcnt + 3))
608 return ERROR_OOM;
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000609
610 /* Assert CS# */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000611 bp_commbuf[i++] = 0x02;
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000612
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000613 bp_commbuf[i++] = 0x10 | (writecnt + readcnt - 1);
614 memcpy(bp_commbuf + i, writearr, writecnt);
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000615 i += writecnt;
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000616 memset(bp_commbuf + i, 0, readcnt);
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000617
618 i += readcnt;
619 /* De-assert CS# */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000620 bp_commbuf[i++] = 0x03;
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000621
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000622 ret = buspirate_sendrecv(bp_commbuf, i, i);
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000623
624 if (ret) {
625 msg_perr("Bus Pirate communication error!\n");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000626 return SPI_GENERIC_ERROR;
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000627 }
628
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000629 if (bp_commbuf[0] != 0x01) {
Sean Nelson84f7bce2010-01-09 23:56:41 +0000630 msg_perr("Protocol error while lowering CS#!\n");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000631 return SPI_GENERIC_ERROR;
632 }
633
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000634 if (bp_commbuf[1] != 0x01) {
Sean Nelson84f7bce2010-01-09 23:56:41 +0000635 msg_perr("Protocol error while reading/writing SPI!\n");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000636 return SPI_GENERIC_ERROR;
637 }
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000638
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000639 if (bp_commbuf[i - 1] != 0x01) {
Sean Nelson84f7bce2010-01-09 23:56:41 +0000640 msg_perr("Protocol error while raising CS#!\n");
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000641 return SPI_GENERIC_ERROR;
642 }
643
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000644 /* Skip CS#, length, writearr. */
Carl-Daniel Hailfinger316fdfb2012-06-08 15:27:47 +0000645 memcpy(readarr, bp_commbuf + 2 + writecnt, readcnt);
Carl-Daniel Hailfinger04e18be2010-07-29 16:24:09 +0000646
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000647 return ret;
648}
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000649
Edward O'Callaghan5eca4272020-04-12 17:27:53 +1000650static int buspirate_spi_send_command_v2(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000651 const unsigned char *writearr, unsigned char *readarr)
652{
653 int i = 0, ret = 0;
654
655 if (writecnt > 4096 || readcnt > 4096 || (readcnt + writecnt) > 4096)
656 return SPI_INVALID_LENGTH;
657
658 /* 5 bytes extra for command, writelen, readlen.
659 * 1 byte extra for Ack/Nack.
660 */
661 if (buspirate_commbuf_grow(max(writecnt + 5, readcnt + 1)))
662 return ERROR_OOM;
663
664 /* Combined SPI write/read. */
665 bp_commbuf[i++] = 0x04;
666 bp_commbuf[i++] = (writecnt >> 8) & 0xff;
667 bp_commbuf[i++] = writecnt & 0xff;
668 bp_commbuf[i++] = (readcnt >> 8) & 0xff;
669 bp_commbuf[i++] = readcnt & 0xff;
670 memcpy(bp_commbuf + i, writearr, writecnt);
Shawn Anastasio2b5adfb2017-12-31 00:17:15 -0600671
Carl-Daniel Hailfinger64263c72012-11-01 23:38:51 +0000672 ret = buspirate_sendrecv(bp_commbuf, i + writecnt, 1 + readcnt);
673
674 if (ret) {
675 msg_perr("Bus Pirate communication error!\n");
676 return SPI_GENERIC_ERROR;
677 }
678
679 if (bp_commbuf[0] != 0x01) {
680 msg_perr("Protocol error while sending SPI write/read!\n");
681 return SPI_GENERIC_ERROR;
682 }
683
684 /* Skip Ack. */
685 memcpy(readarr, bp_commbuf + 1, readcnt);
686
687 return ret;
Nico Huberdeeac7e2017-04-22 00:09:42 +0200688}
Thomas Heijligencc853d82021-05-04 15:32:17 +0200689
690const struct programmer_entry programmer_buspirate_spi = {
691 .name = "buspirate_spi",
692 .type = OTHER,
693 /* FIXME */
694 .devs.note = "Dangerous Prototypes Bus Pirate\n",
695 .init = buspirate_spi_init,
696 .map_flash_region = fallback_map,
697 .unmap_flash_region = fallback_unmap,
698 .delay = internal_delay,
699};