blob: 1e6a87092d93766013172beb0161eb235055101c [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;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100110 default:
111 msg_cerr("Cannot write register: unknown register\n");
112 return 1;
113 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000114
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100115 uint8_t enable_cmd;
116 if (feature_bits & FEATURE_WRSR_WREN) {
117 enable_cmd = JEDEC_WREN;
118 } else if (feature_bits & FEATURE_WRSR_EWSR) {
119 enable_cmd = JEDEC_EWSR;
120 } else {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000121 msg_cdbg("Missing status register write definition, assuming "
122 "EWSR is needed\n");
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100123 enable_cmd = JEDEC_EWSR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000124 }
Nikolai Artemiev01675222021-10-20 22:30:41 +1100125
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100126 struct spi_command cmds[] = {
127 {
128 .writecnt = JEDEC_WREN_OUTSIZE,
129 .writearr = &enable_cmd,
130 .readcnt = 0,
131 .readarr = NULL,
132 }, {
133 .writecnt = write_cmd_len,
134 .writearr = write_cmd,
135 .readcnt = 0,
136 .readarr = NULL,
137 }, {
138 .writecnt = 0,
139 .writearr = NULL,
140 .readcnt = 0,
141 .readarr = NULL,
142 }};
143
144 int result = spi_send_multicommand(flash, cmds);
145 if (result) {
146 msg_cerr("%s failed during command execution\n", __func__);
147 return result;
148 }
149
150 /*
151 * WRSR performs a self-timed erase before the changes take effect.
152 * This may take 50-85 ms in most cases, and some chips apparently
153 * allow running RDSR only once. Therefore pick an initial delay of
154 * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed.
155 *
156 * Newer chips with multiple status registers (SR2 etc.) are unlikely
157 * to have problems with multiple RDSR commands, so only wait for the
158 * initial 100 ms if the register we wrote to was SR1.
159 */
160 int delay_ms = 5000;
161 if (reg == STATUS1) {
162 programmer_delay(100 * 1000);
163 delay_ms -= 100;
164 }
165
166 for (; delay_ms > 0; delay_ms -= 10) {
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100167 uint8_t status;
168 result = spi_read_register(flash, STATUS1, &status);
169 if (result)
170 return result;
171 if ((status & SPI_SR_WIP) == 0)
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100172 return 0;
173 programmer_delay(10 * 1000);
174 }
175
176
177 msg_cerr("Error: WIP bit after WRSR never cleared\n");
178 return TIMEOUT_ERROR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000179}
180
Nikolai Artemiev01675222021-10-20 22:30:41 +1100181int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value)
182{
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100183 int feature_bits = flash->chip->feature_bits;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100184 uint8_t read_cmd;
185
186 switch (reg) {
187 case STATUS1:
188 read_cmd = JEDEC_RDSR;
189 break;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100190 case STATUS2:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200191 if (feature_bits & (FEATURE_WRSR_EXT2 | FEATURE_WRSR2)) {
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100192 read_cmd = JEDEC_RDSR2;
193 break;
194 }
195 msg_cerr("Cannot read SR2: unsupported by chip\n");
196 return 1;
Sergii Dmytruk0b2e7dd2021-12-19 18:37:51 +0200197 case STATUS3:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200198 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3
199 || (feature_bits & FEATURE_WRSR3)) {
200 read_cmd = JEDEC_RDSR3;
201 break;
202 }
203 msg_cerr("Cannot read SR3: unsupported by chip\n");
204 return 1;
Sergii Dmytruk3d728e72021-11-27 15:14:27 +0200205 case SECURITY:
206 read_cmd = JEDEC_RDSCUR;
207 break;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100208 default:
209 msg_cerr("Cannot read register: unknown register\n");
210 return 1;
211 }
212
213 /* FIXME: No workarounds for driver/hardware bugs in generic code. */
214 /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */
215 uint8_t readarr[2];
216
217 int ret = spi_send_command(flash, sizeof(read_cmd), sizeof(readarr), &read_cmd, readarr);
218 if (ret) {
219 msg_cerr("Register read failed!\n");
220 return ret;
221 }
222
223 *value = readarr[0];
224 return 0;
225}
226
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100227static int spi_restore_status(struct flashctx *flash, uint8_t status)
228{
229 msg_cdbg("restoring chip status (0x%02x)\n", status);
Nikolai Artemiev01675222021-10-20 22:30:41 +1100230 return spi_write_register(flash, STATUS1, status);
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100231}
232
Stefan Tauner9530a022012-12-29 15:04:05 +0000233/* A generic block protection disable.
234 * Tests if a protection is enabled with the block protection mask (bp_mask) and returns success otherwise.
235 * Tests if the register bits are locked with the lock_mask (lock_mask).
Stefan Taunercecb2c52013-06-20 22:55:41 +0000236 * Tests if a hardware protection is active (i.e. low pin/high bit value) with the write protection mask
237 * (wp_mask) and bails out in that case.
238 * If there are register lock bits set we try to disable them by unsetting those bits of the previous register
239 * contents that are set in the lock_mask. We then check if removing the lock bits has worked and continue as if
240 * they never had been engaged:
241 * If the lock bits are out of the way try to disable engaged protections.
242 * To support uncommon global unprotects (e.g. on most AT2[56]xx1(A)) unprotect_mask can be used to force
243 * bits to 0 additionally to those set in bp_mask and lock_mask. Only bits set in unprotect_mask are potentially
244 * preserved when doing the final unprotect.
245 *
246 * To sum up:
247 * bp_mask: set those bits that correspond to the bits in the status register that indicate an active protection
248 * (which should be unset after this function returns).
249 * lock_mask: set the bits that correspond to the bits that lock changing the bits above.
250 * wp_mask: set the bits that correspond to bits indicating non-software revocable protections.
251 * unprotect_mask: set the bits that should be preserved if possible when unprotecting.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000252 */
Stefan Taunercecb2c52013-06-20 22:55:41 +0000253static 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 +0000254{
255 uint8_t status;
256 int result;
257
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100258 int ret = spi_read_register(flash, STATUS1, &status);
259 if (ret)
260 return ret;
261
Stefan Tauner9530a022012-12-29 15:04:05 +0000262 if ((status & bp_mask) == 0) {
263 msg_cdbg2("Block protection is disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000264 return 0;
Stefan Tauner9530a022012-12-29 15:04:05 +0000265 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000266
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100267 /* Restore status register content upon exit in finalize_flash_access(). */
268 register_chip_restore(spi_restore_status, flash, status);
269
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000270 msg_cdbg("Some block protection in effect, disabling... ");
Stefan Tauner9530a022012-12-29 15:04:05 +0000271 if ((status & lock_mask) != 0) {
272 msg_cdbg("\n\tNeed to disable the register lock first... ");
273 if (wp_mask != 0 && (status & wp_mask) == 0) {
274 msg_cerr("Hardware protection is active, disabling write protection is impossible.\n");
275 return 1;
276 }
277 /* All bits except the register lock bit (often called SPRL, SRWD, WPEN) are readonly. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100278 result = spi_write_register(flash, STATUS1, status & ~lock_mask);
Stefan Tauner9530a022012-12-29 15:04:05 +0000279 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100280 msg_cerr("Could not write status register 1.\n");
Stefan Tauner9530a022012-12-29 15:04:05 +0000281 return result;
282 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100283
284 ret = spi_read_register(flash, STATUS1, &status);
285 if (ret)
286 return ret;
287
Stefan Taunercecb2c52013-06-20 22:55:41 +0000288 if ((status & lock_mask) != 0) {
289 msg_cerr("Unsetting lock bit(s) failed.\n");
290 return 1;
291 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000292 msg_cdbg("done.\n");
293 }
294 /* Global unprotect. Make sure to mask the register lock bit as well. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100295 result = spi_write_register(flash, STATUS1, status & ~(bp_mask | lock_mask) & unprotect_mask);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000296 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100297 msg_cerr("Could not write status register 1.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000298 return result;
299 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100300
301 ret = spi_read_register(flash, STATUS1, &status);
302 if (ret)
303 return ret;
304
Stefan Tauner9530a022012-12-29 15:04:05 +0000305 if ((status & bp_mask) != 0) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000306 msg_cerr("Block protection could not be disabled!\n");
Yuji Sasaki4af36092019-03-22 10:59:50 -0700307 if (flash->chip->printlock)
308 flash->chip->printlock(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000309 return 1;
310 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000311 msg_cdbg("disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000312 return 0;
313}
314
Stefan Tauner9530a022012-12-29 15:04:05 +0000315/* A common block protection disable that tries to unset the status register bits masked by 0x3C. */
316int spi_disable_blockprotect(struct flashctx *flash)
317{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000318 return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000319}
320
Wei Hu25584de2018-04-30 14:02:08 -0700321int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
322{
323 int result = spi_write_enable(flash);
324 if (result)
325 return result;
326
327 static const unsigned char cmd[] = { 0x98 }; /* ULBPR */
328 result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL);
329 if (result)
330 msg_cerr("ULBPR failed\n");
331 return result;
332}
333
Stefan Taunera60d4082014-06-04 16:17:03 +0000334/* A common block protection disable that tries to unset the status register bits masked by 0x0C (BP0-1) and
335 * protected/locked by bit #7. Useful when bits 4-5 may be non-0). */
336int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
337{
338 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
339}
340
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000341/* A common block protection disable that tries to unset the status register bits masked by 0x1C (BP0-2) and
342 * protected/locked by bit #7. Useful when bit #5 is neither a protection bit nor reserved (and hence possibly
343 * non-0). */
344int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash)
345{
346 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0, 0xFF);
347}
348
349/* A common block protection disable that tries to unset the status register bits masked by 0x3C (BP0-3) and
350 * protected/locked by bit #7. */
351int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash)
352{
353 return spi_disable_blockprotect_generic(flash, 0x3C, 1 << 7, 0, 0xFF);
354}
355
356/* A common block protection disable that tries to unset the status register bits masked by 0x7C (BP0-4) and
357 * protected/locked by bit #7. */
358int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash)
359{
360 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
361}
Stefan Tauner9530a022012-12-29 15:04:05 +0000362
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000363static void spi_prettyprint_status_register_hex(uint8_t status)
364{
365 msg_cdbg("Chip status register is 0x%02x.\n", status);
366}
367
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000368/* Common highest bit: Status Register Write Disable (SRWD) or Status Register Protect (SRP). */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000369static void spi_prettyprint_status_register_srwd(uint8_t status)
370{
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000371 msg_cdbg("Chip status register: Status Register Write Disable (SRWD, SRP, ...) is %sset\n",
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000372 (status & (1 << 7)) ? "" : "not ");
373}
374
375/* Common highest bit: Block Protect Write Disable (BPL). */
376static void spi_prettyprint_status_register_bpl(uint8_t status)
377{
378 msg_cdbg("Chip status register: Block Protect Write Disable (BPL) is %sset\n",
379 (status & (1 << 7)) ? "" : "not ");
380}
381
382/* Common lowest 2 bits: WEL and WIP. */
383static void spi_prettyprint_status_register_welwip(uint8_t status)
384{
385 msg_cdbg("Chip status register: Write Enable Latch (WEL) is %sset\n",
386 (status & (1 << 1)) ? "" : "not ");
387 msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is %sset\n",
388 (status & (1 << 0)) ? "" : "not ");
389}
390
391/* Common block protection (BP) bits. */
392static void spi_prettyprint_status_register_bp(uint8_t status, int bp)
393{
394 switch (bp) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000395 case 4:
396 msg_cdbg("Chip status register: Block Protect 4 (BP4) is %sset\n",
Stefan Tauner5c316f92015-02-08 21:57:52 +0000397 (status & (1 << 6)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000398 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000399 case 3:
400 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
401 (status & (1 << 5)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000402 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000403 case 2:
404 msg_cdbg("Chip status register: Block Protect 2 (BP2) is %sset\n",
405 (status & (1 << 4)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000406 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000407 case 1:
408 msg_cdbg("Chip status register: Block Protect 1 (BP1) is %sset\n",
409 (status & (1 << 3)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000410 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000411 case 0:
412 msg_cdbg("Chip status register: Block Protect 0 (BP0) is %sset\n",
413 (status & (1 << 2)) ? "" : "not ");
414 }
415}
416
417/* Unnamed bits. */
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000418void spi_prettyprint_status_register_bit(uint8_t status, int bit)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000419{
420 msg_cdbg("Chip status register: Bit %i is %sset\n", bit, (status & (1 << bit)) ? "" : "not ");
421}
422
423int spi_prettyprint_status_register_plain(struct flashctx *flash)
424{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100425 uint8_t status;
426 int ret = spi_read_register(flash, STATUS1, &status);
427 if (ret)
428 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000429 spi_prettyprint_status_register_hex(status);
430 return 0;
431}
432
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000433/* Print the plain hex value and the welwip bits only. */
434int spi_prettyprint_status_register_default_welwip(struct flashctx *flash)
435{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100436 uint8_t status;
437 int ret = spi_read_register(flash, STATUS1, &status);
438 if (ret)
439 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000440 spi_prettyprint_status_register_hex(status);
441
442 spi_prettyprint_status_register_welwip(status);
443 return 0;
444}
445
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000446/* Works for many chips of the
447 * AMIC A25L series
448 * and MX MX25L512
449 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000450int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000451{
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 Tauner6ee37e22012-12-29 15:03:51 +0000456 spi_prettyprint_status_register_hex(status);
457
458 spi_prettyprint_status_register_srwd(status);
459 spi_prettyprint_status_register_bit(status, 6);
460 spi_prettyprint_status_register_bit(status, 5);
461 spi_prettyprint_status_register_bit(status, 4);
462 spi_prettyprint_status_register_bp(status, 1);
463 spi_prettyprint_status_register_welwip(status);
464 return 0;
465}
466
467/* Works for many chips of the
468 * AMIC A25L series
Stefan Taunerf4451612013-04-19 01:59:15 +0000469 * PMC Pm25LD series
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000470 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000471int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000472{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100473 uint8_t status;
474 int ret = spi_read_register(flash, STATUS1, &status);
475 if (ret)
476 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000477 spi_prettyprint_status_register_hex(status);
478
479 spi_prettyprint_status_register_srwd(status);
480 spi_prettyprint_status_register_bit(status, 6);
481 spi_prettyprint_status_register_bit(status, 5);
482 spi_prettyprint_status_register_bp(status, 2);
483 spi_prettyprint_status_register_welwip(status);
484 return 0;
485}
486
487/* Works for many chips of the
488 * ST M25P series
489 * MX MX25L series
490 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000491int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000492{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100493 uint8_t status;
494 int ret = spi_read_register(flash, STATUS1, &status);
495 if (ret)
496 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000497 spi_prettyprint_status_register_hex(status);
498
499 spi_prettyprint_status_register_srwd(status);
500 spi_prettyprint_status_register_bit(status, 6);
501 spi_prettyprint_status_register_bp(status, 3);
502 spi_prettyprint_status_register_welwip(status);
503 return 0;
504}
505
Stefan Tauner12f3d512014-05-27 21:27:27 +0000506int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash)
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000507{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100508 uint8_t status;
509 int ret = spi_read_register(flash, STATUS1, &status);
510 if (ret)
511 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000512 spi_prettyprint_status_register_hex(status);
513
514 spi_prettyprint_status_register_srwd(status);
515 spi_prettyprint_status_register_bp(status, 4);
516 spi_prettyprint_status_register_welwip(status);
517 return 0;
518}
519
Stefan Tauner85f09f72014-05-27 21:27:14 +0000520int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash)
521{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100522 uint8_t status;
523 int ret = spi_read_register(flash, STATUS1, &status);
524 if (ret)
525 return ret;
Stefan Tauner85f09f72014-05-27 21:27:14 +0000526 spi_prettyprint_status_register_hex(status);
527
528 spi_prettyprint_status_register_bpl(status);
529 spi_prettyprint_status_register_bit(status, 6);
530 spi_prettyprint_status_register_bit(status, 5);
531 spi_prettyprint_status_register_bp(status, 2);
532 spi_prettyprint_status_register_welwip(status);
533 return 0;
534}
535
Ben Gardnerbcf61092015-11-22 02:23:31 +0000536int spi_prettyprint_status_register_bp2_tb_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;
Ben Gardnerbcf61092015-11-22 02:23:31 +0000542 spi_prettyprint_status_register_hex(status);
543
544 spi_prettyprint_status_register_bpl(status);
545 spi_prettyprint_status_register_bit(status, 6);
546 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
547 spi_prettyprint_status_register_bp(status, 2);
548 spi_prettyprint_status_register_welwip(status);
549 return 0;
550}
551
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000552/* === Amic ===
553 * FIXME: spi_disable_blockprotect is incorrect but works fine for chips using
Stefan Tauner12f3d512014-05-27 21:27:27 +0000554 * spi_prettyprint_status_register_bp1_srwd or
555 * spi_prettyprint_status_register_bp2_srwd.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000556 * FIXME: spi_disable_blockprotect is incorrect and will fail for chips using
557 * spi_prettyprint_status_register_amic_a25l032 if those have locks controlled
558 * by the second status register.
559 */
560
561int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash)
562{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100563 uint8_t status;
564 int ret = spi_read_register(flash, STATUS1, &status);
565 if (ret)
566 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000567 spi_prettyprint_status_register_hex(status);
568
569 spi_prettyprint_status_register_srwd(status);
570 msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64);
571 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
572 spi_prettyprint_status_register_bp(status, 2);
573 spi_prettyprint_status_register_welwip(status);
574 msg_cdbg("Chip status register 2 is NOT decoded!\n");
575 return 0;
576}
577
578/* === Atmel === */
579
580static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)
581{
582 msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n",
583 (status & (1 << 7)) ? "" : "not ");
584}
585
586static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
587{
588 msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n",
589 (status & (1 << 7)) ? "" : "not ");
590}
591
592static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)
593{
594 msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n",
595 (status & (1 << 5)) ? "" : "not ");
596 msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n",
597 (status & (1 << 4)) ? "not " : "");
598}
599
600static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
601{
602 msg_cdbg("Chip status register: Software Protection Status (SWP): ");
603 switch (status & (3 << 2)) {
604 case 0x0 << 2:
605 msg_cdbg("no sectors are protected\n");
606 break;
607 case 0x1 << 2:
608 msg_cdbg("some sectors are protected\n");
609 /* FIXME: Read individual Sector Protection Registers. */
610 break;
611 case 0x3 << 2:
612 msg_cdbg("all sectors are protected\n");
613 break;
614 default:
615 msg_cdbg("reserved for future use\n");
616 break;
617 }
618}
619
620int spi_prettyprint_status_register_at25df(struct flashctx *flash)
621{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100622 uint8_t status;
623 int ret = spi_read_register(flash, STATUS1, &status);
624 if (ret)
625 return ret;
626
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000627 spi_prettyprint_status_register_hex(status);
628
629 spi_prettyprint_status_register_atmel_at25_srpl(status);
630 spi_prettyprint_status_register_bit(status, 6);
631 spi_prettyprint_status_register_atmel_at25_epewpp(status);
632 spi_prettyprint_status_register_atmel_at25_swp(status);
633 spi_prettyprint_status_register_welwip(status);
634 return 0;
635}
636
637int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
638{
639 /* FIXME: We should check the security lockdown. */
640 msg_cdbg("Ignoring security lockdown (if present)\n");
641 msg_cdbg("Ignoring status register byte 2\n");
642 return spi_prettyprint_status_register_at25df(flash);
643}
644
Stefan Tauner57794ac2012-12-29 15:04:20 +0000645/* used for AT25F512, AT25F1024(A), AT25F2048 */
646int spi_prettyprint_status_register_at25f(struct flashctx *flash)
647{
648 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100649 int ret = spi_read_register(flash, STATUS1, &status);
650 if (ret)
651 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000652
Stefan Tauner57794ac2012-12-29 15:04:20 +0000653 spi_prettyprint_status_register_hex(status);
654
655 spi_prettyprint_status_register_atmel_at25_wpen(status);
656 spi_prettyprint_status_register_bit(status, 6);
657 spi_prettyprint_status_register_bit(status, 5);
658 spi_prettyprint_status_register_bit(status, 4);
659 spi_prettyprint_status_register_bp(status, 1);
660 spi_prettyprint_status_register_welwip(status);
661 return 0;
662}
663
664int spi_prettyprint_status_register_at25f512a(struct flashctx *flash)
665{
666 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100667 int ret = spi_read_register(flash, STATUS1, &status);
668 if (ret)
669 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000670
Stefan Tauner57794ac2012-12-29 15:04:20 +0000671 spi_prettyprint_status_register_hex(status);
672
673 spi_prettyprint_status_register_atmel_at25_wpen(status);
674 spi_prettyprint_status_register_bit(status, 6);
675 spi_prettyprint_status_register_bit(status, 5);
676 spi_prettyprint_status_register_bit(status, 4);
677 spi_prettyprint_status_register_bit(status, 3);
678 spi_prettyprint_status_register_bp(status, 0);
679 spi_prettyprint_status_register_welwip(status);
680 return 0;
681}
682
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000683int spi_prettyprint_status_register_at25f512b(struct flashctx *flash)
684{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100685 uint8_t status;
686 int ret = spi_read_register(flash, STATUS1, &status);
687 if (ret)
688 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000689 spi_prettyprint_status_register_hex(status);
690
691 spi_prettyprint_status_register_atmel_at25_srpl(status);
692 spi_prettyprint_status_register_bit(status, 6);
693 spi_prettyprint_status_register_atmel_at25_epewpp(status);
694 spi_prettyprint_status_register_bit(status, 3);
695 spi_prettyprint_status_register_bp(status, 0);
696 spi_prettyprint_status_register_welwip(status);
697 return 0;
698}
699
Stefan Tauner57794ac2012-12-29 15:04:20 +0000700int spi_prettyprint_status_register_at25f4096(struct flashctx *flash)
701{
702 uint8_t status;
703
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100704 int ret = spi_read_register(flash, STATUS1, &status);
705 if (ret)
706 return ret;
707
Stefan Tauner57794ac2012-12-29 15:04:20 +0000708 spi_prettyprint_status_register_hex(status);
709
710 spi_prettyprint_status_register_atmel_at25_wpen(status);
711 spi_prettyprint_status_register_bit(status, 6);
712 spi_prettyprint_status_register_bit(status, 5);
713 spi_prettyprint_status_register_bp(status, 2);
714 spi_prettyprint_status_register_welwip(status);
715 return 0;
716}
717
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000718int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
719{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100720 uint8_t status;
721 int ret = spi_read_register(flash, STATUS1, &status);
722 if (ret)
723 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000724 spi_prettyprint_status_register_hex(status);
725
726 spi_prettyprint_status_register_atmel_at25_wpen(status);
727 msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is "
728 "%sset\n", (status & (1 << 6)) ? "" : "not ");
729 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
730 "%sset\n", (status & (1 << 5)) ? "" : "not ");
731 spi_prettyprint_status_register_bit(status, 4);
732 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
733 "%sset\n", (status & (1 << 3)) ? "" : "not ");
734 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
735 "%sset\n", (status & (1 << 2)) ? "" : "not ");
736 /* FIXME: Pretty-print detailed sector protection status. */
737 spi_prettyprint_status_register_welwip(status);
738 return 0;
739}
740
741int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
742{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100743 uint8_t status;
744 int ret = spi_read_register(flash, STATUS1, &status);
745 if (ret)
746 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000747 spi_prettyprint_status_register_hex(status);
748
749 spi_prettyprint_status_register_atmel_at25_wpen(status);
750 spi_prettyprint_status_register_bp(status, 4);
751 /* FIXME: Pretty-print detailed sector protection status. */
752 spi_prettyprint_status_register_welwip(status);
753 return 0;
754}
755
756int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
757{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100758 uint8_t status;
759 int ret = spi_read_register(flash, STATUS1, &status);
760 if (ret)
761 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000762 spi_prettyprint_status_register_hex(status);
763
764 spi_prettyprint_status_register_atmel_at25_srpl(status);
765 msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n",
766 (status & (1 << 6)) ? "" : "not ");
767 spi_prettyprint_status_register_atmel_at25_epewpp(status);
768 spi_prettyprint_status_register_atmel_at25_swp(status);
769 spi_prettyprint_status_register_welwip(status);
770 return 0;
771}
772
Stefan Taunercecb2c52013-06-20 22:55:41 +0000773/* Some Atmel DataFlash chips support per sector protection bits and the write protection bits in the status
774 * register do indicate if none, some or all sectors are protected. It is possible to globally (un)lock all
775 * sectors at once by writing 0 not only the protection bits (2 and 3) but also completely unrelated bits (4 and
776 * 5) which normally are not touched.
777 * Affected are all known Atmel chips matched by AT2[56]D[FLQ]..1A? but the AT26DF041. */
778int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000779{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000780 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4, 0x00);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000781}
782
Stefan Taunercecb2c52013-06-20 22:55:41 +0000783int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000784{
785 /* FIXME: We should check the security lockdown. */
786 msg_cinfo("Ignoring security lockdown (if present)\n");
Stefan Taunercecb2c52013-06-20 22:55:41 +0000787 return spi_disable_blockprotect_at2x_global_unprotect(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000788}
789
Stefan Tauner57794ac2012-12-29 15:04:20 +0000790int spi_disable_blockprotect_at25f(struct flashctx *flash)
791{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000792 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000793}
794
795int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
796{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000797 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000798}
799
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000800int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
801{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000802 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 1 << 4, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000803}
804
805int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
806{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000807 return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000808 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000809
810int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
811{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000812 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000813}
814
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000815/* === Eon === */
816
817int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash)
818{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100819 uint8_t status;
820 int ret = spi_read_register(flash, STATUS1, &status);
821 if (ret)
822 return ret;
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000823 spi_prettyprint_status_register_hex(status);
824
825 spi_prettyprint_status_register_srwd(status);
826 msg_cdbg("Chip status register: WP# disable (WPDIS) is %sabled\n", (status & (1 << 6)) ? "en " : "dis");
827 spi_prettyprint_status_register_bp(status, 3);
828 spi_prettyprint_status_register_welwip(status);
829 return 0;
830}
831
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000832/* === Intel/Numonyx/Micron - Spansion === */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000833
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000834int spi_disable_blockprotect_n25q(struct flashctx *flash)
835{
836 return spi_disable_blockprotect_generic(flash, 0x5C, 1 << 7, 0, 0xFF);
837}
838
839int spi_prettyprint_status_register_n25q(struct flashctx *flash)
840{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100841 uint8_t status;
842 int ret = spi_read_register(flash, STATUS1, &status);
843 if (ret)
844 return ret;
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000845 spi_prettyprint_status_register_hex(status);
846
847 spi_prettyprint_status_register_srwd(status);
848 if (flash->chip->total_size <= 32 / 8 * 1024) /* N25Q16 and N25Q32: reserved */
849 spi_prettyprint_status_register_bit(status, 6);
850 else
851 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
852 (status & (1 << 6)) ? "" : "not ");
853 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
854 spi_prettyprint_status_register_bp(status, 2);
855 spi_prettyprint_status_register_welwip(status);
856 return 0;
857}
858
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000859/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000860/* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000861int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000862{
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000863 return spi_disable_blockprotect_bp2_srwd(flash);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000864}
865
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000866/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
867int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000868{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100869 uint8_t status;
870 int ret = spi_read_register(flash, STATUS1, &status);
871 if (ret)
872 return ret;
Stefan Taunerc2eec2c2014-05-03 21:33:01 +0000873 spi_prettyprint_status_register_hex(status);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000874
875 spi_prettyprint_status_register_srwd(status);
876 msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n",
877 (status & (1 << 6)) ? "" : "not ");
878 msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n",
879 (status & (1 << 5)) ? "" : "not ");
880 spi_prettyprint_status_register_bp(status, 2);
881 spi_prettyprint_status_register_welwip(status);
882 return 0;
883}
884
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000885/* === SST === */
886
887static void spi_prettyprint_status_register_sst25_common(uint8_t status)
888{
889 spi_prettyprint_status_register_hex(status);
890
891 spi_prettyprint_status_register_bpl(status);
892 msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n",
893 (status & (1 << 6)) ? "" : "not ");
894 spi_prettyprint_status_register_bp(status, 3);
895 spi_prettyprint_status_register_welwip(status);
896}
897
898int spi_prettyprint_status_register_sst25(struct flashctx *flash)
899{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100900 uint8_t status;
901 int ret = spi_read_register(flash, STATUS1, &status);
902 if (ret)
903 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000904 spi_prettyprint_status_register_sst25_common(status);
905 return 0;
906}
907
908int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash)
909{
910 static const char *const bpt[] = {
911 "none",
912 "1F0000H-1FFFFFH",
913 "1E0000H-1FFFFFH",
914 "1C0000H-1FFFFFH",
915 "180000H-1FFFFFH",
916 "100000H-1FFFFFH",
917 "all", "all"
918 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100919 uint8_t status;
920 int ret = spi_read_register(flash, STATUS1, &status);
921 if (ret)
922 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000923 spi_prettyprint_status_register_sst25_common(status);
924 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
925 return 0;
926}
927
928int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash)
929{
930 static const char *const bpt[] = {
931 "none",
932 "0x70000-0x7ffff",
933 "0x60000-0x7ffff",
934 "0x40000-0x7ffff",
935 "all blocks", "all blocks", "all blocks", "all blocks"
936 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100937 uint8_t status;
938 int ret = spi_read_register(flash, STATUS1, &status);
939 if (ret)
940 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000941 spi_prettyprint_status_register_sst25_common(status);
942 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
943 return 0;
944}