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