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 | 5824fbf | 2010-05-21 23:09:42 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009, 2010 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <ctype.h> |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 25 | #include "flash.h" |
Sean Nelson | 14ba668 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 26 | #include "chipdrivers.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 27 | #include "programmer.h" |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 28 | #include "spi.h" |
| 29 | |
| 30 | /* Change this to #define if you want to test without a serial implementation */ |
| 31 | #undef FAKE_COMMUNICATION |
| 32 | |
| 33 | #ifndef FAKE_COMMUNICATION |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 34 | static int buspirate_serialport_setup(char *dev) |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 35 | { |
| 36 | /* 115200bps, 8 databits, no parity, 1 stopbit */ |
| 37 | sp_fd = sp_openserport(dev, 115200); |
| 38 | return 0; |
| 39 | } |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 40 | #else |
| 41 | #define buspirate_serialport_setup(...) 0 |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 42 | #define serialport_shutdown(...) 0 |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 43 | #define serialport_write(...) 0 |
| 44 | #define serialport_read(...) 0 |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 45 | #define sp_flush_incoming(...) 0 |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 48 | static int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, unsigned int readcnt) |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 49 | { |
| 50 | int i, ret = 0; |
| 51 | |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 52 | msg_pspew("%s: write %i, read %i ", __func__, writecnt, readcnt); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 53 | if (!writecnt && !readcnt) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 54 | msg_perr("Zero length command!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 55 | return 1; |
| 56 | } |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 57 | msg_pspew("Sending"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 58 | for (i = 0; i < writecnt; i++) |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 59 | msg_pspew(" 0x%02x", buf[i]); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 60 | #ifdef FAKE_COMMUNICATION |
| 61 | /* Placate the caller for now. */ |
| 62 | if (readcnt) { |
| 63 | buf[0] = 0x01; |
| 64 | memset(buf + 1, 0xff, readcnt - 1); |
| 65 | } |
| 66 | ret = 0; |
| 67 | #else |
| 68 | if (writecnt) |
| 69 | ret = serialport_write(buf, writecnt); |
| 70 | if (ret) |
| 71 | return ret; |
| 72 | if (readcnt) |
| 73 | ret = serialport_read(buf, readcnt); |
| 74 | if (ret) |
| 75 | return ret; |
| 76 | #endif |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 77 | msg_pspew(", receiving"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 78 | for (i = 0; i < readcnt; i++) |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 79 | msg_pspew(" 0x%02x", buf[i]); |
| 80 | msg_pspew("\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 84 | static const struct buspirate_spispeeds spispeeds[] = { |
| 85 | {"30k", 0x0}, |
| 86 | {"125k", 0x1}, |
| 87 | {"250k", 0x2}, |
| 88 | {"1M", 0x3}, |
| 89 | {"2M", 0x4}, |
| 90 | {"2.6M", 0x5}, |
| 91 | {"4M", 0x6}, |
| 92 | {"8M", 0x7}, |
| 93 | {NULL, 0x0} |
| 94 | }; |
| 95 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 96 | int buspirate_spi_init(void) |
| 97 | { |
| 98 | unsigned char buf[512]; |
| 99 | int ret = 0; |
| 100 | int i; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 101 | char *dev = NULL; |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 102 | char *speed = NULL; |
| 103 | int spispeed = 0x7; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 104 | |
Carl-Daniel Hailfinger | 2b6dcb3 | 2010-07-08 10:13:37 +0000 | [diff] [blame] | 105 | dev = extract_programmer_param("dev"); |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 106 | if (!dev || !strlen(dev)) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 107 | msg_perr("No serial device given. Use flashrom -p " |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 108 | "buspirate_spi:dev=/dev/ttyUSB0\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 109 | return 1; |
| 110 | } |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 111 | |
Carl-Daniel Hailfinger | 2b6dcb3 | 2010-07-08 10:13:37 +0000 | [diff] [blame] | 112 | speed = extract_programmer_param("spispeed"); |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 113 | if (speed) { |
| 114 | for (i = 0; spispeeds[i].name; i++) |
| 115 | if (!strncasecmp(spispeeds[i].name, speed, |
| 116 | strlen(spispeeds[i].name))) { |
| 117 | spispeed = spispeeds[i].speed; |
| 118 | break; |
| 119 | } |
| 120 | if (!spispeeds[i].name) |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 121 | msg_perr("Invalid SPI speed, using default.\n"); |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 122 | } |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 123 | free(speed); |
| 124 | |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 125 | /* This works because speeds numbering starts at 0 and is contiguous. */ |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 126 | msg_pdbg("SPI speed is %sHz\n", spispeeds[spispeed].name); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 127 | |
| 128 | ret = buspirate_serialport_setup(dev); |
| 129 | if (ret) |
| 130 | return ret; |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 131 | free(dev); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 132 | |
| 133 | /* This is the brute force version, but it should work. */ |
| 134 | for (i = 0; i < 19; i++) { |
| 135 | /* Enter raw bitbang mode */ |
| 136 | buf[0] = 0x00; |
| 137 | /* Send the command, don't read the response. */ |
| 138 | ret = buspirate_sendrecv(buf, 1, 0); |
| 139 | if (ret) |
| 140 | return ret; |
| 141 | /* Read any response and discard it. */ |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 142 | sp_flush_incoming(); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 143 | } |
| 144 | /* Enter raw bitbang mode */ |
| 145 | buf[0] = 0x00; |
| 146 | ret = buspirate_sendrecv(buf, 1, 5); |
| 147 | if (ret) |
| 148 | return ret; |
| 149 | if (memcmp(buf, "BBIO", 4)) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 150 | msg_perr("Entering raw bitbang mode failed!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 151 | return 1; |
| 152 | } |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 153 | msg_pdbg("Raw bitbang mode version %c\n", buf[4]); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 154 | if (buf[4] != '1') { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 155 | msg_perr("Can't handle raw bitbang mode version %c!\n", |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 156 | buf[4]); |
| 157 | return 1; |
| 158 | } |
| 159 | /* Enter raw SPI mode */ |
| 160 | buf[0] = 0x01; |
| 161 | ret = buspirate_sendrecv(buf, 1, 4); |
| 162 | if (memcmp(buf, "SPI", 3)) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 163 | msg_perr("Entering raw SPI mode failed!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 164 | return 1; |
| 165 | } |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 166 | msg_pdbg("Raw SPI mode version %c\n", buf[3]); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 167 | if (buf[3] != '1') { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 168 | msg_perr("Can't handle raw SPI mode version %c!\n", |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 169 | buf[3]); |
| 170 | return 1; |
| 171 | } |
| 172 | |
| 173 | /* Initial setup (SPI peripherals config): Enable power, CS high, AUX */ |
| 174 | buf[0] = 0x40 | 0xb; |
| 175 | ret = buspirate_sendrecv(buf, 1, 1); |
| 176 | if (ret) |
| 177 | return 1; |
| 178 | if (buf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 179 | msg_perr("Protocol error while setting power/CS/AUX!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 180 | return 1; |
| 181 | } |
| 182 | |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 183 | /* Set SPI speed */ |
| 184 | buf[0] = 0x60 | spispeed; |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 185 | ret = buspirate_sendrecv(buf, 1, 1); |
| 186 | if (ret) |
| 187 | return 1; |
| 188 | if (buf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 189 | msg_perr("Protocol error while setting SPI speed!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | /* Set SPI config: output type, idle, clock edge, sample */ |
| 194 | buf[0] = 0x80 | 0xa; |
| 195 | ret = buspirate_sendrecv(buf, 1, 1); |
| 196 | if (ret) |
| 197 | return 1; |
| 198 | if (buf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 199 | msg_perr("Protocol error while setting SPI config!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 200 | return 1; |
| 201 | } |
| 202 | |
| 203 | /* De-assert CS# */ |
| 204 | buf[0] = 0x03; |
| 205 | ret = buspirate_sendrecv(buf, 1, 1); |
| 206 | if (ret) |
| 207 | return 1; |
| 208 | if (buf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 209 | msg_perr("Protocol error while raising CS#!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 210 | return 1; |
| 211 | } |
| 212 | |
| 213 | buses_supported = CHIP_BUSTYPE_SPI; |
| 214 | spi_controller = SPI_CONTROLLER_BUSPIRATE; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | int buspirate_spi_shutdown(void) |
| 220 | { |
| 221 | unsigned char buf[5]; |
| 222 | int ret = 0; |
| 223 | |
| 224 | /* Exit raw SPI mode (enter raw bitbang mode) */ |
| 225 | buf[0] = 0x00; |
| 226 | ret = buspirate_sendrecv(buf, 1, 5); |
| 227 | if (ret) |
| 228 | return ret; |
| 229 | if (memcmp(buf, "BBIO", 4)) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 230 | msg_perr("Entering raw bitbang mode failed!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 231 | return 1; |
| 232 | } |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 233 | msg_pdbg("Raw bitbang mode version %c\n", buf[4]); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 234 | if (buf[4] != '1') { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 235 | msg_perr("Can't handle raw bitbang mode version %c!\n", |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 236 | buf[4]); |
| 237 | return 1; |
| 238 | } |
| 239 | /* Reset Bus Pirate (return to user terminal) */ |
| 240 | buf[0] = 0x0f; |
| 241 | ret = buspirate_sendrecv(buf, 1, 0); |
| 242 | if (ret) |
| 243 | return ret; |
| 244 | |
| 245 | /* Shut down serial port communication */ |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 246 | ret = serialport_shutdown(); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 247 | if (ret) |
| 248 | return ret; |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 249 | msg_pdbg("Bus Pirate shutdown completed.\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, |
| 255 | const unsigned char *writearr, unsigned char *readarr) |
| 256 | { |
| 257 | static unsigned char *buf = NULL; |
| 258 | int i = 0, ret = 0; |
| 259 | |
| 260 | if (writecnt > 16 || readcnt > 16 || (readcnt + writecnt) > 16) |
| 261 | return SPI_INVALID_LENGTH; |
| 262 | |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 263 | /* 3 bytes extra for CS#, len, CS#. */ |
| 264 | buf = realloc(buf, writecnt + readcnt + 3); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 265 | if (!buf) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 266 | msg_perr("Out of memory!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 267 | exit(1); // -1 |
| 268 | } |
| 269 | |
| 270 | /* Assert CS# */ |
| 271 | buf[i++] = 0x02; |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 272 | |
| 273 | buf[i++] = 0x10 | (writecnt + readcnt - 1); |
| 274 | memcpy(buf + i, writearr, writecnt); |
| 275 | i += writecnt; |
| 276 | memset(buf + i, 0, readcnt); |
| 277 | |
| 278 | i += readcnt; |
| 279 | /* De-assert CS# */ |
| 280 | buf[i++] = 0x03; |
| 281 | |
| 282 | ret = buspirate_sendrecv(buf, i, i); |
| 283 | |
| 284 | if (ret) { |
| 285 | msg_perr("Bus Pirate communication error!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 286 | return SPI_GENERIC_ERROR; |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 289 | if (buf[0] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 290 | msg_perr("Protocol error while lowering CS#!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 291 | return SPI_GENERIC_ERROR; |
| 292 | } |
| 293 | |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 294 | if (buf[1] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 295 | msg_perr("Protocol error while reading/writing SPI!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 296 | return SPI_GENERIC_ERROR; |
| 297 | } |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 298 | |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 299 | if (buf[i - 1] != 0x01) { |
Sean Nelson | 84f7bce | 2010-01-09 23:56:41 +0000 | [diff] [blame] | 300 | msg_perr("Protocol error while raising CS#!\n"); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 301 | return SPI_GENERIC_ERROR; |
| 302 | } |
| 303 | |
Carl-Daniel Hailfinger | 04e18be | 2010-07-29 16:24:09 +0000 | [diff] [blame] | 304 | /* Skip CS#, length, writearr. */ |
| 305 | memcpy(readarr, buf + 2 + writecnt, readcnt); |
| 306 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) |
| 311 | { |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 312 | return spi_read_chunked(flash, buf, start, len, 12); |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Carl-Daniel Hailfinger | 9a795d8 | 2010-07-14 16:19:05 +0000 | [diff] [blame] | 315 | int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) |
Carl-Daniel Hailfinger | 408e47a | 2010-03-22 03:30:58 +0000 | [diff] [blame] | 316 | { |
Carl-Daniel Hailfinger | 9a795d8 | 2010-07-14 16:19:05 +0000 | [diff] [blame] | 317 | return spi_write_chunked(flash, buf, start, len, 12); |
Carl-Daniel Hailfinger | 408e47a | 2010-03-22 03:30:58 +0000 | [diff] [blame] | 318 | } |