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 <[email protected]>
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
20 #include <stdlib.h>
21
22 #include "flash.h"
23 #include "chipdrivers.h"
24 #include "programmer.h"
25 #include "spi.h"
26
27 /* === Generic functions === */
28
29 /*
30 * Writing SR2 or higher with an extended WRSR command requires
31 * writing all lower SRx along with it, so just read the lower
32 * SRx and write them back.
33 */
spi_prepare_wrsr_ext(uint8_t write_cmd[4],size_t * const write_cmd_len,const struct flashctx * const flash,const enum flash_reg reg,const uint8_t value)34 static int spi_prepare_wrsr_ext(
35 uint8_t write_cmd[4], size_t *const write_cmd_len,
36 const struct flashctx *const flash,
37 const enum flash_reg reg, const uint8_t value)
38 {
39 enum flash_reg reg_it;
40 size_t i = 0;
41
42 write_cmd[i++] = JEDEC_WRSR;
43
44 for (reg_it = STATUS1; reg_it < reg; ++reg_it) {
45 uint8_t sr;
46
47 if (spi_read_register(flash, reg_it, &sr)) {
48 msg_cerr("Writing SR%d failed: failed to read SR%d for writeback.\n",
49 reg - STATUS1 + 1, reg_it - STATUS1 + 1);
50 return 1;
51 }
52 write_cmd[i++] = sr;
53 }
54
55 write_cmd[i++] = value;
56 *write_cmd_len = i;
57
58 return 0;
59 }
60
spi_write_register(const struct flashctx * flash,enum flash_reg reg,uint8_t value)61 int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t value)
62 {
63 int feature_bits = flash->chip->feature_bits;
64
65 uint8_t write_cmd[4];
66 size_t write_cmd_len = 0;
67
68 /*
69 * Create SPI write command sequence based on the destination register
70 * and the chip's supported command set.
71 */
72 switch (reg) {
73 case STATUS1:
74 write_cmd[0] = JEDEC_WRSR;
75 write_cmd[1] = value;
76 write_cmd_len = JEDEC_WRSR_OUTSIZE;
77 break;
78 case STATUS2:
79 if (feature_bits & FEATURE_WRSR2) {
80 write_cmd[0] = JEDEC_WRSR2;
81 write_cmd[1] = value;
82 write_cmd_len = JEDEC_WRSR2_OUTSIZE;
83 break;
84 }
85 if (feature_bits & FEATURE_WRSR_EXT2) {
86 if (spi_prepare_wrsr_ext(write_cmd, &write_cmd_len, flash, reg, value))
87 return 1;
88 break;
89 }
90 msg_cerr("Cannot write SR2: unsupported by chip\n");
91 return 1;
92 case STATUS3:
93 if (feature_bits & FEATURE_WRSR3) {
94 write_cmd[0] = JEDEC_WRSR3;
95 write_cmd[1] = value;
96 write_cmd_len = JEDEC_WRSR3_OUTSIZE;
97 break;
98 }
99 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3) {
100 if (spi_prepare_wrsr_ext(write_cmd, &write_cmd_len, flash, reg, value))
101 return 1;
102 break;
103 }
104 msg_cerr("Cannot write SR3: unsupported by chip\n");
105 return 1;
106 case SECURITY:
107 /*
108 * Security register doesn't have a normal write operation. Instead,
109 * there are separate commands that set individual OTP bits.
110 */
111 msg_cerr("Cannot write SECURITY: unsupported by design\n");
112 return 1;
113 case CONFIG:
114 /*
115 * This one is read via a separate command, but written as if it's SR2
116 * in FEATURE_WRSR_EXT2 case of WRSR command.
117 */
118 if (feature_bits & FEATURE_CFGR) {
119 write_cmd[0] = JEDEC_WRSR;
120 if (spi_read_register(flash, STATUS1, &write_cmd[1])) {
121 msg_cerr("Writing CONFIG failed: failed to read SR1 for writeback.\n");
122 return 1;
123 }
124 write_cmd[2] = value;
125 write_cmd_len = 3;
126 break;
127 }
128 msg_cerr("Cannot write CONFIG: unsupported by chip\n");
129 return 1;
130 default:
131 msg_cerr("Cannot write register: unknown register\n");
132 return 1;
133 }
134
135 if (!spi_probe_opcode(flash, write_cmd[0])) {
136 msg_pdbg("%s: write to register %d not supported by programmer, ignoring.\n", __func__, reg);
137 return SPI_INVALID_OPCODE;
138 }
139
140 uint8_t enable_cmd;
141 if (feature_bits & FEATURE_WRSR_WREN) {
142 enable_cmd = JEDEC_WREN;
143 } else if (feature_bits & FEATURE_WRSR_EWSR) {
144 enable_cmd = JEDEC_EWSR;
145 } else {
146 msg_cdbg("Missing status register write definition, assuming "
147 "EWSR is needed\n");
148 enable_cmd = JEDEC_EWSR;
149 }
150
151 struct spi_command cmds[] = {
152 {
153 .writecnt = JEDEC_WREN_OUTSIZE,
154 .writearr = &enable_cmd,
155 .readcnt = 0,
156 .readarr = NULL,
157 }, {
158 .writecnt = write_cmd_len,
159 .writearr = write_cmd,
160 .readcnt = 0,
161 .readarr = NULL,
162 }, {
163 .writecnt = 0,
164 .writearr = NULL,
165 .readcnt = 0,
166 .readarr = NULL,
167 }};
168
169 int result = spi_send_multicommand(flash, cmds);
170 if (result) {
171 msg_cerr("%s failed during command execution\n", __func__);
172 return result;
173 }
174
175 /*
176 * WRSR performs a self-timed erase before the changes take effect.
177 * This may take 50-85 ms in most cases, and some chips apparently
178 * allow running RDSR only once. Therefore pick an initial delay of
179 * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed.
180 *
181 * Newer chips with multiple status registers (SR2 etc.) are unlikely
182 * to have problems with multiple RDSR commands, so only wait for the
183 * initial 100 ms if the register we wrote to was SR1.
184 */
185 int delay_ms = 5000;
186 if (reg == STATUS1) {
187 programmer_delay(flash, 100 * 1000);
188 delay_ms -= 100;
189 }
190
191 for (; delay_ms > 0; delay_ms -= 10) {
192 uint8_t status;
193 result = spi_read_register(flash, STATUS1, &status);
194 if (result)
195 return result;
196 if ((status & SPI_SR_WIP) == 0)
197 return 0;
198 programmer_delay(flash, 10 * 1000);
199 }
200
201
202 msg_cerr("Error: WIP bit after WRSR never cleared\n");
203 return TIMEOUT_ERROR;
204 }
205
spi_read_register(const struct flashctx * flash,enum flash_reg reg,uint8_t * value)206 int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value)
207 {
208 int feature_bits = flash->chip->feature_bits;
209 uint8_t read_cmd;
210
211 switch (reg) {
212 case STATUS1:
213 read_cmd = JEDEC_RDSR;
214 break;
215 case STATUS2:
216 if (feature_bits & (FEATURE_WRSR_EXT2 | FEATURE_WRSR2)) {
217 read_cmd = JEDEC_RDSR2;
218 break;
219 }
220 msg_cerr("Cannot read SR2: unsupported by chip\n");
221 return 1;
222 case STATUS3:
223 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3
224 || (feature_bits & FEATURE_WRSR3)) {
225 read_cmd = JEDEC_RDSR3;
226 break;
227 }
228 msg_cerr("Cannot read SR3: unsupported by chip\n");
229 return 1;
230 case SECURITY:
231 if (feature_bits & FEATURE_SCUR) {
232 read_cmd = JEDEC_RDSCUR;
233 break;
234 }
235 msg_cerr("Cannot read SECURITY: unsupported by chip\n");
236 return 1;
237 case CONFIG:
238 if (feature_bits & FEATURE_CFGR) {
239 read_cmd = JEDEC_RDCR;
240 break;
241 }
242 msg_cerr("Cannot read CONFIG: unsupported by chip\n");
243 return 1;
244 default:
245 msg_cerr("Cannot read register: unknown register\n");
246 return 1;
247 }
248
249 if (!spi_probe_opcode(flash, read_cmd)) {
250 msg_pdbg("%s: read from register %d not supported by programmer.\n", __func__, reg);
251 return SPI_INVALID_OPCODE;
252 }
253
254 /* FIXME: No workarounds for driver/hardware bugs in generic code. */
255 /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */
256 uint8_t readarr[2];
257
258 int ret = spi_send_command(flash, sizeof(read_cmd), sizeof(readarr), &read_cmd, readarr);
259 if (ret) {
260 msg_cerr("Register read failed!\n");
261 return ret;
262 }
263
264 *value = readarr[0];
265 msg_cspew("%s: read_cmd 0x%02x returned 0x%02x\n", __func__, read_cmd, readarr[0]);
266 return 0;
267 }
268
spi_restore_status(struct flashctx * flash,void * data)269 static int spi_restore_status(struct flashctx *flash, void *data)
270 {
271 uint8_t status = *(uint8_t *)data;
272 free(data);
273
274 msg_cdbg("restoring chip status (0x%02x)\n", status);
275 return spi_write_register(flash, STATUS1, status);
276 }
277
278 /* A generic block protection disable.
279 * Tests if a protection is enabled with the block protection mask (bp_mask) and returns success otherwise.
280 * Tests if the register bits are locked with the lock_mask (lock_mask).
281 * Tests if a hardware protection is active (i.e. low pin/high bit value) with the write protection mask
282 * (wp_mask) and bails out in that case.
283 * If there are register lock bits set we try to disable them by unsetting those bits of the previous register
284 * contents that are set in the lock_mask. We then check if removing the lock bits has worked and continue as if
285 * they never had been engaged:
286 * If the lock bits are out of the way try to disable engaged protections.
287 * To support uncommon global unprotects (e.g. on most AT2[56]xx1(A)) unprotect_mask can be used to force
288 * bits to 0 additionally to those set in bp_mask and lock_mask. Only bits set in unprotect_mask are potentially
289 * preserved when doing the final unprotect.
290 *
291 * To sum up:
292 * bp_mask: set those bits that correspond to the bits in the status register that indicate an active protection
293 * (which should be unset after this function returns).
294 * lock_mask: set the bits that correspond to the bits that lock changing the bits above.
295 * wp_mask: set the bits that correspond to bits indicating non-software revocable protections.
296 * unprotect_mask: set the bits that should be preserved if possible when unprotecting.
297 */
spi_disable_blockprotect_generic(struct flashctx * flash,uint8_t bp_mask,uint8_t lock_mask,uint8_t wp_mask,uint8_t unprotect_mask)298 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)
299 {
300 uint8_t status;
301 int result;
302
303 int ret = spi_read_register(flash, STATUS1, &status);
304 if (ret)
305 return ret;
306
307 if ((status & bp_mask) == 0) {
308 msg_cdbg2("Block protection is disabled.\n");
309 return 0;
310 }
311
312 /* Restore status register content upon exit in finalize_flash_access(). */
313 uint8_t *data = calloc(1, sizeof(uint8_t));
314 if (!data) {
315 msg_cerr("Out of memory!\n");
316 return 1;
317 }
318 *data = status;
319 register_chip_restore(spi_restore_status, flash, data);
320
321 msg_cdbg("Some block protection in effect, disabling... ");
322 if ((status & lock_mask) != 0) {
323 msg_cdbg("\n\tNeed to disable the register lock first... ");
324 if (wp_mask != 0 && (status & wp_mask) == 0) {
325 msg_cerr("Hardware protection is active, disabling write protection is impossible.\n");
326 return 1;
327 }
328 /* All bits except the register lock bit (often called SPRL, SRWD, WPEN) are readonly. */
329 result = spi_write_register(flash, STATUS1, status & ~lock_mask);
330 if (result) {
331 msg_cerr("Could not write status register 1.\n");
332 return result;
333 }
334
335 ret = spi_read_register(flash, STATUS1, &status);
336 if (ret)
337 return ret;
338
339 if ((status & lock_mask) != 0) {
340 msg_cerr("Unsetting lock bit(s) failed.\n");
341 return 1;
342 }
343 msg_cdbg("done.\n");
344 }
345 /* Global unprotect. Make sure to mask the register lock bit as well. */
346 result = spi_write_register(flash, STATUS1, status & ~(bp_mask | lock_mask) & unprotect_mask);
347 if (result) {
348 msg_cerr("Could not write status register 1.\n");
349 return result;
350 }
351
352 ret = spi_read_register(flash, STATUS1, &status);
353 if (ret)
354 return ret;
355
356 if ((status & bp_mask) != 0) {
357 msg_cerr("Block protection could not be disabled!\n");
358 printlockfunc_t *printlock = lookup_printlock_func_ptr(flash);
359 if (printlock)
360 printlock(flash);
361 return 1;
362 }
363 msg_cdbg("disabled.\n");
364 return 0;
365 }
366
367 /* A common block protection disable that tries to unset the status register bits masked by 0x3C. */
spi_disable_blockprotect(struct flashctx * flash)368 static int spi_disable_blockprotect(struct flashctx *flash)
369 {
370 return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0, 0xFF);
371 }
372
spi_disable_blockprotect_sst26_global_unprotect(struct flashctx * flash)373 static int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
374 {
375 int result = spi_write_enable(flash);
376 if (result)
377 return result;
378
379 static const unsigned char cmd[] = { 0x98 }; /* ULBPR */
380 result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL);
381 if (result)
382 msg_cerr("ULBPR failed\n");
383 return result;
384 }
385
386 /* A common block protection disable that tries to unset the status register bits masked by 0x0C (BP0-1) and
387 * protected/locked by bit #7. Useful when bits 4-5 may be non-0). */
spi_disable_blockprotect_bp1_srwd(struct flashctx * flash)388 static int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
389 {
390 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
391 }
392
393 /* A common block protection disable that tries to unset the status register bits masked by 0x1C (BP0-2) and
394 * protected/locked by bit #7. Useful when bit #5 is neither a protection bit nor reserved (and hence possibly
395 * non-0). */
spi_disable_blockprotect_bp2_srwd(struct flashctx * flash)396 static int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash)
397 {
398 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0, 0xFF);
399 }
400
401 /* A common block protection disable that tries to unset the status register bits masked by 0x3C (BP0-3) and
402 * protected/locked by bit #7. */
spi_disable_blockprotect_bp3_srwd(struct flashctx * flash)403 static int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash)
404 {
405 return spi_disable_blockprotect_generic(flash, 0x3C, 1 << 7, 0, 0xFF);
406 }
407
408 /* A common block protection disable that tries to unset the status register bits masked by 0x7C (BP0-4) and
409 * protected/locked by bit #7. */
spi_disable_blockprotect_bp4_srwd(struct flashctx * flash)410 static int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash)
411 {
412 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
413 }
414
spi_prettyprint_status_register_hex(uint8_t status)415 static void spi_prettyprint_status_register_hex(uint8_t status)
416 {
417 msg_cdbg("Chip status register is 0x%02x.\n", status);
418 }
419
420 /* Common highest bit: Status Register Write Disable (SRWD) or Status Register Protect (SRP). */
spi_prettyprint_status_register_srwd(uint8_t status)421 static void spi_prettyprint_status_register_srwd(uint8_t status)
422 {
423 msg_cdbg("Chip status register: Status Register Write Disable (SRWD, SRP, ...) is %sset\n",
424 (status & (1 << 7)) ? "" : "not ");
425 }
426
427 /* Common highest bit: Block Protect Write Disable (BPL). */
spi_prettyprint_status_register_bpl(uint8_t status)428 static void spi_prettyprint_status_register_bpl(uint8_t status)
429 {
430 msg_cdbg("Chip status register: Block Protect Write Disable (BPL) is %sset\n",
431 (status & (1 << 7)) ? "" : "not ");
432 }
433
434 /* Common lowest 2 bits: WEL and WIP. */
spi_prettyprint_status_register_welwip(uint8_t status)435 static void spi_prettyprint_status_register_welwip(uint8_t status)
436 {
437 msg_cdbg("Chip status register: Write Enable Latch (WEL) is %sset\n",
438 (status & (1 << 1)) ? "" : "not ");
439 msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is %sset\n",
440 (status & (1 << 0)) ? "" : "not ");
441 }
442
443 /* Common block protection (BP) bits. */
spi_prettyprint_status_register_bp(uint8_t status,int bp)444 static void spi_prettyprint_status_register_bp(uint8_t status, int bp)
445 {
446 switch (bp) {
447 case 4:
448 msg_cdbg("Chip status register: Block Protect 4 (BP4) is %sset\n",
449 (status & (1 << 6)) ? "" : "not ");
450 /* Fall through. */
451 case 3:
452 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
453 (status & (1 << 5)) ? "" : "not ");
454 /* Fall through. */
455 case 2:
456 msg_cdbg("Chip status register: Block Protect 2 (BP2) is %sset\n",
457 (status & (1 << 4)) ? "" : "not ");
458 /* Fall through. */
459 case 1:
460 msg_cdbg("Chip status register: Block Protect 1 (BP1) is %sset\n",
461 (status & (1 << 3)) ? "" : "not ");
462 /* Fall through. */
463 case 0:
464 msg_cdbg("Chip status register: Block Protect 0 (BP0) is %sset\n",
465 (status & (1 << 2)) ? "" : "not ");
466 }
467 }
468
469 /* Unnamed bits. */
spi_prettyprint_status_register_bit(uint8_t status,int bit)470 void spi_prettyprint_status_register_bit(uint8_t status, int bit)
471 {
472 msg_cdbg("Chip status register: Bit %i is %sset\n", bit, (status & (1 << bit)) ? "" : "not ");
473 }
474
spi_prettyprint_status_register_plain(struct flashctx * flash)475 static int spi_prettyprint_status_register_plain(struct flashctx *flash)
476 {
477 uint8_t status;
478 int ret = spi_read_register(flash, STATUS1, &status);
479 if (ret)
480 return ret;
481 spi_prettyprint_status_register_hex(status);
482 return 0;
483 }
484
485 /* Print the plain hex value and the welwip bits only. */
spi_prettyprint_status_register_default_welwip(struct flashctx * flash)486 static int spi_prettyprint_status_register_default_welwip(struct flashctx *flash)
487 {
488 uint8_t status;
489 int ret = spi_read_register(flash, STATUS1, &status);
490 if (ret)
491 return ret;
492 spi_prettyprint_status_register_hex(status);
493
494 spi_prettyprint_status_register_welwip(status);
495 return 0;
496 }
497
498 /* Works for many chips of the
499 * AMIC A25L series
500 * and MX MX25L512
501 */
spi_prettyprint_status_register_bp1_srwd(struct flashctx * flash)502 static int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash)
503 {
504 uint8_t status;
505 int ret = spi_read_register(flash, STATUS1, &status);
506 if (ret)
507 return ret;
508 spi_prettyprint_status_register_hex(status);
509
510 spi_prettyprint_status_register_srwd(status);
511 spi_prettyprint_status_register_bit(status, 6);
512 spi_prettyprint_status_register_bit(status, 5);
513 spi_prettyprint_status_register_bit(status, 4);
514 spi_prettyprint_status_register_bp(status, 1);
515 spi_prettyprint_status_register_welwip(status);
516 return 0;
517 }
518
519 /* Works for many chips of the
520 * AMIC A25L series
521 * PMC Pm25LD series
522 */
spi_prettyprint_status_register_bp2_srwd(struct flashctx * flash)523 static int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash)
524 {
525 uint8_t status;
526 int ret = spi_read_register(flash, STATUS1, &status);
527 if (ret)
528 return ret;
529 spi_prettyprint_status_register_hex(status);
530
531 spi_prettyprint_status_register_srwd(status);
532 spi_prettyprint_status_register_bit(status, 6);
533 spi_prettyprint_status_register_bit(status, 5);
534 spi_prettyprint_status_register_bp(status, 2);
535 spi_prettyprint_status_register_welwip(status);
536 return 0;
537 }
538
539 /* Works for many chips of the
540 * ST M25P series
541 * MX MX25L series
542 */
spi_prettyprint_status_register_bp3_srwd(struct flashctx * flash)543 static int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash)
544 {
545 uint8_t status;
546 int ret = spi_read_register(flash, STATUS1, &status);
547 if (ret)
548 return ret;
549 spi_prettyprint_status_register_hex(status);
550
551 spi_prettyprint_status_register_srwd(status);
552 spi_prettyprint_status_register_bit(status, 6);
553 spi_prettyprint_status_register_bp(status, 3);
554 spi_prettyprint_status_register_welwip(status);
555 return 0;
556 }
557
spi_prettyprint_status_register_bp4_srwd(struct flashctx * flash)558 static int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash)
559 {
560 uint8_t status;
561 int ret = spi_read_register(flash, STATUS1, &status);
562 if (ret)
563 return ret;
564 spi_prettyprint_status_register_hex(status);
565
566 spi_prettyprint_status_register_srwd(status);
567 spi_prettyprint_status_register_bp(status, 4);
568 spi_prettyprint_status_register_welwip(status);
569 return 0;
570 }
571
spi_prettyprint_status_register_bp2_bpl(struct flashctx * flash)572 static int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash)
573 {
574 uint8_t status;
575 int ret = spi_read_register(flash, STATUS1, &status);
576 if (ret)
577 return ret;
578 spi_prettyprint_status_register_hex(status);
579
580 spi_prettyprint_status_register_bpl(status);
581 spi_prettyprint_status_register_bit(status, 6);
582 spi_prettyprint_status_register_bit(status, 5);
583 spi_prettyprint_status_register_bp(status, 2);
584 spi_prettyprint_status_register_welwip(status);
585 return 0;
586 }
587
spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx * flash)588 static int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash)
589 {
590 uint8_t status;
591 int ret = spi_read_register(flash, STATUS1, &status);
592 if (ret)
593 return ret;
594 spi_prettyprint_status_register_hex(status);
595
596 spi_prettyprint_status_register_bpl(status);
597 spi_prettyprint_status_register_bit(status, 6);
598 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
599 spi_prettyprint_status_register_bp(status, 2);
600 spi_prettyprint_status_register_welwip(status);
601 return 0;
602 }
603
spi_prettyprint_status_register_srwd_sec_tb_bp2_welwip(struct flashctx * flash)604 static int spi_prettyprint_status_register_srwd_sec_tb_bp2_welwip(struct flashctx *flash)
605 {
606 uint8_t status;
607 int ret = spi_read_register(flash, STATUS1, &status);
608 if (ret)
609 return ret;
610 spi_prettyprint_status_register_hex(status);
611
612 spi_prettyprint_status_register_srwd(status);
613 msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64);
614 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
615 spi_prettyprint_status_register_bp(status, 2);
616 spi_prettyprint_status_register_welwip(status);
617 msg_cdbg("Chip status register 2 is NOT decoded!\n");
618 return 0;
619 }
620
621 /* === Atmel === */
622
spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)623 static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)
624 {
625 msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n",
626 (status & (1 << 7)) ? "" : "not ");
627 }
628
spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)629 static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
630 {
631 msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n",
632 (status & (1 << 7)) ? "" : "not ");
633 }
634
spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)635 static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)
636 {
637 msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n",
638 (status & (1 << 5)) ? "" : "not ");
639 msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n",
640 (status & (1 << 4)) ? "not " : "");
641 }
642
spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)643 static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
644 {
645 msg_cdbg("Chip status register: Software Protection Status (SWP): ");
646 switch (status & (3 << 2)) {
647 case 0x0 << 2:
648 msg_cdbg("no sectors are protected\n");
649 break;
650 case 0x1 << 2:
651 msg_cdbg("some sectors are protected\n");
652 /* FIXME: Read individual Sector Protection Registers. */
653 break;
654 case 0x3 << 2:
655 msg_cdbg("all sectors are protected\n");
656 break;
657 default:
658 msg_cdbg("reserved for future use\n");
659 break;
660 }
661 }
662
spi_prettyprint_status_register_at25df(struct flashctx * flash)663 static int spi_prettyprint_status_register_at25df(struct flashctx *flash)
664 {
665 uint8_t status;
666 int ret = spi_read_register(flash, STATUS1, &status);
667 if (ret)
668 return ret;
669
670 spi_prettyprint_status_register_hex(status);
671
672 spi_prettyprint_status_register_atmel_at25_srpl(status);
673 spi_prettyprint_status_register_bit(status, 6);
674 spi_prettyprint_status_register_atmel_at25_epewpp(status);
675 spi_prettyprint_status_register_atmel_at25_swp(status);
676 spi_prettyprint_status_register_welwip(status);
677 return 0;
678 }
679
spi_prettyprint_status_register_at25df_sec(struct flashctx * flash)680 static int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
681 {
682 /* FIXME: We should check the security lockdown. */
683 msg_cdbg("Ignoring security lockdown (if present)\n");
684 msg_cdbg("Ignoring status register byte 2\n");
685 return spi_prettyprint_status_register_at25df(flash);
686 }
687
688 /* used for AT25F512, AT25F1024(A), AT25F2048 */
spi_prettyprint_status_register_at25f(struct flashctx * flash)689 static int spi_prettyprint_status_register_at25f(struct flashctx *flash)
690 {
691 uint8_t status;
692 int ret = spi_read_register(flash, STATUS1, &status);
693 if (ret)
694 return ret;
695
696 spi_prettyprint_status_register_hex(status);
697
698 spi_prettyprint_status_register_atmel_at25_wpen(status);
699 spi_prettyprint_status_register_bit(status, 6);
700 spi_prettyprint_status_register_bit(status, 5);
701 spi_prettyprint_status_register_bit(status, 4);
702 spi_prettyprint_status_register_bp(status, 1);
703 spi_prettyprint_status_register_welwip(status);
704 return 0;
705 }
706
spi_prettyprint_status_register_at25f512a(struct flashctx * flash)707 static int spi_prettyprint_status_register_at25f512a(struct flashctx *flash)
708 {
709 uint8_t status;
710 int ret = spi_read_register(flash, STATUS1, &status);
711 if (ret)
712 return ret;
713
714 spi_prettyprint_status_register_hex(status);
715
716 spi_prettyprint_status_register_atmel_at25_wpen(status);
717 spi_prettyprint_status_register_bit(status, 6);
718 spi_prettyprint_status_register_bit(status, 5);
719 spi_prettyprint_status_register_bit(status, 4);
720 spi_prettyprint_status_register_bit(status, 3);
721 spi_prettyprint_status_register_bp(status, 0);
722 spi_prettyprint_status_register_welwip(status);
723 return 0;
724 }
725
spi_prettyprint_status_register_at25f512b(struct flashctx * flash)726 static int spi_prettyprint_status_register_at25f512b(struct flashctx *flash)
727 {
728 uint8_t status;
729 int ret = spi_read_register(flash, STATUS1, &status);
730 if (ret)
731 return ret;
732 spi_prettyprint_status_register_hex(status);
733
734 spi_prettyprint_status_register_atmel_at25_srpl(status);
735 spi_prettyprint_status_register_bit(status, 6);
736 spi_prettyprint_status_register_atmel_at25_epewpp(status);
737 spi_prettyprint_status_register_bit(status, 3);
738 spi_prettyprint_status_register_bp(status, 0);
739 spi_prettyprint_status_register_welwip(status);
740 return 0;
741 }
742
spi_prettyprint_status_register_at25f4096(struct flashctx * flash)743 static int spi_prettyprint_status_register_at25f4096(struct flashctx *flash)
744 {
745 uint8_t status;
746
747 int ret = spi_read_register(flash, STATUS1, &status);
748 if (ret)
749 return ret;
750
751 spi_prettyprint_status_register_hex(status);
752
753 spi_prettyprint_status_register_atmel_at25_wpen(status);
754 spi_prettyprint_status_register_bit(status, 6);
755 spi_prettyprint_status_register_bit(status, 5);
756 spi_prettyprint_status_register_bp(status, 2);
757 spi_prettyprint_status_register_welwip(status);
758 return 0;
759 }
760
spi_prettyprint_status_register_at25fs010(struct flashctx * flash)761 static int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
762 {
763 uint8_t status;
764 int ret = spi_read_register(flash, STATUS1, &status);
765 if (ret)
766 return ret;
767 spi_prettyprint_status_register_hex(status);
768
769 spi_prettyprint_status_register_atmel_at25_wpen(status);
770 msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is "
771 "%sset\n", (status & (1 << 6)) ? "" : "not ");
772 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
773 "%sset\n", (status & (1 << 5)) ? "" : "not ");
774 spi_prettyprint_status_register_bit(status, 4);
775 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
776 "%sset\n", (status & (1 << 3)) ? "" : "not ");
777 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
778 "%sset\n", (status & (1 << 2)) ? "" : "not ");
779 /* FIXME: Pretty-print detailed sector protection status. */
780 spi_prettyprint_status_register_welwip(status);
781 return 0;
782 }
783
spi_prettyprint_status_register_at25fs040(struct flashctx * flash)784 static int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
785 {
786 uint8_t status;
787 int ret = spi_read_register(flash, STATUS1, &status);
788 if (ret)
789 return ret;
790 spi_prettyprint_status_register_hex(status);
791
792 spi_prettyprint_status_register_atmel_at25_wpen(status);
793 spi_prettyprint_status_register_bp(status, 4);
794 /* FIXME: Pretty-print detailed sector protection status. */
795 spi_prettyprint_status_register_welwip(status);
796 return 0;
797 }
798
spi_prettyprint_status_register_at26df081a(struct flashctx * flash)799 static int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
800 {
801 uint8_t status;
802 int ret = spi_read_register(flash, STATUS1, &status);
803 if (ret)
804 return ret;
805 spi_prettyprint_status_register_hex(status);
806
807 spi_prettyprint_status_register_atmel_at25_srpl(status);
808 msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n",
809 (status & (1 << 6)) ? "" : "not ");
810 spi_prettyprint_status_register_atmel_at25_epewpp(status);
811 spi_prettyprint_status_register_atmel_at25_swp(status);
812 spi_prettyprint_status_register_welwip(status);
813 return 0;
814 }
815
816 /* Some Atmel DataFlash chips support per sector protection bits and the write protection bits in the status
817 * register do indicate if none, some or all sectors are protected. It is possible to globally (un)lock all
818 * sectors at once by writing 0 not only the protection bits (2 and 3) but also completely unrelated bits (4 and
819 * 5) which normally are not touched.
820 * Affected are all known Atmel chips matched by AT2[56]D[FLQ]..1A? but the AT26DF041. */
spi_disable_blockprotect_at2x_global_unprotect(struct flashctx * flash)821 static int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash)
822 {
823 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4, 0x00);
824 }
825
spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx * flash)826 static int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash)
827 {
828 /* FIXME: We should check the security lockdown. */
829 msg_cinfo("Ignoring security lockdown (if present)\n");
830 return spi_disable_blockprotect_at2x_global_unprotect(flash);
831 }
832
spi_disable_blockprotect_at25f(struct flashctx * flash)833 static int spi_disable_blockprotect_at25f(struct flashctx *flash)
834 {
835 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
836 }
837
spi_disable_blockprotect_at25f512a(struct flashctx * flash)838 static int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
839 {
840 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0, 0xFF);
841 }
842
spi_disable_blockprotect_at25f512b(struct flashctx * flash)843 static int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
844 {
845 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 1 << 4, 0xFF);
846 }
847
spi_disable_blockprotect_at25fs010(struct flashctx * flash)848 static int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
849 {
850 return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0, 0xFF);
851 }
852
spi_disable_blockprotect_at25fs040(struct flashctx * flash)853 static int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
854 {
855 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
856 }
857
858 /* === Eon === */
859
spi_prettyprint_status_register_en25s_wp(struct flashctx * flash)860 static int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash)
861 {
862 uint8_t status;
863 int ret = spi_read_register(flash, STATUS1, &status);
864 if (ret)
865 return ret;
866 spi_prettyprint_status_register_hex(status);
867
868 spi_prettyprint_status_register_srwd(status);
869 msg_cdbg("Chip status register: WP# disable (WPDIS) is %sabled\n", (status & (1 << 6)) ? "en " : "dis");
870 spi_prettyprint_status_register_bp(status, 3);
871 spi_prettyprint_status_register_welwip(status);
872 return 0;
873 }
874
875 /* === Intel/Numonyx/Micron - Spansion === */
876
spi_disable_blockprotect_n25q(struct flashctx * flash)877 static int spi_disable_blockprotect_n25q(struct flashctx *flash)
878 {
879 return spi_disable_blockprotect_generic(flash, 0x5C, 1 << 7, 0, 0xFF);
880 }
881
spi_prettyprint_status_register_n25q(struct flashctx * flash)882 static int spi_prettyprint_status_register_n25q(struct flashctx *flash)
883 {
884 uint8_t status;
885 int ret = spi_read_register(flash, STATUS1, &status);
886 if (ret)
887 return ret;
888 spi_prettyprint_status_register_hex(status);
889
890 spi_prettyprint_status_register_srwd(status);
891 if (flash->chip->total_size <= 32 / 8 * 1024) /* N25Q16 and N25Q32: reserved */
892 spi_prettyprint_status_register_bit(status, 6);
893 else
894 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
895 (status & (1 << 6)) ? "" : "not ");
896 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
897 spi_prettyprint_status_register_bp(status, 2);
898 spi_prettyprint_status_register_welwip(status);
899 return 0;
900 }
901
902 /* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
903 /* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
spi_disable_blockprotect_bp2_ep_srwd(struct flashctx * flash)904 static int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash)
905 {
906 return spi_disable_blockprotect_bp2_srwd(flash);
907 }
908
lookup_blockprotect_func_ptr(const struct flashchip * const chip)909 blockprotect_func_t *lookup_blockprotect_func_ptr(const struct flashchip *const chip)
910 {
911 switch (chip->unlock) {
912 case SPI_DISABLE_BLOCKPROTECT: return spi_disable_blockprotect;
913 case SPI_DISABLE_BLOCKPROTECT_BP2_EP_SRWD: return spi_disable_blockprotect_bp2_ep_srwd;
914 case SPI_DISABLE_BLOCKPROTECT_BP1_SRWD: return spi_disable_blockprotect_bp1_srwd;
915 case SPI_DISABLE_BLOCKPROTECT_BP2_SRWD: return spi_disable_blockprotect_bp2_srwd;
916 case SPI_DISABLE_BLOCKPROTECT_BP3_SRWD: return spi_disable_blockprotect_bp3_srwd;
917 case SPI_DISABLE_BLOCKPROTECT_BP4_SRWD: return spi_disable_blockprotect_bp4_srwd;
918 case SPI_DISABLE_BLOCKPROTECT_AT45DB: return spi_disable_blockprotect_at45db; /* at45db.c */
919 case SPI_DISABLE_BLOCKPROTECT_AT25F: return spi_disable_blockprotect_at25f;
920 case SPI_DISABLE_BLOCKPROTECT_AT25FS010: return spi_disable_blockprotect_at25fs010;
921 case SPI_DISABLE_BLOCKPROTECT_AT25FS040: return spi_disable_blockprotect_at25fs040;
922 case SPI_DISABLE_BLOCKPROTECT_AT25F512A: return spi_disable_blockprotect_at25f512a;
923 case SPI_DISABLE_BLOCKPROTECT_AT25F512B: return spi_disable_blockprotect_at25f512b;
924 case SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT: return spi_disable_blockprotect_at2x_global_unprotect;
925 case SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT_SEC: return spi_disable_blockprotect_at2x_global_unprotect_sec;
926 case SPI_DISABLE_BLOCKPROTECT_SST26_GLOBAL_UNPROTECT: return spi_disable_blockprotect_sst26_global_unprotect;
927 case SPI_DISABLE_BLOCKPROTECT_N25Q: return spi_disable_blockprotect_n25q;
928 /* fallthough to lookup_jedec_blockprotect_func_ptr() */
929 case UNLOCK_REGSPACE2_BLOCK_ERASER_0:
930 case UNLOCK_REGSPACE2_BLOCK_ERASER_1:
931 case UNLOCK_REGSPACE2_UNIFORM_32K:
932 case UNLOCK_REGSPACE2_UNIFORM_64K:
933 return lookup_jedec_blockprotect_func_ptr(chip);
934 /* fallthough to lookup_82802ab_blockprotect_func_ptr() */
935 case UNLOCK_28F004S5:
936 case UNLOCK_LH28F008BJT:
937 return lookup_82802ab_blockprotect_func_ptr(chip);
938 case UNLOCK_SST_FWHUB: return unlock_sst_fwhub; /* sst_fwhub.c */
939 case UNPROTECT_28SF040: return unprotect_28sf040; /* sst28sf040.c */
940 /* default: non-total function, 0 indicates no unlock function set.
941 * We explicitly do not want a default catch-all case in the switch
942 * to ensure unhandled enum's are compiler warnings.
943 */
944 case NO_BLOCKPROTECT_FUNC: return NULL;
945 };
946
947 return NULL;
948 }
949
950 /* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx * flash)951 static int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash)
952 {
953 uint8_t status;
954 int ret = spi_read_register(flash, STATUS1, &status);
955 if (ret)
956 return ret;
957 spi_prettyprint_status_register_hex(status);
958
959 spi_prettyprint_status_register_srwd(status);
960 msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n",
961 (status & (1 << 6)) ? "" : "not ");
962 msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n",
963 (status & (1 << 5)) ? "" : "not ");
964 spi_prettyprint_status_register_bp(status, 2);
965 spi_prettyprint_status_register_welwip(status);
966 return 0;
967 }
968
969 /* === SST === */
970
spi_prettyprint_status_register_sst25_common(uint8_t status)971 static void spi_prettyprint_status_register_sst25_common(uint8_t status)
972 {
973 spi_prettyprint_status_register_hex(status);
974
975 spi_prettyprint_status_register_bpl(status);
976 msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n",
977 (status & (1 << 6)) ? "" : "not ");
978 spi_prettyprint_status_register_bp(status, 3);
979 spi_prettyprint_status_register_welwip(status);
980 }
981
spi_prettyprint_status_register_sst25(struct flashctx * flash)982 static int spi_prettyprint_status_register_sst25(struct flashctx *flash)
983 {
984 uint8_t status;
985 int ret = spi_read_register(flash, STATUS1, &status);
986 if (ret)
987 return ret;
988 spi_prettyprint_status_register_sst25_common(status);
989 return 0;
990 }
991
spi_prettyprint_status_register_sst25vf016(struct flashctx * flash)992 static int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash)
993 {
994 static const char *const bpt[] = {
995 "none",
996 "1F0000H-1FFFFFH",
997 "1E0000H-1FFFFFH",
998 "1C0000H-1FFFFFH",
999 "180000H-1FFFFFH",
1000 "100000H-1FFFFFH",
1001 "all", "all"
1002 };
1003 uint8_t status;
1004 int ret = spi_read_register(flash, STATUS1, &status);
1005 if (ret)
1006 return ret;
1007 spi_prettyprint_status_register_sst25_common(status);
1008 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
1009 return 0;
1010 }
1011
spi_prettyprint_status_register_sst25vf040b(struct flashctx * flash)1012 static int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash)
1013 {
1014 static const char *const bpt[] = {
1015 "none",
1016 "0x70000-0x7ffff",
1017 "0x60000-0x7ffff",
1018 "0x40000-0x7ffff",
1019 "all blocks", "all blocks", "all blocks", "all blocks"
1020 };
1021 uint8_t status;
1022 int ret = spi_read_register(flash, STATUS1, &status);
1023 if (ret)
1024 return ret;
1025 spi_prettyprint_status_register_sst25_common(status);
1026 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
1027 return 0;
1028 }
1029
lookup_printlock_func_ptr(struct flashctx * flash)1030 printlockfunc_t *lookup_printlock_func_ptr(struct flashctx *flash)
1031 {
1032 switch (flash->chip->printlock) {
1033 case PRINTLOCK_AT49F: return &printlock_at49f;
1034 case PRINTLOCK_REGSPACE2_BLOCK_ERASER_0: return &printlock_regspace2_block_eraser_0;
1035 case PRINTLOCK_REGSPACE2_BLOCK_ERASER_1: return &printlock_regspace2_block_eraser_1;
1036 case PRINTLOCK_SST_FWHUB: return &printlock_sst_fwhub;
1037 case PRINTLOCK_W39F010: return &printlock_w39f010;
1038 case PRINTLOCK_W39L010: return &printlock_w39l010;
1039 case PRINTLOCK_W39L020: return &printlock_w39l020;
1040 case PRINTLOCK_W39L040: return &printlock_w39l040;
1041 case PRINTLOCK_W39V040A: return &printlock_w39v040a;
1042 case PRINTLOCK_W39V040B: return &printlock_w39v040b;
1043 case PRINTLOCK_W39V040C: return &printlock_w39v040c;
1044 case PRINTLOCK_W39V040FA: return &printlock_w39v040fa;
1045 case PRINTLOCK_W39V040FB: return &printlock_w39v040fb;
1046 case PRINTLOCK_W39V040FC: return &printlock_w39v040fc;
1047 case PRINTLOCK_W39V080A: return &printlock_w39v080a;
1048 case PRINTLOCK_W39V080FA: return &printlock_w39v080fa;
1049 case PRINTLOCK_W39V080FA_DUAL: return &printlock_w39v080fa_dual;
1050 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25DF: return &spi_prettyprint_status_register_at25df;
1051 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25DF_SEC: return &spi_prettyprint_status_register_at25df_sec;
1052 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25F: return &spi_prettyprint_status_register_at25f;
1053 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25F4096: return &spi_prettyprint_status_register_at25f4096;
1054 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25F512A: return &spi_prettyprint_status_register_at25f512a;
1055 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25F512B: return &spi_prettyprint_status_register_at25f512b;
1056 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25FS010: return &spi_prettyprint_status_register_at25fs010;
1057 case SPI_PRETTYPRINT_STATUS_REGISTER_AT25FS040: return &spi_prettyprint_status_register_at25fs040;
1058 case SPI_PRETTYPRINT_STATUS_REGISTER_AT26DF081A: return &spi_prettyprint_status_register_at26df081a;
1059 case SPI_PRETTYPRINT_STATUS_REGISTER_AT45DB: return &spi_prettyprint_status_register_at45db;
1060 case SPI_PRETTYPRINT_STATUS_REGISTER_BP1_SRWD: return &spi_prettyprint_status_register_bp1_srwd;
1061 case SPI_PRETTYPRINT_STATUS_REGISTER_BP2_BPL: return &spi_prettyprint_status_register_bp2_bpl;
1062 case SPI_PRETTYPRINT_STATUS_REGISTER_BP2_EP_SRWD: return &spi_prettyprint_status_register_bp2_ep_srwd;
1063 case SPI_PRETTYPRINT_STATUS_REGISTER_BP2_SRWD: return &spi_prettyprint_status_register_bp2_srwd;
1064 case SPI_PRETTYPRINT_STATUS_REGISTER_BP2_TB_BPL: return &spi_prettyprint_status_register_bp2_tb_bpl;
1065 case SPI_PRETTYPRINT_STATUS_REGISTER_SRWD_SEC_TB_BP2_WELWIP: return &spi_prettyprint_status_register_srwd_sec_tb_bp2_welwip;
1066 case SPI_PRETTYPRINT_STATUS_REGISTER_BP3_SRWD: return &spi_prettyprint_status_register_bp3_srwd;
1067 case SPI_PRETTYPRINT_STATUS_REGISTER_BP4_SRWD: return &spi_prettyprint_status_register_bp4_srwd;
1068 case SPI_PRETTYPRINT_STATUS_REGISTER_DEFAULT_WELWIP: return &spi_prettyprint_status_register_default_welwip;
1069 case SPI_PRETTYPRINT_STATUS_REGISTER_EN25S_WP: return &spi_prettyprint_status_register_en25s_wp;
1070 case SPI_PRETTYPRINT_STATUS_REGISTER_N25Q: return &spi_prettyprint_status_register_n25q;
1071 case SPI_PRETTYPRINT_STATUS_REGISTER_PLAIN: return &spi_prettyprint_status_register_plain;
1072 case SPI_PRETTYPRINT_STATUS_REGISTER_SST25: return &spi_prettyprint_status_register_sst25;
1073 case SPI_PRETTYPRINT_STATUS_REGISTER_SST25VF016: return &spi_prettyprint_status_register_sst25vf016;
1074 case SPI_PRETTYPRINT_STATUS_REGISTER_SST25VF040B: return &spi_prettyprint_status_register_sst25vf040b;
1075 /* default: non-total function, 0 indicates no unlock function set.
1076 * We explicitly do not want a default catch-all case in the switch
1077 * to ensure unhandled enum's are compiler warnings.
1078 */
1079 case NO_PRINTLOCK_FUNC: return NULL;
1080 };
1081
1082 return NULL;
1083 }
1084