blob: 5dbba75cad6786e59d35767e34e0e30e991a3620 [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;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100103 default:
104 msg_cerr("Cannot write register: unknown register\n");
105 return 1;
106 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000107
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100108 uint8_t enable_cmd;
109 if (feature_bits & FEATURE_WRSR_WREN) {
110 enable_cmd = JEDEC_WREN;
111 } else if (feature_bits & FEATURE_WRSR_EWSR) {
112 enable_cmd = JEDEC_EWSR;
113 } else {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000114 msg_cdbg("Missing status register write definition, assuming "
115 "EWSR is needed\n");
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100116 enable_cmd = JEDEC_EWSR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000117 }
Nikolai Artemiev01675222021-10-20 22:30:41 +1100118
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100119 struct spi_command cmds[] = {
120 {
121 .writecnt = JEDEC_WREN_OUTSIZE,
122 .writearr = &enable_cmd,
123 .readcnt = 0,
124 .readarr = NULL,
125 }, {
126 .writecnt = write_cmd_len,
127 .writearr = write_cmd,
128 .readcnt = 0,
129 .readarr = NULL,
130 }, {
131 .writecnt = 0,
132 .writearr = NULL,
133 .readcnt = 0,
134 .readarr = NULL,
135 }};
136
137 int result = spi_send_multicommand(flash, cmds);
138 if (result) {
139 msg_cerr("%s failed during command execution\n", __func__);
140 return result;
141 }
142
143 /*
144 * WRSR performs a self-timed erase before the changes take effect.
145 * This may take 50-85 ms in most cases, and some chips apparently
146 * allow running RDSR only once. Therefore pick an initial delay of
147 * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed.
148 *
149 * Newer chips with multiple status registers (SR2 etc.) are unlikely
150 * to have problems with multiple RDSR commands, so only wait for the
151 * initial 100 ms if the register we wrote to was SR1.
152 */
153 int delay_ms = 5000;
154 if (reg == STATUS1) {
155 programmer_delay(100 * 1000);
156 delay_ms -= 100;
157 }
158
159 for (; delay_ms > 0; delay_ms -= 10) {
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100160 uint8_t status;
161 result = spi_read_register(flash, STATUS1, &status);
162 if (result)
163 return result;
164 if ((status & SPI_SR_WIP) == 0)
Nikolai Artemieva1d68652021-11-22 13:18:49 +1100165 return 0;
166 programmer_delay(10 * 1000);
167 }
168
169
170 msg_cerr("Error: WIP bit after WRSR never cleared\n");
171 return TIMEOUT_ERROR;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000172}
173
Nikolai Artemiev01675222021-10-20 22:30:41 +1100174int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value)
175{
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100176 int feature_bits = flash->chip->feature_bits;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100177 uint8_t read_cmd;
178
179 switch (reg) {
180 case STATUS1:
181 read_cmd = JEDEC_RDSR;
182 break;
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100183 case STATUS2:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200184 if (feature_bits & (FEATURE_WRSR_EXT2 | FEATURE_WRSR2)) {
Nikolai Artemiev9de3f872021-10-20 22:32:25 +1100185 read_cmd = JEDEC_RDSR2;
186 break;
187 }
188 msg_cerr("Cannot read SR2: unsupported by chip\n");
189 return 1;
Sergii Dmytruk0b2e7dd2021-12-19 18:37:51 +0200190 case STATUS3:
Nico Huber3f3c1f32022-05-28 16:48:26 +0200191 if ((feature_bits & FEATURE_WRSR_EXT3) == FEATURE_WRSR_EXT3
192 || (feature_bits & FEATURE_WRSR3)) {
193 read_cmd = JEDEC_RDSR3;
194 break;
195 }
196 msg_cerr("Cannot read SR3: unsupported by chip\n");
197 return 1;
Nikolai Artemiev01675222021-10-20 22:30:41 +1100198 default:
199 msg_cerr("Cannot read register: unknown register\n");
200 return 1;
201 }
202
203 /* FIXME: No workarounds for driver/hardware bugs in generic code. */
204 /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */
205 uint8_t readarr[2];
206
207 int ret = spi_send_command(flash, sizeof(read_cmd), sizeof(readarr), &read_cmd, readarr);
208 if (ret) {
209 msg_cerr("Register read failed!\n");
210 return ret;
211 }
212
213 *value = readarr[0];
214 return 0;
215}
216
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100217static int spi_restore_status(struct flashctx *flash, uint8_t status)
218{
219 msg_cdbg("restoring chip status (0x%02x)\n", status);
Nikolai Artemiev01675222021-10-20 22:30:41 +1100220 return spi_write_register(flash, STATUS1, status);
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100221}
222
Stefan Tauner9530a022012-12-29 15:04:05 +0000223/* A generic block protection disable.
224 * Tests if a protection is enabled with the block protection mask (bp_mask) and returns success otherwise.
225 * Tests if the register bits are locked with the lock_mask (lock_mask).
Stefan Taunercecb2c52013-06-20 22:55:41 +0000226 * Tests if a hardware protection is active (i.e. low pin/high bit value) with the write protection mask
227 * (wp_mask) and bails out in that case.
228 * If there are register lock bits set we try to disable them by unsetting those bits of the previous register
229 * contents that are set in the lock_mask. We then check if removing the lock bits has worked and continue as if
230 * they never had been engaged:
231 * If the lock bits are out of the way try to disable engaged protections.
232 * To support uncommon global unprotects (e.g. on most AT2[56]xx1(A)) unprotect_mask can be used to force
233 * bits to 0 additionally to those set in bp_mask and lock_mask. Only bits set in unprotect_mask are potentially
234 * preserved when doing the final unprotect.
235 *
236 * To sum up:
237 * bp_mask: set those bits that correspond to the bits in the status register that indicate an active protection
238 * (which should be unset after this function returns).
239 * lock_mask: set the bits that correspond to the bits that lock changing the bits above.
240 * wp_mask: set the bits that correspond to bits indicating non-software revocable protections.
241 * unprotect_mask: set the bits that should be preserved if possible when unprotecting.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000242 */
Stefan Taunercecb2c52013-06-20 22:55:41 +0000243static 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 +0000244{
245 uint8_t status;
246 int result;
247
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100248 int ret = spi_read_register(flash, STATUS1, &status);
249 if (ret)
250 return ret;
251
Stefan Tauner9530a022012-12-29 15:04:05 +0000252 if ((status & bp_mask) == 0) {
253 msg_cdbg2("Block protection is disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000254 return 0;
Stefan Tauner9530a022012-12-29 15:04:05 +0000255 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000256
Nikolai Artemiev721a4f32020-12-14 07:39:02 +1100257 /* Restore status register content upon exit in finalize_flash_access(). */
258 register_chip_restore(spi_restore_status, flash, status);
259
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000260 msg_cdbg("Some block protection in effect, disabling... ");
Stefan Tauner9530a022012-12-29 15:04:05 +0000261 if ((status & lock_mask) != 0) {
262 msg_cdbg("\n\tNeed to disable the register lock first... ");
263 if (wp_mask != 0 && (status & wp_mask) == 0) {
264 msg_cerr("Hardware protection is active, disabling write protection is impossible.\n");
265 return 1;
266 }
267 /* All bits except the register lock bit (often called SPRL, SRWD, WPEN) are readonly. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100268 result = spi_write_register(flash, STATUS1, status & ~lock_mask);
Stefan Tauner9530a022012-12-29 15:04:05 +0000269 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100270 msg_cerr("Could not write status register 1.\n");
Stefan Tauner9530a022012-12-29 15:04:05 +0000271 return result;
272 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100273
274 ret = spi_read_register(flash, STATUS1, &status);
275 if (ret)
276 return ret;
277
Stefan Taunercecb2c52013-06-20 22:55:41 +0000278 if ((status & lock_mask) != 0) {
279 msg_cerr("Unsetting lock bit(s) failed.\n");
280 return 1;
281 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000282 msg_cdbg("done.\n");
283 }
284 /* Global unprotect. Make sure to mask the register lock bit as well. */
Nikolai Artemiev01675222021-10-20 22:30:41 +1100285 result = spi_write_register(flash, STATUS1, status & ~(bp_mask | lock_mask) & unprotect_mask);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000286 if (result) {
Nikolai Artemiev01675222021-10-20 22:30:41 +1100287 msg_cerr("Could not write status register 1.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000288 return result;
289 }
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100290
291 ret = spi_read_register(flash, STATUS1, &status);
292 if (ret)
293 return ret;
294
Stefan Tauner9530a022012-12-29 15:04:05 +0000295 if ((status & bp_mask) != 0) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000296 msg_cerr("Block protection could not be disabled!\n");
Yuji Sasaki4af36092019-03-22 10:59:50 -0700297 if (flash->chip->printlock)
298 flash->chip->printlock(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000299 return 1;
300 }
Stefan Tauner9530a022012-12-29 15:04:05 +0000301 msg_cdbg("disabled.\n");
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000302 return 0;
303}
304
Stefan Tauner9530a022012-12-29 15:04:05 +0000305/* A common block protection disable that tries to unset the status register bits masked by 0x3C. */
306int spi_disable_blockprotect(struct flashctx *flash)
307{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000308 return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000309}
310
Wei Hu25584de2018-04-30 14:02:08 -0700311int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
312{
313 int result = spi_write_enable(flash);
314 if (result)
315 return result;
316
317 static const unsigned char cmd[] = { 0x98 }; /* ULBPR */
318 result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL);
319 if (result)
320 msg_cerr("ULBPR failed\n");
321 return result;
322}
323
Stefan Taunera60d4082014-06-04 16:17:03 +0000324/* A common block protection disable that tries to unset the status register bits masked by 0x0C (BP0-1) and
325 * protected/locked by bit #7. Useful when bits 4-5 may be non-0). */
326int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
327{
328 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
329}
330
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000331/* A common block protection disable that tries to unset the status register bits masked by 0x1C (BP0-2) and
332 * protected/locked by bit #7. Useful when bit #5 is neither a protection bit nor reserved (and hence possibly
333 * non-0). */
334int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash)
335{
336 return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0, 0xFF);
337}
338
339/* A common block protection disable that tries to unset the status register bits masked by 0x3C (BP0-3) and
340 * protected/locked by bit #7. */
341int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash)
342{
343 return spi_disable_blockprotect_generic(flash, 0x3C, 1 << 7, 0, 0xFF);
344}
345
346/* A common block protection disable that tries to unset the status register bits masked by 0x7C (BP0-4) and
347 * protected/locked by bit #7. */
348int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash)
349{
350 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
351}
Stefan Tauner9530a022012-12-29 15:04:05 +0000352
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000353static void spi_prettyprint_status_register_hex(uint8_t status)
354{
355 msg_cdbg("Chip status register is 0x%02x.\n", status);
356}
357
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000358/* Common highest bit: Status Register Write Disable (SRWD) or Status Register Protect (SRP). */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000359static void spi_prettyprint_status_register_srwd(uint8_t status)
360{
Stefan Taunerb6b00e92013-06-28 21:28:43 +0000361 msg_cdbg("Chip status register: Status Register Write Disable (SRWD, SRP, ...) is %sset\n",
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000362 (status & (1 << 7)) ? "" : "not ");
363}
364
365/* Common highest bit: Block Protect Write Disable (BPL). */
366static void spi_prettyprint_status_register_bpl(uint8_t status)
367{
368 msg_cdbg("Chip status register: Block Protect Write Disable (BPL) is %sset\n",
369 (status & (1 << 7)) ? "" : "not ");
370}
371
372/* Common lowest 2 bits: WEL and WIP. */
373static void spi_prettyprint_status_register_welwip(uint8_t status)
374{
375 msg_cdbg("Chip status register: Write Enable Latch (WEL) is %sset\n",
376 (status & (1 << 1)) ? "" : "not ");
377 msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is %sset\n",
378 (status & (1 << 0)) ? "" : "not ");
379}
380
381/* Common block protection (BP) bits. */
382static void spi_prettyprint_status_register_bp(uint8_t status, int bp)
383{
384 switch (bp) {
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000385 case 4:
386 msg_cdbg("Chip status register: Block Protect 4 (BP4) is %sset\n",
Stefan Tauner5c316f92015-02-08 21:57:52 +0000387 (status & (1 << 6)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000388 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000389 case 3:
390 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
391 (status & (1 << 5)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000392 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000393 case 2:
394 msg_cdbg("Chip status register: Block Protect 2 (BP2) is %sset\n",
395 (status & (1 << 4)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000396 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000397 case 1:
398 msg_cdbg("Chip status register: Block Protect 1 (BP1) is %sset\n",
399 (status & (1 << 3)) ? "" : "not ");
Richard Hughesdb7482b2018-12-19 12:04:30 +0000400 /* Fall through. */
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000401 case 0:
402 msg_cdbg("Chip status register: Block Protect 0 (BP0) is %sset\n",
403 (status & (1 << 2)) ? "" : "not ");
404 }
405}
406
407/* Unnamed bits. */
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000408void spi_prettyprint_status_register_bit(uint8_t status, int bit)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000409{
410 msg_cdbg("Chip status register: Bit %i is %sset\n", bit, (status & (1 << bit)) ? "" : "not ");
411}
412
413int spi_prettyprint_status_register_plain(struct flashctx *flash)
414{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100415 uint8_t status;
416 int ret = spi_read_register(flash, STATUS1, &status);
417 if (ret)
418 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000419 spi_prettyprint_status_register_hex(status);
420 return 0;
421}
422
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000423/* Print the plain hex value and the welwip bits only. */
424int spi_prettyprint_status_register_default_welwip(struct flashctx *flash)
425{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100426 uint8_t status;
427 int ret = spi_read_register(flash, STATUS1, &status);
428 if (ret)
429 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000430 spi_prettyprint_status_register_hex(status);
431
432 spi_prettyprint_status_register_welwip(status);
433 return 0;
434}
435
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000436/* Works for many chips of the
437 * AMIC A25L series
438 * and MX MX25L512
439 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000440int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000441{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100442 uint8_t status;
443 int ret = spi_read_register(flash, STATUS1, &status);
444 if (ret)
445 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000446 spi_prettyprint_status_register_hex(status);
447
448 spi_prettyprint_status_register_srwd(status);
449 spi_prettyprint_status_register_bit(status, 6);
450 spi_prettyprint_status_register_bit(status, 5);
451 spi_prettyprint_status_register_bit(status, 4);
452 spi_prettyprint_status_register_bp(status, 1);
453 spi_prettyprint_status_register_welwip(status);
454 return 0;
455}
456
457/* Works for many chips of the
458 * AMIC A25L series
Stefan Taunerf4451612013-04-19 01:59:15 +0000459 * PMC Pm25LD series
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000460 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000461int spi_prettyprint_status_register_bp2_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_bp(status, 2);
473 spi_prettyprint_status_register_welwip(status);
474 return 0;
475}
476
477/* Works for many chips of the
478 * ST M25P series
479 * MX MX25L series
480 */
Stefan Tauner12f3d512014-05-27 21:27:27 +0000481int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000482{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100483 uint8_t status;
484 int ret = spi_read_register(flash, STATUS1, &status);
485 if (ret)
486 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000487 spi_prettyprint_status_register_hex(status);
488
489 spi_prettyprint_status_register_srwd(status);
490 spi_prettyprint_status_register_bit(status, 6);
491 spi_prettyprint_status_register_bp(status, 3);
492 spi_prettyprint_status_register_welwip(status);
493 return 0;
494}
495
Stefan Tauner12f3d512014-05-27 21:27:27 +0000496int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash)
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000497{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100498 uint8_t status;
499 int ret = spi_read_register(flash, STATUS1, &status);
500 if (ret)
501 return ret;
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000502 spi_prettyprint_status_register_hex(status);
503
504 spi_prettyprint_status_register_srwd(status);
505 spi_prettyprint_status_register_bp(status, 4);
506 spi_prettyprint_status_register_welwip(status);
507 return 0;
508}
509
Stefan Tauner85f09f72014-05-27 21:27:14 +0000510int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash)
511{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100512 uint8_t status;
513 int ret = spi_read_register(flash, STATUS1, &status);
514 if (ret)
515 return ret;
Stefan Tauner85f09f72014-05-27 21:27:14 +0000516 spi_prettyprint_status_register_hex(status);
517
518 spi_prettyprint_status_register_bpl(status);
519 spi_prettyprint_status_register_bit(status, 6);
520 spi_prettyprint_status_register_bit(status, 5);
521 spi_prettyprint_status_register_bp(status, 2);
522 spi_prettyprint_status_register_welwip(status);
523 return 0;
524}
525
Ben Gardnerbcf61092015-11-22 02:23:31 +0000526int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash)
527{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100528 uint8_t status;
529 int ret = spi_read_register(flash, STATUS1, &status);
530 if (ret)
531 return ret;
Ben Gardnerbcf61092015-11-22 02:23:31 +0000532 spi_prettyprint_status_register_hex(status);
533
534 spi_prettyprint_status_register_bpl(status);
535 spi_prettyprint_status_register_bit(status, 6);
536 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
537 spi_prettyprint_status_register_bp(status, 2);
538 spi_prettyprint_status_register_welwip(status);
539 return 0;
540}
541
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000542/* === Amic ===
543 * FIXME: spi_disable_blockprotect is incorrect but works fine for chips using
Stefan Tauner12f3d512014-05-27 21:27:27 +0000544 * spi_prettyprint_status_register_bp1_srwd or
545 * spi_prettyprint_status_register_bp2_srwd.
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000546 * FIXME: spi_disable_blockprotect is incorrect and will fail for chips using
547 * spi_prettyprint_status_register_amic_a25l032 if those have locks controlled
548 * by the second status register.
549 */
550
551int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash)
552{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100553 uint8_t status;
554 int ret = spi_read_register(flash, STATUS1, &status);
555 if (ret)
556 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000557 spi_prettyprint_status_register_hex(status);
558
559 spi_prettyprint_status_register_srwd(status);
560 msg_cdbg("Chip status register: Sector Protect Size (SEC) is %i KB\n", (status & (1 << 6)) ? 4 : 64);
561 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
562 spi_prettyprint_status_register_bp(status, 2);
563 spi_prettyprint_status_register_welwip(status);
564 msg_cdbg("Chip status register 2 is NOT decoded!\n");
565 return 0;
566}
567
568/* === Atmel === */
569
570static void spi_prettyprint_status_register_atmel_at25_wpen(uint8_t status)
571{
572 msg_cdbg("Chip status register: Write Protect Enable (WPEN) is %sset\n",
573 (status & (1 << 7)) ? "" : "not ");
574}
575
576static void spi_prettyprint_status_register_atmel_at25_srpl(uint8_t status)
577{
578 msg_cdbg("Chip status register: Sector Protection Register Lock (SRPL) is %sset\n",
579 (status & (1 << 7)) ? "" : "not ");
580}
581
582static void spi_prettyprint_status_register_atmel_at25_epewpp(uint8_t status)
583{
584 msg_cdbg("Chip status register: Erase/Program Error (EPE) is %sset\n",
585 (status & (1 << 5)) ? "" : "not ");
586 msg_cdbg("Chip status register: WP# pin (WPP) is %sasserted\n",
587 (status & (1 << 4)) ? "not " : "");
588}
589
590static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
591{
592 msg_cdbg("Chip status register: Software Protection Status (SWP): ");
593 switch (status & (3 << 2)) {
594 case 0x0 << 2:
595 msg_cdbg("no sectors are protected\n");
596 break;
597 case 0x1 << 2:
598 msg_cdbg("some sectors are protected\n");
599 /* FIXME: Read individual Sector Protection Registers. */
600 break;
601 case 0x3 << 2:
602 msg_cdbg("all sectors are protected\n");
603 break;
604 default:
605 msg_cdbg("reserved for future use\n");
606 break;
607 }
608}
609
610int spi_prettyprint_status_register_at25df(struct flashctx *flash)
611{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100612 uint8_t status;
613 int ret = spi_read_register(flash, STATUS1, &status);
614 if (ret)
615 return ret;
616
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000617 spi_prettyprint_status_register_hex(status);
618
619 spi_prettyprint_status_register_atmel_at25_srpl(status);
620 spi_prettyprint_status_register_bit(status, 6);
621 spi_prettyprint_status_register_atmel_at25_epewpp(status);
622 spi_prettyprint_status_register_atmel_at25_swp(status);
623 spi_prettyprint_status_register_welwip(status);
624 return 0;
625}
626
627int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
628{
629 /* FIXME: We should check the security lockdown. */
630 msg_cdbg("Ignoring security lockdown (if present)\n");
631 msg_cdbg("Ignoring status register byte 2\n");
632 return spi_prettyprint_status_register_at25df(flash);
633}
634
Stefan Tauner57794ac2012-12-29 15:04:20 +0000635/* used for AT25F512, AT25F1024(A), AT25F2048 */
636int spi_prettyprint_status_register_at25f(struct flashctx *flash)
637{
638 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100639 int ret = spi_read_register(flash, STATUS1, &status);
640 if (ret)
641 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000642
Stefan Tauner57794ac2012-12-29 15:04:20 +0000643 spi_prettyprint_status_register_hex(status);
644
645 spi_prettyprint_status_register_atmel_at25_wpen(status);
646 spi_prettyprint_status_register_bit(status, 6);
647 spi_prettyprint_status_register_bit(status, 5);
648 spi_prettyprint_status_register_bit(status, 4);
649 spi_prettyprint_status_register_bp(status, 1);
650 spi_prettyprint_status_register_welwip(status);
651 return 0;
652}
653
654int spi_prettyprint_status_register_at25f512a(struct flashctx *flash)
655{
656 uint8_t status;
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100657 int ret = spi_read_register(flash, STATUS1, &status);
658 if (ret)
659 return ret;
Stefan Tauner57794ac2012-12-29 15:04:20 +0000660
Stefan Tauner57794ac2012-12-29 15:04:20 +0000661 spi_prettyprint_status_register_hex(status);
662
663 spi_prettyprint_status_register_atmel_at25_wpen(status);
664 spi_prettyprint_status_register_bit(status, 6);
665 spi_prettyprint_status_register_bit(status, 5);
666 spi_prettyprint_status_register_bit(status, 4);
667 spi_prettyprint_status_register_bit(status, 3);
668 spi_prettyprint_status_register_bp(status, 0);
669 spi_prettyprint_status_register_welwip(status);
670 return 0;
671}
672
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000673int spi_prettyprint_status_register_at25f512b(struct flashctx *flash)
674{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100675 uint8_t status;
676 int ret = spi_read_register(flash, STATUS1, &status);
677 if (ret)
678 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000679 spi_prettyprint_status_register_hex(status);
680
681 spi_prettyprint_status_register_atmel_at25_srpl(status);
682 spi_prettyprint_status_register_bit(status, 6);
683 spi_prettyprint_status_register_atmel_at25_epewpp(status);
684 spi_prettyprint_status_register_bit(status, 3);
685 spi_prettyprint_status_register_bp(status, 0);
686 spi_prettyprint_status_register_welwip(status);
687 return 0;
688}
689
Stefan Tauner57794ac2012-12-29 15:04:20 +0000690int spi_prettyprint_status_register_at25f4096(struct flashctx *flash)
691{
692 uint8_t status;
693
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100694 int ret = spi_read_register(flash, STATUS1, &status);
695 if (ret)
696 return ret;
697
Stefan Tauner57794ac2012-12-29 15:04:20 +0000698 spi_prettyprint_status_register_hex(status);
699
700 spi_prettyprint_status_register_atmel_at25_wpen(status);
701 spi_prettyprint_status_register_bit(status, 6);
702 spi_prettyprint_status_register_bit(status, 5);
703 spi_prettyprint_status_register_bp(status, 2);
704 spi_prettyprint_status_register_welwip(status);
705 return 0;
706}
707
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000708int spi_prettyprint_status_register_at25fs010(struct flashctx *flash)
709{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100710 uint8_t status;
711 int ret = spi_read_register(flash, STATUS1, &status);
712 if (ret)
713 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000714 spi_prettyprint_status_register_hex(status);
715
716 spi_prettyprint_status_register_atmel_at25_wpen(status);
717 msg_cdbg("Chip status register: Bit 6 / Block Protect 4 (BP4) is "
718 "%sset\n", (status & (1 << 6)) ? "" : "not ");
719 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
720 "%sset\n", (status & (1 << 5)) ? "" : "not ");
721 spi_prettyprint_status_register_bit(status, 4);
722 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
723 "%sset\n", (status & (1 << 3)) ? "" : "not ");
724 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
725 "%sset\n", (status & (1 << 2)) ? "" : "not ");
726 /* FIXME: Pretty-print detailed sector protection status. */
727 spi_prettyprint_status_register_welwip(status);
728 return 0;
729}
730
731int spi_prettyprint_status_register_at25fs040(struct flashctx *flash)
732{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100733 uint8_t status;
734 int ret = spi_read_register(flash, STATUS1, &status);
735 if (ret)
736 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000737 spi_prettyprint_status_register_hex(status);
738
739 spi_prettyprint_status_register_atmel_at25_wpen(status);
740 spi_prettyprint_status_register_bp(status, 4);
741 /* FIXME: Pretty-print detailed sector protection status. */
742 spi_prettyprint_status_register_welwip(status);
743 return 0;
744}
745
746int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
747{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100748 uint8_t status;
749 int ret = spi_read_register(flash, STATUS1, &status);
750 if (ret)
751 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000752 spi_prettyprint_status_register_hex(status);
753
754 spi_prettyprint_status_register_atmel_at25_srpl(status);
755 msg_cdbg("Chip status register: Sequential Program Mode Status (SPM) is %sset\n",
756 (status & (1 << 6)) ? "" : "not ");
757 spi_prettyprint_status_register_atmel_at25_epewpp(status);
758 spi_prettyprint_status_register_atmel_at25_swp(status);
759 spi_prettyprint_status_register_welwip(status);
760 return 0;
761}
762
Stefan Taunercecb2c52013-06-20 22:55:41 +0000763/* Some Atmel DataFlash chips support per sector protection bits and the write protection bits in the status
764 * register do indicate if none, some or all sectors are protected. It is possible to globally (un)lock all
765 * sectors at once by writing 0 not only the protection bits (2 and 3) but also completely unrelated bits (4 and
766 * 5) which normally are not touched.
767 * Affected are all known Atmel chips matched by AT2[56]D[FLQ]..1A? but the AT26DF041. */
768int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000769{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000770 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4, 0x00);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000771}
772
Stefan Taunercecb2c52013-06-20 22:55:41 +0000773int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash)
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000774{
775 /* FIXME: We should check the security lockdown. */
776 msg_cinfo("Ignoring security lockdown (if present)\n");
Stefan Taunercecb2c52013-06-20 22:55:41 +0000777 return spi_disable_blockprotect_at2x_global_unprotect(flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000778}
779
Stefan Tauner57794ac2012-12-29 15:04:20 +0000780int spi_disable_blockprotect_at25f(struct flashctx *flash)
781{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000782 return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000783}
784
785int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
786{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000787 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0, 0xFF);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000788}
789
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000790int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
791{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000792 return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 1 << 4, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000793}
794
795int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
796{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000797 return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0, 0xFF);
Stefan Tauner9530a022012-12-29 15:04:05 +0000798 }
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000799
800int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
801{
Stefan Taunercecb2c52013-06-20 22:55:41 +0000802 return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000803}
804
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000805/* === Eon === */
806
807int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash)
808{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100809 uint8_t status;
810 int ret = spi_read_register(flash, STATUS1, &status);
811 if (ret)
812 return ret;
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000813 spi_prettyprint_status_register_hex(status);
814
815 spi_prettyprint_status_register_srwd(status);
816 msg_cdbg("Chip status register: WP# disable (WPDIS) is %sabled\n", (status & (1 << 6)) ? "en " : "dis");
817 spi_prettyprint_status_register_bp(status, 3);
818 spi_prettyprint_status_register_welwip(status);
819 return 0;
820}
821
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000822/* === Intel/Numonyx/Micron - Spansion === */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000823
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000824int spi_disable_blockprotect_n25q(struct flashctx *flash)
825{
826 return spi_disable_blockprotect_generic(flash, 0x5C, 1 << 7, 0, 0xFF);
827}
828
829int spi_prettyprint_status_register_n25q(struct flashctx *flash)
830{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100831 uint8_t status;
832 int ret = spi_read_register(flash, STATUS1, &status);
833 if (ret)
834 return ret;
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000835 spi_prettyprint_status_register_hex(status);
836
837 spi_prettyprint_status_register_srwd(status);
838 if (flash->chip->total_size <= 32 / 8 * 1024) /* N25Q16 and N25Q32: reserved */
839 spi_prettyprint_status_register_bit(status, 6);
840 else
841 msg_cdbg("Chip status register: Block Protect 3 (BP3) is %sset\n",
842 (status & (1 << 6)) ? "" : "not ");
843 msg_cdbg("Chip status register: Top/Bottom (TB) is %s\n", (status & (1 << 5)) ? "bottom" : "top");
844 spi_prettyprint_status_register_bp(status, 2);
845 spi_prettyprint_status_register_welwip(status);
846 return 0;
847}
848
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000849/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000850/* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000851int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000852{
Stefan Tauner278ba6e2013-06-28 21:28:27 +0000853 return spi_disable_blockprotect_bp2_srwd(flash);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000854}
855
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000856/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
857int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash)
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000858{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100859 uint8_t status;
860 int ret = spi_read_register(flash, STATUS1, &status);
861 if (ret)
862 return ret;
Stefan Taunerc2eec2c2014-05-03 21:33:01 +0000863 spi_prettyprint_status_register_hex(status);
Stefan Tauner54aaa4a2012-12-29 15:04:12 +0000864
865 spi_prettyprint_status_register_srwd(status);
866 msg_cdbg("Chip status register: Program Fail Flag (P_FAIL) is %sset\n",
867 (status & (1 << 6)) ? "" : "not ");
868 msg_cdbg("Chip status register: Erase Fail Flag (E_FAIL) is %sset\n",
869 (status & (1 << 5)) ? "" : "not ");
870 spi_prettyprint_status_register_bp(status, 2);
871 spi_prettyprint_status_register_welwip(status);
872 return 0;
873}
874
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000875/* === SST === */
876
877static void spi_prettyprint_status_register_sst25_common(uint8_t status)
878{
879 spi_prettyprint_status_register_hex(status);
880
881 spi_prettyprint_status_register_bpl(status);
882 msg_cdbg("Chip status register: Auto Address Increment Programming (AAI) is %sset\n",
883 (status & (1 << 6)) ? "" : "not ");
884 spi_prettyprint_status_register_bp(status, 3);
885 spi_prettyprint_status_register_welwip(status);
886}
887
888int spi_prettyprint_status_register_sst25(struct flashctx *flash)
889{
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100890 uint8_t status;
891 int ret = spi_read_register(flash, STATUS1, &status);
892 if (ret)
893 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000894 spi_prettyprint_status_register_sst25_common(status);
895 return 0;
896}
897
898int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash)
899{
900 static const char *const bpt[] = {
901 "none",
902 "1F0000H-1FFFFFH",
903 "1E0000H-1FFFFFH",
904 "1C0000H-1FFFFFH",
905 "180000H-1FFFFFH",
906 "100000H-1FFFFFH",
907 "all", "all"
908 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100909 uint8_t status;
910 int ret = spi_read_register(flash, STATUS1, &status);
911 if (ret)
912 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000913 spi_prettyprint_status_register_sst25_common(status);
914 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
915 return 0;
916}
917
918int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash)
919{
920 static const char *const bpt[] = {
921 "none",
922 "0x70000-0x7ffff",
923 "0x60000-0x7ffff",
924 "0x40000-0x7ffff",
925 "all blocks", "all blocks", "all blocks", "all blocks"
926 };
Nikolai Artemievb8a90d02021-10-28 16:18:28 +1100927 uint8_t status;
928 int ret = spi_read_register(flash, STATUS1, &status);
929 if (ret)
930 return ret;
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000931 spi_prettyprint_status_register_sst25_common(status);
932 msg_cdbg("Resulting block protection : %s\n", bpt[(status & 0x1c) >> 2]);
933 return 0;
934}