blob: c0891576d57f9ca90d1e2f2cdea2bf867e3c98cf [file] [log] [blame]
Stefan Tauner6ee37e22012-12-29 15:03:51 +00001/*
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.
18 *
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
22 */
23
24#include "flash.h"
25#include "chipdrivers.h"
26#include "spi.h"
27
28/* === Generic functions === */
29int spi_write_status_enable(struct flashctx *flash)
30{
31 static const unsigned char cmd[JEDEC_EWSR_OUTSIZE] = { JEDEC_EWSR };
32 int result;
33
34 /* Send EWSR (Enable Write Status Register). */
35 result = spi_send_command(flash, sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL);
36
37 if (result)
38 msg_cerr("%s failed\n", __func__);
39
40 return result;
41}
42
43static int spi_write_status_register_flag(struct flashctx *flash, int status, const unsigned char enable_opcode)
44{
45 int result;
46 int i = 0;
47 /*
48 * WRSR requires either EWSR or WREN depending on chip type.
49 * The code below relies on the fact hat EWSR and WREN have the same
50 * INSIZE and OUTSIZE.
51 */
52 struct spi_command cmds[] = {
53 {
54 .writecnt = JEDEC_WREN_OUTSIZE,
55 .writearr = (const unsigned char[]){ enable_opcode },
56 .readcnt = 0,
57 .readarr = NULL,
58 }, {
59 .writecnt = JEDEC_WRSR_OUTSIZE,
60 .writearr = (const unsigned char[]){ JEDEC_WRSR, (unsigned char) status },
61 .readcnt = 0,
62 .readarr = NULL,
63 }, {
64 .writecnt = 0,
65 .writearr = NULL,
66 .readcnt = 0,
67 .readarr = NULL,
68 }};
69
70 result = spi_send_multicommand(flash, cmds);
71 if (result) {
72 msg_cerr("%s failed during command execution\n", __func__);
73 /* No point in waiting for the command to complete if execution
74 * failed.
75 */
76 return result;
77 }
78 /* WRSR performs a self-timed erase before the changes take effect.
79 * This may take 50-85 ms in most cases, and some chips apparently
80 * allow running RDSR only once. Therefore pick an initial delay of
81 * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed.
82 */
83 programmer_delay(100 * 1000);
84 while (spi_read_status_register(flash) & SPI_SR_WIP) {
85 if (++i > 490) {
86 msg_cerr("Error: WIP bit after WRSR never cleared\n");
87 return TIMEOUT_ERROR;
88 }
89 programmer_delay(10 * 1000);
90 }
91 return 0;
92}
93
94int spi_write_status_register(struct flashctx *flash, int status)
95{
96 int feature_bits = flash->chip->feature_bits;
97 int ret = 1;
98
99 if (!(feature_bits & (FEATURE_WRSR_WREN | FEATURE_WRSR_EWSR))) {
100 msg_cdbg("Missing status register write definition, assuming "
101 "EWSR is needed\n");
102 feature_bits |= FEATURE_WRSR_EWSR;
103 }
104 if (feature_bits & FEATURE_WRSR_WREN)
105 ret = spi_write_status_register_flag(flash, status, JEDEC_WREN);
106 if (ret && (feature_bits & FEATURE_WRSR_EWSR))
107 ret = spi_write_status_register_flag(flash, status, JEDEC_EWSR);
108 return ret;
109}
110
111uint8_t spi_read_status_register(struct flashctx *flash)
112{
113 static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { JEDEC_RDSR };
114 /* FIXME: No workarounds for driver/hardware bugs in generic code. */
115 unsigned char readarr[2]; /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */
116 int ret;
117
118 /* Read Status Register */
119 ret = spi_send_command(flash, sizeof(cmd), sizeof(readarr), cmd, readarr);
120 if (ret)
121 msg_cerr("RDSR failed!\n");
122
123 return readarr[0];
124}
125
Stefan Tauner9530a022012-12-29 15:04:05 +0000126/* A generic block protection disable.
127 * Tests if a protection is enabled with the block protection mask (bp_mask) and returns success otherwise.
128 * Tests if the register bits are locked with the lock_mask (lock_mask).
129 * Tests if a hardware protection is active (i.e. low) with the write protection mask (wp_mask) and bails out
130 * in that case.
131 * Finally tries to disable engaged protections and checks if any locks are still set.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000132 */
Stefan Tauner9530a022012-12-29 15:04:05 +0000133static int spi_disable_blockprotect_generic(struct flashctx *flash, uint8_t bp_mask, uint8_t lock_mask, uint8_t wp_mask)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000134{
135 uint8_t status;
136 int result;
137
138 status = spi_read_status_register(flash);
Stefan Tauner9530a022012-12-29 15:04:05 +0000139 if ((status & bp_mask) == 0) {
140 msg_cdbg2("Block protection is disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000141 return 0;
Stefan Tauner9530a022012-12-29 15:04:05 +0000142 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000143
144 msg_cdbg("Some block protection in effect, disabling... ");
Stefan Tauner9530a022012-12-29 15:04:05 +0000145 if ((status & lock_mask) != 0) {
146 msg_cdbg("\n\tNeed to disable the register lock first... ");
147 if (wp_mask != 0 && (status & wp_mask) == 0) {
148 msg_cerr("Hardware protection is active, disabling write protection is impossible.\n");
149 return 1;
150 }
151 /* All bits except the register lock bit (often called SPRL, SRWD, WPEN) are readonly. */
152 result = spi_write_status_register(flash, status & ~lock_mask);
153 if (result) {
154 msg_cerr("spi_write_status_register failed.\n");
155 return result;
156 }
157 msg_cdbg("done.\n");
158 }
159 /* Global unprotect. Make sure to mask the register lock bit as well. */
160 result = spi_write_status_register(flash, status & ~(bp_mask | lock_mask));
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000161 if (result) {
162 msg_cerr("spi_write_status_register failed.\n");
163 return result;
164 }
165 status = spi_read_status_register(flash);
Stefan Tauner9530a022012-12-29 15:04:05 +0000166 if ((status & bp_mask) != 0) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000167 msg_cerr("Block protection could not be disabled!\n");
168 return 1;
169 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000170 msg_cdbg("disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000171 return 0;
172}
173
Stefan Tauner9530a022012-12-29 15:04:05 +0000174/* A common block protection disable that tries to unset the status register bits masked by 0x3C. */
175int spi_disable_blockprotect(struct flashctx *flash)
176{
177 return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0);
178}
179
180
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000181static void spi_prettyprint_status_register_hex(uint8_t status)
182{
183 msg_cdbg("Chip status register is 0x%02x.\n", status);
184}
185
186/* Common highest bit: Status Register Write Disable (SRWD). */
187static void spi_prettyprint_status_register_srwd(uint8_t status)
188{
189 msg_cdbg("Chip status register: Status Register Write Disable (SRWD) is %sset\n",
190 (status & (1 << 7)) ? "" : "not ");
191}
192
193/* Common highest bit: Block Protect Write Disable (BPL). */
194static void spi_prettyprint_status_register_bpl(uint8_t status)
195{
196 msg_cdbg("Chip status register: Block Protect Write Disable (BPL) is %sset\n",
197 (status & (1 << 7)) ? "" : "not ");
198}
199
200/* Common lowest 2 bits: WEL and WIP. */
201static void spi_prettyprint_status_register_welwip(uint8_t status)
202{
203 msg_cdbg("Chip status register: Write Enable Latch (WEL) is %sset\n",
204 (status & (1 << 1)) ? "" : "not ");
205 msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is %sset\n",
206 (status & (1 << 0)) ? "" : "not ");
207}
208
209/* Common block protection (BP) bits. */
210static void spi_prettyprint_status_register_bp(uint8_t status, int bp)
211{
212 switch (bp) {
213 /* Fall through. */
214 case 4:
215 msg_cdbg("Chip status register: Block Protect 4 (BP4) is %sset\n",
216 (status & (1 << 5)) ? "" : "not ");
217 case 3:
218 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
219 (status & (1 << 5)) ? "" : "not ");
220 case 2:
221 msg_cdbg("Chip status register: Block Protect 2 (BP2) is %sset\n",
222 (status & (1 << 4)) ? "" : "not ");
223 case 1:
224 msg_cdbg("Chip status register: Block Protect 1 (BP1) is %sset\n",
225 (status & (1 << 3)) ? "" : "not ");
226 case 0:
227 msg_cdbg("Chip status register: Block Protect 0 (BP0) is %sset\n",
228 (status & (1 << 2)) ? "" : "not ");
229 }
230}
231
232/* Unnamed bits. */
233static void spi_prettyprint_status_register_bit(uint8_t status, int bit)
234{
235 msg_cdbg("Chip status register: Bit %i is %sset\n", bit, (status & (1 << bit)) ? "" : "not ");
236}
237
238int spi_prettyprint_status_register_plain(struct flashctx *flash)
239{
240 uint8_t status = spi_read_status_register(flash);
241 spi_prettyprint_status_register_hex(status);
242 return 0;
243}
244
245/* Works for many chips of the
246 * AMIC A25L series
247 * and MX MX25L512
248 */
249int spi_prettyprint_status_register_default_bp1(struct flashctx *flash)
250{
251 uint8_t status = spi_read_status_register(flash);
252 spi_prettyprint_status_register_hex(status);
253
254 spi_prettyprint_status_register_srwd(status);
255 spi_prettyprint_status_register_bit(status, 6);
256 spi_prettyprint_status_register_bit(status, 5);
257 spi_prettyprint_status_register_bit(status, 4);
258 spi_prettyprint_status_register_bp(status, 1);
259 spi_prettyprint_status_register_welwip(status);
260 return 0;
261}
262
263/* Works for many chips of the
264 * AMIC A25L series
265 */
266int spi_prettyprint_status_register_default_bp2(struct flashctx *flash)
267{
268 uint8_t status = spi_read_status_register(flash);
269 spi_prettyprint_status_register_hex(status);
270
271 spi_prettyprint_status_register_srwd(status);
272 spi_prettyprint_status_register_bit(status, 6);
273 spi_prettyprint_status_register_bit(status, 5);
274 spi_prettyprint_status_register_bp(status, 2);
275 spi_prettyprint_status_register_welwip(status);
276 return 0;
277}
278
279/* Works for many chips of the
280 * ST M25P series
281 * MX MX25L series
282 */
283int spi_prettyprint_status_register_default_bp3(struct flashctx *flash)
284{
285 uint8_t status = spi_read_status_register(flash);
286 spi_prettyprint_status_register_hex(status);
287
288 spi_prettyprint_status_register_srwd(status);
289 spi_prettyprint_status_register_bit(status, 6);
290 spi_prettyprint_status_register_bp(status, 3);
291 spi_prettyprint_status_register_welwip(status);
292 return 0;
293}
294
295/* === Amic ===
296 * FIXME: spi_disable_blockprotect is incorrect but works fine for chips using
297 * spi_prettyprint_status_register_default_bp1 or
298 * spi_prettyprint_status_register_default_bp2.
299 * FIXME: spi_disable_blockprotect is incorrect and will fail for chips using
300 * spi_prettyprint_status_register_amic_a25l032 if those have locks controlled
301 * by the second status register.
302 */
303
304int spi_prettyprint_status_register_amic_a25l032(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_srwd(status);
310 msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64);
311 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
312 spi_prettyprint_status_register_bp(status, 2);
313 spi_prettyprint_status_register_welwip(status);
314 msg_cdbg("Chip status register 2 is NOT decoded!\n");
315 return 0;
316}
317
318/* === Atmel === */
319
320static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)
321{
322 msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n",
323 (status & (1 << 7)) ? "" : "not ");
324}
325
326static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
327{
328 msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n",
329 (status & (1 << 7)) ? "" : "not ");
330}
331
332static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)
333{
334 msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n",
335 (status & (1 << 5)) ? "" : "not ");
336 msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n",
337 (status & (1 << 4)) ? "not " : "");
338}
339
340static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
341{
342 msg_cdbg("Chip status register: Software Protection Status (SWP): ");
343 switch (status & (3 << 2)) {
344 case 0x0 << 2:
345 msg_cdbg("no sectors are protected\n");
346 break;
347 case 0x1 << 2:
348 msg_cdbg("some sectors are protected\n");
349 /* FIXME: Read individual Sector Protection Registers. */
350 break;
351 case 0x3 << 2:
352 msg_cdbg("all sectors are protected\n");
353 break;
354 default:
355 msg_cdbg("reserved for future use\n");
356 break;
357 }
358}
359
360int spi_prettyprint_status_register_at25df(struct flashctx *flash)
361{
362 uint8_t status = spi_read_status_register(flash);
363 spi_prettyprint_status_register_hex(status);
364
365 spi_prettyprint_status_register_atmel_at25_srpl(status);
366 spi_prettyprint_status_register_bit(status, 6);
367 spi_prettyprint_status_register_atmel_at25_epewpp(status);
368 spi_prettyprint_status_register_atmel_at25_swp(status);
369 spi_prettyprint_status_register_welwip(status);
370 return 0;
371}
372
373int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
374{
375 /* FIXME: We should check the security lockdown. */
376 msg_cdbg("Ignoring security lockdown (if present)\n");
377 msg_cdbg("Ignoring status register byte 2\n");
378 return spi_prettyprint_status_register_at25df(flash);
379}
380
Stefan Tauner57794ac2012-12-29 15:04:20 +0000381/* used for AT25F512, AT25F1024(A), AT25F2048 */
382int spi_prettyprint_status_register_at25f(struct flashctx *flash)
383{
384 uint8_t status;
385
386 status = spi_read_status_register(flash);
387 spi_prettyprint_status_register_hex(status);
388
389 spi_prettyprint_status_register_atmel_at25_wpen(status);
390 spi_prettyprint_status_register_bit(status, 6);
391 spi_prettyprint_status_register_bit(status, 5);
392 spi_prettyprint_status_register_bit(status, 4);
393 spi_prettyprint_status_register_bp(status, 1);
394 spi_prettyprint_status_register_welwip(status);
395 return 0;
396}
397
398int spi_prettyprint_status_register_at25f512a(struct flashctx *flash)
399{
400 uint8_t status;
401
402 status = spi_read_status_register(flash);
403 spi_prettyprint_status_register_hex(status);
404
405 spi_prettyprint_status_register_atmel_at25_wpen(status);
406 spi_prettyprint_status_register_bit(status, 6);
407 spi_prettyprint_status_register_bit(status, 5);
408 spi_prettyprint_status_register_bit(status, 4);
409 spi_prettyprint_status_register_bit(status, 3);
410 spi_prettyprint_status_register_bp(status, 0);
411 spi_prettyprint_status_register_welwip(status);
412 return 0;
413}
414
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000415int spi_prettyprint_status_register_at25f512b(struct flashctx *flash)
416{
417 uint8_t status = spi_read_status_register(flash);
418 spi_prettyprint_status_register_hex(status);
419
420 spi_prettyprint_status_register_atmel_at25_srpl(status);
421 spi_prettyprint_status_register_bit(status, 6);
422 spi_prettyprint_status_register_atmel_at25_epewpp(status);
423 spi_prettyprint_status_register_bit(status, 3);
424 spi_prettyprint_status_register_bp(status, 0);
425 spi_prettyprint_status_register_welwip(status);
426 return 0;
427}
428
Stefan Tauner57794ac2012-12-29 15:04:20 +0000429int spi_prettyprint_status_register_at25f4096(struct flashctx *flash)
430{
431 uint8_t status;
432
433 status = spi_read_status_register(flash);
434 spi_prettyprint_status_register_hex(status);
435
436 spi_prettyprint_status_register_atmel_at25_wpen(status);
437 spi_prettyprint_status_register_bit(status, 6);
438 spi_prettyprint_status_register_bit(status, 5);
439 spi_prettyprint_status_register_bp(status, 2);
440 spi_prettyprint_status_register_welwip(status);
441 return 0;
442}
443
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000444int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
445{
446 uint8_t status = spi_read_status_register(flash);
447 spi_prettyprint_status_register_hex(status);
448
449 spi_prettyprint_status_register_atmel_at25_wpen(status);
450 msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is "
451 "%sset\n", (status & (1 << 6)) ? "" : "not ");
452 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
453 "%sset\n", (status & (1 << 5)) ? "" : "not ");
454 spi_prettyprint_status_register_bit(status, 4);
455 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
456 "%sset\n", (status & (1 << 3)) ? "" : "not ");
457 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
458 "%sset\n", (status & (1 << 2)) ? "" : "not ");
459 /* FIXME: Pretty-print detailed sector protection status. */
460 spi_prettyprint_status_register_welwip(status);
461 return 0;
462}
463
464int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
465{
466 uint8_t status = spi_read_status_register(flash);
467 spi_prettyprint_status_register_hex(status);
468
469 spi_prettyprint_status_register_atmel_at25_wpen(status);
470 spi_prettyprint_status_register_bp(status, 4);
471 /* FIXME: Pretty-print detailed sector protection status. */
472 spi_prettyprint_status_register_welwip(status);
473 return 0;
474}
475
476int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
477{
478 uint8_t status = spi_read_status_register(flash);
479 spi_prettyprint_status_register_hex(status);
480
481 spi_prettyprint_status_register_atmel_at25_srpl(status);
482 msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n",
483 (status & (1 << 6)) ? "" : "not ");
484 spi_prettyprint_status_register_atmel_at25_epewpp(status);
485 spi_prettyprint_status_register_atmel_at25_swp(status);
486 spi_prettyprint_status_register_welwip(status);
487 return 0;
488}
489
490int spi_disable_blockprotect_at25df(struct flashctx *flash)
491{
Stefan Tauner9530a022012-12-29 15:04:05 +0000492 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000493}
494
495int spi_disable_blockprotect_at25df_sec(struct flashctx *flash)
496{
497 /* FIXME: We should check the security lockdown. */
498 msg_cinfo("Ignoring security lockdown (if present)\n");
499 return spi_disable_blockprotect_at25df(flash);
500}
501
Stefan Tauner57794ac2012-12-29 15:04:20 +0000502int spi_disable_blockprotect_at25f(struct flashctx *flash)
503{
504 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0);
505}
506
507int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
508{
509 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0);
510}
511
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000512int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
513{
514 /* spi_disable_blockprotect_at25df is not really the right way to do
515 * this, but the side effects of said function work here as well.
516 */
517 return spi_disable_blockprotect_at25df(flash);
518}
519
Stefan Tauner57794ac2012-12-29 15:04:20 +0000520int spi_disable_blockprotect_at25f4096(struct flashctx *flash)
521{
522 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0);
523}
524
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000525int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
526{
Stefan Tauner9530a022012-12-29 15:04:05 +0000527 return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0);
528 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000529
530int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
531{
Stefan Tauner9530a022012-12-29 15:04:05 +0000532 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000533}
534
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000535/* === Intel === */
536
537/* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
538int spi_disable_blockprotect_s33(struct flashctx *flash)
539{
540 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0);
541}
542
543int spi_prettyprint_status_register_s33(struct flashctx *flash)
544{
545 uint8_t status = spi_read_status_register(flash);
546 msg_cdbg("Chip status register is %02x\n", status);
547
548 spi_prettyprint_status_register_srwd(status);
549 msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n",
550 (status & (1 << 6)) ? "" : "not ");
551 msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n",
552 (status & (1 << 5)) ? "" : "not ");
553 spi_prettyprint_status_register_bp(status, 2);
554 spi_prettyprint_status_register_welwip(status);
555 return 0;
556}
557
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000558/* === SST === */
559
560static void spi_prettyprint_status_register_sst25_common(uint8_t status)
561{
562 spi_prettyprint_status_register_hex(status);
563
564 spi_prettyprint_status_register_bpl(status);
565 msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n",
566 (status & (1 << 6)) ? "" : "not ");
567 spi_prettyprint_status_register_bp(status, 3);
568 spi_prettyprint_status_register_welwip(status);
569}
570
571int spi_prettyprint_status_register_sst25(struct flashctx *flash)
572{
573 uint8_t status = spi_read_status_register(flash);
574 spi_prettyprint_status_register_sst25_common(status);
575 return 0;
576}
577
578int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash)
579{
580 static const char *const bpt[] = {
581 "none",
582 "1F0000H-1FFFFFH",
583 "1E0000H-1FFFFFH",
584 "1C0000H-1FFFFFH",
585 "180000H-1FFFFFH",
586 "100000H-1FFFFFH",
587 "all", "all"
588 };
589 uint8_t status = spi_read_status_register(flash);
590 spi_prettyprint_status_register_sst25_common(status);
591 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
592 return 0;
593}
594
595int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash)
596{
597 static const char *const bpt[] = {
598 "none",
599 "0x70000-0x7ffff",
600 "0x60000-0x7ffff",
601 "0x40000-0x7ffff",
602 "all blocks", "all blocks", "all blocks", "all blocks"
603 };
604 uint8_t status = spi_read_status_register(flash);
605 spi_prettyprint_status_register_sst25_common(status);
606 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
607 return 0;
608}