Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Carl-Daniel Hailfinger |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 2015 Simon Glass |
| 6 | * Copyright (C) 2015 Stefan Tauner |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
Stefan Tauner | 0cbd8c2 | 2015-01-26 22:06:04 +0000 | [diff] [blame] | 22 | #include "platform.h" |
| 23 | |
Nico Huber | 4d440a7 | 2017-08-15 11:26:48 +0200 | [diff] [blame] | 24 | #include <sys/types.h> |
Stefan Tauner | 5c316f9 | 2015-02-08 21:57:52 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 27 | #include <string.h> |
Stefan Tauner | e34e3e8 | 2013-01-01 00:06:51 +0000 | [diff] [blame] | 28 | #include <limits.h> |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 29 | #include <errno.h> |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 30 | #include <libusb.h> |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 31 | #include "flash.h" |
Sean Nelson | 14ba668 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 32 | #include "chipdrivers.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 33 | #include "programmer.h" |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 34 | #include "spi.h" |
| 35 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 36 | /* LIBUSB_CALL ensures the right calling conventions on libusb callbacks. |
| 37 | * However, the macro is not defined everywhere. m( |
| 38 | */ |
| 39 | #ifndef LIBUSB_CALL |
| 40 | #define LIBUSB_CALL |
| 41 | #endif |
| 42 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 43 | #define FIRMWARE_VERSION(x,y,z) ((x << 16) | (y << 8) | z) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 44 | #define DEFAULT_TIMEOUT 3000 |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 45 | #define DEDIPROG_ASYNC_TRANSFERS 8 /* at most 8 asynchronous transfers */ |
| 46 | #define REQTYPE_OTHER_OUT (LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_OTHER) /* 0x43 */ |
| 47 | #define REQTYPE_OTHER_IN (LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_OTHER) /* 0xC3 */ |
| 48 | #define REQTYPE_EP_OUT (LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_ENDPOINT) /* 0x42 */ |
| 49 | #define REQTYPE_EP_IN (LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_ENDPOINT) /* 0xC2 */ |
| 50 | struct libusb_context *usb_ctx; |
| 51 | static libusb_device_handle *dediprog_handle; |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 52 | static int dediprog_in_endpoint; |
| 53 | static int dediprog_out_endpoint; |
| 54 | |
| 55 | enum dediprog_devtype { |
| 56 | DEV_UNKNOWN = 0, |
| 57 | DEV_SF100 = 100, |
| 58 | DEV_SF600 = 600, |
| 59 | }; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 60 | |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 61 | enum dediprog_leds { |
| 62 | LED_INVALID = -1, |
| 63 | LED_NONE = 0, |
| 64 | LED_PASS = 1 << 0, |
| 65 | LED_BUSY = 1 << 1, |
| 66 | LED_ERROR = 1 << 2, |
| 67 | LED_ALL = 7, |
| 68 | }; |
| 69 | |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 70 | /* IO bits for CMD_SET_IO_LED message */ |
| 71 | enum dediprog_ios { |
| 72 | IO1 = 1 << 0, |
| 73 | IO2 = 1 << 1, |
| 74 | IO3 = 1 << 2, |
| 75 | IO4 = 1 << 3, |
| 76 | }; |
| 77 | |
| 78 | enum dediprog_cmds { |
| 79 | CMD_TRANSCEIVE = 0x01, |
| 80 | CMD_POLL_STATUS_REG = 0x02, |
| 81 | CMD_SET_VPP = 0x03, |
| 82 | CMD_SET_TARGET = 0x04, |
| 83 | CMD_READ_EEPROM = 0x05, |
| 84 | CMD_WRITE_EEPROM = 0x06, |
| 85 | CMD_SET_IO_LED = 0x07, |
| 86 | CMD_READ_PROG_INFO = 0x08, |
| 87 | CMD_SET_VCC = 0x09, |
| 88 | CMD_SET_STANDALONE = 0x0A, |
David Hendricks | c05900f | 2016-02-18 21:42:41 +0000 | [diff] [blame] | 89 | CMD_SET_VOLTAGE = 0x0B, /* Only in firmware older than 6.0.0 */ |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 90 | CMD_GET_BUTTON = 0x11, |
| 91 | CMD_GET_UID = 0x12, |
| 92 | CMD_SET_CS = 0x14, |
| 93 | CMD_IO_MODE = 0x15, |
| 94 | CMD_FW_UPDATE = 0x1A, |
| 95 | CMD_FPGA_UPDATE = 0x1B, |
| 96 | CMD_READ_FPGA_VERSION = 0x1C, |
| 97 | CMD_SET_HOLD = 0x1D, |
| 98 | CMD_READ = 0x20, |
| 99 | CMD_WRITE = 0x30, |
| 100 | CMD_WRITE_AT45DB = 0x31, |
| 101 | CMD_NAND_WRITE = 0x32, |
| 102 | CMD_NAND_READ = 0x33, |
| 103 | CMD_SET_SPI_CLK = 0x61, |
| 104 | CMD_CHECK_SOCKET = 0x62, |
| 105 | CMD_DOWNLOAD_PRJ = 0x63, |
| 106 | CMD_READ_PRJ_NAME = 0x64, |
| 107 | // New protocol/firmware only |
| 108 | CMD_CHECK_SDCARD = 0x65, |
| 109 | CMD_READ_PRJ = 0x66, |
| 110 | }; |
| 111 | |
| 112 | enum dediprog_target { |
| 113 | FLASH_TYPE_APPLICATION_FLASH_1 = 0, |
| 114 | FLASH_TYPE_FLASH_CARD, |
| 115 | FLASH_TYPE_APPLICATION_FLASH_2, |
| 116 | FLASH_TYPE_SOCKET, |
| 117 | }; |
| 118 | |
| 119 | enum dediprog_readmode { |
| 120 | READ_MODE_STD = 1, |
| 121 | READ_MODE_FAST = 2, |
| 122 | READ_MODE_ATMEL45 = 3, |
| 123 | READ_MODE_4B_ADDR_FAST = 4, |
| 124 | READ_MODE_4B_ADDR_FAST_0x0C = 5, /* New protocol only */ |
| 125 | }; |
| 126 | |
| 127 | enum dediprog_writemode { |
| 128 | WRITE_MODE_PAGE_PGM = 1, |
| 129 | WRITE_MODE_PAGE_WRITE = 2, |
| 130 | WRITE_MODE_1B_AAI = 3, |
| 131 | WRITE_MODE_2B_AAI = 4, |
| 132 | WRITE_MODE_128B_PAGE = 5, |
| 133 | WRITE_MODE_PAGE_AT26DF041 = 6, |
| 134 | WRITE_MODE_SILICON_BLUE_FPGA = 7, |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 135 | WRITE_MODE_64B_PAGE_NUMONYX_PCM = 8, /* unit of 512 bytes */ |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 136 | WRITE_MODE_4B_ADDR_256B_PAGE_PGM = 9, |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 137 | WRITE_MODE_32B_PAGE_PGM_MXIC_512K = 10, /* unit of 512 bytes */ |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 138 | WRITE_MODE_4B_ADDR_256B_PAGE_PGM_0x12 = 11, |
| 139 | WRITE_MODE_4B_ADDR_256B_PAGE_PGM_FLAGS = 12, |
| 140 | }; |
| 141 | |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 142 | enum dediprog_standalone_mode { |
| 143 | ENTER_STANDALONE_MODE = 0, |
| 144 | LEAVE_STANDALONE_MODE = 1, |
| 145 | }; |
| 146 | |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 147 | /* |
| 148 | * These are not official designations; they are for use in flashrom only. |
| 149 | * Order must be preserved so that comparison operators work. |
| 150 | */ |
| 151 | enum protocol { |
| 152 | PROTOCOL_UNKNOWN, |
| 153 | PROTOCOL_V1, |
| 154 | PROTOCOL_V2, |
| 155 | PROTOCOL_V3, |
| 156 | }; |
| 157 | |
Stefan Tauner | fdec747 | 2016-02-22 08:59:27 +0000 | [diff] [blame] | 158 | const struct dev_entry devs_dediprog[] = { |
| 159 | {0x0483, 0xDADA, OK, "Dediprog", "SF100/SF600"}, |
| 160 | |
| 161 | {0}, |
| 162 | }; |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 163 | |
| 164 | static int dediprog_firmwareversion = FIRMWARE_VERSION(0, 0, 0); |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 165 | enum dediprog_devtype dediprog_devicetype = DEV_UNKNOWN; |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 166 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 167 | #if defined(LIBUSB_MAJOR) && defined(LIBUSB_MINOR) && defined(LIBUSB_MICRO) && \ |
| 168 | LIBUSB_MAJOR <= 1 && LIBUSB_MINOR == 0 && LIBUSB_MICRO < 9 |
| 169 | /* Quick and dirty replacement for missing libusb_error_name in libusb < 1.0.9 */ |
| 170 | const char * LIBUSB_CALL libusb_error_name(int error_code) |
| 171 | { |
| 172 | if (error_code >= INT16_MIN && error_code <= INT16_MAX) { |
| 173 | /* 18 chars for text, rest for number (16 b should be enough), sign, nullbyte. */ |
| 174 | static char my_libusb_error[18 + 5 + 2]; |
| 175 | sprintf(my_libusb_error, "libusb error code %i", error_code); |
| 176 | return my_libusb_error; |
| 177 | } else { |
| 178 | return "UNKNOWN"; |
| 179 | } |
| 180 | } |
| 181 | #endif |
| 182 | |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 183 | static enum protocol protocol(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 184 | { |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 185 | /* Firmware version < 5.0.0 is handled explicitly in some cases. */ |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 186 | switch (dediprog_devicetype) { |
| 187 | case DEV_SF100: |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 188 | if (dediprog_firmwareversion < FIRMWARE_VERSION(5, 5, 0)) |
| 189 | return PROTOCOL_V1; |
| 190 | else |
| 191 | return PROTOCOL_V2; |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 192 | case DEV_SF600: |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 193 | if (dediprog_firmwareversion < FIRMWARE_VERSION(6, 9, 0)) |
| 194 | return PROTOCOL_V1; |
| 195 | else if (dediprog_firmwareversion <= FIRMWARE_VERSION(7, 2, 21)) |
| 196 | return PROTOCOL_V2; |
| 197 | else |
| 198 | return PROTOCOL_V3; |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 199 | default: |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 200 | return PROTOCOL_UNKNOWN; |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 201 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 202 | } |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 203 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 204 | struct dediprog_transfer_status { |
| 205 | int error; /* OK if 0, ERROR else */ |
| 206 | unsigned int queued_idx; |
| 207 | unsigned int finished_idx; |
| 208 | }; |
| 209 | |
| 210 | static void LIBUSB_CALL dediprog_bulk_read_cb(struct libusb_transfer *const transfer) |
| 211 | { |
| 212 | struct dediprog_transfer_status *const status = (struct dediprog_transfer_status *)transfer->user_data; |
| 213 | if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { |
| 214 | status->error = 1; |
| 215 | msg_perr("SPI bulk read failed!\n"); |
| 216 | } |
| 217 | ++status->finished_idx; |
| 218 | } |
| 219 | |
| 220 | static int dediprog_bulk_read_poll(const struct dediprog_transfer_status *const status, const int finish) |
| 221 | { |
| 222 | if (status->finished_idx >= status->queued_idx) |
| 223 | return 0; |
| 224 | |
| 225 | do { |
| 226 | struct timeval timeout = { 10, 0 }; |
| 227 | const int ret = libusb_handle_events_timeout(usb_ctx, &timeout); |
| 228 | if (ret < 0) { |
| 229 | msg_perr("Polling read events failed: %i %s!\n", ret, libusb_error_name(ret)); |
| 230 | return 1; |
| 231 | } |
| 232 | } while (finish && (status->finished_idx < status->queued_idx)); |
| 233 | return 0; |
| 234 | } |
| 235 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 236 | static int dediprog_read(enum dediprog_cmds cmd, unsigned int value, unsigned int idx, uint8_t *bytes, size_t size) |
| 237 | { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 238 | return libusb_control_transfer(dediprog_handle, REQTYPE_EP_IN, cmd, value, idx, |
| 239 | (unsigned char *)bytes, size, DEFAULT_TIMEOUT); |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static int dediprog_write(enum dediprog_cmds cmd, unsigned int value, unsigned int idx, const uint8_t *bytes, size_t size) |
| 243 | { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 244 | return libusb_control_transfer(dediprog_handle, REQTYPE_EP_OUT, cmd, value, idx, |
| 245 | (unsigned char *)bytes, size, DEFAULT_TIMEOUT); |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 246 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 247 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 248 | |
| 249 | /* Might be useful for other USB devices as well. static for now. |
| 250 | * num parameter allows user to specify one device of multiple installed */ |
| 251 | static struct libusb_device_handle *get_device_by_vid_pid_number(uint16_t vid, uint16_t pid, unsigned int num) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 252 | { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 253 | struct libusb_device **list; |
| 254 | ssize_t count = libusb_get_device_list(usb_ctx, &list); |
| 255 | if (count < 0) { |
| 256 | msg_perr("Getting the USB device list failed (%s)!\n", libusb_error_name(count)); |
| 257 | return NULL; |
| 258 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 259 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 260 | struct libusb_device_handle *handle = NULL; |
| 261 | ssize_t i = 0; |
| 262 | for (i = 0; i < count; i++) { |
| 263 | struct libusb_device *dev = list[i]; |
| 264 | struct libusb_device_descriptor desc; |
| 265 | int err = libusb_get_device_descriptor(dev, &desc); |
| 266 | if (err != 0) { |
| 267 | msg_perr("Reading the USB device descriptor failed (%s)!\n", libusb_error_name(err)); |
| 268 | libusb_free_device_list(list, 1); |
| 269 | return NULL; |
| 270 | } |
| 271 | if ((desc.idVendor == vid) && (desc.idProduct == pid)) { |
| 272 | msg_pdbg("Found USB device %04"PRIx16":%04"PRIx16" at address %d-%d.\n", |
| 273 | desc.idVendor, desc.idProduct, |
| 274 | libusb_get_bus_number(dev), libusb_get_device_address(dev)); |
| 275 | if (num == 0) { |
| 276 | err = libusb_open(dev, &handle); |
| 277 | if (err != 0) { |
| 278 | msg_perr("Opening the USB device failed (%s)!\n", |
| 279 | libusb_error_name(err)); |
| 280 | libusb_free_device_list(list, 1); |
| 281 | return NULL; |
| 282 | } |
| 283 | break; |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 284 | } |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 285 | num--; |
| 286 | } |
| 287 | } |
| 288 | libusb_free_device_list(list, 1); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 289 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 290 | return handle; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 293 | /* This function sets the GPIOs connected to the LEDs as well as IO1-IO4. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 294 | static int dediprog_set_leds(int leds) |
| 295 | { |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 296 | if (leds < LED_NONE || leds > LED_ALL) |
| 297 | leds = LED_ALL; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 298 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 299 | /* Older Dediprogs with 2.x.x and 3.x.x firmware only had two LEDs, assigned to different bits. So map |
| 300 | * them around if we have an old device. On those devices the LEDs map as follows: |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 301 | * bit 2 == 0: green light is on. |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 302 | * bit 0 == 0: red light is on. |
| 303 | * |
| 304 | * Additionally, the command structure has changed with the "new" protocol. |
| 305 | * |
| 306 | * FIXME: take IO pins into account |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 307 | */ |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 308 | int target_leds, ret; |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 309 | if (protocol() >= PROTOCOL_V2) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 310 | target_leds = (leds ^ 7) << 8; |
| 311 | ret = dediprog_write(CMD_SET_IO_LED, target_leds, 0, NULL, 0); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 312 | } else { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 313 | if (dediprog_firmwareversion < FIRMWARE_VERSION(5, 0, 0)) { |
| 314 | target_leds = ((leds & LED_ERROR) >> 2) | ((leds & LED_PASS) << 2); |
| 315 | } else { |
| 316 | target_leds = leds; |
| 317 | } |
| 318 | target_leds ^= 7; |
| 319 | |
| 320 | ret = dediprog_write(CMD_SET_IO_LED, 0x9, target_leds, NULL, 0); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 323 | if (ret != 0x0) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 324 | msg_perr("Command Set LED 0x%x failed (%s)!\n", leds, libusb_error_name(ret)); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 325 | return 1; |
| 326 | } |
| 327 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 331 | static int dediprog_set_spi_voltage(int millivolt) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 332 | { |
| 333 | int ret; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 334 | uint16_t voltage_selector; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 335 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 336 | switch (millivolt) { |
| 337 | case 0: |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 338 | /* Admittedly this one is an assumption. */ |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 339 | voltage_selector = 0x0; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 340 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 341 | case 1800: |
| 342 | voltage_selector = 0x12; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 343 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 344 | case 2500: |
| 345 | voltage_selector = 0x11; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 346 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 347 | case 3500: |
| 348 | voltage_selector = 0x10; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 349 | break; |
| 350 | default: |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 351 | msg_perr("Unknown voltage %i mV! Aborting.\n", millivolt); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 352 | return 1; |
| 353 | } |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 354 | msg_pdbg("Setting SPI voltage to %u.%03u V\n", millivolt / 1000, |
| 355 | millivolt % 1000); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 356 | |
Nico Huber | 4099a8a | 2012-06-16 00:02:27 +0000 | [diff] [blame] | 357 | if (voltage_selector == 0) { |
| 358 | /* Wait some time as the original driver does. */ |
| 359 | programmer_delay(200 * 1000); |
| 360 | } |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 361 | ret = dediprog_write(CMD_SET_VCC, voltage_selector, 0, NULL, 0); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 362 | if (ret != 0x0) { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 363 | msg_perr("Command Set SPI Voltage 0x%x failed!\n", |
| 364 | voltage_selector); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 365 | return 1; |
| 366 | } |
Nico Huber | 4099a8a | 2012-06-16 00:02:27 +0000 | [diff] [blame] | 367 | if (voltage_selector != 0) { |
| 368 | /* Wait some time as the original driver does. */ |
| 369 | programmer_delay(200 * 1000); |
| 370 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 374 | struct dediprog_spispeeds { |
| 375 | const char *const name; |
| 376 | const int speed; |
| 377 | }; |
| 378 | |
| 379 | static const struct dediprog_spispeeds spispeeds[] = { |
| 380 | { "24M", 0x0 }, |
| 381 | { "12M", 0x2 }, |
| 382 | { "8M", 0x1 }, |
| 383 | { "3M", 0x3 }, |
| 384 | { "2.18M", 0x4 }, |
| 385 | { "1.5M", 0x5 }, |
| 386 | { "750k", 0x6 }, |
| 387 | { "375k", 0x7 }, |
| 388 | { NULL, 0x0 }, |
| 389 | }; |
| 390 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 391 | static int dediprog_set_spi_speed(unsigned int spispeed_idx) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 392 | { |
Patrick Georgi | efe2d43 | 2013-05-23 21:47:46 +0000 | [diff] [blame] | 393 | if (dediprog_firmwareversion < FIRMWARE_VERSION(5, 0, 0)) { |
| 394 | msg_pwarn("Skipping to set SPI speed because firmware is too old.\n"); |
| 395 | return 0; |
| 396 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 397 | |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 398 | const struct dediprog_spispeeds *spispeed = &spispeeds[spispeed_idx]; |
| 399 | msg_pdbg("SPI speed is %sHz\n", spispeed->name); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 400 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 401 | int ret = dediprog_write(CMD_SET_SPI_CLK, spispeed->speed, 0, NULL, 0); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 402 | if (ret != 0x0) { |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 403 | msg_perr("Command Set SPI Speed 0x%x failed!\n", spispeed->speed); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 404 | return 1; |
| 405 | } |
| 406 | return 0; |
| 407 | } |
| 408 | |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 409 | static void fill_rw_cmd_payload(uint8_t *data_packet, unsigned int count, uint8_t dedi_spi_cmd, |
| 410 | unsigned int *value, unsigned int *idx, unsigned int start, int is_read) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 411 | /* First 5 bytes are common in both generations. */ |
| 412 | data_packet[0] = count & 0xff; |
| 413 | data_packet[1] = (count >> 8) & 0xff; |
| 414 | data_packet[2] = 0; /* RFU */ |
| 415 | data_packet[3] = dedi_spi_cmd; /* Read/Write Mode (currently READ_MODE_STD, WRITE_MODE_PAGE_PGM or WRITE_MODE_2B_AAI) */ |
| 416 | data_packet[4] = 0; /* "Opcode". Specs imply necessity only for READ_MODE_4B_ADDR_FAST and WRITE_MODE_4B_ADDR_256B_PAGE_PGM */ |
| 417 | |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 418 | if (protocol() >= PROTOCOL_V2) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 419 | *value = *idx = 0; |
| 420 | data_packet[5] = 0; /* RFU */ |
| 421 | data_packet[6] = (start >> 0) & 0xff; |
| 422 | data_packet[7] = (start >> 8) & 0xff; |
| 423 | data_packet[8] = (start >> 16) & 0xff; |
| 424 | data_packet[9] = (start >> 24) & 0xff; |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 425 | if (protocol() >= PROTOCOL_V3) { |
| 426 | if (is_read) { |
| 427 | data_packet[10] = 0x00; /* address length (3 or 4) */ |
| 428 | data_packet[11] = 0x00; /* dummy cycle / 2 */ |
| 429 | } else { |
| 430 | /* 16 LSBs and 16 HSBs of page size */ |
| 431 | /* FIXME: This assumes page size of 256. */ |
| 432 | data_packet[10] = 0x00; |
| 433 | data_packet[11] = 0x01; |
| 434 | data_packet[12] = 0x00; |
| 435 | data_packet[13] = 0x00; |
| 436 | } |
| 437 | } |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 438 | } else { |
| 439 | *value = start % 0x10000; |
| 440 | *idx = start / 0x10000; |
| 441 | } |
| 442 | } |
| 443 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 444 | /* Bulk read interface, will read multiple 512 byte chunks aligned to 512 bytes. |
| 445 | * @start start address |
| 446 | * @len length |
| 447 | * @return 0 on success, 1 on failure |
| 448 | */ |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 449 | static int dediprog_spi_bulk_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 450 | { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 451 | int err = 1; |
| 452 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 453 | /* chunksize must be 512, other sizes will NOT work at all. */ |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 454 | const unsigned int chunksize = 512; |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 455 | const unsigned int count = len / chunksize; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 456 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 457 | struct dediprog_transfer_status status = { 0, 0, 0 }; |
| 458 | struct libusb_transfer *transfers[DEDIPROG_ASYNC_TRANSFERS] = { NULL, }; |
| 459 | struct libusb_transfer *transfer; |
| 460 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 461 | if ((start % chunksize) || (len % chunksize)) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 462 | msg_perr("%s: Unaligned start=%i, len=%i! Please report a bug at flashrom@flashrom.org\n", |
| 463 | __func__, start, len); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 464 | return 1; |
| 465 | } |
| 466 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 467 | if (len == 0) |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 468 | return 0; |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 469 | |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 470 | int command_packet_size; |
| 471 | switch (protocol()) { |
| 472 | case PROTOCOL_V1: |
| 473 | command_packet_size = 5; |
| 474 | break; |
| 475 | case PROTOCOL_V2: |
| 476 | command_packet_size = 10; |
| 477 | break; |
| 478 | case PROTOCOL_V3: |
| 479 | command_packet_size = 12; |
| 480 | break; |
| 481 | default: |
| 482 | return 1; |
| 483 | } |
| 484 | |
| 485 | uint8_t data_packet[command_packet_size]; |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 486 | unsigned int value, idx; |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 487 | fill_rw_cmd_payload(data_packet, count, READ_MODE_STD, &value, &idx, start, 1); |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 488 | |
| 489 | int ret = dediprog_write(CMD_READ, value, idx, data_packet, sizeof(data_packet)); |
| 490 | if (ret != sizeof(data_packet)) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 491 | msg_perr("Command Read SPI Bulk failed, %i %s!\n", ret, libusb_error_name(ret)); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 492 | return 1; |
| 493 | } |
| 494 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 495 | /* |
| 496 | * Ring buffer of bulk transfers. |
| 497 | * Poll until at least one transfer is ready, |
| 498 | * schedule next transfers until buffer is full. |
| 499 | */ |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 500 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 501 | /* Allocate bulk transfers. */ |
| 502 | unsigned int i; |
| 503 | for (i = 0; i < min(DEDIPROG_ASYNC_TRANSFERS, count); ++i) { |
| 504 | transfers[i] = libusb_alloc_transfer(0); |
| 505 | if (!transfers[i]) { |
| 506 | msg_perr("Allocating libusb transfer %i failed: %s!\n", i, libusb_error_name(ret)); |
| 507 | goto err_free; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | /* Now transfer requested chunks using libusb's asynchronous interface. */ |
| 512 | while (!status.error && (status.queued_idx < count)) { |
Nico Huber | f84df9a | 2016-05-04 13:24:07 +0200 | [diff] [blame] | 513 | while ((status.queued_idx < count) && |
| 514 | (status.queued_idx - status.finished_idx) < DEDIPROG_ASYNC_TRANSFERS) |
| 515 | { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 516 | transfer = transfers[status.queued_idx % DEDIPROG_ASYNC_TRANSFERS]; |
| 517 | libusb_fill_bulk_transfer(transfer, dediprog_handle, 0x80 | dediprog_in_endpoint, |
| 518 | (unsigned char *)buf + status.queued_idx * chunksize, chunksize, |
| 519 | dediprog_bulk_read_cb, &status, DEFAULT_TIMEOUT); |
| 520 | transfer->flags |= LIBUSB_TRANSFER_SHORT_NOT_OK; |
| 521 | ret = libusb_submit_transfer(transfer); |
| 522 | if (ret < 0) { |
| 523 | msg_perr("Submitting SPI bulk read %i failed: %s!\n", |
| 524 | status.queued_idx, libusb_error_name(ret)); |
| 525 | goto err_free; |
| 526 | } |
| 527 | ++status.queued_idx; |
| 528 | } |
| 529 | if (dediprog_bulk_read_poll(&status, 0)) |
| 530 | goto err_free; |
| 531 | } |
| 532 | /* Wait for transfers to finish. */ |
| 533 | if (dediprog_bulk_read_poll(&status, 1)) |
| 534 | goto err_free; |
| 535 | /* Check if everything has been transmitted. */ |
| 536 | if ((status.finished_idx < count) || status.error) |
| 537 | goto err_free; |
| 538 | |
| 539 | err = 0; |
| 540 | |
| 541 | err_free: |
| 542 | dediprog_bulk_read_poll(&status, 1); |
| 543 | for (i = 0; i < DEDIPROG_ASYNC_TRANSFERS; ++i) |
| 544 | if (transfers[i]) libusb_free_transfer(transfers[i]); |
| 545 | return err; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 548 | static int dediprog_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 549 | { |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 550 | int ret; |
| 551 | /* chunksize must be 512, other sizes will NOT work at all. */ |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 552 | const unsigned int chunksize = 0x200; |
| 553 | unsigned int residue = start % chunksize ? chunksize - start % chunksize : 0; |
| 554 | unsigned int bulklen; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 555 | |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 556 | dediprog_set_leds(LED_BUSY); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 557 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 558 | if (residue) { |
| 559 | msg_pdbg("Slow read for partial block from 0x%x, length 0x%x\n", |
| 560 | start, residue); |
| 561 | ret = spi_read_chunked(flash, buf, start, residue, 16); |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 562 | if (ret) |
| 563 | goto err; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* Round down. */ |
| 567 | bulklen = (len - residue) / chunksize * chunksize; |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 568 | ret = dediprog_spi_bulk_read(flash, buf + residue, start + residue, bulklen); |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 569 | if (ret) |
| 570 | goto err; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 571 | |
| 572 | len -= residue + bulklen; |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 573 | if (len != 0) { |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 574 | msg_pdbg("Slow read for partial block from 0x%x, length 0x%x\n", |
| 575 | start, len); |
| 576 | ret = spi_read_chunked(flash, buf + residue + bulklen, |
| 577 | start + residue + bulklen, len, 16); |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 578 | if (ret) |
| 579 | goto err; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 582 | dediprog_set_leds(LED_PASS); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 583 | return 0; |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 584 | err: |
| 585 | dediprog_set_leds(LED_ERROR); |
| 586 | return ret; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 589 | /* Bulk write interface, will write multiple chunksize byte chunks aligned to chunksize bytes. |
| 590 | * @chunksize length of data chunks, only 256 supported by now |
| 591 | * @start start address |
| 592 | * @len length |
| 593 | * @dedi_spi_cmd dediprog specific write command for spi bus |
| 594 | * @return 0 on success, 1 on failure |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 595 | */ |
Stefan Tauner | ffb0cf6 | 2014-05-25 07:47:47 +0000 | [diff] [blame] | 596 | static int dediprog_spi_bulk_write(struct flashctx *flash, const uint8_t *buf, unsigned int chunksize, |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 597 | unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 598 | { |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 599 | /* USB transfer size must be 512, other sizes will NOT work at all. |
| 600 | * chunksize is the real data size per USB bulk transfer. The remaining |
| 601 | * space in a USB bulk transfer must be filled with 0xff padding. |
| 602 | */ |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 603 | const unsigned int count = len / chunksize; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 604 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 605 | /* |
| 606 | * We should change this check to |
| 607 | * chunksize > 512 |
| 608 | * once we know how to handle different chunk sizes. |
| 609 | */ |
| 610 | if (chunksize != 256) { |
| 611 | msg_perr("%s: Chunk sizes other than 256 bytes are unsupported, chunksize=%u!\n" |
| 612 | "Please report a bug at flashrom@flashrom.org\n", __func__, chunksize); |
| 613 | return 1; |
| 614 | } |
| 615 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 616 | if ((start % chunksize) || (len % chunksize)) { |
| 617 | msg_perr("%s: Unaligned start=%i, len=%i! Please report a bug " |
| 618 | "at flashrom@flashrom.org\n", __func__, start, len); |
| 619 | return 1; |
| 620 | } |
| 621 | |
| 622 | /* No idea if the hardware can handle empty writes, so chicken out. */ |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 623 | if (len == 0) |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 624 | return 0; |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 625 | |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 626 | int command_packet_size; |
| 627 | switch (protocol()) { |
| 628 | case PROTOCOL_V1: |
| 629 | command_packet_size = 5; |
| 630 | break; |
| 631 | case PROTOCOL_V2: |
| 632 | command_packet_size = 10; |
| 633 | break; |
| 634 | case PROTOCOL_V3: |
| 635 | command_packet_size = 14; |
| 636 | break; |
| 637 | default: |
| 638 | return 1; |
| 639 | } |
| 640 | |
| 641 | uint8_t data_packet[command_packet_size]; |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 642 | unsigned int value, idx; |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 643 | fill_rw_cmd_payload(data_packet, count, dedi_spi_cmd, &value, &idx, start, 0); |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 644 | int ret = dediprog_write(CMD_WRITE, value, idx, data_packet, sizeof(data_packet)); |
| 645 | if (ret != sizeof(data_packet)) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 646 | msg_perr("Command Write SPI Bulk failed, %s!\n", libusb_error_name(ret)); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 647 | return 1; |
| 648 | } |
| 649 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 650 | unsigned int i; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 651 | for (i = 0; i < count; i++) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 652 | unsigned char usbbuf[512]; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 653 | memcpy(usbbuf, buf + i * chunksize, chunksize); |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 654 | memset(usbbuf + chunksize, 0xff, sizeof(usbbuf) - chunksize); // fill up with 0xFF |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 655 | int transferred; |
| 656 | ret = libusb_bulk_transfer(dediprog_handle, dediprog_out_endpoint, usbbuf, 512, &transferred, |
| 657 | DEFAULT_TIMEOUT); |
| 658 | if ((ret < 0) || (transferred != 512)) { |
| 659 | msg_perr("SPI bulk write failed, expected %i, got %s!\n", 512, libusb_error_name(ret)); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 660 | return 1; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
Stefan Tauner | ffb0cf6 | 2014-05-25 07:47:47 +0000 | [diff] [blame] | 667 | static int dediprog_spi_write(struct flashctx *flash, const uint8_t *buf, |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 668 | unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 669 | { |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 670 | int ret; |
Carl-Daniel Hailfinger | 5a7cb84 | 2012-08-25 01:17:58 +0000 | [diff] [blame] | 671 | const unsigned int chunksize = flash->chip->page_size; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 672 | unsigned int residue = start % chunksize ? chunksize - start % chunksize : 0; |
| 673 | unsigned int bulklen; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 674 | |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 675 | dediprog_set_leds(LED_BUSY); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 676 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 677 | if (chunksize != 256) { |
| 678 | msg_pdbg("Page sizes other than 256 bytes are unsupported as " |
| 679 | "we don't know how dediprog\nhandles them.\n"); |
| 680 | /* Write everything like it was residue. */ |
| 681 | residue = len; |
| 682 | } |
| 683 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 684 | if (residue) { |
| 685 | msg_pdbg("Slow write for partial block from 0x%x, length 0x%x\n", |
| 686 | start, residue); |
| 687 | /* No idea about the real limit. Maybe 12, maybe more. */ |
| 688 | ret = spi_write_chunked(flash, buf, start, residue, 12); |
| 689 | if (ret) { |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 690 | dediprog_set_leds(LED_ERROR); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 691 | return ret; |
| 692 | } |
| 693 | } |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 694 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 695 | /* Round down. */ |
| 696 | bulklen = (len - residue) / chunksize * chunksize; |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 697 | ret = dediprog_spi_bulk_write(flash, buf + residue, chunksize, start + residue, bulklen, dedi_spi_cmd); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 698 | if (ret) { |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 699 | dediprog_set_leds(LED_ERROR); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 700 | return ret; |
| 701 | } |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 702 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 703 | len -= residue + bulklen; |
| 704 | if (len) { |
| 705 | msg_pdbg("Slow write for partial block from 0x%x, length 0x%x\n", |
| 706 | start, len); |
| 707 | ret = spi_write_chunked(flash, buf + residue + bulklen, |
| 708 | start + residue + bulklen, len, 12); |
| 709 | if (ret) { |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 710 | dediprog_set_leds(LED_ERROR); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 711 | return ret; |
| 712 | } |
| 713 | } |
| 714 | |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 715 | dediprog_set_leds(LED_PASS); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 716 | return 0; |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Stefan Tauner | ffb0cf6 | 2014-05-25 07:47:47 +0000 | [diff] [blame] | 719 | static int dediprog_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 720 | { |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 721 | return dediprog_spi_write(flash, buf, start, len, WRITE_MODE_PAGE_PGM); |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Stefan Tauner | ffb0cf6 | 2014-05-25 07:47:47 +0000 | [diff] [blame] | 724 | static int dediprog_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 725 | { |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 726 | return dediprog_spi_write(flash, buf, start, len, WRITE_MODE_2B_AAI); |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 729 | static int dediprog_spi_send_command(struct flashctx *flash, |
| 730 | unsigned int writecnt, |
| 731 | unsigned int readcnt, |
| 732 | const unsigned char *writearr, |
| 733 | unsigned char *readarr) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 734 | { |
| 735 | int ret; |
| 736 | |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 737 | msg_pspew("%s, writecnt=%i, readcnt=%i\n", __func__, writecnt, readcnt); |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 738 | if (writecnt > flash->mst->spi.max_data_write) { |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 739 | msg_perr("Invalid writecnt=%i, aborting.\n", writecnt); |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 740 | return 1; |
| 741 | } |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 742 | if (readcnt > flash->mst->spi.max_data_read) { |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 743 | msg_perr("Invalid readcnt=%i, aborting.\n", readcnt); |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 744 | return 1; |
| 745 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 746 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 747 | unsigned int idx, value; |
| 748 | /* New protocol has options and timeout combined as value while the old one used the value field for |
| 749 | * timeout and the index field for options. */ |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 750 | if (protocol() >= PROTOCOL_V2) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 751 | idx = 0; |
| 752 | value = readcnt ? 0x1 : 0x0; // Indicate if we require a read |
| 753 | } else { |
| 754 | idx = readcnt ? 0x1 : 0x0; // Indicate if we require a read |
| 755 | value = 0; |
| 756 | } |
| 757 | ret = dediprog_write(CMD_TRANSCEIVE, value, idx, writearr, writecnt); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 758 | if (ret != writecnt) { |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 759 | msg_perr("Send SPI failed, expected %i, got %i %s!\n", |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 760 | writecnt, ret, libusb_error_name(ret)); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 761 | return 1; |
| 762 | } |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 763 | if (readcnt == 0) // If we don't require a response, we are done here |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 764 | return 0; |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 765 | |
Stefan Tauner | 74367bf | 2016-02-20 20:53:46 +0000 | [diff] [blame] | 766 | /* The specifications do state the possibility to set a timeout for transceive transactions. |
| 767 | * Apparently the "timeout" is a delay, and you can use long delays to accelerate writing - in case you |
| 768 | * can predict the time needed by the previous command or so (untested). In any case, using this |
| 769 | * "feature" to set sane-looking timouts for the read below will completely trash performance with |
| 770 | * SF600 and/or firmwares >= 6.0 while they seem to be benign on SF100 with firmwares <= 5.5.2. *shrug* |
| 771 | * |
| 772 | * The specification also uses only 0 in its examples, so the lesson to learn here: |
| 773 | * "Never trust the description of an interface in the documentation but use the example code and pray." |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 774 | const uint8_t read_timeout = 10 + readcnt/512; |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 775 | if (protocol() >= PROTOCOL_V2) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 776 | idx = 0; |
| 777 | value = min(read_timeout, 0xFF) | (0 << 8) ; // Timeout in lower byte, option in upper byte |
| 778 | } else { |
| 779 | idx = (0 & 0xFF); // Lower byte is option (0x01 = require SR, 0x02 keep CS low) |
| 780 | value = min(read_timeout, 0xFF); // Possibly two bytes but we play safe here |
| 781 | } |
| 782 | ret = dediprog_read(CMD_TRANSCEIVE, value, idx, readarr, readcnt); |
Stefan Tauner | 74367bf | 2016-02-20 20:53:46 +0000 | [diff] [blame] | 783 | */ |
| 784 | ret = dediprog_read(CMD_TRANSCEIVE, 0, 0, readarr, readcnt); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 785 | if (ret != readcnt) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 786 | msg_perr("Receive SPI failed, expected %i, got %i %s!\n", readcnt, ret, libusb_error_name(ret)); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 787 | return 1; |
| 788 | } |
| 789 | return 0; |
| 790 | } |
| 791 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 792 | static int dediprog_check_devicestring(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 793 | { |
| 794 | int ret; |
| 795 | char buf[0x11]; |
| 796 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 797 | /* Command Receive Device String. */ |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 798 | ret = dediprog_read(CMD_READ_PROG_INFO, 0, 0, (uint8_t *)buf, 0x10); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 799 | if (ret != 0x10) { |
| 800 | msg_perr("Incomplete/failed Command Receive Device String!\n"); |
| 801 | return 1; |
| 802 | } |
| 803 | buf[0x10] = '\0'; |
| 804 | msg_pdbg("Found a %s\n", buf); |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 805 | if (memcmp(buf, "SF100", 0x5) == 0) |
| 806 | dediprog_devicetype = DEV_SF100; |
| 807 | else if (memcmp(buf, "SF600", 0x5) == 0) |
| 808 | dediprog_devicetype = DEV_SF600; |
| 809 | else { |
| 810 | msg_perr("Device not a SF100 or SF600!\n"); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 811 | return 1; |
| 812 | } |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 813 | |
| 814 | int sfnum; |
| 815 | int fw[3]; |
| 816 | if (sscanf(buf, "SF%d V:%d.%d.%d ", &sfnum, &fw[0], &fw[1], &fw[2]) != 4 || |
| 817 | sfnum != dediprog_devicetype) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 818 | msg_perr("Unexpected firmware version string '%s'\n", buf); |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 819 | return 1; |
| 820 | } |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 821 | /* Only these major versions were tested. */ |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 822 | if (fw[0] < 2 || fw[0] > 7) { |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 823 | msg_perr("Unexpected firmware version %d.%d.%d!\n", fw[0], fw[1], fw[2]); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 824 | return 1; |
| 825 | } |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 826 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 827 | dediprog_firmwareversion = FIRMWARE_VERSION(fw[0], fw[1], fw[2]); |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 828 | if (protocol() == PROTOCOL_UNKNOWN) { |
| 829 | msg_perr("Internal error: Unable to determine protocol version.\n"); |
| 830 | return 1; |
| 831 | } |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 832 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 833 | return 0; |
| 834 | } |
| 835 | |
David Hendricks | c05900f | 2016-02-18 21:42:41 +0000 | [diff] [blame] | 836 | /* |
| 837 | * This command presumably sets the voltage for the SF100 itself (not the |
| 838 | * SPI flash). Only use this command with firmware older than V6.0.0. Newer |
| 839 | * (including all SF600s) do not support it. |
| 840 | */ |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 841 | |
David Hendricks | c05900f | 2016-02-18 21:42:41 +0000 | [diff] [blame] | 842 | /* This command presumably sets the voltage for the SF100 itself (not the SPI flash). |
| 843 | * Only use dediprog_set_voltage on SF100 programmers with firmware older |
| 844 | * than V6.0.0. Newer programmers (including all SF600s) do not support it. */ |
| 845 | static int dediprog_set_voltage(void) |
| 846 | { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 847 | unsigned char buf[1] = {0}; |
| 848 | int ret = libusb_control_transfer(dediprog_handle, REQTYPE_OTHER_IN, CMD_SET_VOLTAGE, 0x0, 0x0, |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 849 | buf, 0x1, DEFAULT_TIMEOUT); |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 850 | if (ret < 0) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 851 | msg_perr("Command Set Voltage failed (%s)!\n", libusb_error_name(ret)); |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 852 | return 1; |
| 853 | } |
David Hendricks | c05900f | 2016-02-18 21:42:41 +0000 | [diff] [blame] | 854 | if ((ret != 1) || (buf[0] != 0x6f)) { |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 855 | msg_perr("Unexpected response to init!\n"); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 856 | return 1; |
| 857 | } |
David Hendricks | c05900f | 2016-02-18 21:42:41 +0000 | [diff] [blame] | 858 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 859 | return 0; |
| 860 | } |
| 861 | |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 862 | static int dediprog_standalone_mode(void) |
| 863 | { |
| 864 | int ret; |
| 865 | |
| 866 | if (dediprog_devicetype != DEV_SF600) |
| 867 | return 0; |
| 868 | |
| 869 | msg_pdbg2("Disabling standalone mode.\n"); |
| 870 | ret = dediprog_write(CMD_SET_STANDALONE, LEAVE_STANDALONE_MODE, 0, NULL, 0); |
| 871 | if (ret) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 872 | msg_perr("Failed to disable standalone mode: %s\n", libusb_error_name(ret)); |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 873 | return 1; |
| 874 | } |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 879 | #if 0 |
| 880 | /* Something. |
| 881 | * Present in eng_detect_blink.log with firmware 3.1.8 |
| 882 | * Always preceded by Command Receive Device String |
| 883 | */ |
| 884 | static int dediprog_command_b(void) |
| 885 | { |
| 886 | int ret; |
| 887 | char buf[0x3]; |
| 888 | |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 889 | ret = usb_control_msg(dediprog_handle, REQTYPE_OTHER_IN, 0x7, 0x0, 0xef00, |
| 890 | buf, 0x3, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 891 | if (ret < 0) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 892 | msg_perr("Command B failed (%s)!\n", libusb_error_name(ret)); |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 893 | return 1; |
| 894 | } |
| 895 | if ((ret != 0x3) || (buf[0] != 0xff) || (buf[1] != 0xff) || |
| 896 | (buf[2] != 0xff)) { |
| 897 | msg_perr("Unexpected response to Command B!\n"); |
| 898 | return 1; |
| 899 | } |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | #endif |
| 904 | |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 905 | static int set_target_flash(enum dediprog_target target) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 906 | { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 907 | int ret = dediprog_write(CMD_SET_TARGET, target, 0, NULL, 0); |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 908 | if (ret != 0) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 909 | msg_perr("set_target_flash failed (%s)!\n", libusb_error_name(ret)); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 910 | return 1; |
| 911 | } |
| 912 | return 0; |
| 913 | } |
| 914 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 915 | #if 0 |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 916 | /* Returns true if the button is currently pressed. */ |
| 917 | static bool dediprog_get_button(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 918 | { |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 919 | char buf[1]; |
| 920 | int ret = usb_control_msg(dediprog_handle, REQTYPE_EP_IN, CMD_GET_BUTTON, 0, 0, |
| 921 | buf, 0x1, DEFAULT_TIMEOUT); |
| 922 | if (ret != 0) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 923 | msg_perr("Could not get button state (%s)!\n", libusb_error_name(ret)); |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 924 | return 1; |
| 925 | } |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 926 | return buf[0] != 1; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 927 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 928 | #endif |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 929 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 930 | static int parse_voltage(char *voltage) |
| 931 | { |
| 932 | char *tmp = NULL; |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 933 | int i; |
| 934 | int millivolt = 0, fraction = 0; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 935 | |
| 936 | if (!voltage || !strlen(voltage)) { |
| 937 | msg_perr("Empty voltage= specified.\n"); |
| 938 | return -1; |
| 939 | } |
| 940 | millivolt = (int)strtol(voltage, &tmp, 0); |
| 941 | voltage = tmp; |
| 942 | /* Handle "," and "." as decimal point. Everything after it is assumed |
| 943 | * to be in decimal notation. |
| 944 | */ |
| 945 | if ((*voltage == '.') || (*voltage == ',')) { |
| 946 | voltage++; |
| 947 | for (i = 0; i < 3; i++) { |
| 948 | fraction *= 10; |
| 949 | /* Don't advance if the current character is invalid, |
| 950 | * but continue multiplying. |
| 951 | */ |
| 952 | if ((*voltage < '0') || (*voltage > '9')) |
| 953 | continue; |
| 954 | fraction += *voltage - '0'; |
| 955 | voltage++; |
| 956 | } |
| 957 | /* Throw away remaining digits. */ |
| 958 | voltage += strspn(voltage, "0123456789"); |
| 959 | } |
| 960 | /* The remaining string must be empty or "mV" or "V". */ |
| 961 | tolower_string(voltage); |
| 962 | |
| 963 | /* No unit or "V". */ |
| 964 | if ((*voltage == '\0') || !strncmp(voltage, "v", 1)) { |
| 965 | millivolt *= 1000; |
| 966 | millivolt += fraction; |
| 967 | } else if (!strncmp(voltage, "mv", 2) || |
| 968 | !strncmp(voltage, "milliv", 6)) { |
| 969 | /* No adjustment. fraction is discarded. */ |
| 970 | } else { |
| 971 | /* Garbage at the end of the string. */ |
| 972 | msg_perr("Garbage voltage= specified.\n"); |
| 973 | return -1; |
| 974 | } |
| 975 | return millivolt; |
| 976 | } |
| 977 | |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 978 | static const struct spi_master spi_master_dediprog = { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 979 | .type = SPI_CONTROLLER_DEDIPROG, |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 980 | .max_data_read = 16, /* 18 seems to work fine as well, but 19 times out sometimes with FW 5.15. */ |
| 981 | .max_data_write = 16, |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 982 | .command = dediprog_spi_send_command, |
| 983 | .multicommand = default_spi_send_multicommand, |
| 984 | .read = dediprog_spi_read, |
| 985 | .write_256 = dediprog_spi_write_256, |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 986 | .write_aai = dediprog_spi_write_aai, |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 987 | }; |
| 988 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 989 | static int dediprog_shutdown(void *data) |
| 990 | { |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 991 | dediprog_devicetype = DEV_UNKNOWN; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 992 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 993 | /* URB 28. Command Set SPI Voltage to 0. */ |
| 994 | if (dediprog_set_spi_voltage(0x0)) |
| 995 | return 1; |
| 996 | |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 997 | if (libusb_release_interface(dediprog_handle, 0)) { |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 998 | msg_perr("Could not release USB interface!\n"); |
| 999 | return 1; |
| 1000 | } |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 1001 | libusb_close(dediprog_handle); |
| 1002 | libusb_exit(usb_ctx); |
| 1003 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 1004 | return 0; |
| 1005 | } |
| 1006 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1007 | int dediprog_init(void) |
| 1008 | { |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame] | 1009 | char *voltage, *device, *spispeed, *target_str; |
Patrick Georgi | efe2d43 | 2013-05-23 21:47:46 +0000 | [diff] [blame] | 1010 | int spispeed_idx = 1; |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 1011 | int millivolt = 3500; |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 1012 | long usedevice = 0; |
Nico Huber | 5e5e821 | 2016-05-04 12:27:58 +0200 | [diff] [blame] | 1013 | long target = FLASH_TYPE_APPLICATION_FLASH_1; |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 1014 | int i, ret; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1015 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 1016 | spispeed = extract_programmer_param("spispeed"); |
| 1017 | if (spispeed) { |
| 1018 | for (i = 0; spispeeds[i].name; ++i) { |
| 1019 | if (!strcasecmp(spispeeds[i].name, spispeed)) { |
| 1020 | spispeed_idx = i; |
| 1021 | break; |
| 1022 | } |
| 1023 | } |
| 1024 | if (!spispeeds[i].name) { |
Patrick Georgi | efe2d43 | 2013-05-23 21:47:46 +0000 | [diff] [blame] | 1025 | msg_perr("Error: Invalid spispeed value: '%s'.\n", spispeed); |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 1026 | free(spispeed); |
| 1027 | return 1; |
| 1028 | } |
| 1029 | free(spispeed); |
| 1030 | } |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 1031 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 1032 | voltage = extract_programmer_param("voltage"); |
| 1033 | if (voltage) { |
| 1034 | millivolt = parse_voltage(voltage); |
| 1035 | free(voltage); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 1036 | if (millivolt < 0) |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 1037 | return 1; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 1038 | msg_pinfo("Setting voltage to %i mV\n", millivolt); |
| 1039 | } |
| 1040 | |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 1041 | device = extract_programmer_param("device"); |
| 1042 | if (device) { |
| 1043 | char *dev_suffix; |
| 1044 | errno = 0; |
| 1045 | usedevice = strtol(device, &dev_suffix, 10); |
| 1046 | if (errno != 0 || device == dev_suffix) { |
| 1047 | msg_perr("Error: Could not convert 'device'.\n"); |
| 1048 | free(device); |
| 1049 | return 1; |
| 1050 | } |
| 1051 | if (usedevice < 0 || usedevice > UINT_MAX) { |
| 1052 | msg_perr("Error: Value for 'device' is out of range.\n"); |
| 1053 | free(device); |
| 1054 | return 1; |
| 1055 | } |
| 1056 | if (strlen(dev_suffix) > 0) { |
| 1057 | msg_perr("Error: Garbage following 'device' value.\n"); |
| 1058 | free(device); |
| 1059 | return 1; |
| 1060 | } |
| 1061 | msg_pinfo("Using device %li.\n", usedevice); |
| 1062 | } |
| 1063 | free(device); |
| 1064 | |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame] | 1065 | target_str = extract_programmer_param("target"); |
| 1066 | if (target_str) { |
| 1067 | char *target_suffix; |
| 1068 | errno = 0; |
| 1069 | target = strtol(target_str, &target_suffix, 10); |
| 1070 | if (errno != 0 || target_str == target_suffix) { |
| 1071 | msg_perr("Error: Could not convert 'target'.\n"); |
| 1072 | free(target_str); |
| 1073 | return 1; |
| 1074 | } |
| 1075 | if (target < 1 || target > 2) { |
| 1076 | msg_perr("Error: Value for 'target' is out of range.\n"); |
| 1077 | free(target_str); |
| 1078 | return 1; |
| 1079 | } |
| 1080 | if (strlen(target_suffix) > 0) { |
| 1081 | msg_perr("Error: Garbage following 'target' value.\n"); |
| 1082 | free(target_str); |
| 1083 | return 1; |
| 1084 | } |
Nico Huber | 5e5e821 | 2016-05-04 12:27:58 +0200 | [diff] [blame] | 1085 | switch (target) { |
| 1086 | case 1: |
| 1087 | msg_pinfo("Using target %s.\n", "FLASH_TYPE_APPLICATION_FLASH_1"); |
| 1088 | target = FLASH_TYPE_APPLICATION_FLASH_1; |
| 1089 | break; |
| 1090 | case 2: |
| 1091 | msg_pinfo("Using target %s.\n", "FLASH_TYPE_APPLICATION_FLASH_2"); |
| 1092 | target = FLASH_TYPE_APPLICATION_FLASH_2; |
| 1093 | break; |
| 1094 | default: |
| 1095 | break; |
| 1096 | } |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame] | 1097 | } |
| 1098 | free(target_str); |
| 1099 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1100 | /* Here comes the USB stuff. */ |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 1101 | libusb_init(&usb_ctx); |
| 1102 | if (!usb_ctx) { |
| 1103 | msg_perr("Could not initialize libusb!\n"); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1104 | return 1; |
| 1105 | } |
Stefan Tauner | fdec747 | 2016-02-22 08:59:27 +0000 | [diff] [blame] | 1106 | |
| 1107 | const uint16_t vid = devs_dediprog[0].vendor_id; |
| 1108 | const uint16_t pid = devs_dediprog[0].device_id; |
| 1109 | dediprog_handle = get_device_by_vid_pid_number(vid, pid, (unsigned int) usedevice); |
David Woodhouse | d2a7e87 | 2013-07-30 09:34:44 +0000 | [diff] [blame] | 1110 | if (!dediprog_handle) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 1111 | msg_perr("Could not find a Dediprog programmer on USB.\n"); |
| 1112 | libusb_exit(usb_ctx); |
David Woodhouse | d2a7e87 | 2013-07-30 09:34:44 +0000 | [diff] [blame] | 1113 | return 1; |
| 1114 | } |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 1115 | ret = libusb_set_configuration(dediprog_handle, 1); |
| 1116 | if (ret != 0) { |
| 1117 | msg_perr("Could not set USB device configuration: %i %s\n", ret, libusb_error_name(ret)); |
| 1118 | libusb_close(dediprog_handle); |
| 1119 | libusb_exit(usb_ctx); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 1120 | return 1; |
| 1121 | } |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 1122 | ret = libusb_claim_interface(dediprog_handle, 0); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 1123 | if (ret < 0) { |
Nico Huber | d99a2bd | 2016-02-18 21:42:49 +0000 | [diff] [blame] | 1124 | msg_perr("Could not claim USB device interface %i: %i %s\n", 0, ret, libusb_error_name(ret)); |
| 1125 | libusb_close(dediprog_handle); |
| 1126 | libusb_exit(usb_ctx); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 1127 | return 1; |
| 1128 | } |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 1129 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 1130 | if (register_shutdown(dediprog_shutdown, NULL)) |
| 1131 | return 1; |
| 1132 | |
David Hendricks | c05900f | 2016-02-18 21:42:41 +0000 | [diff] [blame] | 1133 | /* Try reading the devicestring. If that fails and the device is old (FW < 6.0.0, which we can not know) |
| 1134 | * then we need to try the "set voltage" command and then attempt to read the devicestring again. */ |
| 1135 | if (dediprog_check_devicestring()) { |
| 1136 | if (dediprog_set_voltage()) |
| 1137 | return 1; |
| 1138 | if (dediprog_check_devicestring()) |
| 1139 | return 1; |
| 1140 | } |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 1141 | |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 1142 | /* SF100 only has 1 endpoint for in/out, SF600 uses two separate endpoints instead. */ |
| 1143 | dediprog_in_endpoint = 2; |
| 1144 | if (dediprog_devicetype == DEV_SF100) |
| 1145 | dediprog_out_endpoint = 2; |
| 1146 | else |
| 1147 | dediprog_out_endpoint = 1; |
| 1148 | |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 1149 | /* Set all possible LEDs as soon as possible to indicate activity. |
| 1150 | * Because knowing the firmware version is required to set the LEDs correctly we need to this after |
David Hendricks | f73f8a7 | 2018-02-21 07:34:34 -0800 | [diff] [blame^] | 1151 | * dediprog_check_devicestring() has queried the device. */ |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 1152 | dediprog_set_leds(LED_ALL); |
| 1153 | |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 1154 | /* Select target/socket, frequency and VCC. */ |
Nico Huber | 5e5e821 | 2016-05-04 12:27:58 +0200 | [diff] [blame] | 1155 | if (set_target_flash(target) || |
Simon Glass | 557eb4f | 2015-07-05 16:53:22 +0000 | [diff] [blame] | 1156 | dediprog_set_spi_speed(spispeed_idx) || |
| 1157 | dediprog_set_spi_voltage(millivolt)) { |
Simon Glass | 25e9f40 | 2015-06-28 13:31:19 +0000 | [diff] [blame] | 1158 | dediprog_set_leds(LED_ERROR); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1159 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 1160 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1161 | |
David Woodhouse | 7f3b89f | 2016-02-18 21:42:15 +0000 | [diff] [blame] | 1162 | if (dediprog_standalone_mode()) |
| 1163 | return 1; |
| 1164 | |
Simon Glass | ae61651 | 2016-01-23 23:27:58 +0000 | [diff] [blame] | 1165 | if (register_spi_master(&spi_master_dediprog) || dediprog_set_leds(LED_NONE)) |
| 1166 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 1167 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1168 | return 0; |
| 1169 | } |