blob: 53952fefa9202e730b91ab51638375f98ca4dbb6 [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
Stefan Taunerf4451612013-04-19 01:59:15 +0000265 * PMC Pm25LD series
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000266 */
267int spi_prettyprint_status_register_default_bp2(struct flashctx *flash)
268{
269 uint8_t status = spi_read_status_register(flash);
270 spi_prettyprint_status_register_hex(status);
271
272 spi_prettyprint_status_register_srwd(status);
273 spi_prettyprint_status_register_bit(status, 6);
274 spi_prettyprint_status_register_bit(status, 5);
275 spi_prettyprint_status_register_bp(status, 2);
276 spi_prettyprint_status_register_welwip(status);
277 return 0;
278}
279
280/* Works for many chips of the
281 * ST M25P series
282 * MX MX25L series
283 */
284int spi_prettyprint_status_register_default_bp3(struct flashctx *flash)
285{
286 uint8_t status = spi_read_status_register(flash);
287 spi_prettyprint_status_register_hex(status);
288
289 spi_prettyprint_status_register_srwd(status);
290 spi_prettyprint_status_register_bit(status, 6);
291 spi_prettyprint_status_register_bp(status, 3);
292 spi_prettyprint_status_register_welwip(status);
293 return 0;
294}
295
296/* === Amic ===
297 * FIXME: spi_disable_blockprotect is incorrect but works fine for chips using
298 * spi_prettyprint_status_register_default_bp1 or
299 * spi_prettyprint_status_register_default_bp2.
300 * FIXME: spi_disable_blockprotect is incorrect and will fail for chips using
301 * spi_prettyprint_status_register_amic_a25l032 if those have locks controlled
302 * by the second status register.
303 */
304
305int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash)
306{
307 uint8_t status = spi_read_status_register(flash);
308 spi_prettyprint_status_register_hex(status);
309
310 spi_prettyprint_status_register_srwd(status);
311 msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64);
312 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
313 spi_prettyprint_status_register_bp(status, 2);
314 spi_prettyprint_status_register_welwip(status);
315 msg_cdbg("Chip status register 2 is NOT decoded!\n");
316 return 0;
317}
318
319/* === Atmel === */
320
321static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)
322{
323 msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n",
324 (status & (1 << 7)) ? "" : "not ");
325}
326
327static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
328{
329 msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n",
330 (status & (1 << 7)) ? "" : "not ");
331}
332
333static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)
334{
335 msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n",
336 (status & (1 << 5)) ? "" : "not ");
337 msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n",
338 (status & (1 << 4)) ? "not " : "");
339}
340
341static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
342{
343 msg_cdbg("Chip status register: Software Protection Status (SWP): ");
344 switch (status & (3 << 2)) {
345 case 0x0 << 2:
346 msg_cdbg("no sectors are protected\n");
347 break;
348 case 0x1 << 2:
349 msg_cdbg("some sectors are protected\n");
350 /* FIXME: Read individual Sector Protection Registers. */
351 break;
352 case 0x3 << 2:
353 msg_cdbg("all sectors are protected\n");
354 break;
355 default:
356 msg_cdbg("reserved for future use\n");
357 break;
358 }
359}
360
361int spi_prettyprint_status_register_at25df(struct flashctx *flash)
362{
363 uint8_t status = spi_read_status_register(flash);
364 spi_prettyprint_status_register_hex(status);
365
366 spi_prettyprint_status_register_atmel_at25_srpl(status);
367 spi_prettyprint_status_register_bit(status, 6);
368 spi_prettyprint_status_register_atmel_at25_epewpp(status);
369 spi_prettyprint_status_register_atmel_at25_swp(status);
370 spi_prettyprint_status_register_welwip(status);
371 return 0;
372}
373
374int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
375{
376 /* FIXME: We should check the security lockdown. */
377 msg_cdbg("Ignoring security lockdown (if present)\n");
378 msg_cdbg("Ignoring status register byte 2\n");
379 return spi_prettyprint_status_register_at25df(flash);
380}
381
Stefan Tauner57794ac2012-12-29 15:04:20 +0000382/* used for AT25F512, AT25F1024(A), AT25F2048 */
383int spi_prettyprint_status_register_at25f(struct flashctx *flash)
384{
385 uint8_t status;
386
387 status = spi_read_status_register(flash);
388 spi_prettyprint_status_register_hex(status);
389
390 spi_prettyprint_status_register_atmel_at25_wpen(status);
391 spi_prettyprint_status_register_bit(status, 6);
392 spi_prettyprint_status_register_bit(status, 5);
393 spi_prettyprint_status_register_bit(status, 4);
394 spi_prettyprint_status_register_bp(status, 1);
395 spi_prettyprint_status_register_welwip(status);
396 return 0;
397}
398
399int spi_prettyprint_status_register_at25f512a(struct flashctx *flash)
400{
401 uint8_t status;
402
403 status = spi_read_status_register(flash);
404 spi_prettyprint_status_register_hex(status);
405
406 spi_prettyprint_status_register_atmel_at25_wpen(status);
407 spi_prettyprint_status_register_bit(status, 6);
408 spi_prettyprint_status_register_bit(status, 5);
409 spi_prettyprint_status_register_bit(status, 4);
410 spi_prettyprint_status_register_bit(status, 3);
411 spi_prettyprint_status_register_bp(status, 0);
412 spi_prettyprint_status_register_welwip(status);
413 return 0;
414}
415
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000416int spi_prettyprint_status_register_at25f512b(struct flashctx *flash)
417{
418 uint8_t status = spi_read_status_register(flash);
419 spi_prettyprint_status_register_hex(status);
420
421 spi_prettyprint_status_register_atmel_at25_srpl(status);
422 spi_prettyprint_status_register_bit(status, 6);
423 spi_prettyprint_status_register_atmel_at25_epewpp(status);
424 spi_prettyprint_status_register_bit(status, 3);
425 spi_prettyprint_status_register_bp(status, 0);
426 spi_prettyprint_status_register_welwip(status);
427 return 0;
428}
429
Stefan Tauner57794ac2012-12-29 15:04:20 +0000430int spi_prettyprint_status_register_at25f4096(struct flashctx *flash)
431{
432 uint8_t status;
433
434 status = spi_read_status_register(flash);
435 spi_prettyprint_status_register_hex(status);
436
437 spi_prettyprint_status_register_atmel_at25_wpen(status);
438 spi_prettyprint_status_register_bit(status, 6);
439 spi_prettyprint_status_register_bit(status, 5);
440 spi_prettyprint_status_register_bp(status, 2);
441 spi_prettyprint_status_register_welwip(status);
442 return 0;
443}
444
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000445int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
446{
447 uint8_t status = spi_read_status_register(flash);
448 spi_prettyprint_status_register_hex(status);
449
450 spi_prettyprint_status_register_atmel_at25_wpen(status);
451 msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is "
452 "%sset\n", (status & (1 << 6)) ? "" : "not ");
453 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
454 "%sset\n", (status & (1 << 5)) ? "" : "not ");
455 spi_prettyprint_status_register_bit(status, 4);
456 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
457 "%sset\n", (status & (1 << 3)) ? "" : "not ");
458 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
459 "%sset\n", (status & (1 << 2)) ? "" : "not ");
460 /* FIXME: Pretty-print detailed sector protection status. */
461 spi_prettyprint_status_register_welwip(status);
462 return 0;
463}
464
465int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
466{
467 uint8_t status = spi_read_status_register(flash);
468 spi_prettyprint_status_register_hex(status);
469
470 spi_prettyprint_status_register_atmel_at25_wpen(status);
471 spi_prettyprint_status_register_bp(status, 4);
472 /* FIXME: Pretty-print detailed sector protection status. */
473 spi_prettyprint_status_register_welwip(status);
474 return 0;
475}
476
477int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
478{
479 uint8_t status = spi_read_status_register(flash);
480 spi_prettyprint_status_register_hex(status);
481
482 spi_prettyprint_status_register_atmel_at25_srpl(status);
483 msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n",
484 (status & (1 << 6)) ? "" : "not ");
485 spi_prettyprint_status_register_atmel_at25_epewpp(status);
486 spi_prettyprint_status_register_atmel_at25_swp(status);
487 spi_prettyprint_status_register_welwip(status);
488 return 0;
489}
490
491int spi_disable_blockprotect_at25df(struct flashctx *flash)
492{
Stefan Tauner9530a022012-12-29 15:04:05 +0000493 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000494}
495
496int spi_disable_blockprotect_at25df_sec(struct flashctx *flash)
497{
498 /* FIXME: We should check the security lockdown. */
499 msg_cinfo("Ignoring security lockdown (if present)\n");
500 return spi_disable_blockprotect_at25df(flash);
501}
502
Stefan Tauner57794ac2012-12-29 15:04:20 +0000503int spi_disable_blockprotect_at25f(struct flashctx *flash)
504{
505 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0);
506}
507
508int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
509{
510 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0);
511}
512
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000513int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
514{
515 /* spi_disable_blockprotect_at25df is not really the right way to do
516 * this, but the side effects of said function work here as well.
517 */
518 return spi_disable_blockprotect_at25df(flash);
519}
520
Stefan Tauner57794ac2012-12-29 15:04:20 +0000521int spi_disable_blockprotect_at25f4096(struct flashctx *flash)
522{
523 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0);
524}
525
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000526int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
527{
Stefan Tauner9530a022012-12-29 15:04:05 +0000528 return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0);
529 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000530
531int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
532{
Stefan Tauner9530a022012-12-29 15:04:05 +0000533 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000534}
535
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000536/* === Intel === */
537
538/* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
539int spi_disable_blockprotect_s33(struct flashctx *flash)
540{
541 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0);
542}
543
544int spi_prettyprint_status_register_s33(struct flashctx *flash)
545{
546 uint8_t status = spi_read_status_register(flash);
547 msg_cdbg("Chip status register is %02x\n", status);
548
549 spi_prettyprint_status_register_srwd(status);
550 msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n",
551 (status & (1 << 6)) ? "" : "not ");
552 msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n",
553 (status & (1 << 5)) ? "" : "not ");
554 spi_prettyprint_status_register_bp(status, 2);
555 spi_prettyprint_status_register_welwip(status);
556 return 0;
557}
558
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000559/* === SST === */
560
561static void spi_prettyprint_status_register_sst25_common(uint8_t status)
562{
563 spi_prettyprint_status_register_hex(status);
564
565 spi_prettyprint_status_register_bpl(status);
566 msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n",
567 (status & (1 << 6)) ? "" : "not ");
568 spi_prettyprint_status_register_bp(status, 3);
569 spi_prettyprint_status_register_welwip(status);
570}
571
572int spi_prettyprint_status_register_sst25(struct flashctx *flash)
573{
574 uint8_t status = spi_read_status_register(flash);
575 spi_prettyprint_status_register_sst25_common(status);
576 return 0;
577}
578
579int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash)
580{
581 static const char *const bpt[] = {
582 "none",
583 "1F0000H-1FFFFFH",
584 "1E0000H-1FFFFFH",
585 "1C0000H-1FFFFFH",
586 "180000H-1FFFFFH",
587 "100000H-1FFFFFH",
588 "all", "all"
589 };
590 uint8_t status = spi_read_status_register(flash);
591 spi_prettyprint_status_register_sst25_common(status);
592 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
593 return 0;
594}
595
596int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash)
597{
598 static const char *const bpt[] = {
599 "none",
600 "0x70000-0x7ffff",
601 "0x60000-0x7ffff",
602 "0x40000-0x7ffff",
603 "all blocks", "all blocks", "all blocks", "all blocks"
604 };
605 uint8_t status = spi_read_status_register(flash);
606 spi_prettyprint_status_register_sst25_common(status);
607 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
608 return 0;
609}