blob: 508ee5d58a1284b4575f9a59aa4f23f75e342152 [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.
Stefan Tauner6ee37e22012-12-29 15:03:51 +000018 */
19
20#include "flash.h"
21#include "chipdrivers.h"
22#include "spi.h"
23
24/* === Generic functions === */
Nico Huber3f3c1f32022-05-28 16:48:26 +020025
26/*
27 * Writing SR2 or higher with an extended WRSR command requires
28 * writing all lower SRx along with it, so just read the lower
29 * SRx and write them back.
30 */
31static int spi_prepare_wrsr_ext(
32 uint8_t write_cmd[4], size_t *const write_cmd_len,
33 const struct flashctx *const flash,
34 const enum flash_reg reg, const uint8_t value)
35{
36 enum flash_reg reg_it;
37 size_t i = 0;
38
39 write_cmd[i++] = JEDEC_WRSR;
40
41 for (reg_it = STATUS1; reg_it < reg; ++reg_it) {
42 uint8_t sr;
43
44 if (spi_read_register(flash, reg_it, &sr)) {
45 msg_cerr("Writing SR%d failed: failed to read SR%d for writeback.\n",
46 reg - STATUS1 + 1, reg_it - STATUS1 + 1);
47 return 1;
48 }
49 write_cmd[i++] = sr;
50 }
51
52 write_cmd[i++] = value;
53 *write_cmd_len = i;
54
55 return 0;
56}
57
Nikolai Artemiev01675222021-10-20 22:30:41 +110058int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t value)
Stefan Tauner6ee37e22012-12-29 15:03:51 +000059{
60 int feature_bits = flash->chip->feature_bits;
Nikolai Artemiev01675222021-10-20 22:30:41 +110061
Nico Huber3f3c1f32022-05-28 16:48:26 +020062 uint8_t write_cmd[4];
Nikolai Artemiev01675222021-10-20 22:30:41 +110063 size_t write_cmd_len = 0;
64
65 /*
66 * Create SPI write command sequence based on the destination register
67 * and the chip's supported command set.
68 */
69 switch (reg) {
70 case STATUS1:
71 write_cmd[0] = JEDEC_WRSR;
72 write_cmd[1] = value;
73 write_cmd_len = JEDEC_WRSR_OUTSIZE;
74 break;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +110075 case STATUS2:
76 if (feature_bits & FEATURE_WRSR2) {
77 write_cmd[0] = JEDEC_WRSR2;
78 write_cmd[1] = value;
79 write_cmd_len = JEDEC_WRSR2_OUTSIZE;
80 break;
81 }
Nico Huber3f3c1f32022-05-28 16:48:26 +020082 if (feature_bits & FEATURE_WRSR_EXT2) {
83 if (spi_prepare_wrsr_ext(write_cmd, &write_cmd_len, flash, reg, value))
Nikolai Artemiev9de3f872021-10-20 22:32:25 +110084 return 1;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +110085 break;
86 }
87 msg_cerr("Cannot write SR2: unsupported by chip\n");
88 return 1;
Sergii Dmytruk0b2e7dd2021-12-19 18:37:51 +020089 case STATUS3:
Nico Huber3f3c1f32022-05-28 16:48:26 +020090 if (feature_bits & FEATURE_WRSR3) {
91 write_cmd[0] = JEDEC_WRSR3;
92 write_cmd[1] = value;
93 write_cmd_len = JEDEC_WRSR3_OUTSIZE;
94 break;
95 }
96 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3) {
97 if (spi_prepare_wrsr_ext(write_cmd, &write_cmd_len, flash, reg, value))
98 return 1;
99 break;
100 }
101 msg_cerr("Cannot write SR3: unsupported by chip\n");
102 return 1;
Sergii Dmytruk3d728e72021-11-27 15:14:27 +0200103 case SECURITY:
104 /*
105 * Security register doesn't have a normal write operation. Instead,
106 * there are separate commands that set individual OTP bits.
107 */
108 msg_cerr("Cannot write SECURITY: unsupported by design\n");
109 return 1;
Sergii Dmytrukbd72a472022-07-24 17:11:05 +0300110 case CONFIG:
111 /*
112 * This one is read via a separate command, but written as if it's SR2
113 * in FEATURE_WRSR_EXT2 case of WRSR command.
114 */
115 write_cmd[0] = JEDEC_WRSR;
116 if (spi_read_register(flash, STATUS1, &write_cmd[1])) {
117 msg_cerr("Writing CONFIG failed: failed to read SR1 for writeback.\n");
118 return 1;
119 }
120 write_cmd[2] = value;
121 write_cmd_len = 3;
122 break;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100123 default:
124 msg_cerr("Cannot write register: unknown register\n");
125 return 1;
126 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000127
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100128 uint8_t enable_cmd;
129 if (feature_bits & FEATURE_WRSR_WREN) {
130 enable_cmd = JEDEC_WREN;
131 } else if (feature_bits & FEATURE_WRSR_EWSR) {
132 enable_cmd = JEDEC_EWSR;
133 } else {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000134 msg_cdbg("Missing status register write definition, assuming "
135 "EWSR is needed\n");
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100136 enable_cmd = JEDEC_EWSR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000137 }
Nikolai Artemiev01675222021-10-20 22:30:41 +1100138
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100139 struct spi_command cmds[] = {
140 {
141 .writecnt = JEDEC_WREN_OUTSIZE,
142 .writearr = &enable_cmd,
143 .readcnt = 0,
144 .readarr = NULL,
145 }, {
146 .writecnt = write_cmd_len,
147 .writearr = write_cmd,
148 .readcnt = 0,
149 .readarr = NULL,
150 }, {
151 .writecnt = 0,
152 .writearr = NULL,
153 .readcnt = 0,
154 .readarr = NULL,
155 }};
156
157 int result = spi_send_multicommand(flash, cmds);
158 if (result) {
159 msg_cerr("%s failed during command execution\n", __func__);
160 return result;
161 }
162
163 /*
164 * WRSR performs a self-timed erase before the changes take effect.
165 * This may take 50-85 ms in most cases, and some chips apparently
166 * allow running RDSR only once. Therefore pick an initial delay of
167 * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed.
168 *
169 * Newer chips with multiple status registers (SR2 etc.) are unlikely
170 * to have problems with multiple RDSR commands, so only wait for the
171 * initial 100 ms if the register we wrote to was SR1.
172 */
173 int delay_ms = 5000;
174 if (reg == STATUS1) {
175 programmer_delay(100 * 1000);
176 delay_ms -= 100;
177 }
178
179 for (; delay_ms > 0; delay_ms -= 10) {
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100180 uint8_t status;
181 result = spi_read_register(flash, STATUS1, &status);
182 if (result)
183 return result;
184 if ((status & SPI_SR_WIP) == 0)
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100185 return 0;
186 programmer_delay(10 * 1000);
187 }
188
189
190 msg_cerr("Error: WIP bit after WRSR never cleared\n");
191 return TIMEOUT_ERROR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000192}
193
Nikolai Artemiev01675222021-10-20 22:30:41 +1100194int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value)
195{
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100196 int feature_bits = flash->chip->feature_bits;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100197 uint8_t read_cmd;
198
199 switch (reg) {
200 case STATUS1:
201 read_cmd = JEDEC_RDSR;
202 break;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100203 case STATUS2:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200204 if (feature_bits & (FEATURE_WRSR_EXT2 | FEATURE_WRSR2)) {
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100205 read_cmd = JEDEC_RDSR2;
206 break;
207 }
208 msg_cerr("Cannot read SR2: unsupported by chip\n");
209 return 1;
Sergii Dmytruk0b2e7dd2021-12-19 18:37:51 +0200210 case STATUS3:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200211 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3
212 || (feature_bits & FEATURE_WRSR3)) {
213 read_cmd = JEDEC_RDSR3;
214 break;
215 }
216 msg_cerr("Cannot read SR3: unsupported by chip\n");
217 return 1;
Sergii Dmytruk3d728e72021-11-27 15:14:27 +0200218 case SECURITY:
219 read_cmd = JEDEC_RDSCUR;
220 break;
Sergii Dmytrukbd72a472022-07-24 17:11:05 +0300221 case CONFIG:
222 read_cmd = JEDEC_RDCR;
223 break;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100224 default:
225 msg_cerr("Cannot read register: unknown register\n");
226 return 1;
227 }
228
229 /* FIXME: No workarounds for driver/hardware bugs in generic code. */
230 /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */
231 uint8_t readarr[2];
232
233 int ret = spi_send_command(flash, sizeof(read_cmd), sizeof(readarr), &read_cmd, readarr);
234 if (ret) {
235 msg_cerr("Register read failed!\n");
236 return ret;
237 }
238
239 *value = readarr[0];
240 return 0;
241}
242
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100243static int spi_restore_status(struct flashctx *flash, uint8_t status)
244{
245 msg_cdbg("restoring chip status (0x%02x)\n", status);
Nikolai Artemiev01675222021-10-20 22:30:41 +1100246 return spi_write_register(flash, STATUS1, status);
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100247}
248
Stefan Tauner9530a022012-12-29 15:04:05 +0000249/* A generic block protection disable.
250 * Tests if a protection is enabled with the block protection mask (bp_mask) and returns success otherwise.
251 * Tests if the register bits are locked with the lock_mask (lock_mask).
Stefan Taunercecb2c52013-06-20 22:55:41 +0000252 * Tests if a hardware protection is active (i.e. low pin/high bit value) with the write protection mask
253 * (wp_mask) and bails out in that case.
254 * If there are register lock bits set we try to disable them by unsetting those bits of the previous register
255 * contents that are set in the lock_mask. We then check if removing the lock bits has worked and continue as if
256 * they never had been engaged:
257 * If the lock bits are out of the way try to disable engaged protections.
258 * To support uncommon global unprotects (e.g. on most AT2[56]xx1(A)) unprotect_mask can be used to force
259 * bits to 0 additionally to those set in bp_mask and lock_mask. Only bits set in unprotect_mask are potentially
260 * preserved when doing the final unprotect.
261 *
262 * To sum up:
263 * bp_mask: set those bits that correspond to the bits in the status register that indicate an active protection
264 * (which should be unset after this function returns).
265 * lock_mask: set the bits that correspond to the bits that lock changing the bits above.
266 * wp_mask: set the bits that correspond to bits indicating non-software revocable protections.
267 * unprotect_mask: set the bits that should be preserved if possible when unprotecting.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000268 */
Stefan Taunercecb2c52013-06-20 22:55:41 +0000269static 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 Tauner6ee37e22012-12-29 15:03:51 +0000270{
271 uint8_t status;
272 int result;
273
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100274 int ret = spi_read_register(flash, STATUS1, &status);
275 if (ret)
276 return ret;
277
Stefan Tauner9530a022012-12-29 15:04:05 +0000278 if ((status & bp_mask) == 0) {
279 msg_cdbg2("Block protection is disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000280 return 0;
Stefan Tauner9530a022012-12-29 15:04:05 +0000281 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000282
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100283 /* Restore status register content upon exit in finalize_flash_access(). */
284 register_chip_restore(spi_restore_status, flash, status);
285
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000286 msg_cdbg("Some block protection in effect, disabling... ");
Stefan Tauner9530a022012-12-29 15:04:05 +0000287 if ((status & lock_mask) != 0) {
288 msg_cdbg("\n\tNeed to disable the register lock first... ");
289 if (wp_mask != 0 && (status & wp_mask) == 0) {
290 msg_cerr("Hardware protection is active, disabling write protection is impossible.\n");
291 return 1;
292 }
293 /* All bits except the register lock bit (often called SPRL, SRWD, WPEN) are readonly. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100294 result = spi_write_register(flash, STATUS1, status & ~lock_mask);
Stefan Tauner9530a022012-12-29 15:04:05 +0000295 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100296 msg_cerr("Could not write status register 1.\n");
Stefan Tauner9530a022012-12-29 15:04:05 +0000297 return result;
298 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100299
300 ret = spi_read_register(flash, STATUS1, &status);
301 if (ret)
302 return ret;
303
Stefan Taunercecb2c52013-06-20 22:55:41 +0000304 if ((status & lock_mask) != 0) {
305 msg_cerr("Unsetting lock bit(s) failed.\n");
306 return 1;
307 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000308 msg_cdbg("done.\n");
309 }
310 /* Global unprotect. Make sure to mask the register lock bit as well. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100311 result = spi_write_register(flash, STATUS1, status & ~(bp_mask | lock_mask) & unprotect_mask);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000312 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100313 msg_cerr("Could not write status register 1.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000314 return result;
315 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100316
317 ret = spi_read_register(flash, STATUS1, &status);
318 if (ret)
319 return ret;
320
Stefan Tauner9530a022012-12-29 15:04:05 +0000321 if ((status & bp_mask) != 0) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000322 msg_cerr("Block protection could not be disabled!\n");
Yuji Sasaki4af36092019-03-22 10:59:50 -0700323 if (flash->chip->printlock)
324 flash->chip->printlock(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000325 return 1;
326 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000327 msg_cdbg("disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000328 return 0;
329}
330
Stefan Tauner9530a022012-12-29 15:04:05 +0000331/* A common block protection disable that tries to unset the status register bits masked by 0x3C. */
332int spi_disable_blockprotect(struct flashctx *flash)
333{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000334 return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000335}
336
Wei Hu25584de2018-04-30 14:02:08 -0700337int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
338{
339 int result = spi_write_enable(flash);
340 if (result)
341 return result;
342
343 static const unsigned char cmd[] = { 0x98 }; /* ULBPR */
344 result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL);
345 if (result)
346 msg_cerr("ULBPR failed\n");
347 return result;
348}
349
Stefan Taunera60d4082014-06-04 16:17:03 +0000350/* A common block protection disable that tries to unset the status register bits masked by 0x0C (BP0-1) and
351 * protected/locked by bit #7. Useful when bits 4-5 may be non-0). */
352int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
353{
354 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
355}
356
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000357/* A common block protection disable that tries to unset the status register bits masked by 0x1C (BP0-2) and
358 * protected/locked by bit #7. Useful when bit #5 is neither a protection bit nor reserved (and hence possibly
359 * non-0). */
360int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash)
361{
362 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0, 0xFF);
363}
364
365/* A common block protection disable that tries to unset the status register bits masked by 0x3C (BP0-3) and
366 * protected/locked by bit #7. */
367int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash)
368{
369 return spi_disable_blockprotect_generic(flash, 0x3C, 1 << 7, 0, 0xFF);
370}
371
372/* A common block protection disable that tries to unset the status register bits masked by 0x7C (BP0-4) and
373 * protected/locked by bit #7. */
374int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash)
375{
376 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
377}
Stefan Tauner9530a022012-12-29 15:04:05 +0000378
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000379static void spi_prettyprint_status_register_hex(uint8_t status)
380{
381 msg_cdbg("Chip status register is 0x%02x.\n", status);
382}
383
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000384/* Common highest bit: Status Register Write Disable (SRWD) or Status Register Protect (SRP). */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000385static void spi_prettyprint_status_register_srwd(uint8_t status)
386{
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000387 msg_cdbg("Chip status register: Status Register Write Disable (SRWD, SRP, ...) is %sset\n",
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000388 (status & (1 << 7)) ? "" : "not ");
389}
390
391/* Common highest bit: Block Protect Write Disable (BPL). */
392static void spi_prettyprint_status_register_bpl(uint8_t status)
393{
394 msg_cdbg("Chip status register: Block Protect Write Disable (BPL) is %sset\n",
395 (status & (1 << 7)) ? "" : "not ");
396}
397
398/* Common lowest 2 bits: WEL and WIP. */
399static void spi_prettyprint_status_register_welwip(uint8_t status)
400{
401 msg_cdbg("Chip status register: Write Enable Latch (WEL) is %sset\n",
402 (status & (1 << 1)) ? "" : "not ");
403 msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is %sset\n",
404 (status & (1 << 0)) ? "" : "not ");
405}
406
407/* Common block protection (BP) bits. */
408static void spi_prettyprint_status_register_bp(uint8_t status, int bp)
409{
410 switch (bp) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000411 case 4:
412 msg_cdbg("Chip status register: Block Protect 4 (BP4) is %sset\n",
Stefan Tauner5c316f92015-02-08 21:57:52 +0000413 (status & (1 << 6)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000414 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000415 case 3:
416 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
417 (status & (1 << 5)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000418 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000419 case 2:
420 msg_cdbg("Chip status register: Block Protect 2 (BP2) is %sset\n",
421 (status & (1 << 4)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000422 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000423 case 1:
424 msg_cdbg("Chip status register: Block Protect 1 (BP1) is %sset\n",
425 (status & (1 << 3)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000426 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000427 case 0:
428 msg_cdbg("Chip status register: Block Protect 0 (BP0) is %sset\n",
429 (status & (1 << 2)) ? "" : "not ");
430 }
431}
432
433/* Unnamed bits. */
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000434void spi_prettyprint_status_register_bit(uint8_t status, int bit)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000435{
436 msg_cdbg("Chip status register: Bit %i is %sset\n", bit, (status & (1 << bit)) ? "" : "not ");
437}
438
439int spi_prettyprint_status_register_plain(struct flashctx *flash)
440{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100441 uint8_t status;
442 int ret = spi_read_register(flash, STATUS1, &status);
443 if (ret)
444 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000445 spi_prettyprint_status_register_hex(status);
446 return 0;
447}
448
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000449/* Print the plain hex value and the welwip bits only. */
450int spi_prettyprint_status_register_default_welwip(struct flashctx *flash)
451{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100452 uint8_t status;
453 int ret = spi_read_register(flash, STATUS1, &status);
454 if (ret)
455 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000456 spi_prettyprint_status_register_hex(status);
457
458 spi_prettyprint_status_register_welwip(status);
459 return 0;
460}
461
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000462/* Works for many chips of the
463 * AMIC A25L series
464 * and MX MX25L512
465 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000466int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000467{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100468 uint8_t status;
469 int ret = spi_read_register(flash, STATUS1, &status);
470 if (ret)
471 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000472 spi_prettyprint_status_register_hex(status);
473
474 spi_prettyprint_status_register_srwd(status);
475 spi_prettyprint_status_register_bit(status, 6);
476 spi_prettyprint_status_register_bit(status, 5);
477 spi_prettyprint_status_register_bit(status, 4);
478 spi_prettyprint_status_register_bp(status, 1);
479 spi_prettyprint_status_register_welwip(status);
480 return 0;
481}
482
483/* Works for many chips of the
484 * AMIC A25L series
Stefan Taunerf4451612013-04-19 01:59:15 +0000485 * PMC Pm25LD series
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000486 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000487int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000488{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100489 uint8_t status;
490 int ret = spi_read_register(flash, STATUS1, &status);
491 if (ret)
492 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000493 spi_prettyprint_status_register_hex(status);
494
495 spi_prettyprint_status_register_srwd(status);
496 spi_prettyprint_status_register_bit(status, 6);
497 spi_prettyprint_status_register_bit(status, 5);
498 spi_prettyprint_status_register_bp(status, 2);
499 spi_prettyprint_status_register_welwip(status);
500 return 0;
501}
502
503/* Works for many chips of the
504 * ST M25P series
505 * MX MX25L series
506 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000507int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000508{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100509 uint8_t status;
510 int ret = spi_read_register(flash, STATUS1, &status);
511 if (ret)
512 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000513 spi_prettyprint_status_register_hex(status);
514
515 spi_prettyprint_status_register_srwd(status);
516 spi_prettyprint_status_register_bit(status, 6);
517 spi_prettyprint_status_register_bp(status, 3);
518 spi_prettyprint_status_register_welwip(status);
519 return 0;
520}
521
Stefan Tauner12f3d512014-05-27 21:27:27 +0000522int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash)
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000523{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100524 uint8_t status;
525 int ret = spi_read_register(flash, STATUS1, &status);
526 if (ret)
527 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000528 spi_prettyprint_status_register_hex(status);
529
530 spi_prettyprint_status_register_srwd(status);
531 spi_prettyprint_status_register_bp(status, 4);
532 spi_prettyprint_status_register_welwip(status);
533 return 0;
534}
535
Stefan Tauner85f09f72014-05-27 21:27:14 +0000536int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash)
537{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100538 uint8_t status;
539 int ret = spi_read_register(flash, STATUS1, &status);
540 if (ret)
541 return ret;
Stefan Tauner85f09f72014-05-27 21:27:14 +0000542 spi_prettyprint_status_register_hex(status);
543
544 spi_prettyprint_status_register_bpl(status);
545 spi_prettyprint_status_register_bit(status, 6);
546 spi_prettyprint_status_register_bit(status, 5);
547 spi_prettyprint_status_register_bp(status, 2);
548 spi_prettyprint_status_register_welwip(status);
549 return 0;
550}
551
Ben Gardnerbcf61092015-11-22 02:23:31 +0000552int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash)
553{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100554 uint8_t status;
555 int ret = spi_read_register(flash, STATUS1, &status);
556 if (ret)
557 return ret;
Ben Gardnerbcf61092015-11-22 02:23:31 +0000558 spi_prettyprint_status_register_hex(status);
559
560 spi_prettyprint_status_register_bpl(status);
561 spi_prettyprint_status_register_bit(status, 6);
562 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
563 spi_prettyprint_status_register_bp(status, 2);
564 spi_prettyprint_status_register_welwip(status);
565 return 0;
566}
567
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000568/* === Amic ===
569 * FIXME: spi_disable_blockprotect is incorrect but works fine for chips using
Stefan Tauner12f3d512014-05-27 21:27:27 +0000570 * spi_prettyprint_status_register_bp1_srwd or
571 * spi_prettyprint_status_register_bp2_srwd.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000572 * FIXME: spi_disable_blockprotect is incorrect and will fail for chips using
573 * spi_prettyprint_status_register_amic_a25l032 if those have locks controlled
574 * by the second status register.
575 */
576
577int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash)
578{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100579 uint8_t status;
580 int ret = spi_read_register(flash, STATUS1, &status);
581 if (ret)
582 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000583 spi_prettyprint_status_register_hex(status);
584
585 spi_prettyprint_status_register_srwd(status);
586 msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64);
587 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
588 spi_prettyprint_status_register_bp(status, 2);
589 spi_prettyprint_status_register_welwip(status);
590 msg_cdbg("Chip status register 2 is NOT decoded!\n");
591 return 0;
592}
593
594/* === Atmel === */
595
596static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)
597{
598 msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n",
599 (status & (1 << 7)) ? "" : "not ");
600}
601
602static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
603{
604 msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n",
605 (status & (1 << 7)) ? "" : "not ");
606}
607
608static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)
609{
610 msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n",
611 (status & (1 << 5)) ? "" : "not ");
612 msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n",
613 (status & (1 << 4)) ? "not " : "");
614}
615
616static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
617{
618 msg_cdbg("Chip status register: Software Protection Status (SWP): ");
619 switch (status & (3 << 2)) {
620 case 0x0 << 2:
621 msg_cdbg("no sectors are protected\n");
622 break;
623 case 0x1 << 2:
624 msg_cdbg("some sectors are protected\n");
625 /* FIXME: Read individual Sector Protection Registers. */
626 break;
627 case 0x3 << 2:
628 msg_cdbg("all sectors are protected\n");
629 break;
630 default:
631 msg_cdbg("reserved for future use\n");
632 break;
633 }
634}
635
636int spi_prettyprint_status_register_at25df(struct flashctx *flash)
637{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100638 uint8_t status;
639 int ret = spi_read_register(flash, STATUS1, &status);
640 if (ret)
641 return ret;
642
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000643 spi_prettyprint_status_register_hex(status);
644
645 spi_prettyprint_status_register_atmel_at25_srpl(status);
646 spi_prettyprint_status_register_bit(status, 6);
647 spi_prettyprint_status_register_atmel_at25_epewpp(status);
648 spi_prettyprint_status_register_atmel_at25_swp(status);
649 spi_prettyprint_status_register_welwip(status);
650 return 0;
651}
652
653int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
654{
655 /* FIXME: We should check the security lockdown. */
656 msg_cdbg("Ignoring security lockdown (if present)\n");
657 msg_cdbg("Ignoring status register byte 2\n");
658 return spi_prettyprint_status_register_at25df(flash);
659}
660
Stefan Tauner57794ac2012-12-29 15:04:20 +0000661/* used for AT25F512, AT25F1024(A), AT25F2048 */
662int spi_prettyprint_status_register_at25f(struct flashctx *flash)
663{
664 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100665 int ret = spi_read_register(flash, STATUS1, &status);
666 if (ret)
667 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000668
Stefan Tauner57794ac2012-12-29 15:04:20 +0000669 spi_prettyprint_status_register_hex(status);
670
671 spi_prettyprint_status_register_atmel_at25_wpen(status);
672 spi_prettyprint_status_register_bit(status, 6);
673 spi_prettyprint_status_register_bit(status, 5);
674 spi_prettyprint_status_register_bit(status, 4);
675 spi_prettyprint_status_register_bp(status, 1);
676 spi_prettyprint_status_register_welwip(status);
677 return 0;
678}
679
680int spi_prettyprint_status_register_at25f512a(struct flashctx *flash)
681{
682 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100683 int ret = spi_read_register(flash, STATUS1, &status);
684 if (ret)
685 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000686
Stefan Tauner57794ac2012-12-29 15:04:20 +0000687 spi_prettyprint_status_register_hex(status);
688
689 spi_prettyprint_status_register_atmel_at25_wpen(status);
690 spi_prettyprint_status_register_bit(status, 6);
691 spi_prettyprint_status_register_bit(status, 5);
692 spi_prettyprint_status_register_bit(status, 4);
693 spi_prettyprint_status_register_bit(status, 3);
694 spi_prettyprint_status_register_bp(status, 0);
695 spi_prettyprint_status_register_welwip(status);
696 return 0;
697}
698
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000699int spi_prettyprint_status_register_at25f512b(struct flashctx *flash)
700{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100701 uint8_t status;
702 int ret = spi_read_register(flash, STATUS1, &status);
703 if (ret)
704 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000705 spi_prettyprint_status_register_hex(status);
706
707 spi_prettyprint_status_register_atmel_at25_srpl(status);
708 spi_prettyprint_status_register_bit(status, 6);
709 spi_prettyprint_status_register_atmel_at25_epewpp(status);
710 spi_prettyprint_status_register_bit(status, 3);
711 spi_prettyprint_status_register_bp(status, 0);
712 spi_prettyprint_status_register_welwip(status);
713 return 0;
714}
715
Stefan Tauner57794ac2012-12-29 15:04:20 +0000716int spi_prettyprint_status_register_at25f4096(struct flashctx *flash)
717{
718 uint8_t status;
719
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100720 int ret = spi_read_register(flash, STATUS1, &status);
721 if (ret)
722 return ret;
723
Stefan Tauner57794ac2012-12-29 15:04:20 +0000724 spi_prettyprint_status_register_hex(status);
725
726 spi_prettyprint_status_register_atmel_at25_wpen(status);
727 spi_prettyprint_status_register_bit(status, 6);
728 spi_prettyprint_status_register_bit(status, 5);
729 spi_prettyprint_status_register_bp(status, 2);
730 spi_prettyprint_status_register_welwip(status);
731 return 0;
732}
733
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000734int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
735{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100736 uint8_t status;
737 int ret = spi_read_register(flash, STATUS1, &status);
738 if (ret)
739 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000740 spi_prettyprint_status_register_hex(status);
741
742 spi_prettyprint_status_register_atmel_at25_wpen(status);
743 msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is "
744 "%sset\n", (status & (1 << 6)) ? "" : "not ");
745 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
746 "%sset\n", (status & (1 << 5)) ? "" : "not ");
747 spi_prettyprint_status_register_bit(status, 4);
748 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
749 "%sset\n", (status & (1 << 3)) ? "" : "not ");
750 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
751 "%sset\n", (status & (1 << 2)) ? "" : "not ");
752 /* FIXME: Pretty-print detailed sector protection status. */
753 spi_prettyprint_status_register_welwip(status);
754 return 0;
755}
756
757int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
758{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100759 uint8_t status;
760 int ret = spi_read_register(flash, STATUS1, &status);
761 if (ret)
762 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000763 spi_prettyprint_status_register_hex(status);
764
765 spi_prettyprint_status_register_atmel_at25_wpen(status);
766 spi_prettyprint_status_register_bp(status, 4);
767 /* FIXME: Pretty-print detailed sector protection status. */
768 spi_prettyprint_status_register_welwip(status);
769 return 0;
770}
771
772int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
773{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100774 uint8_t status;
775 int ret = spi_read_register(flash, STATUS1, &status);
776 if (ret)
777 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000778 spi_prettyprint_status_register_hex(status);
779
780 spi_prettyprint_status_register_atmel_at25_srpl(status);
781 msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n",
782 (status & (1 << 6)) ? "" : "not ");
783 spi_prettyprint_status_register_atmel_at25_epewpp(status);
784 spi_prettyprint_status_register_atmel_at25_swp(status);
785 spi_prettyprint_status_register_welwip(status);
786 return 0;
787}
788
Stefan Taunercecb2c52013-06-20 22:55:41 +0000789/* Some Atmel DataFlash chips support per sector protection bits and the write protection bits in the status
790 * register do indicate if none, some or all sectors are protected. It is possible to globally (un)lock all
791 * sectors at once by writing 0 not only the protection bits (2 and 3) but also completely unrelated bits (4 and
792 * 5) which normally are not touched.
793 * Affected are all known Atmel chips matched by AT2[56]D[FLQ]..1A? but the AT26DF041. */
794int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000795{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000796 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4, 0x00);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000797}
798
Stefan Taunercecb2c52013-06-20 22:55:41 +0000799int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000800{
801 /* FIXME: We should check the security lockdown. */
802 msg_cinfo("Ignoring security lockdown (if present)\n");
Stefan Taunercecb2c52013-06-20 22:55:41 +0000803 return spi_disable_blockprotect_at2x_global_unprotect(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000804}
805
Stefan Tauner57794ac2012-12-29 15:04:20 +0000806int spi_disable_blockprotect_at25f(struct flashctx *flash)
807{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000808 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000809}
810
811int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
812{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000813 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000814}
815
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000816int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
817{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000818 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 1 << 4, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000819}
820
821int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
822{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000823 return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000824 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000825
826int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
827{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000828 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000829}
830
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000831/* === Eon === */
832
833int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash)
834{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100835 uint8_t status;
836 int ret = spi_read_register(flash, STATUS1, &status);
837 if (ret)
838 return ret;
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000839 spi_prettyprint_status_register_hex(status);
840
841 spi_prettyprint_status_register_srwd(status);
842 msg_cdbg("Chip status register: WP# disable (WPDIS) is %sabled\n", (status & (1 << 6)) ? "en " : "dis");
843 spi_prettyprint_status_register_bp(status, 3);
844 spi_prettyprint_status_register_welwip(status);
845 return 0;
846}
847
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000848/* === Intel/Numonyx/Micron - Spansion === */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000849
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000850int spi_disable_blockprotect_n25q(struct flashctx *flash)
851{
852 return spi_disable_blockprotect_generic(flash, 0x5C, 1 << 7, 0, 0xFF);
853}
854
855int spi_prettyprint_status_register_n25q(struct flashctx *flash)
856{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100857 uint8_t status;
858 int ret = spi_read_register(flash, STATUS1, &status);
859 if (ret)
860 return ret;
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000861 spi_prettyprint_status_register_hex(status);
862
863 spi_prettyprint_status_register_srwd(status);
864 if (flash->chip->total_size <= 32 / 8 * 1024) /* N25Q16 and N25Q32: reserved */
865 spi_prettyprint_status_register_bit(status, 6);
866 else
867 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
868 (status & (1 << 6)) ? "" : "not ");
869 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
870 spi_prettyprint_status_register_bp(status, 2);
871 spi_prettyprint_status_register_welwip(status);
872 return 0;
873}
874
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000875/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000876/* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000877int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000878{
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000879 return spi_disable_blockprotect_bp2_srwd(flash);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000880}
881
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000882/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
883int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000884{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100885 uint8_t status;
886 int ret = spi_read_register(flash, STATUS1, &status);
887 if (ret)
888 return ret;
Stefan Taunerc2eec2c2014-05-03 21:33:01 +0000889 spi_prettyprint_status_register_hex(status);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000890
891 spi_prettyprint_status_register_srwd(status);
892 msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n",
893 (status & (1 << 6)) ? "" : "not ");
894 msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n",
895 (status & (1 << 5)) ? "" : "not ");
896 spi_prettyprint_status_register_bp(status, 2);
897 spi_prettyprint_status_register_welwip(status);
898 return 0;
899}
900
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000901/* === SST === */
902
903static void spi_prettyprint_status_register_sst25_common(uint8_t status)
904{
905 spi_prettyprint_status_register_hex(status);
906
907 spi_prettyprint_status_register_bpl(status);
908 msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n",
909 (status & (1 << 6)) ? "" : "not ");
910 spi_prettyprint_status_register_bp(status, 3);
911 spi_prettyprint_status_register_welwip(status);
912}
913
914int spi_prettyprint_status_register_sst25(struct flashctx *flash)
915{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100916 uint8_t status;
917 int ret = spi_read_register(flash, STATUS1, &status);
918 if (ret)
919 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000920 spi_prettyprint_status_register_sst25_common(status);
921 return 0;
922}
923
924int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash)
925{
926 static const char *const bpt[] = {
927 "none",
928 "1F0000H-1FFFFFH",
929 "1E0000H-1FFFFFH",
930 "1C0000H-1FFFFFH",
931 "180000H-1FFFFFH",
932 "100000H-1FFFFFH",
933 "all", "all"
934 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100935 uint8_t status;
936 int ret = spi_read_register(flash, STATUS1, &status);
937 if (ret)
938 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000939 spi_prettyprint_status_register_sst25_common(status);
940 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
941 return 0;
942}
943
944int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash)
945{
946 static const char *const bpt[] = {
947 "none",
948 "0x70000-0x7ffff",
949 "0x60000-0x7ffff",
950 "0x40000-0x7ffff",
951 "all blocks", "all blocks", "all blocks", "all blocks"
952 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100953 uint8_t status;
954 int ret = spi_read_register(flash, STATUS1, &status);
955 if (ret)
956 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000957 spi_prettyprint_status_register_sst25_common(status);
958 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
959 return 0;
960}