Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * It handles everything related to status registers of the JEDEC family 25. |
| 4 | * |
| 5 | * Copyright (C) 2007, 2008, 2009, 2010 Carl-Daniel Hailfinger |
| 6 | * Copyright (C) 2008 coresystems GmbH |
| 7 | * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl> |
| 8 | * Copyright (C) 2012 Stefan Tauner |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; version 2 of the License. |
| 13 | * |
| 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. |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "flash.h" |
| 21 | #include "chipdrivers.h" |
| 22 | #include "spi.h" |
| 23 | |
| 24 | /* === Generic functions === */ |
Edward O'Callaghan | 5eca427 | 2020-04-12 17:27:53 +1000 | [diff] [blame] | 25 | static int spi_write_status_register_flag(const struct flashctx *flash, int status, const unsigned char enable_opcode) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 26 | { |
| 27 | int result; |
| 28 | int i = 0; |
| 29 | /* |
| 30 | * WRSR requires either EWSR or WREN depending on chip type. |
| 31 | * The code below relies on the fact hat EWSR and WREN have the same |
| 32 | * INSIZE and OUTSIZE. |
| 33 | */ |
| 34 | struct spi_command cmds[] = { |
| 35 | { |
| 36 | .writecnt = JEDEC_WREN_OUTSIZE, |
| 37 | .writearr = (const unsigned char[]){ enable_opcode }, |
| 38 | .readcnt = 0, |
| 39 | .readarr = NULL, |
| 40 | }, { |
| 41 | .writecnt = JEDEC_WRSR_OUTSIZE, |
| 42 | .writearr = (const unsigned char[]){ JEDEC_WRSR, (unsigned char) status }, |
| 43 | .readcnt = 0, |
| 44 | .readarr = NULL, |
| 45 | }, { |
| 46 | .writecnt = 0, |
| 47 | .writearr = NULL, |
| 48 | .readcnt = 0, |
| 49 | .readarr = NULL, |
| 50 | }}; |
| 51 | |
| 52 | result = spi_send_multicommand(flash, cmds); |
| 53 | if (result) { |
| 54 | msg_cerr("%s failed during command execution\n", __func__); |
| 55 | /* No point in waiting for the command to complete if execution |
| 56 | * failed. |
| 57 | */ |
| 58 | return result; |
| 59 | } |
| 60 | /* WRSR performs a self-timed erase before the changes take effect. |
| 61 | * This may take 50-85 ms in most cases, and some chips apparently |
| 62 | * allow running RDSR only once. Therefore pick an initial delay of |
| 63 | * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed. |
| 64 | */ |
| 65 | programmer_delay(100 * 1000); |
| 66 | while (spi_read_status_register(flash) & SPI_SR_WIP) { |
| 67 | if (++i > 490) { |
| 68 | msg_cerr("Error: WIP bit after WRSR never cleared\n"); |
| 69 | return TIMEOUT_ERROR; |
| 70 | } |
| 71 | programmer_delay(10 * 1000); |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
Edward O'Callaghan | 5eca427 | 2020-04-12 17:27:53 +1000 | [diff] [blame] | 76 | int spi_write_status_register(const struct flashctx *flash, int status) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 77 | { |
| 78 | int feature_bits = flash->chip->feature_bits; |
| 79 | int ret = 1; |
| 80 | |
| 81 | if (!(feature_bits & (FEATURE_WRSR_WREN | FEATURE_WRSR_EWSR))) { |
| 82 | msg_cdbg("Missing status register write definition, assuming " |
| 83 | "EWSR is needed\n"); |
| 84 | feature_bits |= FEATURE_WRSR_EWSR; |
| 85 | } |
| 86 | if (feature_bits & FEATURE_WRSR_WREN) |
| 87 | ret = spi_write_status_register_flag(flash, status, JEDEC_WREN); |
| 88 | if (ret && (feature_bits & FEATURE_WRSR_EWSR)) |
| 89 | ret = spi_write_status_register_flag(flash, status, JEDEC_EWSR); |
| 90 | return ret; |
| 91 | } |
| 92 | |
Edward O'Callaghan | 5eca427 | 2020-04-12 17:27:53 +1000 | [diff] [blame] | 93 | uint8_t spi_read_status_register(const struct flashctx *flash) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 94 | { |
| 95 | static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { JEDEC_RDSR }; |
| 96 | /* FIXME: No workarounds for driver/hardware bugs in generic code. */ |
| 97 | unsigned char readarr[2]; /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */ |
| 98 | int ret; |
| 99 | |
| 100 | /* Read Status Register */ |
| 101 | ret = spi_send_command(flash, sizeof(cmd), sizeof(readarr), cmd, readarr); |
Nico Huber | 1f08153 | 2017-10-14 15:01:13 +0200 | [diff] [blame] | 102 | if (ret) { |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 103 | msg_cerr("RDSR failed!\n"); |
Nico Huber | 1f08153 | 2017-10-14 15:01:13 +0200 | [diff] [blame] | 104 | /* FIXME: We should propagate the error. */ |
| 105 | return 0; |
| 106 | } |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 107 | |
| 108 | return readarr[0]; |
| 109 | } |
| 110 | |
Nikolai Artemiev | 721a4f3 | 2020-12-14 07:39:02 +1100 | [diff] [blame] | 111 | static int spi_restore_status(struct flashctx *flash, uint8_t status) |
| 112 | { |
| 113 | msg_cdbg("restoring chip status (0x%02x)\n", status); |
| 114 | return spi_write_status_register(flash, status); |
| 115 | } |
| 116 | |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 117 | /* A generic block protection disable. |
| 118 | * Tests if a protection is enabled with the block protection mask (bp_mask) and returns success otherwise. |
| 119 | * Tests if the register bits are locked with the lock_mask (lock_mask). |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 120 | * Tests if a hardware protection is active (i.e. low pin/high bit value) with the write protection mask |
| 121 | * (wp_mask) and bails out in that case. |
| 122 | * If there are register lock bits set we try to disable them by unsetting those bits of the previous register |
| 123 | * contents that are set in the lock_mask. We then check if removing the lock bits has worked and continue as if |
| 124 | * they never had been engaged: |
| 125 | * If the lock bits are out of the way try to disable engaged protections. |
| 126 | * To support uncommon global unprotects (e.g. on most AT2[56]xx1(A)) unprotect_mask can be used to force |
| 127 | * bits to 0 additionally to those set in bp_mask and lock_mask. Only bits set in unprotect_mask are potentially |
| 128 | * preserved when doing the final unprotect. |
| 129 | * |
| 130 | * To sum up: |
| 131 | * bp_mask: set those bits that correspond to the bits in the status register that indicate an active protection |
| 132 | * (which should be unset after this function returns). |
| 133 | * lock_mask: set the bits that correspond to the bits that lock changing the bits above. |
| 134 | * wp_mask: set the bits that correspond to bits indicating non-software revocable protections. |
| 135 | * unprotect_mask: set the bits that should be preserved if possible when unprotecting. |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 136 | */ |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 137 | static int spi_disable_blockprotect_generic(struct flashctx *flash, uint8_t bp_mask, uint8_t lock_mask, uint8_t wp_mask, uint8_t unprotect_mask) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 138 | { |
| 139 | uint8_t status; |
| 140 | int result; |
| 141 | |
| 142 | status = spi_read_status_register(flash); |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 143 | if ((status & bp_mask) == 0) { |
| 144 | msg_cdbg2("Block protection is disabled.\n"); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 145 | return 0; |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 146 | } |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 147 | |
Nikolai Artemiev | 721a4f3 | 2020-12-14 07:39:02 +1100 | [diff] [blame] | 148 | /* Restore status register content upon exit in finalize_flash_access(). */ |
| 149 | register_chip_restore(spi_restore_status, flash, status); |
| 150 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 151 | msg_cdbg("Some block protection in effect, disabling... "); |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 152 | if ((status & lock_mask) != 0) { |
| 153 | msg_cdbg("\n\tNeed to disable the register lock first... "); |
| 154 | if (wp_mask != 0 && (status & wp_mask) == 0) { |
| 155 | msg_cerr("Hardware protection is active, disabling write protection is impossible.\n"); |
| 156 | return 1; |
| 157 | } |
| 158 | /* All bits except the register lock bit (often called SPRL, SRWD, WPEN) are readonly. */ |
| 159 | result = spi_write_status_register(flash, status & ~lock_mask); |
| 160 | if (result) { |
| 161 | msg_cerr("spi_write_status_register failed.\n"); |
| 162 | return result; |
| 163 | } |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 164 | status = spi_read_status_register(flash); |
| 165 | if ((status & lock_mask) != 0) { |
| 166 | msg_cerr("Unsetting lock bit(s) failed.\n"); |
| 167 | return 1; |
| 168 | } |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 169 | msg_cdbg("done.\n"); |
| 170 | } |
| 171 | /* Global unprotect. Make sure to mask the register lock bit as well. */ |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 172 | result = spi_write_status_register(flash, status & ~(bp_mask | lock_mask) & unprotect_mask); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 173 | if (result) { |
| 174 | msg_cerr("spi_write_status_register failed.\n"); |
| 175 | return result; |
| 176 | } |
| 177 | status = spi_read_status_register(flash); |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 178 | if ((status & bp_mask) != 0) { |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 179 | msg_cerr("Block protection could not be disabled!\n"); |
Yuji Sasaki | 4af3609 | 2019-03-22 10:59:50 -0700 | [diff] [blame] | 180 | if (flash->chip->printlock) |
| 181 | flash->chip->printlock(flash); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 182 | return 1; |
| 183 | } |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 184 | msg_cdbg("disabled.\n"); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 188 | /* A common block protection disable that tries to unset the status register bits masked by 0x3C. */ |
| 189 | int spi_disable_blockprotect(struct flashctx *flash) |
| 190 | { |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 191 | return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0, 0xFF); |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Wei Hu | 25584de | 2018-04-30 14:02:08 -0700 | [diff] [blame] | 194 | int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash) |
| 195 | { |
| 196 | int result = spi_write_enable(flash); |
| 197 | if (result) |
| 198 | return result; |
| 199 | |
| 200 | static const unsigned char cmd[] = { 0x98 }; /* ULBPR */ |
| 201 | result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL); |
| 202 | if (result) |
| 203 | msg_cerr("ULBPR failed\n"); |
| 204 | return result; |
| 205 | } |
| 206 | |
Stefan Tauner | a60d408 | 2014-06-04 16:17:03 +0000 | [diff] [blame] | 207 | /* A common block protection disable that tries to unset the status register bits masked by 0x0C (BP0-1) and |
| 208 | * protected/locked by bit #7. Useful when bits 4-5 may be non-0). */ |
| 209 | int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash) |
| 210 | { |
| 211 | return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF); |
| 212 | } |
| 213 | |
Stefan Tauner | 278ba6e | 2013-06-28 21:28:27 +0000 | [diff] [blame] | 214 | /* A common block protection disable that tries to unset the status register bits masked by 0x1C (BP0-2) and |
| 215 | * protected/locked by bit #7. Useful when bit #5 is neither a protection bit nor reserved (and hence possibly |
| 216 | * non-0). */ |
| 217 | int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash) |
| 218 | { |
| 219 | return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0, 0xFF); |
| 220 | } |
| 221 | |
| 222 | /* A common block protection disable that tries to unset the status register bits masked by 0x3C (BP0-3) and |
| 223 | * protected/locked by bit #7. */ |
| 224 | int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash) |
| 225 | { |
| 226 | return spi_disable_blockprotect_generic(flash, 0x3C, 1 << 7, 0, 0xFF); |
| 227 | } |
| 228 | |
| 229 | /* A common block protection disable that tries to unset the status register bits masked by 0x7C (BP0-4) and |
| 230 | * protected/locked by bit #7. */ |
| 231 | int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash) |
| 232 | { |
| 233 | return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF); |
| 234 | } |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 235 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 236 | static void spi_prettyprint_status_register_hex(uint8_t status) |
| 237 | { |
| 238 | msg_cdbg("Chip status register is 0x%02x.\n", status); |
| 239 | } |
| 240 | |
Stefan Tauner | b6b00e9 | 2013-06-28 21:28:43 +0000 | [diff] [blame] | 241 | /* Common highest bit: Status Register Write Disable (SRWD) or Status Register Protect (SRP). */ |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 242 | static void spi_prettyprint_status_register_srwd(uint8_t status) |
| 243 | { |
Stefan Tauner | b6b00e9 | 2013-06-28 21:28:43 +0000 | [diff] [blame] | 244 | msg_cdbg("Chip status register: Status Register Write Disable (SRWD, SRP, ...) is %sset\n", |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 245 | (status & (1 << 7)) ? "" : "not "); |
| 246 | } |
| 247 | |
| 248 | /* Common highest bit: Block Protect Write Disable (BPL). */ |
| 249 | static void spi_prettyprint_status_register_bpl(uint8_t status) |
| 250 | { |
| 251 | msg_cdbg("Chip status register: Block Protect Write Disable (BPL) is %sset\n", |
| 252 | (status & (1 << 7)) ? "" : "not "); |
| 253 | } |
| 254 | |
| 255 | /* Common lowest 2 bits: WEL and WIP. */ |
| 256 | static void spi_prettyprint_status_register_welwip(uint8_t status) |
| 257 | { |
| 258 | msg_cdbg("Chip status register: Write Enable Latch (WEL) is %sset\n", |
| 259 | (status & (1 << 1)) ? "" : "not "); |
| 260 | msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is %sset\n", |
| 261 | (status & (1 << 0)) ? "" : "not "); |
| 262 | } |
| 263 | |
| 264 | /* Common block protection (BP) bits. */ |
| 265 | static void spi_prettyprint_status_register_bp(uint8_t status, int bp) |
| 266 | { |
| 267 | switch (bp) { |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 268 | case 4: |
| 269 | msg_cdbg("Chip status register: Block Protect 4 (BP4) is %sset\n", |
Stefan Tauner | 5c316f9 | 2015-02-08 21:57:52 +0000 | [diff] [blame] | 270 | (status & (1 << 6)) ? "" : "not "); |
Richard Hughes | db7482b | 2018-12-19 12:04:30 +0000 | [diff] [blame] | 271 | /* Fall through. */ |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 272 | case 3: |
| 273 | msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n", |
| 274 | (status & (1 << 5)) ? "" : "not "); |
Richard Hughes | db7482b | 2018-12-19 12:04:30 +0000 | [diff] [blame] | 275 | /* Fall through. */ |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 276 | case 2: |
| 277 | msg_cdbg("Chip status register: Block Protect 2 (BP2) is %sset\n", |
| 278 | (status & (1 << 4)) ? "" : "not "); |
Richard Hughes | db7482b | 2018-12-19 12:04:30 +0000 | [diff] [blame] | 279 | /* Fall through. */ |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 280 | case 1: |
| 281 | msg_cdbg("Chip status register: Block Protect 1 (BP1) is %sset\n", |
| 282 | (status & (1 << 3)) ? "" : "not "); |
Richard Hughes | db7482b | 2018-12-19 12:04:30 +0000 | [diff] [blame] | 283 | /* Fall through. */ |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 284 | case 0: |
| 285 | msg_cdbg("Chip status register: Block Protect 0 (BP0) is %sset\n", |
| 286 | (status & (1 << 2)) ? "" : "not "); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /* Unnamed bits. */ |
Aidan Thornton | db4e87d | 2013-08-27 18:01:53 +0000 | [diff] [blame] | 291 | void spi_prettyprint_status_register_bit(uint8_t status, int bit) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 292 | { |
| 293 | msg_cdbg("Chip status register: Bit %i is %sset\n", bit, (status & (1 << bit)) ? "" : "not "); |
| 294 | } |
| 295 | |
| 296 | int spi_prettyprint_status_register_plain(struct flashctx *flash) |
| 297 | { |
| 298 | uint8_t status = spi_read_status_register(flash); |
| 299 | spi_prettyprint_status_register_hex(status); |
| 300 | return 0; |
| 301 | } |
| 302 | |
Stefan Tauner | 278ba6e | 2013-06-28 21:28:27 +0000 | [diff] [blame] | 303 | /* Print the plain hex value and the welwip bits only. */ |
| 304 | int spi_prettyprint_status_register_default_welwip(struct flashctx *flash) |
| 305 | { |
| 306 | uint8_t status = spi_read_status_register(flash); |
| 307 | spi_prettyprint_status_register_hex(status); |
| 308 | |
| 309 | spi_prettyprint_status_register_welwip(status); |
| 310 | return 0; |
| 311 | } |
| 312 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 313 | /* Works for many chips of the |
| 314 | * AMIC A25L series |
| 315 | * and MX MX25L512 |
| 316 | */ |
Stefan Tauner | 12f3d51 | 2014-05-27 21:27:27 +0000 | [diff] [blame] | 317 | int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 318 | { |
| 319 | uint8_t status = spi_read_status_register(flash); |
| 320 | spi_prettyprint_status_register_hex(status); |
| 321 | |
| 322 | spi_prettyprint_status_register_srwd(status); |
| 323 | spi_prettyprint_status_register_bit(status, 6); |
| 324 | spi_prettyprint_status_register_bit(status, 5); |
| 325 | spi_prettyprint_status_register_bit(status, 4); |
| 326 | spi_prettyprint_status_register_bp(status, 1); |
| 327 | spi_prettyprint_status_register_welwip(status); |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | /* Works for many chips of the |
| 332 | * AMIC A25L series |
Stefan Tauner | f445161 | 2013-04-19 01:59:15 +0000 | [diff] [blame] | 333 | * PMC Pm25LD series |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 334 | */ |
Stefan Tauner | 12f3d51 | 2014-05-27 21:27:27 +0000 | [diff] [blame] | 335 | int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 336 | { |
| 337 | uint8_t status = spi_read_status_register(flash); |
| 338 | spi_prettyprint_status_register_hex(status); |
| 339 | |
| 340 | spi_prettyprint_status_register_srwd(status); |
| 341 | spi_prettyprint_status_register_bit(status, 6); |
| 342 | spi_prettyprint_status_register_bit(status, 5); |
| 343 | spi_prettyprint_status_register_bp(status, 2); |
| 344 | spi_prettyprint_status_register_welwip(status); |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /* Works for many chips of the |
| 349 | * ST M25P series |
| 350 | * MX MX25L series |
| 351 | */ |
Stefan Tauner | 12f3d51 | 2014-05-27 21:27:27 +0000 | [diff] [blame] | 352 | int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 353 | { |
| 354 | uint8_t status = spi_read_status_register(flash); |
| 355 | spi_prettyprint_status_register_hex(status); |
| 356 | |
| 357 | spi_prettyprint_status_register_srwd(status); |
| 358 | spi_prettyprint_status_register_bit(status, 6); |
| 359 | spi_prettyprint_status_register_bp(status, 3); |
| 360 | spi_prettyprint_status_register_welwip(status); |
| 361 | return 0; |
| 362 | } |
| 363 | |
Stefan Tauner | 12f3d51 | 2014-05-27 21:27:27 +0000 | [diff] [blame] | 364 | int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash) |
Stefan Tauner | 278ba6e | 2013-06-28 21:28:27 +0000 | [diff] [blame] | 365 | { |
| 366 | uint8_t status = spi_read_status_register(flash); |
| 367 | spi_prettyprint_status_register_hex(status); |
| 368 | |
| 369 | spi_prettyprint_status_register_srwd(status); |
| 370 | spi_prettyprint_status_register_bp(status, 4); |
| 371 | spi_prettyprint_status_register_welwip(status); |
| 372 | return 0; |
| 373 | } |
| 374 | |
Stefan Tauner | 85f09f7 | 2014-05-27 21:27:14 +0000 | [diff] [blame] | 375 | int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash) |
| 376 | { |
| 377 | uint8_t status = spi_read_status_register(flash); |
| 378 | spi_prettyprint_status_register_hex(status); |
| 379 | |
| 380 | spi_prettyprint_status_register_bpl(status); |
| 381 | spi_prettyprint_status_register_bit(status, 6); |
| 382 | spi_prettyprint_status_register_bit(status, 5); |
| 383 | spi_prettyprint_status_register_bp(status, 2); |
| 384 | spi_prettyprint_status_register_welwip(status); |
| 385 | return 0; |
| 386 | } |
| 387 | |
Ben Gardner | bcf6109 | 2015-11-22 02:23:31 +0000 | [diff] [blame] | 388 | int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash) |
| 389 | { |
| 390 | uint8_t status = spi_read_status_register(flash); |
| 391 | spi_prettyprint_status_register_hex(status); |
| 392 | |
| 393 | spi_prettyprint_status_register_bpl(status); |
| 394 | spi_prettyprint_status_register_bit(status, 6); |
| 395 | msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top"); |
| 396 | spi_prettyprint_status_register_bp(status, 2); |
| 397 | spi_prettyprint_status_register_welwip(status); |
| 398 | return 0; |
| 399 | } |
| 400 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 401 | /* === Amic === |
| 402 | * FIXME: spi_disable_blockprotect is incorrect but works fine for chips using |
Stefan Tauner | 12f3d51 | 2014-05-27 21:27:27 +0000 | [diff] [blame] | 403 | * spi_prettyprint_status_register_bp1_srwd or |
| 404 | * spi_prettyprint_status_register_bp2_srwd. |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 405 | * FIXME: spi_disable_blockprotect is incorrect and will fail for chips using |
| 406 | * spi_prettyprint_status_register_amic_a25l032 if those have locks controlled |
| 407 | * by the second status register. |
| 408 | */ |
| 409 | |
| 410 | int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash) |
| 411 | { |
| 412 | uint8_t status = spi_read_status_register(flash); |
| 413 | spi_prettyprint_status_register_hex(status); |
| 414 | |
| 415 | spi_prettyprint_status_register_srwd(status); |
| 416 | msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64); |
| 417 | msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top"); |
| 418 | spi_prettyprint_status_register_bp(status, 2); |
| 419 | spi_prettyprint_status_register_welwip(status); |
| 420 | msg_cdbg("Chip status register 2 is NOT decoded!\n"); |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | /* === Atmel === */ |
| 425 | |
| 426 | static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status) |
| 427 | { |
| 428 | msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n", |
| 429 | (status & (1 << 7)) ? "" : "not "); |
| 430 | } |
| 431 | |
| 432 | static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status) |
| 433 | { |
| 434 | msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n", |
| 435 | (status & (1 << 7)) ? "" : "not "); |
| 436 | } |
| 437 | |
| 438 | static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status) |
| 439 | { |
| 440 | msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n", |
| 441 | (status & (1 << 5)) ? "" : "not "); |
| 442 | msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n", |
| 443 | (status & (1 << 4)) ? "not " : ""); |
| 444 | } |
| 445 | |
| 446 | static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status) |
| 447 | { |
| 448 | msg_cdbg("Chip status register: Software Protection Status (SWP): "); |
| 449 | switch (status & (3 << 2)) { |
| 450 | case 0x0 << 2: |
| 451 | msg_cdbg("no sectors are protected\n"); |
| 452 | break; |
| 453 | case 0x1 << 2: |
| 454 | msg_cdbg("some sectors are protected\n"); |
| 455 | /* FIXME: Read individual Sector Protection Registers. */ |
| 456 | break; |
| 457 | case 0x3 << 2: |
| 458 | msg_cdbg("all sectors are protected\n"); |
| 459 | break; |
| 460 | default: |
| 461 | msg_cdbg("reserved for future use\n"); |
| 462 | break; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | int spi_prettyprint_status_register_at25df(struct flashctx *flash) |
| 467 | { |
| 468 | uint8_t status = spi_read_status_register(flash); |
| 469 | spi_prettyprint_status_register_hex(status); |
| 470 | |
| 471 | spi_prettyprint_status_register_atmel_at25_srpl(status); |
| 472 | spi_prettyprint_status_register_bit(status, 6); |
| 473 | spi_prettyprint_status_register_atmel_at25_epewpp(status); |
| 474 | spi_prettyprint_status_register_atmel_at25_swp(status); |
| 475 | spi_prettyprint_status_register_welwip(status); |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash) |
| 480 | { |
| 481 | /* FIXME: We should check the security lockdown. */ |
| 482 | msg_cdbg("Ignoring security lockdown (if present)\n"); |
| 483 | msg_cdbg("Ignoring status register byte 2\n"); |
| 484 | return spi_prettyprint_status_register_at25df(flash); |
| 485 | } |
| 486 | |
Stefan Tauner | 57794ac | 2012-12-29 15:04:20 +0000 | [diff] [blame] | 487 | /* used for AT25F512, AT25F1024(A), AT25F2048 */ |
| 488 | int spi_prettyprint_status_register_at25f(struct flashctx *flash) |
| 489 | { |
| 490 | uint8_t status; |
| 491 | |
| 492 | status = spi_read_status_register(flash); |
| 493 | spi_prettyprint_status_register_hex(status); |
| 494 | |
| 495 | spi_prettyprint_status_register_atmel_at25_wpen(status); |
| 496 | spi_prettyprint_status_register_bit(status, 6); |
| 497 | spi_prettyprint_status_register_bit(status, 5); |
| 498 | spi_prettyprint_status_register_bit(status, 4); |
| 499 | spi_prettyprint_status_register_bp(status, 1); |
| 500 | spi_prettyprint_status_register_welwip(status); |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | int spi_prettyprint_status_register_at25f512a(struct flashctx *flash) |
| 505 | { |
| 506 | uint8_t status; |
| 507 | |
| 508 | status = spi_read_status_register(flash); |
| 509 | spi_prettyprint_status_register_hex(status); |
| 510 | |
| 511 | spi_prettyprint_status_register_atmel_at25_wpen(status); |
| 512 | spi_prettyprint_status_register_bit(status, 6); |
| 513 | spi_prettyprint_status_register_bit(status, 5); |
| 514 | spi_prettyprint_status_register_bit(status, 4); |
| 515 | spi_prettyprint_status_register_bit(status, 3); |
| 516 | spi_prettyprint_status_register_bp(status, 0); |
| 517 | spi_prettyprint_status_register_welwip(status); |
| 518 | return 0; |
| 519 | } |
| 520 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 521 | int spi_prettyprint_status_register_at25f512b(struct flashctx *flash) |
| 522 | { |
| 523 | uint8_t status = spi_read_status_register(flash); |
| 524 | spi_prettyprint_status_register_hex(status); |
| 525 | |
| 526 | spi_prettyprint_status_register_atmel_at25_srpl(status); |
| 527 | spi_prettyprint_status_register_bit(status, 6); |
| 528 | spi_prettyprint_status_register_atmel_at25_epewpp(status); |
| 529 | spi_prettyprint_status_register_bit(status, 3); |
| 530 | spi_prettyprint_status_register_bp(status, 0); |
| 531 | spi_prettyprint_status_register_welwip(status); |
| 532 | return 0; |
| 533 | } |
| 534 | |
Stefan Tauner | 57794ac | 2012-12-29 15:04:20 +0000 | [diff] [blame] | 535 | int spi_prettyprint_status_register_at25f4096(struct flashctx *flash) |
| 536 | { |
| 537 | uint8_t status; |
| 538 | |
| 539 | status = spi_read_status_register(flash); |
| 540 | spi_prettyprint_status_register_hex(status); |
| 541 | |
| 542 | spi_prettyprint_status_register_atmel_at25_wpen(status); |
| 543 | spi_prettyprint_status_register_bit(status, 6); |
| 544 | spi_prettyprint_status_register_bit(status, 5); |
| 545 | spi_prettyprint_status_register_bp(status, 2); |
| 546 | spi_prettyprint_status_register_welwip(status); |
| 547 | return 0; |
| 548 | } |
| 549 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 550 | int spi_prettyprint_status_register_at25fs010(struct flashctx *flash) |
| 551 | { |
| 552 | uint8_t status = spi_read_status_register(flash); |
| 553 | spi_prettyprint_status_register_hex(status); |
| 554 | |
| 555 | spi_prettyprint_status_register_atmel_at25_wpen(status); |
| 556 | msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is " |
| 557 | "%sset\n", (status & (1 << 6)) ? "" : "not "); |
| 558 | msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is " |
| 559 | "%sset\n", (status & (1 << 5)) ? "" : "not "); |
| 560 | spi_prettyprint_status_register_bit(status, 4); |
| 561 | msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is " |
| 562 | "%sset\n", (status & (1 << 3)) ? "" : "not "); |
| 563 | msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is " |
| 564 | "%sset\n", (status & (1 << 2)) ? "" : "not "); |
| 565 | /* FIXME: Pretty-print detailed sector protection status. */ |
| 566 | spi_prettyprint_status_register_welwip(status); |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | int spi_prettyprint_status_register_at25fs040(struct flashctx *flash) |
| 571 | { |
| 572 | uint8_t status = spi_read_status_register(flash); |
| 573 | spi_prettyprint_status_register_hex(status); |
| 574 | |
| 575 | spi_prettyprint_status_register_atmel_at25_wpen(status); |
| 576 | spi_prettyprint_status_register_bp(status, 4); |
| 577 | /* FIXME: Pretty-print detailed sector protection status. */ |
| 578 | spi_prettyprint_status_register_welwip(status); |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | int spi_prettyprint_status_register_at26df081a(struct flashctx *flash) |
| 583 | { |
| 584 | uint8_t status = spi_read_status_register(flash); |
| 585 | spi_prettyprint_status_register_hex(status); |
| 586 | |
| 587 | spi_prettyprint_status_register_atmel_at25_srpl(status); |
| 588 | msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n", |
| 589 | (status & (1 << 6)) ? "" : "not "); |
| 590 | spi_prettyprint_status_register_atmel_at25_epewpp(status); |
| 591 | spi_prettyprint_status_register_atmel_at25_swp(status); |
| 592 | spi_prettyprint_status_register_welwip(status); |
| 593 | return 0; |
| 594 | } |
| 595 | |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 596 | /* Some Atmel DataFlash chips support per sector protection bits and the write protection bits in the status |
| 597 | * register do indicate if none, some or all sectors are protected. It is possible to globally (un)lock all |
| 598 | * sectors at once by writing 0 not only the protection bits (2 and 3) but also completely unrelated bits (4 and |
| 599 | * 5) which normally are not touched. |
| 600 | * Affected are all known Atmel chips matched by AT2[56]D[FLQ]..1A? but the AT26DF041. */ |
| 601 | int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 602 | { |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 603 | return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4, 0x00); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 606 | int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash) |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 607 | { |
| 608 | /* FIXME: We should check the security lockdown. */ |
| 609 | msg_cinfo("Ignoring security lockdown (if present)\n"); |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 610 | return spi_disable_blockprotect_at2x_global_unprotect(flash); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Stefan Tauner | 57794ac | 2012-12-29 15:04:20 +0000 | [diff] [blame] | 613 | int spi_disable_blockprotect_at25f(struct flashctx *flash) |
| 614 | { |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 615 | return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF); |
Stefan Tauner | 57794ac | 2012-12-29 15:04:20 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | int spi_disable_blockprotect_at25f512a(struct flashctx *flash) |
| 619 | { |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 620 | return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0, 0xFF); |
Stefan Tauner | 57794ac | 2012-12-29 15:04:20 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 623 | int spi_disable_blockprotect_at25f512b(struct flashctx *flash) |
| 624 | { |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 625 | return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 1 << 4, 0xFF); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | int spi_disable_blockprotect_at25fs010(struct flashctx *flash) |
| 629 | { |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 630 | return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0, 0xFF); |
Stefan Tauner | 9530a02 | 2012-12-29 15:04:05 +0000 | [diff] [blame] | 631 | } |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 632 | |
| 633 | int spi_disable_blockprotect_at25fs040(struct flashctx *flash) |
| 634 | { |
Stefan Tauner | cecb2c5 | 2013-06-20 22:55:41 +0000 | [diff] [blame] | 635 | return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF); |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Nikolay Nikolaev | d0e3ea1 | 2013-06-28 21:29:08 +0000 | [diff] [blame] | 638 | /* === Eon === */ |
| 639 | |
| 640 | int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash) |
| 641 | { |
| 642 | uint8_t status = spi_read_status_register(flash); |
| 643 | spi_prettyprint_status_register_hex(status); |
| 644 | |
| 645 | spi_prettyprint_status_register_srwd(status); |
| 646 | msg_cdbg("Chip status register: WP# disable (WPDIS) is %sabled\n", (status & (1 << 6)) ? "en " : "dis"); |
| 647 | spi_prettyprint_status_register_bp(status, 3); |
| 648 | spi_prettyprint_status_register_welwip(status); |
| 649 | return 0; |
| 650 | } |
| 651 | |
Nikolay Nikolaev | c80c4a3 | 2013-06-28 21:29:44 +0000 | [diff] [blame] | 652 | /* === Intel/Numonyx/Micron - Spansion === */ |
Stefan Tauner | 54aaa4a | 2012-12-29 15:04:12 +0000 | [diff] [blame] | 653 | |
Nikolay Nikolaev | 6f59b0b | 2013-06-28 21:29:51 +0000 | [diff] [blame] | 654 | int spi_disable_blockprotect_n25q(struct flashctx *flash) |
| 655 | { |
| 656 | return spi_disable_blockprotect_generic(flash, 0x5C, 1 << 7, 0, 0xFF); |
| 657 | } |
| 658 | |
| 659 | int spi_prettyprint_status_register_n25q(struct flashctx *flash) |
| 660 | { |
| 661 | uint8_t status = spi_read_status_register(flash); |
| 662 | spi_prettyprint_status_register_hex(status); |
| 663 | |
| 664 | spi_prettyprint_status_register_srwd(status); |
| 665 | if (flash->chip->total_size <= 32 / 8 * 1024) /* N25Q16 and N25Q32: reserved */ |
| 666 | spi_prettyprint_status_register_bit(status, 6); |
| 667 | else |
| 668 | msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n", |
| 669 | (status & (1 << 6)) ? "" : "not "); |
| 670 | msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top"); |
| 671 | spi_prettyprint_status_register_bp(status, 2); |
| 672 | spi_prettyprint_status_register_welwip(status); |
| 673 | return 0; |
| 674 | } |
| 675 | |
Nikolay Nikolaev | c80c4a3 | 2013-06-28 21:29:44 +0000 | [diff] [blame] | 676 | /* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */ |
Stefan Tauner | 54aaa4a | 2012-12-29 15:04:12 +0000 | [diff] [blame] | 677 | /* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */ |
Nikolay Nikolaev | c80c4a3 | 2013-06-28 21:29:44 +0000 | [diff] [blame] | 678 | int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash) |
Stefan Tauner | 54aaa4a | 2012-12-29 15:04:12 +0000 | [diff] [blame] | 679 | { |
Stefan Tauner | 278ba6e | 2013-06-28 21:28:27 +0000 | [diff] [blame] | 680 | return spi_disable_blockprotect_bp2_srwd(flash); |
Stefan Tauner | 54aaa4a | 2012-12-29 15:04:12 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Nikolay Nikolaev | c80c4a3 | 2013-06-28 21:29:44 +0000 | [diff] [blame] | 683 | /* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */ |
| 684 | int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash) |
Stefan Tauner | 54aaa4a | 2012-12-29 15:04:12 +0000 | [diff] [blame] | 685 | { |
| 686 | uint8_t status = spi_read_status_register(flash); |
Stefan Tauner | c2eec2c | 2014-05-03 21:33:01 +0000 | [diff] [blame] | 687 | spi_prettyprint_status_register_hex(status); |
Stefan Tauner | 54aaa4a | 2012-12-29 15:04:12 +0000 | [diff] [blame] | 688 | |
| 689 | spi_prettyprint_status_register_srwd(status); |
| 690 | msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n", |
| 691 | (status & (1 << 6)) ? "" : "not "); |
| 692 | msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n", |
| 693 | (status & (1 << 5)) ? "" : "not "); |
| 694 | spi_prettyprint_status_register_bp(status, 2); |
| 695 | spi_prettyprint_status_register_welwip(status); |
| 696 | return 0; |
| 697 | } |
| 698 | |
Stefan Tauner | 6ee37e2 | 2012-12-29 15:03:51 +0000 | [diff] [blame] | 699 | /* === SST === */ |
| 700 | |
| 701 | static void spi_prettyprint_status_register_sst25_common(uint8_t status) |
| 702 | { |
| 703 | spi_prettyprint_status_register_hex(status); |
| 704 | |
| 705 | spi_prettyprint_status_register_bpl(status); |
| 706 | msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n", |
| 707 | (status & (1 << 6)) ? "" : "not "); |
| 708 | spi_prettyprint_status_register_bp(status, 3); |
| 709 | spi_prettyprint_status_register_welwip(status); |
| 710 | } |
| 711 | |
| 712 | int spi_prettyprint_status_register_sst25(struct flashctx *flash) |
| 713 | { |
| 714 | uint8_t status = spi_read_status_register(flash); |
| 715 | spi_prettyprint_status_register_sst25_common(status); |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash) |
| 720 | { |
| 721 | static const char *const bpt[] = { |
| 722 | "none", |
| 723 | "1F0000H-1FFFFFH", |
| 724 | "1E0000H-1FFFFFH", |
| 725 | "1C0000H-1FFFFFH", |
| 726 | "180000H-1FFFFFH", |
| 727 | "100000H-1FFFFFH", |
| 728 | "all", "all" |
| 729 | }; |
| 730 | uint8_t status = spi_read_status_register(flash); |
| 731 | spi_prettyprint_status_register_sst25_common(status); |
| 732 | msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash) |
| 737 | { |
| 738 | static const char *const bpt[] = { |
| 739 | "none", |
| 740 | "0x70000-0x7ffff", |
| 741 | "0x60000-0x7ffff", |
| 742 | "0x40000-0x7ffff", |
| 743 | "all blocks", "all blocks", "all blocks", "all blocks" |
| 744 | }; |
| 745 | uint8_t status = spi_read_status_register(flash); |
| 746 | spi_prettyprint_status_register_sst25_common(status); |
| 747 | msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]); |
| 748 | return 0; |
| 749 | } |