Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | d22a1d4 | 2007-09-09 20:21:05 +0000 | [diff] [blame] | 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
| 5 | * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com> |
Uwe Hermann | c7e8a0c | 2009-05-19 14:14:21 +0000 | [diff] [blame] | 6 | * Copyright (C) 2005-2008 coresystems GmbH |
Carl-Daniel Hailfinger | 03b4e71 | 2009-05-08 12:49:03 +0000 | [diff] [blame] | 7 | * Copyright (C) 2008,2009 Carl-Daniel Hailfinger |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 8 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 13 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 18 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 24 | #include <fcntl.h> |
Stefan Reinauer | 018aca8 | 2006-11-21 23:48:51 +0000 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
Ronald G. Minnich | ceec420 | 2003-07-25 04:37:41 +0000 | [diff] [blame] | 27 | #include <string.h> |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 28 | #include <stdlib.h> |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 29 | #include <getopt.h> |
Carl-Daniel Hailfinger | 132e2ec | 2010-03-27 16:36:40 +0000 | [diff] [blame] | 30 | #if HAVE_UTSNAME == 1 |
| 31 | #include <sys/utsname.h> |
| 32 | #endif |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 33 | #include "flash.h" |
Carl-Daniel Hailfinger | 0845464 | 2009-06-15 14:14:48 +0000 | [diff] [blame] | 34 | #include "flashchips.h" |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 35 | |
Carl-Daniel Hailfinger | a80cfbc | 2009-07-22 20:13:00 +0000 | [diff] [blame] | 36 | const char *flashrom_version = FLASHROM_VERSION; |
Ronald G. Minnich | ceec420 | 2003-07-25 04:37:41 +0000 | [diff] [blame] | 37 | char *chip_to_probe = NULL; |
Peter Stuge | 7ffbc6f | 2008-06-18 02:08:40 +0000 | [diff] [blame] | 38 | int verbose = 0; |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 39 | |
| 40 | #if INTERNAL_SUPPORT == 1 |
Carl-Daniel Hailfinger | 415e513 | 2009-08-12 11:39:29 +0000 | [diff] [blame] | 41 | enum programmer programmer = PROGRAMMER_INTERNAL; |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 42 | #elif DUMMY_SUPPORT == 1 |
| 43 | enum programmer programmer = PROGRAMMER_DUMMY; |
| 44 | #else |
Carl-Daniel Hailfinger | 1a1415c | 2010-01-10 13:28:48 +0000 | [diff] [blame] | 45 | /* If neither internal nor dummy are selected, we must pick a sensible default. |
| 46 | * Since there is no reason to prefer a particular external programmer, we fail |
| 47 | * if more than one of them is selected. If only one is selected, it is clear |
| 48 | * that the user wants that one to become the default. |
| 49 | */ |
Joerg Fischer | 5665ef3 | 2010-05-21 21:54:07 +0000 | [diff] [blame] | 50 | #if NIC3COM_SUPPORT+GFXNVIDIA_SUPPORT+DRKAISER_SUPPORT+SATASII_SUPPORT+ATAHPT_SUPPORT+FT2232_SPI_SUPPORT+SERPROG_SUPPORT+BUSPIRATE_SPI_SUPPORT+DEDIPROG_SUPPORT+NICREALTEK_SUPPORT > 1 |
Carl-Daniel Hailfinger | 1a1415c | 2010-01-10 13:28:48 +0000 | [diff] [blame] | 51 | #error Please enable either CONFIG_DUMMY or CONFIG_INTERNAL or disable support for all external programmers except one. |
| 52 | #endif |
| 53 | enum programmer programmer = |
| 54 | #if NIC3COM_SUPPORT == 1 |
| 55 | PROGRAMMER_NIC3COM |
| 56 | #endif |
Joerg Fischer | 5665ef3 | 2010-05-21 21:54:07 +0000 | [diff] [blame] | 57 | #if NICREALTEK_SUPPORT == 1 |
| 58 | PROGRAMMER_NICREALTEK |
| 59 | PROGRAMMER_NICREALTEK2 |
| 60 | #endif |
Carl-Daniel Hailfinger | 1a1415c | 2010-01-10 13:28:48 +0000 | [diff] [blame] | 61 | #if GFXNVIDIA_SUPPORT == 1 |
| 62 | PROGRAMMER_GFXNVIDIA |
| 63 | #endif |
| 64 | #if DRKAISER_SUPPORT == 1 |
| 65 | PROGRAMMER_DRKAISER |
| 66 | #endif |
| 67 | #if SATASII_SUPPORT == 1 |
| 68 | PROGRAMMER_SATASII |
| 69 | #endif |
Uwe Hermann | ddd5c9e | 2010-02-21 21:17:00 +0000 | [diff] [blame] | 70 | #if ATAHPT_SUPPORT == 1 |
| 71 | PROGRAMMER_ATAHPT |
| 72 | #endif |
Carl-Daniel Hailfinger | 1a1415c | 2010-01-10 13:28:48 +0000 | [diff] [blame] | 73 | #if FT2232_SPI_SUPPORT == 1 |
| 74 | PROGRAMMER_FT2232SPI |
| 75 | #endif |
| 76 | #if SERPROG_SUPPORT == 1 |
| 77 | PROGRAMMER_SERPROG |
| 78 | #endif |
| 79 | #if BUSPIRATE_SPI_SUPPORT == 1 |
| 80 | PROGRAMMER_BUSPIRATESPI |
| 81 | #endif |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 82 | #if DEDIPROG_SUPPORT == 1 |
| 83 | PROGRAMMER_DEDIPROG |
| 84 | #endif |
Carl-Daniel Hailfinger | 1a1415c | 2010-01-10 13:28:48 +0000 | [diff] [blame] | 85 | ; |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
Carl-Daniel Hailfinger | ef58a9c | 2009-08-12 13:32:56 +0000 | [diff] [blame] | 88 | char *programmer_param = NULL; |
Stefan Reinauer | 7038564 | 2007-04-06 11:58:03 +0000 | [diff] [blame] | 89 | |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 90 | /** |
| 91 | * flashrom defaults to Parallel/LPC/FWH flash devices. If a known host |
| 92 | * controller is found, the init routine sets the buses_supported bitfield to |
| 93 | * contain the supported buses for that controller. |
| 94 | */ |
| 95 | enum chipbustype buses_supported = CHIP_BUSTYPE_NONSPI; |
| 96 | |
| 97 | /** |
| 98 | * Programmers supporting multiple buses can have differing size limits on |
| 99 | * each bus. Store the limits for each bus in a common struct. |
| 100 | */ |
| 101 | struct decode_sizes max_rom_decode = { |
| 102 | .parallel = 0xffffffff, |
| 103 | .lpc = 0xffffffff, |
| 104 | .fwh = 0xffffffff, |
| 105 | .spi = 0xffffffff |
| 106 | }; |
| 107 | |
Carl-Daniel Hailfinger | 702218d | 2009-05-08 17:43:22 +0000 | [diff] [blame] | 108 | const struct programmer_entry programmer_table[] = { |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 109 | #if INTERNAL_SUPPORT == 1 |
Carl-Daniel Hailfinger | 702218d | 2009-05-08 17:43:22 +0000 | [diff] [blame] | 110 | { |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 111 | .name = "internal", |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 112 | .init = internal_init, |
| 113 | .shutdown = internal_shutdown, |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 114 | .map_flash_region = physmap, |
| 115 | .unmap_flash_region = physunmap, |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 116 | .chip_readb = internal_chip_readb, |
| 117 | .chip_readw = internal_chip_readw, |
| 118 | .chip_readl = internal_chip_readl, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 119 | .chip_readn = internal_chip_readn, |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 120 | .chip_writeb = internal_chip_writeb, |
| 121 | .chip_writew = internal_chip_writew, |
| 122 | .chip_writel = internal_chip_writel, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 123 | .chip_writen = fallback_chip_writen, |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 124 | .delay = internal_delay, |
Carl-Daniel Hailfinger | 702218d | 2009-05-08 17:43:22 +0000 | [diff] [blame] | 125 | }, |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 126 | #endif |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 127 | |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 128 | #if DUMMY_SUPPORT == 1 |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 129 | { |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 130 | .name = "dummy", |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 131 | .init = dummy_init, |
| 132 | .shutdown = dummy_shutdown, |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 133 | .map_flash_region = dummy_map, |
| 134 | .unmap_flash_region = dummy_unmap, |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 135 | .chip_readb = dummy_chip_readb, |
| 136 | .chip_readw = dummy_chip_readw, |
| 137 | .chip_readl = dummy_chip_readl, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 138 | .chip_readn = dummy_chip_readn, |
Carl-Daniel Hailfinger | 1e334e6 | 2009-05-11 15:46:43 +0000 | [diff] [blame] | 139 | .chip_writeb = dummy_chip_writeb, |
| 140 | .chip_writew = dummy_chip_writew, |
| 141 | .chip_writel = dummy_chip_writel, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 142 | .chip_writen = dummy_chip_writen, |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 143 | .delay = internal_delay, |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 144 | }, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 145 | #endif |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 146 | |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 147 | #if NIC3COM_SUPPORT == 1 |
Uwe Hermann | b4dcb71 | 2009-05-13 11:36:06 +0000 | [diff] [blame] | 148 | { |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 149 | .name = "nic3com", |
Uwe Hermann | b4dcb71 | 2009-05-13 11:36:06 +0000 | [diff] [blame] | 150 | .init = nic3com_init, |
| 151 | .shutdown = nic3com_shutdown, |
Uwe Hermann | c691593 | 2009-05-17 23:12:17 +0000 | [diff] [blame] | 152 | .map_flash_region = fallback_map, |
| 153 | .unmap_flash_region = fallback_unmap, |
Uwe Hermann | b4dcb71 | 2009-05-13 11:36:06 +0000 | [diff] [blame] | 154 | .chip_readb = nic3com_chip_readb, |
Carl-Daniel Hailfinger | 9ee1077 | 2009-05-16 01:23:55 +0000 | [diff] [blame] | 155 | .chip_readw = fallback_chip_readw, |
| 156 | .chip_readl = fallback_chip_readl, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 157 | .chip_readn = fallback_chip_readn, |
Uwe Hermann | b4dcb71 | 2009-05-13 11:36:06 +0000 | [diff] [blame] | 158 | .chip_writeb = nic3com_chip_writeb, |
Carl-Daniel Hailfinger | 9ee1077 | 2009-05-16 01:23:55 +0000 | [diff] [blame] | 159 | .chip_writew = fallback_chip_writew, |
| 160 | .chip_writel = fallback_chip_writel, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 161 | .chip_writen = fallback_chip_writen, |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 162 | .delay = internal_delay, |
Uwe Hermann | b4dcb71 | 2009-05-13 11:36:06 +0000 | [diff] [blame] | 163 | }, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 164 | #endif |
Uwe Hermann | b4dcb71 | 2009-05-13 11:36:06 +0000 | [diff] [blame] | 165 | |
Joerg Fischer | 5665ef3 | 2010-05-21 21:54:07 +0000 | [diff] [blame] | 166 | #if NICREALTEK_SUPPORT == 1 |
| 167 | { |
| 168 | .name = "nicrealtek", |
| 169 | .init = nicrealtek_init, |
| 170 | .shutdown = nicrealtek_shutdown, |
| 171 | .map_flash_region = fallback_map, |
| 172 | .unmap_flash_region = fallback_unmap, |
| 173 | .chip_readb = nicrealtek_chip_readb, |
| 174 | .chip_readw = fallback_chip_readw, |
| 175 | .chip_readl = fallback_chip_readl, |
| 176 | .chip_readn = fallback_chip_readn, |
| 177 | .chip_writeb = nicrealtek_chip_writeb, |
| 178 | .chip_writew = fallback_chip_writew, |
| 179 | .chip_writel = fallback_chip_writel, |
| 180 | .chip_writen = fallback_chip_writen, |
| 181 | .delay = internal_delay, |
| 182 | }, |
| 183 | { |
| 184 | .name = "nicsmc1211", |
| 185 | .init = nicsmc1211_init, |
| 186 | .shutdown = nicrealtek_shutdown, |
| 187 | .map_flash_region = fallback_map, |
| 188 | .unmap_flash_region = fallback_unmap, |
| 189 | .chip_readb = nicrealtek_chip_readb, |
| 190 | .chip_readw = fallback_chip_readw, |
| 191 | .chip_readl = fallback_chip_readl, |
| 192 | .chip_readn = fallback_chip_readn, |
| 193 | .chip_writeb = nicrealtek_chip_writeb, |
| 194 | .chip_writew = fallback_chip_writew, |
| 195 | .chip_writel = fallback_chip_writel, |
| 196 | .chip_writen = fallback_chip_writen, |
| 197 | .delay = internal_delay, |
| 198 | }, |
| 199 | #endif |
| 200 | |
| 201 | |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 202 | #if GFXNVIDIA_SUPPORT == 1 |
| 203 | { |
| 204 | .name = "gfxnvidia", |
| 205 | .init = gfxnvidia_init, |
| 206 | .shutdown = gfxnvidia_shutdown, |
| 207 | .map_flash_region = fallback_map, |
| 208 | .unmap_flash_region = fallback_unmap, |
| 209 | .chip_readb = gfxnvidia_chip_readb, |
| 210 | .chip_readw = fallback_chip_readw, |
| 211 | .chip_readl = fallback_chip_readl, |
| 212 | .chip_readn = fallback_chip_readn, |
| 213 | .chip_writeb = gfxnvidia_chip_writeb, |
| 214 | .chip_writew = fallback_chip_writew, |
| 215 | .chip_writel = fallback_chip_writel, |
| 216 | .chip_writen = fallback_chip_writen, |
| 217 | .delay = internal_delay, |
| 218 | }, |
| 219 | #endif |
| 220 | |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 221 | #if DRKAISER_SUPPORT == 1 |
Rudolf Marek | 68720c7 | 2009-05-17 19:39:27 +0000 | [diff] [blame] | 222 | { |
TURBO J | b0912c0 | 2009-09-02 23:00:46 +0000 | [diff] [blame] | 223 | .name = "drkaiser", |
| 224 | .init = drkaiser_init, |
| 225 | .shutdown = drkaiser_shutdown, |
| 226 | .map_flash_region = fallback_map, |
| 227 | .unmap_flash_region = fallback_unmap, |
| 228 | .chip_readb = drkaiser_chip_readb, |
| 229 | .chip_readw = fallback_chip_readw, |
| 230 | .chip_readl = fallback_chip_readl, |
| 231 | .chip_readn = fallback_chip_readn, |
| 232 | .chip_writeb = drkaiser_chip_writeb, |
| 233 | .chip_writew = fallback_chip_writew, |
| 234 | .chip_writel = fallback_chip_writel, |
| 235 | .chip_writen = fallback_chip_writen, |
| 236 | .delay = internal_delay, |
| 237 | }, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 238 | #endif |
TURBO J | b0912c0 | 2009-09-02 23:00:46 +0000 | [diff] [blame] | 239 | |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 240 | #if SATASII_SUPPORT == 1 |
TURBO J | b0912c0 | 2009-09-02 23:00:46 +0000 | [diff] [blame] | 241 | { |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 242 | .name = "satasii", |
Rudolf Marek | 68720c7 | 2009-05-17 19:39:27 +0000 | [diff] [blame] | 243 | .init = satasii_init, |
| 244 | .shutdown = satasii_shutdown, |
Uwe Hermann | c691593 | 2009-05-17 23:12:17 +0000 | [diff] [blame] | 245 | .map_flash_region = fallback_map, |
| 246 | .unmap_flash_region = fallback_unmap, |
Rudolf Marek | 68720c7 | 2009-05-17 19:39:27 +0000 | [diff] [blame] | 247 | .chip_readb = satasii_chip_readb, |
| 248 | .chip_readw = fallback_chip_readw, |
| 249 | .chip_readl = fallback_chip_readl, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 250 | .chip_readn = fallback_chip_readn, |
Rudolf Marek | 68720c7 | 2009-05-17 19:39:27 +0000 | [diff] [blame] | 251 | .chip_writeb = satasii_chip_writeb, |
| 252 | .chip_writew = fallback_chip_writew, |
| 253 | .chip_writel = fallback_chip_writel, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 254 | .chip_writen = fallback_chip_writen, |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 255 | .delay = internal_delay, |
Rudolf Marek | 68720c7 | 2009-05-17 19:39:27 +0000 | [diff] [blame] | 256 | }, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 257 | #endif |
Rudolf Marek | 68720c7 | 2009-05-17 19:39:27 +0000 | [diff] [blame] | 258 | |
Uwe Hermann | ddd5c9e | 2010-02-21 21:17:00 +0000 | [diff] [blame] | 259 | #if ATAHPT_SUPPORT == 1 |
| 260 | { |
| 261 | .name = "atahpt", |
| 262 | .init = atahpt_init, |
| 263 | .shutdown = atahpt_shutdown, |
| 264 | .map_flash_region = fallback_map, |
| 265 | .unmap_flash_region = fallback_unmap, |
| 266 | .chip_readb = atahpt_chip_readb, |
| 267 | .chip_readw = fallback_chip_readw, |
| 268 | .chip_readl = fallback_chip_readl, |
| 269 | .chip_readn = fallback_chip_readn, |
| 270 | .chip_writeb = atahpt_chip_writeb, |
| 271 | .chip_writew = fallback_chip_writew, |
| 272 | .chip_writel = fallback_chip_writel, |
| 273 | .chip_writen = fallback_chip_writen, |
| 274 | .delay = internal_delay, |
| 275 | }, |
| 276 | #endif |
| 277 | |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 278 | #if INTERNAL_SUPPORT == 1 |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 279 | #if defined(__i386__) || defined(__x86_64__) |
Carl-Daniel Hailfinger | b8afecd | 2009-05-31 18:00:57 +0000 | [diff] [blame] | 280 | { |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 281 | .name = "it87spi", |
Carl-Daniel Hailfinger | b8afecd | 2009-05-31 18:00:57 +0000 | [diff] [blame] | 282 | .init = it87spi_init, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 283 | .shutdown = noop_shutdown, |
Carl-Daniel Hailfinger | 415e513 | 2009-08-12 11:39:29 +0000 | [diff] [blame] | 284 | .map_flash_region = fallback_map, |
| 285 | .unmap_flash_region = fallback_unmap, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 286 | .chip_readb = noop_chip_readb, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 287 | .chip_readw = fallback_chip_readw, |
| 288 | .chip_readl = fallback_chip_readl, |
| 289 | .chip_readn = fallback_chip_readn, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 290 | .chip_writeb = noop_chip_writeb, |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 291 | .chip_writew = fallback_chip_writew, |
| 292 | .chip_writel = fallback_chip_writel, |
| 293 | .chip_writen = fallback_chip_writen, |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 294 | .delay = internal_delay, |
Carl-Daniel Hailfinger | b8afecd | 2009-05-31 18:00:57 +0000 | [diff] [blame] | 295 | }, |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 296 | #endif |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 297 | #endif |
Carl-Daniel Hailfinger | b8afecd | 2009-05-31 18:00:57 +0000 | [diff] [blame] | 298 | |
Carl-Daniel Hailfinger | 3426ef6 | 2009-08-19 13:27:58 +0000 | [diff] [blame] | 299 | #if FT2232_SPI_SUPPORT == 1 |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 300 | { |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 301 | .name = "ft2232spi", |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 302 | .init = ft2232_spi_init, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 303 | .shutdown = noop_shutdown, /* Missing shutdown */ |
Carl-Daniel Hailfinger | 415e513 | 2009-08-12 11:39:29 +0000 | [diff] [blame] | 304 | .map_flash_region = fallback_map, |
| 305 | .unmap_flash_region = fallback_unmap, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 306 | .chip_readb = noop_chip_readb, |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 307 | .chip_readw = fallback_chip_readw, |
| 308 | .chip_readl = fallback_chip_readl, |
| 309 | .chip_readn = fallback_chip_readn, |
Carl-Daniel Hailfinger | 4740c6f | 2009-09-16 10:09:21 +0000 | [diff] [blame] | 310 | .chip_writeb = noop_chip_writeb, |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 311 | .chip_writew = fallback_chip_writew, |
| 312 | .chip_writel = fallback_chip_writel, |
| 313 | .chip_writen = fallback_chip_writen, |
| 314 | .delay = internal_delay, |
| 315 | }, |
Carl-Daniel Hailfinger | 3426ef6 | 2009-08-19 13:27:58 +0000 | [diff] [blame] | 316 | #endif |
Carl-Daniel Hailfinger | 415e513 | 2009-08-12 11:39:29 +0000 | [diff] [blame] | 317 | |
Carl-Daniel Hailfinger | 6be7411 | 2009-08-12 16:17:41 +0000 | [diff] [blame] | 318 | #if SERPROG_SUPPORT == 1 |
Urja Rannikko | 2291535 | 2009-06-23 11:33:43 +0000 | [diff] [blame] | 319 | { |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 320 | .name = "serprog", |
Urja Rannikko | 2291535 | 2009-06-23 11:33:43 +0000 | [diff] [blame] | 321 | .init = serprog_init, |
| 322 | .shutdown = serprog_shutdown, |
| 323 | .map_flash_region = fallback_map, |
| 324 | .unmap_flash_region = fallback_unmap, |
| 325 | .chip_readb = serprog_chip_readb, |
| 326 | .chip_readw = fallback_chip_readw, |
| 327 | .chip_readl = fallback_chip_readl, |
| 328 | .chip_readn = serprog_chip_readn, |
| 329 | .chip_writeb = serprog_chip_writeb, |
| 330 | .chip_writew = fallback_chip_writew, |
| 331 | .chip_writel = fallback_chip_writel, |
| 332 | .chip_writen = fallback_chip_writen, |
| 333 | .delay = serprog_delay, |
| 334 | }, |
Carl-Daniel Hailfinger | 6be7411 | 2009-08-12 16:17:41 +0000 | [diff] [blame] | 335 | #endif |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 336 | |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 337 | #if BUSPIRATE_SPI_SUPPORT == 1 |
| 338 | { |
| 339 | .name = "buspiratespi", |
| 340 | .init = buspirate_spi_init, |
| 341 | .shutdown = buspirate_spi_shutdown, |
| 342 | .map_flash_region = fallback_map, |
| 343 | .unmap_flash_region = fallback_unmap, |
| 344 | .chip_readb = noop_chip_readb, |
| 345 | .chip_readw = fallback_chip_readw, |
| 346 | .chip_readl = fallback_chip_readl, |
| 347 | .chip_readn = fallback_chip_readn, |
| 348 | .chip_writeb = noop_chip_writeb, |
| 349 | .chip_writew = fallback_chip_writew, |
| 350 | .chip_writel = fallback_chip_writel, |
| 351 | .chip_writen = fallback_chip_writen, |
| 352 | .delay = internal_delay, |
| 353 | }, |
| 354 | #endif |
| 355 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 356 | #if DEDIPROG_SUPPORT == 1 |
| 357 | { |
| 358 | .name = "dediprog", |
| 359 | .init = dediprog_init, |
| 360 | .shutdown = dediprog_shutdown, |
| 361 | .map_flash_region = fallback_map, |
| 362 | .unmap_flash_region = fallback_unmap, |
| 363 | .chip_readb = noop_chip_readb, |
| 364 | .chip_readw = fallback_chip_readw, |
| 365 | .chip_readl = fallback_chip_readl, |
| 366 | .chip_readn = fallback_chip_readn, |
| 367 | .chip_writeb = noop_chip_writeb, |
| 368 | .chip_writew = fallback_chip_writew, |
| 369 | .chip_writel = fallback_chip_writel, |
| 370 | .chip_writen = fallback_chip_writen, |
| 371 | .delay = internal_delay, |
| 372 | }, |
| 373 | #endif |
| 374 | |
Carl-Daniel Hailfinger | 37fc469 | 2009-08-12 14:34:35 +0000 | [diff] [blame] | 375 | {}, /* This entry corresponds to PROGRAMMER_INVALID. */ |
Carl-Daniel Hailfinger | 702218d | 2009-05-08 17:43:22 +0000 | [diff] [blame] | 376 | }; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 377 | |
Carl-Daniel Hailfinger | cc389fc | 2010-02-14 01:20:28 +0000 | [diff] [blame] | 378 | #define SHUTDOWN_MAXFN 4 |
| 379 | static int shutdown_fn_count = 0; |
| 380 | struct shutdown_func_data { |
| 381 | void (*func) (void *data); |
| 382 | void *data; |
| 383 | } shutdown_fn[SHUTDOWN_MAXFN]; |
| 384 | |
| 385 | /* Register a function to be executed on programmer shutdown. |
| 386 | * The advantage over atexit() is that you can supply a void pointer which will |
| 387 | * be used as parameter to the registered function upon programmer shutdown. |
| 388 | * This pointer can point to arbitrary data used by said function, e.g. undo |
| 389 | * information for GPIO settings etc. If unneeded, set data=NULL. |
| 390 | * Please note that the first (void *data) belongs to the function signature of |
| 391 | * the function passed as first parameter. |
| 392 | */ |
| 393 | int register_shutdown(void (*function) (void *data), void *data) |
| 394 | { |
| 395 | if (shutdown_fn_count >= SHUTDOWN_MAXFN) { |
| 396 | msg_perr("Tried to register more than %n shutdown functions.\n", |
| 397 | SHUTDOWN_MAXFN); |
| 398 | return 1; |
| 399 | } |
| 400 | shutdown_fn[shutdown_fn_count].func = function; |
| 401 | shutdown_fn[shutdown_fn_count].data = data; |
| 402 | shutdown_fn_count++; |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 407 | int programmer_init(void) |
| 408 | { |
| 409 | return programmer_table[programmer].init(); |
| 410 | } |
| 411 | |
| 412 | int programmer_shutdown(void) |
| 413 | { |
Carl-Daniel Hailfinger | cc389fc | 2010-02-14 01:20:28 +0000 | [diff] [blame] | 414 | int i; |
| 415 | |
| 416 | for (i = shutdown_fn_count - 1; i >= 0; i--) |
| 417 | shutdown_fn[i].func(shutdown_fn[i].data); |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 418 | return programmer_table[programmer].shutdown(); |
| 419 | } |
| 420 | |
| 421 | void *programmer_map_flash_region(const char *descr, unsigned long phys_addr, |
| 422 | size_t len) |
| 423 | { |
| 424 | return programmer_table[programmer].map_flash_region(descr, |
| 425 | phys_addr, len); |
| 426 | } |
| 427 | |
| 428 | void programmer_unmap_flash_region(void *virt_addr, size_t len) |
| 429 | { |
| 430 | programmer_table[programmer].unmap_flash_region(virt_addr, len); |
| 431 | } |
| 432 | |
| 433 | void chip_writeb(uint8_t val, chipaddr addr) |
| 434 | { |
| 435 | programmer_table[programmer].chip_writeb(val, addr); |
| 436 | } |
| 437 | |
| 438 | void chip_writew(uint16_t val, chipaddr addr) |
| 439 | { |
| 440 | programmer_table[programmer].chip_writew(val, addr); |
| 441 | } |
| 442 | |
| 443 | void chip_writel(uint32_t val, chipaddr addr) |
| 444 | { |
| 445 | programmer_table[programmer].chip_writel(val, addr); |
| 446 | } |
| 447 | |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 448 | void chip_writen(uint8_t *buf, chipaddr addr, size_t len) |
| 449 | { |
| 450 | programmer_table[programmer].chip_writen(buf, addr, len); |
| 451 | } |
| 452 | |
Uwe Hermann | 09e04f7 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 453 | uint8_t chip_readb(const chipaddr addr) |
| 454 | { |
| 455 | return programmer_table[programmer].chip_readb(addr); |
| 456 | } |
| 457 | |
| 458 | uint16_t chip_readw(const chipaddr addr) |
| 459 | { |
| 460 | return programmer_table[programmer].chip_readw(addr); |
| 461 | } |
| 462 | |
| 463 | uint32_t chip_readl(const chipaddr addr) |
| 464 | { |
| 465 | return programmer_table[programmer].chip_readl(addr); |
| 466 | } |
| 467 | |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 468 | void chip_readn(uint8_t *buf, chipaddr addr, size_t len) |
| 469 | { |
| 470 | programmer_table[programmer].chip_readn(buf, addr, len); |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 473 | void programmer_delay(int usecs) |
| 474 | { |
| 475 | programmer_table[programmer].delay(usecs); |
| 476 | } |
| 477 | |
Peter Stuge | 776d202 | 2009-01-26 00:39:57 +0000 | [diff] [blame] | 478 | void map_flash_registers(struct flashchip *flash) |
Stefan Reinauer | ff4f197 | 2007-05-24 08:48:10 +0000 | [diff] [blame] | 479 | { |
Stefan Reinauer | ff4f197 | 2007-05-24 08:48:10 +0000 | [diff] [blame] | 480 | size_t size = flash->total_size * 1024; |
Carl-Daniel Hailfinger | d0fc946 | 2009-05-11 14:01:17 +0000 | [diff] [blame] | 481 | /* Flash registers live 4 MByte below the flash. */ |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 482 | /* FIXME: This is incorrect for nonstandard flashbase. */ |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 483 | flash->virtual_registers = (chipaddr)programmer_map_flash_region("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size); |
Stefan Reinauer | ff4f197 | 2007-05-24 08:48:10 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Carl-Daniel Hailfinger | cbf563c | 2009-06-16 08:55:44 +0000 | [diff] [blame] | 486 | int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len) |
Carl-Daniel Hailfinger | 03b4e71 | 2009-05-08 12:49:03 +0000 | [diff] [blame] | 487 | { |
Carl-Daniel Hailfinger | cbf563c | 2009-06-16 08:55:44 +0000 | [diff] [blame] | 488 | chip_readn(buf, flash->virtual_memory + start, len); |
Carl-Daniel Hailfinger | 03b4e71 | 2009-05-08 12:49:03 +0000 | [diff] [blame] | 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 493 | unsigned long flashbase = 0; |
| 494 | |
Carl-Daniel Hailfinger | 38a059d | 2009-06-13 12:04:03 +0000 | [diff] [blame] | 495 | int min(int a, int b) |
| 496 | { |
| 497 | return (a < b) ? a : b; |
| 498 | } |
| 499 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 500 | int max(int a, int b) |
| 501 | { |
| 502 | return (a > b) ? a : b; |
| 503 | } |
| 504 | |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 505 | int bitcount(unsigned long a) |
| 506 | { |
| 507 | int i = 0; |
| 508 | for (; a != 0; a >>= 1) |
| 509 | if (a & 1) |
| 510 | i++; |
| 511 | return i; |
| 512 | } |
| 513 | |
Carl-Daniel Hailfinger | b22918c | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 514 | char *strcat_realloc(char *dest, const char *src) |
| 515 | { |
| 516 | dest = realloc(dest, strlen(dest) + strlen(src) + 1); |
| 517 | if (!dest) |
| 518 | return NULL; |
| 519 | strcat(dest, src); |
| 520 | return dest; |
| 521 | } |
| 522 | |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 523 | /* This is a somewhat hacked function similar in some ways to strtok(). |
| 524 | * It will look for needle in haystack, return a copy of needle and remove |
| 525 | * everything from the first occurrence of needle to the next delimiter |
| 526 | * from haystack. |
| 527 | */ |
| 528 | char *extract_param(char **haystack, char *needle, char *delim) |
| 529 | { |
| 530 | char *param_pos, *rest, *tmp; |
| 531 | char *dev = NULL; |
| 532 | int devlen; |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 533 | int needlelen; |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 534 | |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 535 | needlelen = strlen(needle); |
| 536 | if (!needlelen) { |
| 537 | msg_gerr("%s: empty needle! Please report a bug at " |
| 538 | "flashrom@flashrom.org\n", __func__); |
| 539 | return NULL; |
| 540 | } |
| 541 | /* No programmer parameters given. */ |
| 542 | if (*haystack == NULL) |
| 543 | return NULL; |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 544 | param_pos = strstr(*haystack, needle); |
| 545 | do { |
| 546 | if (!param_pos) |
| 547 | return NULL; |
| 548 | /* Beginning of the string? */ |
| 549 | if (param_pos == *haystack) |
| 550 | break; |
| 551 | /* After a delimiter? */ |
| 552 | if (strchr(delim, *(param_pos - 1))) |
| 553 | break; |
| 554 | /* Continue searching. */ |
| 555 | param_pos++; |
| 556 | param_pos = strstr(param_pos, needle); |
| 557 | } while (1); |
| 558 | |
| 559 | if (param_pos) { |
| 560 | param_pos += strlen(needle); |
| 561 | devlen = strcspn(param_pos, delim); |
| 562 | if (devlen) { |
| 563 | dev = malloc(devlen + 1); |
| 564 | if (!dev) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 565 | msg_gerr("Out of memory!\n"); |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 566 | exit(1); |
| 567 | } |
| 568 | strncpy(dev, param_pos, devlen); |
| 569 | dev[devlen] = '\0'; |
| 570 | } |
| 571 | rest = param_pos + devlen; |
| 572 | rest += strspn(rest, delim); |
| 573 | param_pos -= strlen(needle); |
| 574 | memmove(param_pos, rest, strlen(rest) + 1); |
| 575 | tmp = realloc(*haystack, strlen(*haystack) + 1); |
| 576 | if (!tmp) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 577 | msg_gerr("Out of memory!\n"); |
Carl-Daniel Hailfinger | d5b28fa | 2009-11-24 18:27:10 +0000 | [diff] [blame] | 578 | exit(1); |
| 579 | } |
| 580 | *haystack = tmp; |
| 581 | } |
| 582 | |
| 583 | |
| 584 | return dev; |
| 585 | } |
| 586 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 587 | /* start is an offset to the base address of the flash chip */ |
| 588 | int check_erased_range(struct flashchip *flash, int start, int len) |
| 589 | { |
| 590 | int ret; |
| 591 | uint8_t *cmpbuf = malloc(len); |
| 592 | |
| 593 | if (!cmpbuf) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 594 | msg_gerr("Could not allocate memory!\n"); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 595 | exit(1); |
| 596 | } |
| 597 | memset(cmpbuf, 0xff, len); |
| 598 | ret = verify_range(flash, cmpbuf, start, len, "ERASE"); |
| 599 | free(cmpbuf); |
| 600 | return ret; |
| 601 | } |
| 602 | |
| 603 | /** |
Carl-Daniel Hailfinger | d0250a3 | 2009-11-25 17:05:52 +0000 | [diff] [blame] | 604 | * @cmpbuf buffer to compare against, cmpbuf[0] is expected to match the |
| 605 | flash content at location start |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 606 | * @start offset to the base address of the flash chip |
| 607 | * @len length of the verified area |
| 608 | * @message string to print in the "FAILED" message |
| 609 | * @return 0 for success, -1 for failure |
| 610 | */ |
| 611 | int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message) |
| 612 | { |
| 613 | int i, j, starthere, lenhere, ret = 0; |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 614 | int page_size = flash->page_size; |
| 615 | uint8_t *readbuf = malloc(page_size); |
Carl-Daniel Hailfinger | 49b9cab | 2009-07-23 01:42:56 +0000 | [diff] [blame] | 616 | int failcount = 0; |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 617 | |
| 618 | if (!len) |
| 619 | goto out_free; |
| 620 | |
Carl-Daniel Hailfinger | 2329066 | 2009-06-24 08:20:45 +0000 | [diff] [blame] | 621 | if (!flash->read) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 622 | msg_cerr("ERROR: flashrom has no read function for this flash chip.\n"); |
Carl-Daniel Hailfinger | 2329066 | 2009-06-24 08:20:45 +0000 | [diff] [blame] | 623 | return 1; |
| 624 | } |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 625 | if (!readbuf) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 626 | msg_gerr("Could not allocate memory!\n"); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 627 | exit(1); |
| 628 | } |
| 629 | |
| 630 | if (start + len > flash->total_size * 1024) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 631 | msg_gerr("Error: %s called with start 0x%x + len 0x%x >" |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 632 | " total_size 0x%x\n", __func__, start, len, |
| 633 | flash->total_size * 1024); |
| 634 | ret = -1; |
| 635 | goto out_free; |
| 636 | } |
| 637 | if (!message) |
| 638 | message = "VERIFY"; |
| 639 | |
| 640 | /* Warning: This loop has a very unusual condition and body. |
| 641 | * The loop needs to go through each page with at least one affected |
| 642 | * byte. The lowest page number is (start / page_size) since that |
| 643 | * division rounds down. The highest page number we want is the page |
| 644 | * where the last byte of the range lives. That last byte has the |
| 645 | * address (start + len - 1), thus the highest page number is |
| 646 | * (start + len - 1) / page_size. Since we want to include that last |
| 647 | * page as well, the loop condition uses <=. |
| 648 | */ |
| 649 | for (i = start / page_size; i <= (start + len - 1) / page_size; i++) { |
| 650 | /* Byte position of the first byte in the range in this page. */ |
| 651 | starthere = max(start, i * page_size); |
| 652 | /* Length of bytes in the range in this page. */ |
| 653 | lenhere = min(start + len, (i + 1) * page_size) - starthere; |
Carl-Daniel Hailfinger | 2329066 | 2009-06-24 08:20:45 +0000 | [diff] [blame] | 654 | flash->read(flash, readbuf, starthere, lenhere); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 655 | for (j = 0; j < lenhere; j++) { |
| 656 | if (cmpbuf[starthere - start + j] != readbuf[j]) { |
Carl-Daniel Hailfinger | 49b9cab | 2009-07-23 01:42:56 +0000 | [diff] [blame] | 657 | /* Only print the first failure. */ |
| 658 | if (!failcount++) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 659 | msg_cerr("%s FAILED at 0x%08x! " |
Carl-Daniel Hailfinger | 49b9cab | 2009-07-23 01:42:56 +0000 | [diff] [blame] | 660 | "Expected=0x%02x, Read=0x%02x,", |
| 661 | message, starthere + j, |
| 662 | cmpbuf[starthere - start + j], |
| 663 | readbuf[j]); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | } |
Carl-Daniel Hailfinger | 49b9cab | 2009-07-23 01:42:56 +0000 | [diff] [blame] | 667 | if (failcount) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 668 | msg_cerr(" failed byte count from 0x%08x-0x%08x: 0x%x\n", |
Carl-Daniel Hailfinger | 49b9cab | 2009-07-23 01:42:56 +0000 | [diff] [blame] | 669 | start, start + len - 1, failcount); |
| 670 | ret = -1; |
| 671 | } |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 672 | |
| 673 | out_free: |
| 674 | free(readbuf); |
| 675 | return ret; |
| 676 | } |
| 677 | |
Carl-Daniel Hailfinger | e8e369f | 2010-03-08 00:42:32 +0000 | [diff] [blame] | 678 | /** |
| 679 | * Check if the buffer @have can be programmed to the content of @want without |
| 680 | * erasing. This is only possible if all chunks of size @gran are either kept |
| 681 | * as-is or changed from an all-ones state to any other state. |
| 682 | * The following write granularities (enum @gran) are known: |
| 683 | * - 1 bit. Each bit can be cleared individually. |
| 684 | * - 1 byte. A byte can be written once. Further writes to an already written |
| 685 | * byte cause the contents to be either undefined or to stay unchanged. |
| 686 | * - 128 bytes. If less than 128 bytes are written, the rest will be |
| 687 | * erased. Each write to a 128-byte region will trigger an automatic erase |
| 688 | * before anything is written. Very uncommon behaviour and unsupported by |
| 689 | * this function. |
| 690 | * - 256 bytes. If less than 256 bytes are written, the contents of the |
| 691 | * unwritten bytes are undefined. |
| 692 | * |
| 693 | * @have buffer with current content |
| 694 | * @want buffer with desired content |
| 695 | * @len length of the verified area |
| 696 | * @gran write granularity (enum, not count) |
| 697 | * @return 0 if no erase is needed, 1 otherwise |
| 698 | */ |
| 699 | int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran) |
| 700 | { |
| 701 | int result = 0; |
| 702 | int i, j, limit; |
| 703 | |
| 704 | switch (gran) { |
| 705 | case write_gran_1bit: |
| 706 | for (i = 0; i < len; i++) |
| 707 | if ((have[i] & want[i]) != want[i]) { |
| 708 | result = 1; |
| 709 | break; |
| 710 | } |
| 711 | break; |
| 712 | case write_gran_1byte: |
| 713 | for (i = 0; i < len; i++) |
| 714 | if ((have[i] != want[i]) && (have[i] != 0xff)) { |
| 715 | result = 1; |
| 716 | break; |
| 717 | } |
| 718 | break; |
| 719 | case write_gran_256bytes: |
| 720 | for (j = 0; j < len / 256; j++) { |
| 721 | limit = min (256, len - j * 256); |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 722 | /* Are 'have' and 'want' identical? */ |
Carl-Daniel Hailfinger | e8e369f | 2010-03-08 00:42:32 +0000 | [diff] [blame] | 723 | if (!memcmp(have + j * 256, want + j * 256, limit)) |
| 724 | continue; |
| 725 | /* have needs to be in erased state. */ |
| 726 | for (i = 0; i < limit; i++) |
| 727 | if (have[i] != 0xff) { |
| 728 | result = 1; |
| 729 | break; |
| 730 | } |
| 731 | if (result) |
| 732 | break; |
| 733 | } |
| 734 | break; |
| 735 | } |
| 736 | return result; |
| 737 | } |
| 738 | |
Carl-Daniel Hailfinger | eaac68b | 2009-11-23 12:55:31 +0000 | [diff] [blame] | 739 | /* This function generates various test patterns useful for testing controller |
| 740 | * and chip communication as well as chip behaviour. |
| 741 | * |
| 742 | * If a byte can be written multiple times, each time keeping 0-bits at 0 |
| 743 | * and changing 1-bits to 0 if the new value for that bit is 0, the effect |
| 744 | * is essentially an AND operation. That's also the reason why this function |
| 745 | * provides the result of AND between various patterns. |
| 746 | * |
| 747 | * Below is a list of patterns (and their block length). |
| 748 | * Pattern 0 is 05 15 25 35 45 55 65 75 85 95 a5 b5 c5 d5 e5 f5 (16 Bytes) |
| 749 | * Pattern 1 is 0a 1a 2a 3a 4a 5a 6a 7a 8a 9a aa ba ca da ea fa (16 Bytes) |
| 750 | * Pattern 2 is 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f (16 Bytes) |
| 751 | * Pattern 3 is a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af (16 Bytes) |
| 752 | * Pattern 4 is 00 10 20 30 40 50 60 70 80 90 a0 b0 c0 d0 e0 f0 (16 Bytes) |
| 753 | * Pattern 5 is 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f (16 Bytes) |
| 754 | * Pattern 6 is 00 (1 Byte) |
| 755 | * Pattern 7 is ff (1 Byte) |
| 756 | * Patterns 0-7 have a big-endian block number in the last 2 bytes of each 256 |
| 757 | * byte block. |
| 758 | * |
| 759 | * Pattern 8 is 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11... (256 B) |
| 760 | * Pattern 9 is ff fe fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee... (256 B) |
| 761 | * Pattern 10 is 00 00 00 01 00 02 00 03 00 04... (128 kB big-endian counter) |
| 762 | * Pattern 11 is ff ff ff fe ff fd ff fc ff fb... (128 kB big-endian downwards) |
| 763 | * Pattern 12 is 00 (1 Byte) |
| 764 | * Pattern 13 is ff (1 Byte) |
| 765 | * Patterns 8-13 have no block number. |
| 766 | * |
| 767 | * Patterns 0-3 are created to detect and efficiently diagnose communication |
| 768 | * slips like missed bits or bytes and their repetitive nature gives good visual |
| 769 | * cues to the person inspecting the results. In addition, the following holds: |
| 770 | * AND Pattern 0/1 == Pattern 4 |
| 771 | * AND Pattern 2/3 == Pattern 5 |
| 772 | * AND Pattern 0/1/2/3 == AND Pattern 4/5 == Pattern 6 |
| 773 | * A weakness of pattern 0-5 is the inability to detect swaps/copies between |
| 774 | * any two 16-byte blocks except for the last 16-byte block in a 256-byte bloc. |
| 775 | * They work perfectly for detecting any swaps/aliasing of blocks >= 256 bytes. |
| 776 | * 0x5 and 0xa were picked because they are 0101 and 1010 binary. |
| 777 | * Patterns 8-9 are best for detecting swaps/aliasing of blocks < 256 bytes. |
| 778 | * Besides that, they provide for bit testing of the last two bytes of every |
| 779 | * 256 byte block which contains the block number for patterns 0-6. |
| 780 | * Patterns 10-11 are special purpose for detecting subblock aliasing with |
| 781 | * block sizes >256 bytes (some Dataflash chips etc.) |
| 782 | * AND Pattern 8/9 == Pattern 12 |
| 783 | * AND Pattern 10/11 == Pattern 12 |
| 784 | * Pattern 13 is the completely erased state. |
| 785 | * None of the patterns can detect aliasing at boundaries which are a multiple |
| 786 | * of 16 MBytes (but such chips do not exist anyway for Parallel/LPC/FWH/SPI). |
| 787 | */ |
| 788 | int generate_testpattern(uint8_t *buf, uint32_t size, int variant) |
| 789 | { |
| 790 | int i; |
| 791 | |
| 792 | if (!buf) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 793 | msg_gerr("Invalid buffer!\n"); |
Carl-Daniel Hailfinger | eaac68b | 2009-11-23 12:55:31 +0000 | [diff] [blame] | 794 | return 1; |
| 795 | } |
| 796 | |
| 797 | switch (variant) { |
| 798 | case 0: |
| 799 | for (i = 0; i < size; i++) |
| 800 | buf[i] = (i & 0xf) << 4 | 0x5; |
| 801 | break; |
| 802 | case 1: |
| 803 | for (i = 0; i < size; i++) |
| 804 | buf[i] = (i & 0xf) << 4 | 0xa; |
| 805 | break; |
| 806 | case 2: |
| 807 | for (i = 0; i < size; i++) |
| 808 | buf[i] = 0x50 | (i & 0xf); |
| 809 | break; |
| 810 | case 3: |
| 811 | for (i = 0; i < size; i++) |
| 812 | buf[i] = 0xa0 | (i & 0xf); |
| 813 | break; |
| 814 | case 4: |
| 815 | for (i = 0; i < size; i++) |
| 816 | buf[i] = (i & 0xf) << 4; |
| 817 | break; |
| 818 | case 5: |
| 819 | for (i = 0; i < size; i++) |
| 820 | buf[i] = i & 0xf; |
| 821 | break; |
| 822 | case 6: |
| 823 | memset(buf, 0x00, size); |
| 824 | break; |
| 825 | case 7: |
| 826 | memset(buf, 0xff, size); |
| 827 | break; |
| 828 | case 8: |
| 829 | for (i = 0; i < size; i++) |
| 830 | buf[i] = i & 0xff; |
| 831 | break; |
| 832 | case 9: |
| 833 | for (i = 0; i < size; i++) |
| 834 | buf[i] = ~(i & 0xff); |
| 835 | break; |
| 836 | case 10: |
| 837 | for (i = 0; i < size % 2; i++) { |
| 838 | buf[i * 2] = (i >> 8) & 0xff; |
| 839 | buf[i * 2 + 1] = i & 0xff; |
| 840 | } |
| 841 | if (size & 0x1) |
| 842 | buf[i * 2] = (i >> 8) & 0xff; |
| 843 | break; |
| 844 | case 11: |
| 845 | for (i = 0; i < size % 2; i++) { |
| 846 | buf[i * 2] = ~((i >> 8) & 0xff); |
| 847 | buf[i * 2 + 1] = ~(i & 0xff); |
| 848 | } |
| 849 | if (size & 0x1) |
| 850 | buf[i * 2] = ~((i >> 8) & 0xff); |
| 851 | break; |
| 852 | case 12: |
| 853 | memset(buf, 0x00, size); |
| 854 | break; |
| 855 | case 13: |
| 856 | memset(buf, 0xff, size); |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | if ((variant >= 0) && (variant <= 7)) { |
| 861 | /* Write block number in the last two bytes of each 256-byte |
| 862 | * block, big endian for easier reading of the hexdump. |
| 863 | * Note that this wraps around for chips larger than 2^24 bytes |
| 864 | * (16 MB). |
| 865 | */ |
| 866 | for (i = 0; i < size / 256; i++) { |
| 867 | buf[i * 256 + 254] = (i >> 8) & 0xff; |
| 868 | buf[i * 256 + 255] = i & 0xff; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 875 | int check_max_decode(enum chipbustype buses, uint32_t size) |
| 876 | { |
| 877 | int limitexceeded = 0; |
| 878 | if ((buses & CHIP_BUSTYPE_PARALLEL) && |
| 879 | (max_rom_decode.parallel < size)) { |
| 880 | limitexceeded++; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 881 | msg_pdbg("Chip size %u kB is bigger than supported " |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 882 | "size %u kB of chipset/board/programmer " |
| 883 | "for %s interface, " |
| 884 | "probe/read/erase/write may fail. ", size / 1024, |
| 885 | max_rom_decode.parallel / 1024, "Parallel"); |
| 886 | } |
| 887 | if ((buses & CHIP_BUSTYPE_LPC) && (max_rom_decode.lpc < size)) { |
| 888 | limitexceeded++; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 889 | msg_pdbg("Chip size %u kB is bigger than supported " |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 890 | "size %u kB of chipset/board/programmer " |
| 891 | "for %s interface, " |
| 892 | "probe/read/erase/write may fail. ", size / 1024, |
| 893 | max_rom_decode.lpc / 1024, "LPC"); |
| 894 | } |
| 895 | if ((buses & CHIP_BUSTYPE_FWH) && (max_rom_decode.fwh < size)) { |
| 896 | limitexceeded++; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 897 | msg_pdbg("Chip size %u kB is bigger than supported " |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 898 | "size %u kB of chipset/board/programmer " |
| 899 | "for %s interface, " |
| 900 | "probe/read/erase/write may fail. ", size / 1024, |
| 901 | max_rom_decode.fwh / 1024, "FWH"); |
| 902 | } |
| 903 | if ((buses & CHIP_BUSTYPE_SPI) && (max_rom_decode.spi < size)) { |
| 904 | limitexceeded++; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 905 | msg_pdbg("Chip size %u kB is bigger than supported " |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 906 | "size %u kB of chipset/board/programmer " |
| 907 | "for %s interface, " |
| 908 | "probe/read/erase/write may fail. ", size / 1024, |
| 909 | max_rom_decode.spi / 1024, "SPI"); |
| 910 | } |
| 911 | if (!limitexceeded) |
| 912 | return 0; |
| 913 | /* Sometimes chip and programmer have more than one bus in common, |
| 914 | * and the limit is not exceeded on all buses. Tell the user. |
| 915 | */ |
| 916 | if (bitcount(buses) > limitexceeded) |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 917 | /* FIXME: This message is designed towards CLI users. */ |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 918 | msg_pdbg("There is at least one common chip/programmer " |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 919 | "interface which can support a chip of this size. " |
| 920 | "You can try --force at your own risk.\n"); |
| 921 | return 1; |
| 922 | } |
| 923 | |
Peter Stuge | 483b8f0 | 2008-09-03 23:10:05 +0000 | [diff] [blame] | 924 | struct flashchip *probe_flash(struct flashchip *first_flash, int force) |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 925 | { |
Peter Stuge | 483b8f0 | 2008-09-03 23:10:05 +0000 | [diff] [blame] | 926 | struct flashchip *flash; |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 927 | unsigned long base = 0; |
| 928 | uint32_t size; |
| 929 | enum chipbustype buses_common; |
Carl-Daniel Hailfinger | b22918c | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 930 | char *tmp; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 931 | |
Peter Stuge | 483b8f0 | 2008-09-03 23:10:05 +0000 | [diff] [blame] | 932 | for (flash = first_flash; flash && flash->name; flash++) { |
Peter Stuge | 27c3e2d | 2008-07-02 17:15:47 +0000 | [diff] [blame] | 933 | if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 934 | continue; |
Carl-Daniel Hailfinger | 12575e5 | 2010-03-22 23:43:51 +0000 | [diff] [blame] | 935 | msg_gdbg("Probing for %s %s, %d KB: ", |
Stefan Reinauer | ac37897 | 2008-03-17 22:59:40 +0000 | [diff] [blame] | 936 | flash->vendor, flash->name, flash->total_size); |
Peter Stuge | 7ffbc6f | 2008-06-18 02:08:40 +0000 | [diff] [blame] | 937 | if (!flash->probe && !force) { |
Carl-Daniel Hailfinger | 12575e5 | 2010-03-22 23:43:51 +0000 | [diff] [blame] | 938 | msg_gdbg("failed! flashrom has no probe function for " |
| 939 | "this flash chip.\n"); |
Peter Stuge | f31104c | 2008-04-28 14:47:30 +0000 | [diff] [blame] | 940 | continue; |
| 941 | } |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 942 | buses_common = buses_supported & flash->bustype; |
| 943 | if (!buses_common) { |
Carl-Daniel Hailfinger | b22918c | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 944 | tmp = flashbuses_to_text(buses_supported); |
Carl-Daniel Hailfinger | 12575e5 | 2010-03-22 23:43:51 +0000 | [diff] [blame] | 945 | msg_gdbg("skipped."); |
| 946 | msg_gspew(" Host bus type %s ", tmp); |
Carl-Daniel Hailfinger | b22918c | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 947 | free(tmp); |
| 948 | tmp = flashbuses_to_text(flash->bustype); |
Carl-Daniel Hailfinger | 12575e5 | 2010-03-22 23:43:51 +0000 | [diff] [blame] | 949 | msg_gspew("and chip bus type %s are incompatible.", |
| 950 | tmp); |
Carl-Daniel Hailfinger | b22918c | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 951 | free(tmp); |
Carl-Daniel Hailfinger | 12575e5 | 2010-03-22 23:43:51 +0000 | [diff] [blame] | 952 | msg_gdbg("\n"); |
Carl-Daniel Hailfinger | b22918c | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 953 | continue; |
| 954 | } |
Stefan Reinauer | 7038564 | 2007-04-06 11:58:03 +0000 | [diff] [blame] | 955 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 956 | size = flash->total_size * 1024; |
Carl-Daniel Hailfinger | 115d390 | 2009-10-31 01:53:09 +0000 | [diff] [blame] | 957 | check_max_decode(buses_common, size); |
Stefan Reinauer | 7038564 | 2007-04-06 11:58:03 +0000 | [diff] [blame] | 958 | |
Carl-Daniel Hailfinger | 97d6b09 | 2009-05-09 07:27:23 +0000 | [diff] [blame] | 959 | base = flashbase ? flashbase : (0xffffffff - size + 1); |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 960 | flash->virtual_memory = (chipaddr)programmer_map_flash_region("flash chip", base, size); |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 961 | |
Peter Stuge | 27c3e2d | 2008-07-02 17:15:47 +0000 | [diff] [blame] | 962 | if (force) |
| 963 | break; |
Stefan Reinauer | fcb6368 | 2006-03-16 16:57:41 +0000 | [diff] [blame] | 964 | |
Peter Stuge | 483b8f0 | 2008-09-03 23:10:05 +0000 | [diff] [blame] | 965 | if (flash->probe(flash) != 1) |
| 966 | goto notfound; |
| 967 | |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 968 | if (first_flash == flashchips |
| 969 | || flash->model_id != GENERIC_DEVICE_ID) |
Peter Stuge | 27c3e2d | 2008-07-02 17:15:47 +0000 | [diff] [blame] | 970 | break; |
| 971 | |
Peter Stuge | 483b8f0 | 2008-09-03 23:10:05 +0000 | [diff] [blame] | 972 | notfound: |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 973 | programmer_unmap_flash_region((void *)flash->virtual_memory, size); |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 974 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 975 | |
Peter Stuge | 27c3e2d | 2008-07-02 17:15:47 +0000 | [diff] [blame] | 976 | if (!flash || !flash->name) |
| 977 | return NULL; |
| 978 | |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 979 | msg_cinfo("%s chip \"%s %s\" (%d KB, %s) at physical address 0x%lx.\n", |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 980 | force ? "Assuming" : "Found", |
Uwe Hermann | 9899cad | 2009-06-28 21:47:57 +0000 | [diff] [blame] | 981 | flash->vendor, flash->name, flash->total_size, |
| 982 | flashbuses_to_text(flash->bustype), base); |
| 983 | |
Sean Nelson | 6e0b912 | 2010-02-19 00:52:10 +0000 | [diff] [blame] | 984 | if (flash->printlock) |
| 985 | flash->printlock(flash); |
| 986 | |
Peter Stuge | 27c3e2d | 2008-07-02 17:15:47 +0000 | [diff] [blame] | 987 | return flash; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Stefan Reinauer | e370528 | 2005-12-18 16:41:10 +0000 | [diff] [blame] | 990 | int verify_flash(struct flashchip *flash, uint8_t *buf) |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 991 | { |
Carl-Daniel Hailfinger | 2329066 | 2009-06-24 08:20:45 +0000 | [diff] [blame] | 992 | int ret; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 993 | int total_size = flash->total_size * 1024; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 994 | |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 995 | msg_cinfo("Verifying flash... "); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 996 | |
Carl-Daniel Hailfinger | 2329066 | 2009-06-24 08:20:45 +0000 | [diff] [blame] | 997 | ret = verify_range(flash, buf, 0, total_size, NULL); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 998 | |
Carl-Daniel Hailfinger | 2329066 | 2009-06-24 08:20:45 +0000 | [diff] [blame] | 999 | if (!ret) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1000 | msg_cinfo("VERIFIED. \n"); |
Stefan Reinauer | fcb6368 | 2006-03-16 16:57:41 +0000 | [diff] [blame] | 1001 | |
Carl-Daniel Hailfinger | 2329066 | 2009-06-24 08:20:45 +0000 | [diff] [blame] | 1002 | return ret; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Carl-Daniel Hailfinger | 49eb4dd | 2009-06-19 11:23:57 +0000 | [diff] [blame] | 1005 | int read_flash(struct flashchip *flash, char *filename) |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1006 | { |
| 1007 | unsigned long numbytes; |
| 1008 | FILE *image; |
| 1009 | unsigned long size = flash->total_size * 1024; |
| 1010 | unsigned char *buf = calloc(size, sizeof(char)); |
Stephan Guilloux | 21dd55b | 2009-06-01 22:07:52 +0000 | [diff] [blame] | 1011 | |
| 1012 | if (!filename) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1013 | msg_gerr("Error: No filename specified.\n"); |
Stephan Guilloux | 21dd55b | 2009-06-01 22:07:52 +0000 | [diff] [blame] | 1014 | return 1; |
| 1015 | } |
Patrick Georgi | 0bf842d | 2010-01-25 22:55:33 +0000 | [diff] [blame] | 1016 | if ((image = fopen(filename, "wb")) == NULL) { |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1017 | perror(filename); |
| 1018 | exit(1); |
| 1019 | } |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1020 | msg_cinfo("Reading flash... "); |
Carl-Daniel Hailfinger | 03b4e71 | 2009-05-08 12:49:03 +0000 | [diff] [blame] | 1021 | if (!flash->read) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1022 | msg_cinfo("FAILED!\n"); |
| 1023 | msg_cerr("ERROR: flashrom has no read function for this flash chip.\n"); |
Carl-Daniel Hailfinger | 03b4e71 | 2009-05-08 12:49:03 +0000 | [diff] [blame] | 1024 | return 1; |
| 1025 | } else |
Carl-Daniel Hailfinger | cbf563c | 2009-06-16 08:55:44 +0000 | [diff] [blame] | 1026 | flash->read(flash, buf, 0, size); |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1027 | |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1028 | numbytes = fwrite(buf, 1, size, image); |
| 1029 | fclose(image); |
Stephan Guilloux | 5a8b244 | 2009-06-01 21:37:00 +0000 | [diff] [blame] | 1030 | free(buf); |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1031 | msg_cinfo("%s.\n", numbytes == size ? "done" : "FAILED"); |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1032 | if (numbytes != size) |
| 1033 | return 1; |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1037 | /* This function shares a lot of its structure with erase_flash(). |
| 1038 | * Even if an error is found, the function will keep going and check the rest. |
| 1039 | */ |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1040 | int selfcheck_eraseblocks(struct flashchip *flash) |
| 1041 | { |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1042 | int i, j, k; |
| 1043 | int ret = 0; |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1044 | |
| 1045 | for (k = 0; k < NUM_ERASEFUNCTIONS; k++) { |
| 1046 | unsigned int done = 0; |
| 1047 | struct block_eraser eraser = flash->block_erasers[k]; |
| 1048 | |
| 1049 | for (i = 0; i < NUM_ERASEREGIONS; i++) { |
| 1050 | /* Blocks with zero size are bugs in flashchips.c. */ |
| 1051 | if (eraser.eraseblocks[i].count && |
| 1052 | !eraser.eraseblocks[i].size) { |
| 1053 | msg_gerr("ERROR: Flash chip %s erase function " |
| 1054 | "%i region %i has size 0. Please report" |
| 1055 | " a bug at flashrom@flashrom.org\n", |
| 1056 | flash->name, k, i); |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1057 | ret = 1; |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1058 | } |
| 1059 | /* Blocks with zero count are bugs in flashchips.c. */ |
| 1060 | if (!eraser.eraseblocks[i].count && |
| 1061 | eraser.eraseblocks[i].size) { |
| 1062 | msg_gerr("ERROR: Flash chip %s erase function " |
| 1063 | "%i region %i has count 0. Please report" |
| 1064 | " a bug at flashrom@flashrom.org\n", |
| 1065 | flash->name, k, i); |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1066 | ret = 1; |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1067 | } |
| 1068 | done += eraser.eraseblocks[i].count * |
| 1069 | eraser.eraseblocks[i].size; |
| 1070 | } |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1071 | /* Empty eraseblock definition with erase function. */ |
| 1072 | if (!done && eraser.block_erase) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1073 | msg_gspew("Strange: Empty eraseblock definition with " |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1074 | "non-empty erase function. Not an error.\n"); |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1075 | if (!done) |
| 1076 | continue; |
| 1077 | if (done != flash->total_size * 1024) { |
| 1078 | msg_gerr("ERROR: Flash chip %s erase function %i " |
| 1079 | "region walking resulted in 0x%06x bytes total," |
| 1080 | " expected 0x%06x bytes. Please report a bug at" |
| 1081 | " flashrom@flashrom.org\n", flash->name, k, |
| 1082 | done, flash->total_size * 1024); |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1083 | ret = 1; |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1084 | } |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1085 | if (!eraser.block_erase) |
| 1086 | continue; |
| 1087 | /* Check if there are identical erase functions for different |
| 1088 | * layouts. That would imply "magic" erase functions. The |
| 1089 | * easiest way to check this is with function pointers. |
| 1090 | */ |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 1091 | for (j = k + 1; j < NUM_ERASEFUNCTIONS; j++) { |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1092 | if (eraser.block_erase == |
| 1093 | flash->block_erasers[j].block_erase) { |
| 1094 | msg_gerr("ERROR: Flash chip %s erase function " |
| 1095 | "%i and %i are identical. Please report" |
| 1096 | " a bug at flashrom@flashrom.org\n", |
| 1097 | flash->name, k, j); |
| 1098 | ret = 1; |
| 1099 | } |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 1100 | } |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1101 | } |
Carl-Daniel Hailfinger | 415afcf | 2010-01-19 06:42:46 +0000 | [diff] [blame] | 1102 | return ret; |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1105 | int erase_flash(struct flashchip *flash) |
| 1106 | { |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1107 | int i, j, k, ret = 0, found = 0; |
Carl-Daniel Hailfinger | 9d48916 | 2009-12-14 04:04:18 +0000 | [diff] [blame] | 1108 | unsigned int start, len; |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1109 | |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1110 | msg_cinfo("Erasing flash chip... "); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1111 | for (k = 0; k < NUM_ERASEFUNCTIONS; k++) { |
Carl-Daniel Hailfinger | 9d48916 | 2009-12-14 04:04:18 +0000 | [diff] [blame] | 1112 | unsigned int done = 0; |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1113 | struct block_eraser eraser = flash->block_erasers[k]; |
| 1114 | |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1115 | msg_cdbg("Looking at blockwise erase function %i... ", k); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1116 | if (!eraser.block_erase && !eraser.eraseblocks[0].count) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1117 | msg_cdbg("not defined. " |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1118 | "Looking for another erase function.\n"); |
| 1119 | continue; |
| 1120 | } |
| 1121 | if (!eraser.block_erase && eraser.eraseblocks[0].count) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1122 | msg_cdbg("eraseblock layout is known, but no " |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1123 | "matching block erase function found. " |
| 1124 | "Looking for another erase function.\n"); |
| 1125 | continue; |
| 1126 | } |
| 1127 | if (eraser.block_erase && !eraser.eraseblocks[0].count) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1128 | msg_cdbg("block erase function found, but " |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1129 | "eraseblock layout is unknown. " |
| 1130 | "Looking for another erase function.\n"); |
| 1131 | continue; |
| 1132 | } |
| 1133 | found = 1; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1134 | msg_cdbg("trying... "); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1135 | for (i = 0; i < NUM_ERASEREGIONS; i++) { |
| 1136 | /* count==0 for all automatically initialized array |
| 1137 | * members so the loop below won't be executed for them. |
| 1138 | */ |
| 1139 | for (j = 0; j < eraser.eraseblocks[i].count; j++) { |
Carl-Daniel Hailfinger | 9d48916 | 2009-12-14 04:04:18 +0000 | [diff] [blame] | 1140 | start = done + eraser.eraseblocks[i].size * j; |
| 1141 | len = eraser.eraseblocks[i].size; |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1142 | msg_cdbg("0x%06x-0x%06x, ", start, |
Carl-Daniel Hailfinger | 9d48916 | 2009-12-14 04:04:18 +0000 | [diff] [blame] | 1143 | start + len - 1); |
| 1144 | ret = eraser.block_erase(flash, start, len); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1145 | if (ret) |
| 1146 | break; |
| 1147 | } |
| 1148 | if (ret) |
| 1149 | break; |
Carl-Daniel Hailfinger | 9d48916 | 2009-12-14 04:04:18 +0000 | [diff] [blame] | 1150 | done += eraser.eraseblocks[i].count * |
| 1151 | eraser.eraseblocks[i].size; |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1152 | } |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1153 | msg_cdbg("\n"); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1154 | /* If everything is OK, don't try another erase function. */ |
| 1155 | if (!ret) |
| 1156 | break; |
| 1157 | } |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1158 | if (!found) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1159 | msg_cerr("ERROR: flashrom has no erase function for this flash chip.\n"); |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1160 | return 1; |
| 1161 | } |
Carl-Daniel Hailfinger | f160a12 | 2009-05-08 17:15:15 +0000 | [diff] [blame] | 1162 | |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1163 | if (ret) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1164 | msg_cerr("FAILED!\n"); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1165 | } else { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1166 | msg_cinfo("SUCCESS.\n"); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 1167 | } |
| 1168 | return ret; |
Carl-Daniel Hailfinger | 7314cc3 | 2009-01-28 00:27:54 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 1171 | void emergency_help_message(void) |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1172 | { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1173 | msg_gerr("Your flash chip is in an unknown state.\n" |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 1174 | "Get help on IRC at irc.freenode.net (channel #flashrom) or\n" |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 1175 | "mail flashrom@flashrom.org!\n" |
| 1176 | "-------------------------------------------------------------" |
| 1177 | "------------------\n" |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1178 | "DO NOT REBOOT OR POWEROFF!\n"); |
| 1179 | } |
| 1180 | |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1181 | /* The way to go if you want a delimited list of programmers*/ |
| 1182 | void list_programmers(char *delim) |
| 1183 | { |
| 1184 | enum programmer p; |
| 1185 | for (p = 0; p < PROGRAMMER_INVALID; p++) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1186 | msg_ginfo("%s", programmer_table[p].name); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1187 | if (p < PROGRAMMER_INVALID - 1) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1188 | msg_ginfo("%s", delim); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1189 | } |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1190 | msg_ginfo("\n"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Carl-Daniel Hailfinger | 132e2ec | 2010-03-27 16:36:40 +0000 | [diff] [blame] | 1193 | void print_sysinfo(void) |
| 1194 | { |
| 1195 | #if HAVE_UTSNAME == 1 |
| 1196 | struct utsname osinfo; |
| 1197 | uname(&osinfo); |
| 1198 | |
| 1199 | msg_ginfo(" on %s %s (%s)", osinfo.sysname, osinfo.release, |
| 1200 | osinfo.machine); |
| 1201 | #else |
| 1202 | msg_ginfo(" on unknown machine"); |
| 1203 | #endif |
| 1204 | msg_ginfo(", built with"); |
| 1205 | #if NEED_PCI == 1 |
| 1206 | #ifdef PCILIB_VERSION |
| 1207 | msg_ginfo(" libpci %s,", PCILIB_VERSION); |
| 1208 | #else |
| 1209 | msg_ginfo(" unknown PCI library,"); |
| 1210 | #endif |
| 1211 | #endif |
| 1212 | #ifdef __clang__ |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 1213 | msg_ginfo(" LLVM %i/clang %i, ", __llvm__, __clang__); |
Carl-Daniel Hailfinger | 132e2ec | 2010-03-27 16:36:40 +0000 | [diff] [blame] | 1214 | #elif defined(__GNUC__) |
| 1215 | msg_ginfo(" GCC"); |
| 1216 | #ifdef __VERSION__ |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 1217 | msg_ginfo(" %s,", __VERSION__); |
Carl-Daniel Hailfinger | 132e2ec | 2010-03-27 16:36:40 +0000 | [diff] [blame] | 1218 | #else |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 1219 | msg_ginfo(" unknown version,"); |
Carl-Daniel Hailfinger | 132e2ec | 2010-03-27 16:36:40 +0000 | [diff] [blame] | 1220 | #endif |
| 1221 | #else |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 1222 | msg_ginfo(" unknown compiler,"); |
| 1223 | #endif |
| 1224 | #if defined (__FLASHROM_LITTLE_ENDIAN__) |
| 1225 | msg_ginfo(" little endian"); |
| 1226 | #else |
| 1227 | msg_ginfo(" big endian"); |
Carl-Daniel Hailfinger | 132e2ec | 2010-03-27 16:36:40 +0000 | [diff] [blame] | 1228 | #endif |
| 1229 | msg_ginfo("\n"); |
| 1230 | } |
| 1231 | |
Bernhard Walle | 201bde3 | 2008-01-21 15:24:22 +0000 | [diff] [blame] | 1232 | void print_version(void) |
| 1233 | { |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 1234 | msg_ginfo("flashrom v%s", flashrom_version); |
Carl-Daniel Hailfinger | 132e2ec | 2010-03-27 16:36:40 +0000 | [diff] [blame] | 1235 | print_sysinfo(); |
Bernhard Walle | 201bde3 | 2008-01-21 15:24:22 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 1238 | void print_banner(void) |
| 1239 | { |
| 1240 | msg_ginfo("flashrom is free software, get the source code at " |
| 1241 | "http://www.flashrom.org\n"); |
| 1242 | msg_ginfo("\n"); |
| 1243 | } |
| 1244 | |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1245 | int selfcheck(void) |
| 1246 | { |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1247 | int ret = 0; |
| 1248 | struct flashchip *flash; |
| 1249 | |
| 1250 | /* Safety check. Instead of aborting after the first error, check |
| 1251 | * if more errors exist. |
| 1252 | */ |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1253 | if (ARRAY_SIZE(programmer_table) - 1 != PROGRAMMER_INVALID) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1254 | msg_gerr("Programmer table miscompilation!\n"); |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1255 | ret = 1; |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1256 | } |
| 1257 | if (spi_programmer_count - 1 != SPI_CONTROLLER_INVALID) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1258 | msg_gerr("SPI programmer table miscompilation!\n"); |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1259 | ret = 1; |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1260 | } |
| 1261 | #if BITBANG_SPI_SUPPORT == 1 |
| 1262 | if (bitbang_spi_master_count - 1 != BITBANG_SPI_INVALID) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1263 | msg_gerr("Bitbanging SPI master table miscompilation!\n"); |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1264 | ret = 1; |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1265 | } |
| 1266 | #endif |
Carl-Daniel Hailfinger | 293adf0 | 2010-01-18 08:14:43 +0000 | [diff] [blame] | 1267 | for (flash = flashchips; flash && flash->name; flash++) |
| 1268 | if (selfcheck_eraseblocks(flash)) |
| 1269 | ret = 1; |
| 1270 | return ret; |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | void check_chip_supported(struct flashchip *flash) |
| 1274 | { |
| 1275 | if (TEST_OK_MASK != (flash->tested & TEST_OK_MASK)) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1276 | msg_cinfo("===\n"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1277 | if (flash->tested & TEST_BAD_MASK) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1278 | msg_cinfo("This flash part has status NOT WORKING for operations:"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1279 | if (flash->tested & TEST_BAD_PROBE) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1280 | msg_cinfo(" PROBE"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1281 | if (flash->tested & TEST_BAD_READ) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1282 | msg_cinfo(" READ"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1283 | if (flash->tested & TEST_BAD_ERASE) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1284 | msg_cinfo(" ERASE"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1285 | if (flash->tested & TEST_BAD_WRITE) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1286 | msg_cinfo(" WRITE"); |
| 1287 | msg_cinfo("\n"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1288 | } |
| 1289 | if ((!(flash->tested & TEST_BAD_PROBE) && !(flash->tested & TEST_OK_PROBE)) || |
| 1290 | (!(flash->tested & TEST_BAD_READ) && !(flash->tested & TEST_OK_READ)) || |
| 1291 | (!(flash->tested & TEST_BAD_ERASE) && !(flash->tested & TEST_OK_ERASE)) || |
| 1292 | (!(flash->tested & TEST_BAD_WRITE) && !(flash->tested & TEST_OK_WRITE))) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1293 | msg_cinfo("This flash part has status UNTESTED for operations:"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1294 | if (!(flash->tested & TEST_BAD_PROBE) && !(flash->tested & TEST_OK_PROBE)) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1295 | msg_cinfo(" PROBE"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1296 | if (!(flash->tested & TEST_BAD_READ) && !(flash->tested & TEST_OK_READ)) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1297 | msg_cinfo(" READ"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1298 | if (!(flash->tested & TEST_BAD_ERASE) && !(flash->tested & TEST_OK_ERASE)) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1299 | msg_cinfo(" ERASE"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1300 | if (!(flash->tested & TEST_BAD_WRITE) && !(flash->tested & TEST_OK_WRITE)) |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1301 | msg_cinfo(" WRITE"); |
| 1302 | msg_cinfo("\n"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1303 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 1304 | /* FIXME: This message is designed towards CLI users. */ |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 1305 | msg_cinfo("The test status of this chip may have been updated " |
| 1306 | "in the latest development\n" |
| 1307 | "version of flashrom. If you are running the latest " |
| 1308 | "development version,\n" |
| 1309 | "please email a report to flashrom@flashrom.org if " |
| 1310 | "any of the above operations\n" |
| 1311 | "work correctly for you with this flash part. Please " |
| 1312 | "include the flashrom\n" |
| 1313 | "output with the additional -V option for all " |
| 1314 | "operations you tested (-V, -Vr,\n" |
| 1315 | "-Vw, -VE), and mention which mainboard or " |
| 1316 | "programmer you tested.\n" |
| 1317 | "Thanks for your help!\n" |
| 1318 | "===\n"); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 1322 | int main(int argc, char *argv[]) |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 1323 | { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 1324 | return cli_classic(argc, argv); |
Carl-Daniel Hailfinger | 552420b | 2009-12-24 02:15:55 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | /* This function signature is horrible. We need to design a better interface, |
| 1328 | * but right now it allows us to split off the CLI code. |
| 1329 | */ |
| 1330 | int doit(struct flashchip *flash, int force, char *filename, int read_it, int write_it, int erase_it, int verify_it) |
| 1331 | { |
| 1332 | uint8_t *buf; |
| 1333 | unsigned long numbytes; |
| 1334 | FILE *image; |
| 1335 | int ret = 0; |
| 1336 | unsigned long size; |
| 1337 | |
| 1338 | size = flash->total_size * 1024; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 1339 | buf = (uint8_t *) calloc(size, sizeof(char)); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 1340 | |
Ollie Lho | efa2858 | 2004-12-08 20:10:01 +0000 | [diff] [blame] | 1341 | if (erase_it) { |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1342 | if (flash->tested & TEST_BAD_ERASE) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1343 | msg_cerr("Erase is not working on this chip. "); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1344 | if (!force) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1345 | msg_cerr("Aborting.\n"); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1346 | programmer_shutdown(); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1347 | return 1; |
| 1348 | } else { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1349 | msg_cerr("Continuing anyway.\n"); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1350 | } |
| 1351 | } |
Sean Nelson | 6e0b912 | 2010-02-19 00:52:10 +0000 | [diff] [blame] | 1352 | if (flash->unlock) |
| 1353 | flash->unlock(flash); |
| 1354 | |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1355 | if (erase_flash(flash)) { |
| 1356 | emergency_help_message(); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1357 | programmer_shutdown(); |
Peter Stuge | f31104c | 2008-04-28 14:47:30 +0000 | [diff] [blame] | 1358 | return 1; |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1359 | } |
Ollie Lho | efa2858 | 2004-12-08 20:10:01 +0000 | [diff] [blame] | 1360 | } else if (read_it) { |
Sean Nelson | 6e0b912 | 2010-02-19 00:52:10 +0000 | [diff] [blame] | 1361 | if (flash->unlock) |
| 1362 | flash->unlock(flash); |
| 1363 | |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1364 | if (read_flash(flash, filename)) { |
| 1365 | programmer_shutdown(); |
Peter Stuge | 1fec0f3 | 2009-01-12 21:00:35 +0000 | [diff] [blame] | 1366 | return 1; |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1367 | } |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 1368 | } else { |
Stefan Reinauer | 018aca8 | 2006-11-21 23:48:51 +0000 | [diff] [blame] | 1369 | struct stat image_stat; |
| 1370 | |
Sean Nelson | 6e0b912 | 2010-02-19 00:52:10 +0000 | [diff] [blame] | 1371 | if (flash->unlock) |
| 1372 | flash->unlock(flash); |
| 1373 | |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1374 | if (flash->tested & TEST_BAD_ERASE) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1375 | msg_cerr("Erase is not working on this chip " |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1376 | "and erase is needed for write. "); |
| 1377 | if (!force) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1378 | msg_cerr("Aborting.\n"); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1379 | programmer_shutdown(); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1380 | return 1; |
| 1381 | } else { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1382 | msg_cerr("Continuing anyway.\n"); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | if (flash->tested & TEST_BAD_WRITE) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1386 | msg_cerr("Write is not working on this chip. "); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1387 | if (!force) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1388 | msg_cerr("Aborting.\n"); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1389 | programmer_shutdown(); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1390 | return 1; |
| 1391 | } else { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1392 | msg_cerr("Continuing anyway.\n"); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1393 | } |
| 1394 | } |
Patrick Georgi | 0bf842d | 2010-01-25 22:55:33 +0000 | [diff] [blame] | 1395 | if ((image = fopen(filename, "rb")) == NULL) { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 1396 | perror(filename); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1397 | programmer_shutdown(); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 1398 | exit(1); |
| 1399 | } |
Stefan Reinauer | 018aca8 | 2006-11-21 23:48:51 +0000 | [diff] [blame] | 1400 | if (fstat(fileno(image), &image_stat) != 0) { |
| 1401 | perror(filename); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1402 | programmer_shutdown(); |
Stefan Reinauer | 018aca8 | 2006-11-21 23:48:51 +0000 | [diff] [blame] | 1403 | exit(1); |
| 1404 | } |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 1405 | if (image_stat.st_size != flash->total_size * 1024) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1406 | msg_gerr("Error: Image size doesn't match\n"); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1407 | programmer_shutdown(); |
Stefan Reinauer | 018aca8 | 2006-11-21 23:48:51 +0000 | [diff] [blame] | 1408 | exit(1); |
| 1409 | } |
| 1410 | |
Peter Stuge | 1fec0f3 | 2009-01-12 21:00:35 +0000 | [diff] [blame] | 1411 | numbytes = fread(buf, 1, size, image); |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 1412 | #if INTERNAL_SUPPORT == 1 |
Peter Stuge | 7ffbc6f | 2008-06-18 02:08:40 +0000 | [diff] [blame] | 1413 | show_id(buf, size, force); |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 1414 | #endif |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 1415 | fclose(image); |
Peter Stuge | 1fec0f3 | 2009-01-12 21:00:35 +0000 | [diff] [blame] | 1416 | if (numbytes != size) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1417 | msg_gerr("Error: Failed to read file. Got %ld bytes, wanted %ld!\n", numbytes, size); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1418 | programmer_shutdown(); |
Peter Stuge | 1fec0f3 | 2009-01-12 21:00:35 +0000 | [diff] [blame] | 1419 | return 1; |
| 1420 | } |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 1423 | // This should be moved into each flash part's code to do it |
| 1424 | // cleanly. This does the job. |
Carl-Daniel Hailfinger | f5fb51c | 2009-08-19 15:19:18 +0000 | [diff] [blame] | 1425 | handle_romentries(buf, flash); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 1426 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 1427 | // //////////////////////////////////////////////////////////// |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 1428 | |
Peter Stuge | f31104c | 2008-04-28 14:47:30 +0000 | [diff] [blame] | 1429 | if (write_it) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1430 | msg_cinfo("Writing flash chip... "); |
Peter Stuge | f31104c | 2008-04-28 14:47:30 +0000 | [diff] [blame] | 1431 | if (!flash->write) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1432 | msg_cerr("Error: flashrom has no write function for this flash chip.\n"); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1433 | programmer_shutdown(); |
Peter Stuge | f31104c | 2008-04-28 14:47:30 +0000 | [diff] [blame] | 1434 | return 1; |
| 1435 | } |
Carl-Daniel Hailfinger | 0a3e5ae | 2009-07-24 12:18:54 +0000 | [diff] [blame] | 1436 | ret = flash->write(flash, buf); |
| 1437 | if (ret) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1438 | msg_cerr("FAILED!\n"); |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1439 | emergency_help_message(); |
Uwe Hermann | 2bc98f6 | 2009-09-30 18:29:55 +0000 | [diff] [blame] | 1440 | programmer_shutdown(); |
Carl-Daniel Hailfinger | 0a3e5ae | 2009-07-24 12:18:54 +0000 | [diff] [blame] | 1441 | return 1; |
| 1442 | } else { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 1443 | msg_cinfo("COMPLETE.\n"); |
Carl-Daniel Hailfinger | 0a3e5ae | 2009-07-24 12:18:54 +0000 | [diff] [blame] | 1444 | } |
Peter Stuge | f31104c | 2008-04-28 14:47:30 +0000 | [diff] [blame] | 1445 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 1446 | |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1447 | if (verify_it) { |
| 1448 | /* Work around chips which need some time to calm down. */ |
| 1449 | if (write_it) |
| 1450 | programmer_delay(1000*1000); |
Carl-Daniel Hailfinger | 0a3e5ae | 2009-07-24 12:18:54 +0000 | [diff] [blame] | 1451 | ret = verify_flash(flash, buf); |
Carl-Daniel Hailfinger | f529205 | 2009-11-17 09:57:34 +0000 | [diff] [blame] | 1452 | /* If we tried to write, and verification now fails, we |
Carl-Daniel Hailfinger | 8ab49e7 | 2009-08-19 13:55:34 +0000 | [diff] [blame] | 1453 | * might have an emergency situation. |
| 1454 | */ |
| 1455 | if (ret && write_it) |
| 1456 | emergency_help_message(); |
| 1457 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 1458 | |
Carl-Daniel Hailfinger | 702218d | 2009-05-08 17:43:22 +0000 | [diff] [blame] | 1459 | programmer_shutdown(); |
| 1460 | |
Stefan Reinauer | 143da0b | 2006-01-04 16:42:57 +0000 | [diff] [blame] | 1461 | return ret; |
Ronald G. Minnich | f4cf2ba | 2002-01-29 18:26:26 +0000 | [diff] [blame] | 1462 | } |