blob: b363b5f2e1355475cfff6d0610cb0e49e8d3c7ce [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"
Nico Huberd5185632024-01-05 18:44:41 +010022#include "spi_command.h"
Stefan Tauner6ee37e22012-12-29 15:03:51 +000023#include "spi.h"
24
25/* === Generic functions === */
Nico Huber3f3c1f32022-05-28 16:48:26 +020026
27/*
28 * Writing SR2 or higher with an extended WRSR command requires
29 * writing all lower SRx along with it, so just read the lower
30 * SRx and write them back.
31 */
32static int spi_prepare_wrsr_ext(
33 uint8_t write_cmd[4], size_t *const write_cmd_len,
34 const struct flashctx *const flash,
35 const enum flash_reg reg, const uint8_t value)
36{
37 enum flash_reg reg_it;
38 size_t i = 0;
39
40 write_cmd[i++] = JEDEC_WRSR;
41
42 for (reg_it = STATUS1; reg_it < reg; ++reg_it) {
43 uint8_t sr;
44
45 if (spi_read_register(flash, reg_it, &sr)) {
46 msg_cerr("Writing SR%d failed: failed to read SR%d for writeback.\n",
47 reg - STATUS1 + 1, reg_it - STATUS1 + 1);
48 return 1;
49 }
50 write_cmd[i++] = sr;
51 }
52
53 write_cmd[i++] = value;
54 *write_cmd_len = i;
55
56 return 0;
57}
58
Nikolai Artemiev01675222021-10-20 22:30:41 +110059int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t value)
Stefan Tauner6ee37e22012-12-29 15:03:51 +000060{
61 int feature_bits = flash->chip->feature_bits;
Nikolai Artemiev01675222021-10-20 22:30:41 +110062
Nico Huber3f3c1f32022-05-28 16:48:26 +020063 uint8_t write_cmd[4];
Nikolai Artemiev01675222021-10-20 22:30:41 +110064 size_t write_cmd_len = 0;
65
66 /*
67 * Create SPI write command sequence based on the destination register
68 * and the chip's supported command set.
69 */
70 switch (reg) {
71 case STATUS1:
72 write_cmd[0] = JEDEC_WRSR;
73 write_cmd[1] = value;
74 write_cmd_len = JEDEC_WRSR_OUTSIZE;
75 break;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +110076 case STATUS2:
77 if (feature_bits & FEATURE_WRSR2) {
78 write_cmd[0] = JEDEC_WRSR2;
79 write_cmd[1] = value;
80 write_cmd_len = JEDEC_WRSR2_OUTSIZE;
81 break;
82 }
Nico Huber3f3c1f32022-05-28 16:48:26 +020083 if (feature_bits & FEATURE_WRSR_EXT2) {
84 if (spi_prepare_wrsr_ext(write_cmd, &write_cmd_len, flash, reg, value))
Nikolai Artemiev9de3f872021-10-20 22:32:25 +110085 return 1;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +110086 break;
87 }
88 msg_cerr("Cannot write SR2: unsupported by chip\n");
89 return 1;
Sergii Dmytruk0b2e7dd2021-12-19 18:37:51 +020090 case STATUS3:
Nico Huber3f3c1f32022-05-28 16:48:26 +020091 if (feature_bits & FEATURE_WRSR3) {
92 write_cmd[0] = JEDEC_WRSR3;
93 write_cmd[1] = value;
94 write_cmd_len = JEDEC_WRSR3_OUTSIZE;
95 break;
96 }
97 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3) {
98 if (spi_prepare_wrsr_ext(write_cmd, &write_cmd_len, flash, reg, value))
99 return 1;
100 break;
101 }
102 msg_cerr("Cannot write SR3: unsupported by chip\n");
103 return 1;
Sergii Dmytruk3d728e72021-11-27 15:14:27 +0200104 case SECURITY:
105 /*
106 * Security register doesn't have a normal write operation. Instead,
107 * there are separate commands that set individual OTP bits.
108 */
109 msg_cerr("Cannot write SECURITY: unsupported by design\n");
110 return 1;
Sergii Dmytrukbd72a472022-07-24 17:11:05 +0300111 case CONFIG:
112 /*
113 * This one is read via a separate command, but written as if it's SR2
114 * in FEATURE_WRSR_EXT2 case of WRSR command.
115 */
116 write_cmd[0] = JEDEC_WRSR;
117 if (spi_read_register(flash, STATUS1, &write_cmd[1])) {
118 msg_cerr("Writing CONFIG failed: failed to read SR1 for writeback.\n");
119 return 1;
120 }
121 write_cmd[2] = value;
122 write_cmd_len = 3;
123 break;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100124 default:
125 msg_cerr("Cannot write register: unknown register\n");
126 return 1;
127 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000128
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100129 uint8_t enable_cmd;
130 if (feature_bits & FEATURE_WRSR_WREN) {
131 enable_cmd = JEDEC_WREN;
132 } else if (feature_bits & FEATURE_WRSR_EWSR) {
133 enable_cmd = JEDEC_EWSR;
134 } else {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000135 msg_cdbg("Missing status register write definition, assuming "
136 "EWSR is needed\n");
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100137 enable_cmd = JEDEC_EWSR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000138 }
Nikolai Artemiev01675222021-10-20 22:30:41 +1100139
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100140 struct spi_command cmds[] = {
141 {
Nico Huberd5185632024-01-05 18:44:41 +0100142 .opcode_len = JEDEC_WREN_OUTSIZE,
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100143 .writearr = &enable_cmd,
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100144 }, {
Nico Huberd5185632024-01-05 18:44:41 +0100145 .opcode_len = 1,
146 .write_len = write_cmd_len - 1,
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100147 .writearr = write_cmd,
Nico Huberd5185632024-01-05 18:44:41 +0100148 },
149 NULL_SPI_CMD
150 };
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100151
152 int result = spi_send_multicommand(flash, cmds);
153 if (result) {
154 msg_cerr("%s failed during command execution\n", __func__);
155 return result;
156 }
157
158 /*
159 * WRSR performs a self-timed erase before the changes take effect.
160 * This may take 50-85 ms in most cases, and some chips apparently
161 * allow running RDSR only once. Therefore pick an initial delay of
162 * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed.
163 *
164 * Newer chips with multiple status registers (SR2 etc.) are unlikely
165 * to have problems with multiple RDSR commands, so only wait for the
166 * initial 100 ms if the register we wrote to was SR1.
167 */
168 int delay_ms = 5000;
169 if (reg == STATUS1) {
170 programmer_delay(100 * 1000);
171 delay_ms -= 100;
172 }
173
174 for (; delay_ms > 0; delay_ms -= 10) {
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100175 uint8_t status;
176 result = spi_read_register(flash, STATUS1, &status);
177 if (result)
178 return result;
179 if ((status & SPI_SR_WIP) == 0)
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100180 return 0;
181 programmer_delay(10 * 1000);
182 }
183
184
185 msg_cerr("Error: WIP bit after WRSR never cleared\n");
186 return TIMEOUT_ERROR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000187}
188
Nikolai Artemiev01675222021-10-20 22:30:41 +1100189int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value)
190{
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100191 int feature_bits = flash->chip->feature_bits;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100192 uint8_t read_cmd;
193
194 switch (reg) {
195 case STATUS1:
196 read_cmd = JEDEC_RDSR;
197 break;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100198 case STATUS2:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200199 if (feature_bits & (FEATURE_WRSR_EXT2 | FEATURE_WRSR2)) {
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100200 read_cmd = JEDEC_RDSR2;
201 break;
202 }
203 msg_cerr("Cannot read SR2: unsupported by chip\n");
204 return 1;
Sergii Dmytruk0b2e7dd2021-12-19 18:37:51 +0200205 case STATUS3:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200206 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3
207 || (feature_bits & FEATURE_WRSR3)) {
208 read_cmd = JEDEC_RDSR3;
209 break;
210 }
211 msg_cerr("Cannot read SR3: unsupported by chip\n");
212 return 1;
Sergii Dmytruk3d728e72021-11-27 15:14:27 +0200213 case SECURITY:
214 read_cmd = JEDEC_RDSCUR;
215 break;
Sergii Dmytrukbd72a472022-07-24 17:11:05 +0300216 case CONFIG:
217 read_cmd = JEDEC_RDCR;
218 break;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100219 default:
220 msg_cerr("Cannot read register: unknown register\n");
221 return 1;
222 }
223
224 /* FIXME: No workarounds for driver/hardware bugs in generic code. */
225 /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */
226 uint8_t readarr[2];
227
228 int ret = spi_send_command(flash, sizeof(read_cmd), sizeof(readarr), &read_cmd, readarr);
229 if (ret) {
230 msg_cerr("Register read failed!\n");
231 return ret;
232 }
233
234 *value = readarr[0];
235 return 0;
236}
237
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100238static int spi_restore_status(struct flashctx *flash, uint8_t status)
239{
240 msg_cdbg("restoring chip status (0x%02x)\n", status);
Nikolai Artemiev01675222021-10-20 22:30:41 +1100241 return spi_write_register(flash, STATUS1, status);
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100242}
243
Stefan Tauner9530a022012-12-29 15:04:05 +0000244/* A generic block protection disable.
245 * Tests if a protection is enabled with the block protection mask (bp_mask) and returns success otherwise.
246 * Tests if the register bits are locked with the lock_mask (lock_mask).
Stefan Taunercecb2c52013-06-20 22:55:41 +0000247 * Tests if a hardware protection is active (i.e. low pin/high bit value) with the write protection mask
248 * (wp_mask) and bails out in that case.
249 * If there are register lock bits set we try to disable them by unsetting those bits of the previous register
250 * contents that are set in the lock_mask. We then check if removing the lock bits has worked and continue as if
251 * they never had been engaged:
252 * If the lock bits are out of the way try to disable engaged protections.
253 * To support uncommon global unprotects (e.g. on most AT2[56]xx1(A)) unprotect_mask can be used to force
254 * bits to 0 additionally to those set in bp_mask and lock_mask. Only bits set in unprotect_mask are potentially
255 * preserved when doing the final unprotect.
256 *
257 * To sum up:
258 * bp_mask: set those bits that correspond to the bits in the status register that indicate an active protection
259 * (which should be unset after this function returns).
260 * lock_mask: set the bits that correspond to the bits that lock changing the bits above.
261 * wp_mask: set the bits that correspond to bits indicating non-software revocable protections.
262 * unprotect_mask: set the bits that should be preserved if possible when unprotecting.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000263 */
Stefan Taunercecb2c52013-06-20 22:55:41 +0000264static 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 +0000265{
266 uint8_t status;
267 int result;
268
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100269 int ret = spi_read_register(flash, STATUS1, &status);
270 if (ret)
271 return ret;
272
Stefan Tauner9530a022012-12-29 15:04:05 +0000273 if ((status & bp_mask) == 0) {
274 msg_cdbg2("Block protection is disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000275 return 0;
Stefan Tauner9530a022012-12-29 15:04:05 +0000276 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000277
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100278 /* Restore status register content upon exit in finalize_flash_access(). */
279 register_chip_restore(spi_restore_status, flash, status);
280
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000281 msg_cdbg("Some block protection in effect, disabling... ");
Stefan Tauner9530a022012-12-29 15:04:05 +0000282 if ((status & lock_mask) != 0) {
283 msg_cdbg("\n\tNeed to disable the register lock first... ");
284 if (wp_mask != 0 && (status & wp_mask) == 0) {
285 msg_cerr("Hardware protection is active, disabling write protection is impossible.\n");
286 return 1;
287 }
288 /* All bits except the register lock bit (often called SPRL, SRWD, WPEN) are readonly. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100289 result = spi_write_register(flash, STATUS1, status & ~lock_mask);
Stefan Tauner9530a022012-12-29 15:04:05 +0000290 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100291 msg_cerr("Could not write status register 1.\n");
Stefan Tauner9530a022012-12-29 15:04:05 +0000292 return result;
293 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100294
295 ret = spi_read_register(flash, STATUS1, &status);
296 if (ret)
297 return ret;
298
Stefan Taunercecb2c52013-06-20 22:55:41 +0000299 if ((status & lock_mask) != 0) {
300 msg_cerr("Unsetting lock bit(s) failed.\n");
301 return 1;
302 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000303 msg_cdbg("done.\n");
304 }
305 /* Global unprotect. Make sure to mask the register lock bit as well. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100306 result = spi_write_register(flash, STATUS1, status & ~(bp_mask | lock_mask) & unprotect_mask);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000307 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100308 msg_cerr("Could not write status register 1.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000309 return result;
310 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100311
312 ret = spi_read_register(flash, STATUS1, &status);
313 if (ret)
314 return ret;
315
Stefan Tauner9530a022012-12-29 15:04:05 +0000316 if ((status & bp_mask) != 0) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000317 msg_cerr("Block protection could not be disabled!\n");
Yuji Sasaki4af36092019-03-22 10:59:50 -0700318 if (flash->chip->printlock)
319 flash->chip->printlock(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000320 return 1;
321 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000322 msg_cdbg("disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000323 return 0;
324}
325
Stefan Tauner9530a022012-12-29 15:04:05 +0000326/* A common block protection disable that tries to unset the status register bits masked by 0x3C. */
327int spi_disable_blockprotect(struct flashctx *flash)
328{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000329 return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000330}
331
Wei Hu25584de2018-04-30 14:02:08 -0700332int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
333{
334 int result = spi_write_enable(flash);
335 if (result)
336 return result;
337
338 static const unsigned char cmd[] = { 0x98 }; /* ULBPR */
339 result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL);
340 if (result)
341 msg_cerr("ULBPR failed\n");
342 return result;
343}
344
Stefan Taunera60d4082014-06-04 16:17:03 +0000345/* A common block protection disable that tries to unset the status register bits masked by 0x0C (BP0-1) and
346 * protected/locked by bit #7. Useful when bits 4-5 may be non-0). */
347int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
348{
349 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
350}
351
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000352/* A common block protection disable that tries to unset the status register bits masked by 0x1C (BP0-2) and
353 * protected/locked by bit #7. Useful when bit #5 is neither a protection bit nor reserved (and hence possibly
354 * non-0). */
355int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash)
356{
357 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0, 0xFF);
358}
359
360/* A common block protection disable that tries to unset the status register bits masked by 0x3C (BP0-3) and
361 * protected/locked by bit #7. */
362int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash)
363{
364 return spi_disable_blockprotect_generic(flash, 0x3C, 1 << 7, 0, 0xFF);
365}
366
367/* A common block protection disable that tries to unset the status register bits masked by 0x7C (BP0-4) and
368 * protected/locked by bit #7. */
369int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash)
370{
371 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
372}
Stefan Tauner9530a022012-12-29 15:04:05 +0000373
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000374static void spi_prettyprint_status_register_hex(uint8_t status)
375{
376 msg_cdbg("Chip status register is 0x%02x.\n", status);
377}
378
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000379/* Common highest bit: Status Register Write Disable (SRWD) or Status Register Protect (SRP). */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000380static void spi_prettyprint_status_register_srwd(uint8_t status)
381{
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000382 msg_cdbg("Chip status register: Status Register Write Disable (SRWD, SRP, ...) is %sset\n",
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000383 (status & (1 << 7)) ? "" : "not ");
384}
385
386/* Common highest bit: Block Protect Write Disable (BPL). */
387static void spi_prettyprint_status_register_bpl(uint8_t status)
388{
389 msg_cdbg("Chip status register: Block Protect Write Disable (BPL) is %sset\n",
390 (status & (1 << 7)) ? "" : "not ");
391}
392
393/* Common lowest 2 bits: WEL and WIP. */
394static void spi_prettyprint_status_register_welwip(uint8_t status)
395{
396 msg_cdbg("Chip status register: Write Enable Latch (WEL) is %sset\n",
397 (status & (1 << 1)) ? "" : "not ");
398 msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is %sset\n",
399 (status & (1 << 0)) ? "" : "not ");
400}
401
402/* Common block protection (BP) bits. */
403static void spi_prettyprint_status_register_bp(uint8_t status, int bp)
404{
405 switch (bp) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000406 case 4:
407 msg_cdbg("Chip status register: Block Protect 4 (BP4) is %sset\n",
Stefan Tauner5c316f92015-02-08 21:57:52 +0000408 (status & (1 << 6)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000409 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000410 case 3:
411 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
412 (status & (1 << 5)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000413 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000414 case 2:
415 msg_cdbg("Chip status register: Block Protect 2 (BP2) is %sset\n",
416 (status & (1 << 4)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000417 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000418 case 1:
419 msg_cdbg("Chip status register: Block Protect 1 (BP1) is %sset\n",
420 (status & (1 << 3)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000421 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000422 case 0:
423 msg_cdbg("Chip status register: Block Protect 0 (BP0) is %sset\n",
424 (status & (1 << 2)) ? "" : "not ");
425 }
426}
427
428/* Unnamed bits. */
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000429void spi_prettyprint_status_register_bit(uint8_t status, int bit)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000430{
431 msg_cdbg("Chip status register: Bit %i is %sset\n", bit, (status & (1 << bit)) ? "" : "not ");
432}
433
434int spi_prettyprint_status_register_plain(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 Tauner6ee37e22012-12-29 15:03:51 +0000440 spi_prettyprint_status_register_hex(status);
441 return 0;
442}
443
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000444/* Print the plain hex value and the welwip bits only. */
445int spi_prettyprint_status_register_default_welwip(struct flashctx *flash)
446{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100447 uint8_t status;
448 int ret = spi_read_register(flash, STATUS1, &status);
449 if (ret)
450 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000451 spi_prettyprint_status_register_hex(status);
452
453 spi_prettyprint_status_register_welwip(status);
454 return 0;
455}
456
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000457/* Works for many chips of the
458 * AMIC A25L series
459 * and MX MX25L512
460 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000461int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000462{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100463 uint8_t status;
464 int ret = spi_read_register(flash, STATUS1, &status);
465 if (ret)
466 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000467 spi_prettyprint_status_register_hex(status);
468
469 spi_prettyprint_status_register_srwd(status);
470 spi_prettyprint_status_register_bit(status, 6);
471 spi_prettyprint_status_register_bit(status, 5);
472 spi_prettyprint_status_register_bit(status, 4);
473 spi_prettyprint_status_register_bp(status, 1);
474 spi_prettyprint_status_register_welwip(status);
475 return 0;
476}
477
478/* Works for many chips of the
479 * AMIC A25L series
Stefan Taunerf4451612013-04-19 01:59:15 +0000480 * PMC Pm25LD series
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000481 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000482int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000483{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100484 uint8_t status;
485 int ret = spi_read_register(flash, STATUS1, &status);
486 if (ret)
487 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000488 spi_prettyprint_status_register_hex(status);
489
490 spi_prettyprint_status_register_srwd(status);
491 spi_prettyprint_status_register_bit(status, 6);
492 spi_prettyprint_status_register_bit(status, 5);
493 spi_prettyprint_status_register_bp(status, 2);
494 spi_prettyprint_status_register_welwip(status);
495 return 0;
496}
497
498/* Works for many chips of the
499 * ST M25P series
500 * MX MX25L series
501 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000502int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000503{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100504 uint8_t status;
505 int ret = spi_read_register(flash, STATUS1, &status);
506 if (ret)
507 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000508 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_bp(status, 3);
513 spi_prettyprint_status_register_welwip(status);
514 return 0;
515}
516
Stefan Tauner12f3d512014-05-27 21:27:27 +0000517int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash)
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000518{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100519 uint8_t status;
520 int ret = spi_read_register(flash, STATUS1, &status);
521 if (ret)
522 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000523 spi_prettyprint_status_register_hex(status);
524
525 spi_prettyprint_status_register_srwd(status);
526 spi_prettyprint_status_register_bp(status, 4);
527 spi_prettyprint_status_register_welwip(status);
528 return 0;
529}
530
Stefan Tauner85f09f72014-05-27 21:27:14 +0000531int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash)
532{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100533 uint8_t status;
534 int ret = spi_read_register(flash, STATUS1, &status);
535 if (ret)
536 return ret;
Stefan Tauner85f09f72014-05-27 21:27:14 +0000537 spi_prettyprint_status_register_hex(status);
538
539 spi_prettyprint_status_register_bpl(status);
540 spi_prettyprint_status_register_bit(status, 6);
541 spi_prettyprint_status_register_bit(status, 5);
542 spi_prettyprint_status_register_bp(status, 2);
543 spi_prettyprint_status_register_welwip(status);
544 return 0;
545}
546
Ben Gardnerbcf61092015-11-22 02:23:31 +0000547int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash)
548{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100549 uint8_t status;
550 int ret = spi_read_register(flash, STATUS1, &status);
551 if (ret)
552 return ret;
Ben Gardnerbcf61092015-11-22 02:23:31 +0000553 spi_prettyprint_status_register_hex(status);
554
555 spi_prettyprint_status_register_bpl(status);
556 spi_prettyprint_status_register_bit(status, 6);
557 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
558 spi_prettyprint_status_register_bp(status, 2);
559 spi_prettyprint_status_register_welwip(status);
560 return 0;
561}
562
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000563/* === Amic ===
564 * FIXME: spi_disable_blockprotect is incorrect but works fine for chips using
Stefan Tauner12f3d512014-05-27 21:27:27 +0000565 * spi_prettyprint_status_register_bp1_srwd or
566 * spi_prettyprint_status_register_bp2_srwd.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000567 * FIXME: spi_disable_blockprotect is incorrect and will fail for chips using
568 * spi_prettyprint_status_register_amic_a25l032 if those have locks controlled
569 * by the second status register.
570 */
571
572int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash)
573{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100574 uint8_t status;
575 int ret = spi_read_register(flash, STATUS1, &status);
576 if (ret)
577 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000578 spi_prettyprint_status_register_hex(status);
579
580 spi_prettyprint_status_register_srwd(status);
581 msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64);
582 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
583 spi_prettyprint_status_register_bp(status, 2);
584 spi_prettyprint_status_register_welwip(status);
585 msg_cdbg("Chip status register 2 is NOT decoded!\n");
586 return 0;
587}
588
589/* === Atmel === */
590
591static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)
592{
593 msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n",
594 (status & (1 << 7)) ? "" : "not ");
595}
596
597static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
598{
599 msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n",
600 (status & (1 << 7)) ? "" : "not ");
601}
602
603static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)
604{
605 msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n",
606 (status & (1 << 5)) ? "" : "not ");
607 msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n",
608 (status & (1 << 4)) ? "not " : "");
609}
610
611static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
612{
613 msg_cdbg("Chip status register: Software Protection Status (SWP): ");
614 switch (status & (3 << 2)) {
615 case 0x0 << 2:
616 msg_cdbg("no sectors are protected\n");
617 break;
618 case 0x1 << 2:
619 msg_cdbg("some sectors are protected\n");
620 /* FIXME: Read individual Sector Protection Registers. */
621 break;
622 case 0x3 << 2:
623 msg_cdbg("all sectors are protected\n");
624 break;
625 default:
626 msg_cdbg("reserved for future use\n");
627 break;
628 }
629}
630
631int spi_prettyprint_status_register_at25df(struct flashctx *flash)
632{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100633 uint8_t status;
634 int ret = spi_read_register(flash, STATUS1, &status);
635 if (ret)
636 return ret;
637
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000638 spi_prettyprint_status_register_hex(status);
639
640 spi_prettyprint_status_register_atmel_at25_srpl(status);
641 spi_prettyprint_status_register_bit(status, 6);
642 spi_prettyprint_status_register_atmel_at25_epewpp(status);
643 spi_prettyprint_status_register_atmel_at25_swp(status);
644 spi_prettyprint_status_register_welwip(status);
645 return 0;
646}
647
648int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
649{
650 /* FIXME: We should check the security lockdown. */
651 msg_cdbg("Ignoring security lockdown (if present)\n");
652 msg_cdbg("Ignoring status register byte 2\n");
653 return spi_prettyprint_status_register_at25df(flash);
654}
655
Stefan Tauner57794ac2012-12-29 15:04:20 +0000656/* used for AT25F512, AT25F1024(A), AT25F2048 */
657int spi_prettyprint_status_register_at25f(struct flashctx *flash)
658{
659 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100660 int ret = spi_read_register(flash, STATUS1, &status);
661 if (ret)
662 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000663
Stefan Tauner57794ac2012-12-29 15:04:20 +0000664 spi_prettyprint_status_register_hex(status);
665
666 spi_prettyprint_status_register_atmel_at25_wpen(status);
667 spi_prettyprint_status_register_bit(status, 6);
668 spi_prettyprint_status_register_bit(status, 5);
669 spi_prettyprint_status_register_bit(status, 4);
670 spi_prettyprint_status_register_bp(status, 1);
671 spi_prettyprint_status_register_welwip(status);
672 return 0;
673}
674
675int spi_prettyprint_status_register_at25f512a(struct flashctx *flash)
676{
677 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100678 int ret = spi_read_register(flash, STATUS1, &status);
679 if (ret)
680 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000681
Stefan Tauner57794ac2012-12-29 15:04:20 +0000682 spi_prettyprint_status_register_hex(status);
683
684 spi_prettyprint_status_register_atmel_at25_wpen(status);
685 spi_prettyprint_status_register_bit(status, 6);
686 spi_prettyprint_status_register_bit(status, 5);
687 spi_prettyprint_status_register_bit(status, 4);
688 spi_prettyprint_status_register_bit(status, 3);
689 spi_prettyprint_status_register_bp(status, 0);
690 spi_prettyprint_status_register_welwip(status);
691 return 0;
692}
693
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000694int spi_prettyprint_status_register_at25f512b(struct flashctx *flash)
695{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100696 uint8_t status;
697 int ret = spi_read_register(flash, STATUS1, &status);
698 if (ret)
699 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000700 spi_prettyprint_status_register_hex(status);
701
702 spi_prettyprint_status_register_atmel_at25_srpl(status);
703 spi_prettyprint_status_register_bit(status, 6);
704 spi_prettyprint_status_register_atmel_at25_epewpp(status);
705 spi_prettyprint_status_register_bit(status, 3);
706 spi_prettyprint_status_register_bp(status, 0);
707 spi_prettyprint_status_register_welwip(status);
708 return 0;
709}
710
Stefan Tauner57794ac2012-12-29 15:04:20 +0000711int spi_prettyprint_status_register_at25f4096(struct flashctx *flash)
712{
713 uint8_t status;
714
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100715 int ret = spi_read_register(flash, STATUS1, &status);
716 if (ret)
717 return ret;
718
Stefan Tauner57794ac2012-12-29 15:04:20 +0000719 spi_prettyprint_status_register_hex(status);
720
721 spi_prettyprint_status_register_atmel_at25_wpen(status);
722 spi_prettyprint_status_register_bit(status, 6);
723 spi_prettyprint_status_register_bit(status, 5);
724 spi_prettyprint_status_register_bp(status, 2);
725 spi_prettyprint_status_register_welwip(status);
726 return 0;
727}
728
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000729int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
730{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100731 uint8_t status;
732 int ret = spi_read_register(flash, STATUS1, &status);
733 if (ret)
734 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000735 spi_prettyprint_status_register_hex(status);
736
737 spi_prettyprint_status_register_atmel_at25_wpen(status);
738 msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is "
739 "%sset\n", (status & (1 << 6)) ? "" : "not ");
740 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
741 "%sset\n", (status & (1 << 5)) ? "" : "not ");
742 spi_prettyprint_status_register_bit(status, 4);
743 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
744 "%sset\n", (status & (1 << 3)) ? "" : "not ");
745 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
746 "%sset\n", (status & (1 << 2)) ? "" : "not ");
747 /* FIXME: Pretty-print detailed sector protection status. */
748 spi_prettyprint_status_register_welwip(status);
749 return 0;
750}
751
752int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
753{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100754 uint8_t status;
755 int ret = spi_read_register(flash, STATUS1, &status);
756 if (ret)
757 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000758 spi_prettyprint_status_register_hex(status);
759
760 spi_prettyprint_status_register_atmel_at25_wpen(status);
761 spi_prettyprint_status_register_bp(status, 4);
762 /* FIXME: Pretty-print detailed sector protection status. */
763 spi_prettyprint_status_register_welwip(status);
764 return 0;
765}
766
767int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
768{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100769 uint8_t status;
770 int ret = spi_read_register(flash, STATUS1, &status);
771 if (ret)
772 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000773 spi_prettyprint_status_register_hex(status);
774
775 spi_prettyprint_status_register_atmel_at25_srpl(status);
776 msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n",
777 (status & (1 << 6)) ? "" : "not ");
778 spi_prettyprint_status_register_atmel_at25_epewpp(status);
779 spi_prettyprint_status_register_atmel_at25_swp(status);
780 spi_prettyprint_status_register_welwip(status);
781 return 0;
782}
783
Stefan Taunercecb2c52013-06-20 22:55:41 +0000784/* Some Atmel DataFlash chips support per sector protection bits and the write protection bits in the status
785 * register do indicate if none, some or all sectors are protected. It is possible to globally (un)lock all
786 * sectors at once by writing 0 not only the protection bits (2 and 3) but also completely unrelated bits (4 and
787 * 5) which normally are not touched.
788 * Affected are all known Atmel chips matched by AT2[56]D[FLQ]..1A? but the AT26DF041. */
789int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000790{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000791 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4, 0x00);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000792}
793
Stefan Taunercecb2c52013-06-20 22:55:41 +0000794int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000795{
796 /* FIXME: We should check the security lockdown. */
797 msg_cinfo("Ignoring security lockdown (if present)\n");
Stefan Taunercecb2c52013-06-20 22:55:41 +0000798 return spi_disable_blockprotect_at2x_global_unprotect(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000799}
800
Stefan Tauner57794ac2012-12-29 15:04:20 +0000801int spi_disable_blockprotect_at25f(struct flashctx *flash)
802{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000803 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000804}
805
806int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
807{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000808 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000809}
810
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000811int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
812{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000813 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 1 << 4, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000814}
815
816int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
817{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000818 return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000819 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000820
821int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
822{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000823 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000824}
825
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000826/* === Eon === */
827
828int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash)
829{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100830 uint8_t status;
831 int ret = spi_read_register(flash, STATUS1, &status);
832 if (ret)
833 return ret;
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000834 spi_prettyprint_status_register_hex(status);
835
836 spi_prettyprint_status_register_srwd(status);
837 msg_cdbg("Chip status register: WP# disable (WPDIS) is %sabled\n", (status & (1 << 6)) ? "en " : "dis");
838 spi_prettyprint_status_register_bp(status, 3);
839 spi_prettyprint_status_register_welwip(status);
840 return 0;
841}
842
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000843/* === Intel/Numonyx/Micron - Spansion === */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000844
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000845int spi_disable_blockprotect_n25q(struct flashctx *flash)
846{
847 return spi_disable_blockprotect_generic(flash, 0x5C, 1 << 7, 0, 0xFF);
848}
849
850int spi_prettyprint_status_register_n25q(struct flashctx *flash)
851{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100852 uint8_t status;
853 int ret = spi_read_register(flash, STATUS1, &status);
854 if (ret)
855 return ret;
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000856 spi_prettyprint_status_register_hex(status);
857
858 spi_prettyprint_status_register_srwd(status);
859 if (flash->chip->total_size <= 32 / 8 * 1024) /* N25Q16 and N25Q32: reserved */
860 spi_prettyprint_status_register_bit(status, 6);
861 else
862 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
863 (status & (1 << 6)) ? "" : "not ");
864 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
865 spi_prettyprint_status_register_bp(status, 2);
866 spi_prettyprint_status_register_welwip(status);
867 return 0;
868}
869
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000870/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000871/* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000872int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000873{
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000874 return spi_disable_blockprotect_bp2_srwd(flash);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000875}
876
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000877/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
878int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000879{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100880 uint8_t status;
881 int ret = spi_read_register(flash, STATUS1, &status);
882 if (ret)
883 return ret;
Stefan Taunerc2eec2c2014-05-03 21:33:01 +0000884 spi_prettyprint_status_register_hex(status);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000885
886 spi_prettyprint_status_register_srwd(status);
887 msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n",
888 (status & (1 << 6)) ? "" : "not ");
889 msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n",
890 (status & (1 << 5)) ? "" : "not ");
891 spi_prettyprint_status_register_bp(status, 2);
892 spi_prettyprint_status_register_welwip(status);
893 return 0;
894}
895
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000896/* === SST === */
897
898static void spi_prettyprint_status_register_sst25_common(uint8_t status)
899{
900 spi_prettyprint_status_register_hex(status);
901
902 spi_prettyprint_status_register_bpl(status);
903 msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n",
904 (status & (1 << 6)) ? "" : "not ");
905 spi_prettyprint_status_register_bp(status, 3);
906 spi_prettyprint_status_register_welwip(status);
907}
908
909int spi_prettyprint_status_register_sst25(struct flashctx *flash)
910{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100911 uint8_t status;
912 int ret = spi_read_register(flash, STATUS1, &status);
913 if (ret)
914 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000915 spi_prettyprint_status_register_sst25_common(status);
916 return 0;
917}
918
919int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash)
920{
921 static const char *const bpt[] = {
922 "none",
923 "1F0000H-1FFFFFH",
924 "1E0000H-1FFFFFH",
925 "1C0000H-1FFFFFH",
926 "180000H-1FFFFFH",
927 "100000H-1FFFFFH",
928 "all", "all"
929 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100930 uint8_t status;
931 int ret = spi_read_register(flash, STATUS1, &status);
932 if (ret)
933 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000934 spi_prettyprint_status_register_sst25_common(status);
935 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
936 return 0;
937}
938
939int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash)
940{
941 static const char *const bpt[] = {
942 "none",
943 "0x70000-0x7ffff",
944 "0x60000-0x7ffff",
945 "0x40000-0x7ffff",
946 "all blocks", "all blocks", "all blocks", "all blocks"
947 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100948 uint8_t status;
949 int ret = spi_read_register(flash, STATUS1, &status);
950 if (ret)
951 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000952 spi_prettyprint_status_register_sst25_common(status);
953 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
954 return 0;
955}