David Hendricks | d1c55d7 | 2010-08-24 15:14:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
David Hendricks | d1c55d7 | 2010-08-24 15:14:19 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Edward O'Callaghan | b4300ca | 2019-09-03 16:15:21 +1000 | [diff] [blame] | 20 | #include <strings.h> |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 21 | |
| 22 | #include "flash.h" |
| 23 | #include "flashchips.h" |
| 24 | #include "chipdrivers.h" |
Louis Yung-Chieh Lo | 52aa930 | 2010-09-06 10:45:02 +0800 | [diff] [blame] | 25 | #include "spi.h" |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 26 | #include "writeprotect.h" |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 27 | |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 28 | /* |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 29 | * The following procedures rely on look-up tables to match the user-specified |
| 30 | * range with the chip's supported ranges. This turned out to be the most |
| 31 | * elegant approach since diferent flash chips use different levels of |
| 32 | * granularity and methods to determine protected ranges. In other words, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 33 | * be stupid and simple since clever arithmetic will not work for many chips. |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | struct wp_range { |
| 37 | unsigned int start; /* starting address */ |
| 38 | unsigned int len; /* len */ |
| 39 | }; |
| 40 | |
| 41 | enum bit_state { |
| 42 | OFF = 0, |
| 43 | ON = 1, |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 44 | X = -1 /* don't care. Must be bigger than max # of bp. */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 47 | /* |
| 48 | * Generic write-protection schema for 25-series SPI flash chips. This assumes |
| 49 | * there is a status register that contains one or more consecutive bits which |
| 50 | * determine which address range is protected. |
| 51 | */ |
| 52 | |
| 53 | struct status_register_layout { |
| 54 | int bp0_pos; /* position of BP0 */ |
| 55 | int bp_bits; /* number of block protect bits */ |
| 56 | int srp_pos; /* position of status register protect enable bit */ |
| 57 | }; |
| 58 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 59 | /* |
| 60 | * The following ranges and functions are useful for representing the |
| 61 | * writeprotect schema in which there are typically 5 bits of |
| 62 | * relevant information stored in status register 1: |
| 63 | * m.sec: This bit indicates the units (sectors vs. blocks) |
| 64 | * m.tb: The top-bottom bit indicates if the affected range is at the top of |
| 65 | * the flash memory's address space or at the bottom. |
| 66 | * bp: Bitmask representing the number of affected sectors/blocks. |
| 67 | */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 68 | struct wp_range_descriptor { |
Edward O'Callaghan | 9c4c9a5 | 2019-12-04 18:18:01 +1100 | [diff] [blame] | 69 | struct modifier_bits m; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 70 | unsigned int bp; /* block protect bitfield */ |
| 71 | struct wp_range range; |
| 72 | }; |
| 73 | |
Edward O'Callaghan | c69f6b8 | 2019-12-05 16:49:21 +1100 | [diff] [blame] | 74 | struct w25q_status { |
| 75 | /* this maps to register layout -- do not change ordering */ |
| 76 | unsigned char busy : 1; |
| 77 | unsigned char wel : 1; |
| 78 | unsigned char bp0 : 1; |
| 79 | unsigned char bp1 : 1; |
| 80 | unsigned char bp2 : 1; |
| 81 | unsigned char tb : 1; |
| 82 | unsigned char sec : 1; |
| 83 | unsigned char srp0 : 1; |
| 84 | } __attribute__ ((packed)); |
| 85 | |
| 86 | /* Status register for large flash layouts with 4 BP bits */ |
| 87 | struct w25q_status_large { |
| 88 | unsigned char busy : 1; |
| 89 | unsigned char wel : 1; |
| 90 | unsigned char bp0 : 1; |
| 91 | unsigned char bp1 : 1; |
| 92 | unsigned char bp2 : 1; |
| 93 | unsigned char bp3 : 1; |
| 94 | unsigned char tb : 1; |
| 95 | unsigned char srp0 : 1; |
| 96 | } __attribute__ ((packed)); |
| 97 | |
| 98 | struct w25q_status_2 { |
| 99 | unsigned char srp1 : 1; |
| 100 | unsigned char qe : 1; |
| 101 | unsigned char rsvd : 6; |
| 102 | } __attribute__ ((packed)); |
| 103 | |
| 104 | int w25_range_to_status(const struct flashctx *flash, |
| 105 | unsigned int start, unsigned int len, |
| 106 | struct w25q_status *status); |
| 107 | int w25_status_to_range(const struct flashctx *flash, |
| 108 | const struct w25q_status *status, |
| 109 | unsigned int *start, unsigned int *len); |
| 110 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 111 | /* |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 112 | * Mask to extract write-protect enable and range bits |
| 113 | * Status register 1: |
| 114 | * SRP0: bit 7 |
| 115 | * range(BP2-BP0): bit 4-2 |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 116 | * range(BP3-BP0): bit 5-2 (large chips) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 117 | * Status register 2: |
| 118 | * SRP1: bit 1 |
| 119 | */ |
| 120 | #define MASK_WP_AREA (0x9C) |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 121 | #define MASK_WP_AREA_LARGE (0x9C) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 122 | #define MASK_WP2_AREA (0x01) |
| 123 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 124 | static struct wp_range_descriptor en25f40_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 125 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 126 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 504 * 1024} }, |
| 127 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 496 * 1024} }, |
| 128 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 480 * 1024} }, |
| 129 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 448 * 1024} }, |
| 130 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 384 * 1024} }, |
| 131 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 256 * 1024} }, |
| 132 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 512 * 1024} }, |
David Hendricks | 57566ed | 2010-08-16 18:24:45 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 135 | static struct wp_range_descriptor en25q40_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 136 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 137 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 504 * 1024} }, |
| 138 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 496 * 1024} }, |
| 139 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 480 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 140 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 141 | { .m = { .sec = 0, .tb = 1 }, 0x0, {0x000000, 448 * 1024} }, |
| 142 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 384 * 1024} }, |
| 143 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 256 * 1024} }, |
| 144 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 512 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 147 | static struct wp_range_descriptor en25q80_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 148 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 149 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 1016 * 1024} }, |
| 150 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 1008 * 1024} }, |
| 151 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 992 * 1024} }, |
| 152 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 960 * 1024} }, |
| 153 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 896 * 1024} }, |
| 154 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 768 * 1024} }, |
| 155 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 1024 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 158 | static struct wp_range_descriptor en25q32_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 159 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 160 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 4032 * 1024} }, |
| 161 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 3968 * 1024} }, |
| 162 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 3840 * 1024} }, |
| 163 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 3584 * 1024} }, |
| 164 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 3072 * 1024} }, |
| 165 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 2048 * 1024} }, |
| 166 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 167 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 168 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 169 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 4032 * 1024} }, |
| 170 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 3968 * 1024} }, |
| 171 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 3840 * 1024} }, |
| 172 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x080000, 3584 * 1024} }, |
| 173 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x100000, 3072 * 1024} }, |
| 174 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x200000, 2048 * 1024} }, |
| 175 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 178 | static struct wp_range_descriptor en25q64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 179 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 180 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 8128 * 1024} }, |
| 181 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 8064 * 1024} }, |
| 182 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 7936 * 1024} }, |
| 183 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 7680 * 1024} }, |
| 184 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 7168 * 1024} }, |
| 185 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 6144 * 1024} }, |
| 186 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 8192 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 187 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 188 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 189 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 8128 * 1024} }, |
| 190 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 8064 * 1024} }, |
| 191 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 7936 * 1024} }, |
| 192 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x080000, 7680 * 1024} }, |
| 193 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x100000, 7168 * 1024} }, |
| 194 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x200000, 6144 * 1024} }, |
| 195 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 8192 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 198 | static struct wp_range_descriptor en25q128_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 199 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 200 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 16320 * 1024} }, |
| 201 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 16256 * 1024} }, |
| 202 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 16128 * 1024} }, |
| 203 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 15872 * 1024} }, |
| 204 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 15360 * 1024} }, |
| 205 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 14336 * 1024} }, |
| 206 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 16384 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 207 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 208 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 209 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 16320 * 1024} }, |
| 210 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 16256 * 1024} }, |
| 211 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 16128 * 1024} }, |
| 212 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x080000, 15872 * 1024} }, |
| 213 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x100000, 15360 * 1024} }, |
| 214 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x200000, 14336 * 1024} }, |
| 215 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 16384 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 218 | static struct wp_range_descriptor en25s64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 219 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 220 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 8064 * 1024} }, |
| 221 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 7936 * 1024} }, |
| 222 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 7680 * 1024} }, |
| 223 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 7168 * 1024} }, |
| 224 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 6144 * 1024} }, |
| 225 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 4096 * 1024} }, |
| 226 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 8192 * 1024} }, |
Marc Jones | b2f9002 | 2014-04-29 17:37:23 -0600 | [diff] [blame] | 227 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 228 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 229 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x7e0000, 128 * 1024} }, |
| 230 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x7c0000, 256 * 1024} }, |
| 231 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x780000, 512 * 1024} }, |
| 232 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x700000, 1024 * 1024} }, |
| 233 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x600000, 2048 * 1024} }, |
| 234 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x400000, 4096 * 1024} }, |
| 235 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 8192 * 1024} }, |
Marc Jones | b2f9002 | 2014-04-29 17:37:23 -0600 | [diff] [blame] | 236 | }; |
| 237 | |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 238 | /* mx25l1005 ranges also work for the mx25l1005c */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 239 | static struct wp_range_descriptor mx25l1005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 240 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 241 | { .m = { .sec = X, .tb = X }, 0x1, {0x010000, 64 * 1024} }, |
| 242 | { .m = { .sec = X, .tb = X }, 0x2, {0x000000, 128 * 1024} }, |
| 243 | { .m = { .sec = X, .tb = X }, 0x3, {0x000000, 128 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 244 | }; |
| 245 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 246 | static struct wp_range_descriptor mx25l2005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 247 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 248 | { .m = { .sec = X, .tb = X }, 0x1, {0x030000, 64 * 1024} }, |
| 249 | { .m = { .sec = X, .tb = X }, 0x2, {0x020000, 128 * 1024} }, |
| 250 | { .m = { .sec = X, .tb = X }, 0x3, {0x000000, 256 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 251 | }; |
| 252 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 253 | static struct wp_range_descriptor mx25l4005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 254 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 255 | { .m = { .sec = X, .tb = X }, 0x1, {0x070000, 64 * 1 * 1024} }, /* block 7 */ |
| 256 | { .m = { .sec = X, .tb = X }, 0x2, {0x060000, 64 * 2 * 1024} }, /* blocks 6-7 */ |
| 257 | { .m = { .sec = X, .tb = X }, 0x3, {0x040000, 64 * 4 * 1024} }, /* blocks 4-7 */ |
| 258 | { .m = { .sec = X, .tb = X }, 0x4, {0x000000, 512 * 1024} }, |
| 259 | { .m = { .sec = X, .tb = X }, 0x5, {0x000000, 512 * 1024} }, |
| 260 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 512 * 1024} }, |
| 261 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 512 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 262 | }; |
| 263 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 264 | static struct wp_range_descriptor mx25l8005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 265 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 266 | { .m = { .sec = X, .tb = X }, 0x1, {0x0f0000, 64 * 1 * 1024} }, /* block 15 */ |
| 267 | { .m = { .sec = X, .tb = X }, 0x2, {0x0e0000, 64 * 2 * 1024} }, /* blocks 14-15 */ |
| 268 | { .m = { .sec = X, .tb = X }, 0x3, {0x0c0000, 64 * 4 * 1024} }, /* blocks 12-15 */ |
| 269 | { .m = { .sec = X, .tb = X }, 0x4, {0x080000, 64 * 8 * 1024} }, /* blocks 8-15 */ |
| 270 | { .m = { .sec = X, .tb = X }, 0x5, {0x000000, 1024 * 1024} }, |
| 271 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 1024 * 1024} }, |
| 272 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 1024 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 275 | static struct wp_range_descriptor mx25l1605d_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 276 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 277 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x1f0000, 64 * 1 * 1024} }, /* block 31 */ |
| 278 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x1e0000, 64 * 2 * 1024} }, /* blocks 30-31 */ |
| 279 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x1c0000, 64 * 4 * 1024} }, /* blocks 28-31 */ |
| 280 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x180000, 64 * 8 * 1024} }, /* blocks 24-31 */ |
| 281 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x100000, 64 * 16 * 1024} }, /* blocks 16-31 */ |
| 282 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 283 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 284 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 285 | { .m = { .sec = X, .tb = 1 }, 0x0, {0x000000, 2048 * 1024} }, |
| 286 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x000000, 2048 * 1024} }, |
| 287 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x000000, 64 * 16 * 1024} }, /* blocks 0-15 */ |
| 288 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x000000, 64 * 24 * 1024} }, /* blocks 0-23 */ |
| 289 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x000000, 64 * 28 * 1024} }, /* blocks 0-27 */ |
| 290 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x000000, 64 * 30 * 1024} }, /* blocks 0-29 */ |
| 291 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x000000, 64 * 31 * 1024} }, /* blocks 0-30 */ |
| 292 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | /* FIXME: Is there an mx25l3205 (without a trailing letter)? */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 296 | static struct wp_range_descriptor mx25l3205d_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 297 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 298 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x3f0000, 64 * 1024} }, |
| 299 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x3e0000, 128 * 1024} }, |
| 300 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x3c0000, 256 * 1024} }, |
| 301 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x380000, 512 * 1024} }, |
| 302 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x300000, 1024 * 1024} }, |
| 303 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x200000, 2048 * 1024} }, |
| 304 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 305 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 306 | { .m = { .sec = X, .tb = 1 }, 0x0, {0x000000, 4096 * 1024} }, |
| 307 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x000000, 2048 * 1024} }, |
| 308 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x000000, 3072 * 1024} }, |
| 309 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x000000, 3584 * 1024} }, |
| 310 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x000000, 3840 * 1024} }, |
| 311 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x000000, 3968 * 1024} }, |
| 312 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x000000, 4032 * 1024} }, |
| 313 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 316 | static struct wp_range_descriptor mx25u3235e_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 317 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 318 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x3f0000, 64 * 1024} }, |
| 319 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x3e0000, 128 * 1024} }, |
| 320 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x3c0000, 256 * 1024} }, |
| 321 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x380000, 512 * 1024} }, |
| 322 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x300000, 1024 * 1024} }, |
| 323 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x200000, 2048 * 1024} }, |
| 324 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 4096 * 1024} }, |
Vincent Palatin | 87e092a | 2013-02-28 15:46:14 -0800 | [diff] [blame] | 325 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 326 | { .m = { .sec = 0, .tb = 1 }, 0x0, {0x000000, 4096 * 1024} }, |
| 327 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 2048 * 1024} }, |
| 328 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 3072 * 1024} }, |
| 329 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 3584 * 1024} }, |
| 330 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 3840 * 1024} }, |
| 331 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 3968 * 1024} }, |
| 332 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 4032 * 1024} }, |
| 333 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 4096 * 1024} }, |
Vincent Palatin | 87e092a | 2013-02-28 15:46:14 -0800 | [diff] [blame] | 334 | }; |
| 335 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 336 | static struct wp_range_descriptor mx25u6435e_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 337 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 338 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7f0000, 1 * 64 * 1024} }, /* block 127 */ |
| 339 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7e0000, 2 * 64 * 1024} }, /* blocks 126-127 */ |
| 340 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x7c0000, 4 * 64 * 1024} }, /* blocks 124-127 */ |
| 341 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x780000, 8 * 64 * 1024} }, /* blocks 120-127 */ |
| 342 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x700000, 16 * 64 * 1024} }, /* blocks 112-127 */ |
| 343 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x600000, 32 * 64 * 1024} }, /* blocks 96-127 */ |
| 344 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
Jongpil | 66a9649 | 2014-08-14 17:59:06 +0900 | [diff] [blame] | 345 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 346 | { .m = { .sec = 0, .tb = 1 }, 0x0, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 347 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 96 * 64 * 1024} }, /* blocks 0-95 */ |
| 348 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 112 * 64 * 1024} }, /* blocks 0-111 */ |
| 349 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 120 * 64 * 1024} }, /* blocks 0-119 */ |
| 350 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 124 * 64 * 1024} }, /* blocks 0-123 */ |
| 351 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 126 * 64 * 1024} }, /* blocks 0-125 */ |
| 352 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 127 * 64 * 1024} }, /* blocks 0-126 */ |
| 353 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 128 * 64 * 1024} }, /* blocks 0-127 */ |
Jongpil | 66a9649 | 2014-08-14 17:59:06 +0900 | [diff] [blame] | 354 | }; |
| 355 | |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 356 | #define MX25U12835E_TB (1 << 3) |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 357 | static struct wp_range_descriptor mx25u12835e_tb0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 358 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 359 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0xff0000, 1 * 64 * 1024} }, /* block 255 */ |
| 360 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0xfe0000, 2 * 64 * 1024} }, /* blocks 254-255 */ |
| 361 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0xfc0000, 4 * 64 * 1024} }, /* blocks 252-255 */ |
| 362 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0xf80000, 8 * 64 * 1024} }, /* blocks 248-255 */ |
| 363 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0xf00000, 16 * 64 * 1024} }, /* blocks 240-255 */ |
| 364 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0xe00000, 32 * 64 * 1024} }, /* blocks 224-255 */ |
| 365 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0xc00000, 64 * 64 * 1024} }, /* blocks 192-255 */ |
| 366 | { .m = { .sec = 0, .tb = 0 }, 0x8, {0x800000, 128 * 64 * 1024} }, /* blocks 128-255 */ |
| 367 | { .m = { .sec = 0, .tb = 0 }, 0x9, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 368 | { .m = { .sec = 0, .tb = 0 }, 0xa, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 369 | { .m = { .sec = 0, .tb = 0 }, 0xb, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 370 | { .m = { .sec = 0, .tb = 0 }, 0xc, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 371 | { .m = { .sec = 0, .tb = 0 }, 0xd, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 372 | { .m = { .sec = 0, .tb = 0 }, 0xe, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 373 | { .m = { .sec = 0, .tb = 0 }, 0xf, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 374 | }; |
Alex Lu | 831c609 | 2017-11-02 23:19:34 -0700 | [diff] [blame] | 375 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 376 | static struct wp_range_descriptor mx25u12835e_tb1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 377 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 1 * 64 * 1024} }, /* block 0 */ |
| 378 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 2 * 64 * 1024} }, /* blocks 0-1 */ |
| 379 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 4 * 64 * 1024} }, /* blocks 0-3 */ |
| 380 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 8 * 64 * 1024} }, /* blocks 0-7 */ |
| 381 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 16 * 64 * 1024} }, /* blocks 0-15 */ |
| 382 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 32 * 64 * 1024} }, /* blocks 0-31 */ |
| 383 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 384 | { .m = { .sec = 0, .tb = 1 }, 0x8, {0x000000, 128 * 64 * 1024} }, /* blocks 0-127 */ |
| 385 | { .m = { .sec = 0, .tb = 1 }, 0x9, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 386 | { .m = { .sec = 0, .tb = 1 }, 0xa, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 387 | { .m = { .sec = 0, .tb = 1 }, 0xb, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 388 | { .m = { .sec = 0, .tb = 1 }, 0xc, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 389 | { .m = { .sec = 0, .tb = 1 }, 0xd, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 390 | { .m = { .sec = 0, .tb = 1 }, 0xe, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 391 | { .m = { .sec = 0, .tb = 1 }, 0xf, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
Alex Lu | 831c609 | 2017-11-02 23:19:34 -0700 | [diff] [blame] | 392 | }; |
| 393 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 394 | static struct wp_range_descriptor n25q064_ranges[] = { |
David Hendricks | fe9123b | 2015-04-21 13:18:31 -0700 | [diff] [blame] | 395 | /* |
| 396 | * Note: For N25Q064, sec (usually in bit position 6) is called BP3 |
| 397 | * (block protect bit 3). It is only useful when all blocks are to |
| 398 | * be write-protected. |
| 399 | */ |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 400 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 401 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 402 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7f0000, 64 * 1024} }, /* block 127 */ |
| 403 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7e0000, 2 * 64 * 1024} }, /* blocks 126-127 */ |
| 404 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x7c0000, 4 * 64 * 1024} }, /* blocks 124-127 */ |
| 405 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x780000, 8 * 64 * 1024} }, /* blocks 120-127 */ |
| 406 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x700000, 16 * 64 * 1024} }, /* blocks 112-127 */ |
| 407 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x600000, 32 * 64 * 1024} }, /* blocks 96-127 */ |
| 408 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 409 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 410 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, /* block 0 */ |
| 411 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 2 * 64 * 1024} }, /* blocks 0-1 */ |
| 412 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 4 * 64 * 1024} }, /* blocks 0-3 */ |
| 413 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 8 * 64 * 1024} }, /* blocks 0-7 */ |
| 414 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 16 * 64 * 1024} }, /* blocks 0-15 */ |
| 415 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 32 * 64 * 1024} }, /* blocks 0-31 */ |
| 416 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 417 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 418 | { .m = { .sec = X, .tb = 1 }, 0x0, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 419 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 420 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 421 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 422 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 423 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 424 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 425 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x000000, 128 * 64 * 1024} }, /* all */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 426 | }; |
| 427 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 428 | static struct wp_range_descriptor w25q16_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 429 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 430 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x1f0000, 64 * 1024} }, |
| 431 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x1e0000, 128 * 1024} }, |
| 432 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x1c0000, 256 * 1024} }, |
| 433 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x180000, 512 * 1024} }, |
| 434 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x100000, 1024 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 435 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 436 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 437 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 438 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 439 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 440 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 1024 * 1024} }, |
| 441 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 2048 * 1024} }, |
| 442 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 2048 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 443 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 444 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x1ff000, 4 * 1024} }, |
| 445 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x1fe000, 8 * 1024} }, |
| 446 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x1fc000, 16 * 1024} }, |
| 447 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x1f8000, 32 * 1024} }, |
| 448 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x1f8000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 449 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 450 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 451 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 452 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 453 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 454 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 457 | static struct wp_range_descriptor w25q32_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 458 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 459 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x3f0000, 64 * 1024} }, |
| 460 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x3e0000, 128 * 1024} }, |
| 461 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x3c0000, 256 * 1024} }, |
| 462 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x380000, 512 * 1024} }, |
| 463 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x300000, 1024 * 1024} }, |
| 464 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x200000, 2048 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 465 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 466 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 467 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 468 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 469 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 470 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 1024 * 1024} }, |
| 471 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 2048 * 1024} }, |
| 472 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 473 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 474 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x3ff000, 4 * 1024} }, |
| 475 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x3fe000, 8 * 1024} }, |
| 476 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x3fc000, 16 * 1024} }, |
| 477 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x3f8000, 32 * 1024} }, |
| 478 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x3f8000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 479 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 480 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 481 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 482 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 483 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 484 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 485 | }; |
| 486 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 487 | static struct wp_range_descriptor w25q80_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 488 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 489 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x0f0000, 64 * 1024} }, |
| 490 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x0e0000, 128 * 1024} }, |
| 491 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x0c0000, 256 * 1024} }, |
| 492 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x080000, 512 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 493 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 494 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 495 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 496 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 497 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 498 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 1024 * 1024} }, |
| 499 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 1024 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 500 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 501 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x1ff000, 4 * 1024} }, |
| 502 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x1fe000, 8 * 1024} }, |
| 503 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x1fc000, 16 * 1024} }, |
| 504 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x1f8000, 32 * 1024} }, |
| 505 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x1f8000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 506 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 507 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 508 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 509 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 510 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 511 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 512 | }; |
| 513 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 514 | static struct wp_range_descriptor w25q64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 515 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 516 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 517 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7e0000, 128 * 1024} }, |
| 518 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7c0000, 256 * 1024} }, |
| 519 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x780000, 512 * 1024} }, |
| 520 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x700000, 1024 * 1024} }, |
| 521 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x600000, 2048 * 1024} }, |
| 522 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x400000, 4096 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 523 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 524 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 128 * 1024} }, |
| 525 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 256 * 1024} }, |
| 526 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 512 * 1024} }, |
| 527 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 1024 * 1024} }, |
| 528 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 2048 * 1024} }, |
| 529 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 4096 * 1024} }, |
| 530 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 8192 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 531 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 532 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x7ff000, 4 * 1024} }, |
| 533 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x7fe000, 8 * 1024} }, |
| 534 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x7fc000, 16 * 1024} }, |
| 535 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x7f8000, 32 * 1024} }, |
| 536 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x7f8000, 32 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 537 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 538 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 539 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 540 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 541 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 542 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 543 | }; |
| 544 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 545 | static struct wp_range_descriptor w25rq128_cmp0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 546 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* NONE */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 547 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 548 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0xfc0000, 256 * 1024} }, /* Upper 1/64 */ |
| 549 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0xf80000, 512 * 1024} }, /* Upper 1/32 */ |
| 550 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0xf00000, 1024 * 1024} }, /* Upper 1/16 */ |
| 551 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0xe00000, 2048 * 1024} }, /* Upper 1/8 */ |
| 552 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0xc00000, 4096 * 1024} }, /* Upper 1/4 */ |
| 553 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x800000, 8192 * 1024} }, /* Upper 1/2 */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 554 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 555 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 256 * 1024} }, /* Lower 1/64 */ |
| 556 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 512 * 1024} }, /* Lower 1/32 */ |
| 557 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 1024 * 1024} }, /* Lower 1/16 */ |
| 558 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 2048 * 1024} }, /* Lower 1/8 */ |
| 559 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 4096 * 1024} }, /* Lower 1/4 */ |
| 560 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 8192 * 1024} }, /* Lower 1/2 */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 561 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 562 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 16384 * 1024} }, /* ALL */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 563 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 564 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0xfff000, 4 * 1024} }, /* Upper 1/4096 */ |
| 565 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0xffe000, 8 * 1024} }, /* Upper 1/2048 */ |
| 566 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0xffc000, 16 * 1024} }, /* Upper 1/1024 */ |
| 567 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0xff8000, 32 * 1024} }, /* Upper 1/512 */ |
| 568 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0xff8000, 32 * 1024} }, /* Upper 1/512 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 569 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 570 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, /* Lower 1/4096 */ |
| 571 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, /* Lower 1/2048 */ |
| 572 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, /* Lower 1/1024 */ |
| 573 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, /* Lower 1/512 */ |
| 574 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, /* Lower 1/512 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 575 | }; |
| 576 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 577 | static struct wp_range_descriptor w25rq128_cmp1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 578 | { .m = { .sec = X, .tb = X }, 0x0, {0x000000, 16 * 1024 * 1024} }, /* ALL */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 579 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 580 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 16128 * 1024} }, /* Lower 63/64 */ |
| 581 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 15872 * 1024} }, /* Lower 31/32 */ |
| 582 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 15 * 1024 * 1024} }, /* Lower 15/16 */ |
| 583 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 14 * 1024 * 1024} }, /* Lower 7/8 */ |
| 584 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 12 * 1024 * 1024} }, /* Lower 3/4 */ |
| 585 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 8 * 1024 * 1024} }, /* Lower 1/2 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 586 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 587 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x040000, 16128 * 1024} }, /* Upper 63/64 */ |
| 588 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x080000, 15872 * 1024} }, /* Upper 31/32 */ |
| 589 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x100000, 15 * 1024 * 1024} }, /* Upper 15/16 */ |
| 590 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x200000, 14 * 1024 * 1024} }, /* Upper 7/8 */ |
| 591 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x400000, 12 * 1024 * 1024} }, /* Upper 3/4 */ |
| 592 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x800000, 8 * 1024 * 1024} }, /* Upper 1/2 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 593 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 594 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 0} }, /* NONE */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 595 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 596 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x000000, 16380 * 1024} }, /* Lower 4095/4096 */ |
| 597 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x000000, 16376 * 1024} }, /* Lower 2048/2048 */ |
| 598 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x000000, 16368 * 1024} }, /* Lower 1023/1024 */ |
| 599 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x000000, 16352 * 1024} }, /* Lower 511/512 */ |
| 600 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x000000, 16352 * 1024} }, /* Lower 511/512 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 601 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 602 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x001000, 16380 * 1024} }, /* Upper 4095/4096 */ |
| 603 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x002000, 16376 * 1024} }, /* Upper 2047/2048 */ |
| 604 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x004000, 16368 * 1024} }, /* Upper 1023/1024 */ |
| 605 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x008000, 16352 * 1024} }, /* Upper 511/512 */ |
| 606 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x008000, 16352 * 1024} }, /* Upper 511/512 */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 607 | }; |
| 608 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 609 | static struct wp_range_descriptor w25rq256_cmp0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 610 | { .m = { .sec = X, .tb = X }, 0x0, {0x0000000, 0x0000000} }, /* NONE */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 611 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 612 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x1ff0000, 64 * 1 * 1024} }, /* Upper 1/512 */ |
| 613 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x1fe0000, 64 * 2 * 1024} }, /* Upper 1/256 */ |
| 614 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x1fc0000, 64 * 4 * 1024} }, /* Upper 1/128 */ |
| 615 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x1f80000, 64 * 8 * 1024} }, /* Upper 1/64 */ |
| 616 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x1f00000, 64 * 16 * 1024} }, /* Upper 1/32 */ |
| 617 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x1e00000, 64 * 32 * 1024} }, /* Upper 1/16 */ |
| 618 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x1c00000, 64 * 64 * 1024} }, /* Upper 1/8 */ |
| 619 | { .m = { .sec = X, .tb = 0 }, 0x8, {0x1800000, 64 * 128 * 1024} }, /* Upper 1/4 */ |
| 620 | { .m = { .sec = X, .tb = 0 }, 0x9, {0x1000000, 64 * 256 * 1024} }, /* Upper 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 621 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 622 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x0000000, 64 * 1 * 1024} }, /* Lower 1/512 */ |
| 623 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x0000000, 64 * 2 * 1024} }, /* Lower 1/256 */ |
| 624 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x0000000, 64 * 4 * 1024} }, /* Lower 1/128 */ |
| 625 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x0000000, 64 * 8 * 1024} }, /* Lower 1/64 */ |
| 626 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x0000000, 64 * 16 * 1024} }, /* Lower 1/32 */ |
| 627 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x0000000, 64 * 32 * 1024} }, /* Lower 1/16 */ |
| 628 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x0000000, 64 * 64 * 1024} }, /* Lower 1/8 */ |
| 629 | { .m = { .sec = X, .tb = 1 }, 0x8, {0x0000000, 64 * 128 * 1024} }, /* Lower 1/4 */ |
| 630 | { .m = { .sec = X, .tb = 1 }, 0x9, {0x0000000, 64 * 256 * 1024} }, /* Lower 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 631 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 632 | { .m = { .sec = X, .tb = X }, 0xa, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 633 | { .m = { .sec = X, .tb = X }, 0xb, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 634 | { .m = { .sec = X, .tb = X }, 0xc, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 635 | { .m = { .sec = X, .tb = X }, 0xd, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 636 | { .m = { .sec = X, .tb = X }, 0xe, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 637 | { .m = { .sec = X, .tb = X }, 0xf, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 638 | }; |
| 639 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 640 | static struct wp_range_descriptor w25rq256_cmp1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 641 | { .m = { .sec = X, .tb = X }, 0x0, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 642 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 643 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x0000000, 64 * 511 * 1024} }, /* Lower 511/512 */ |
| 644 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x0000000, 64 * 510 * 1024} }, /* Lower 255/256 */ |
| 645 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x0000000, 64 * 508 * 1024} }, /* Lower 127/128 */ |
| 646 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x0000000, 64 * 504 * 1024} }, /* Lower 63/64 */ |
| 647 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x0000000, 64 * 496 * 1024} }, /* Lower 31/32 */ |
| 648 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x0000000, 64 * 480 * 1024} }, /* Lower 15/16 */ |
| 649 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x0000000, 64 * 448 * 1024} }, /* Lower 7/8 */ |
| 650 | { .m = { .sec = X, .tb = 0 }, 0x8, {0x0000000, 64 * 384 * 1024} }, /* Lower 3/4 */ |
| 651 | { .m = { .sec = X, .tb = 0 }, 0x9, {0x0000000, 64 * 256 * 1024} }, /* Lower 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 652 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 653 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x0010000, 64 * 511 * 1024} }, /* Upper 511/512 */ |
| 654 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x0020000, 64 * 510 * 1024} }, /* Upper 255/256 */ |
| 655 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x0040000, 64 * 508 * 1024} }, /* Upper 127/128 */ |
| 656 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x0080000, 64 * 504 * 1024} }, /* Upper 63/64 */ |
| 657 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x0100000, 64 * 496 * 1024} }, /* Upper 31/32 */ |
| 658 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x0200000, 64 * 480 * 1024} }, /* Upper 15/16 */ |
| 659 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x0400000, 64 * 448 * 1024} }, /* Upper 7/8 */ |
| 660 | { .m = { .sec = X, .tb = 1 }, 0x8, {0x0800000, 64 * 384 * 1024} }, /* Upper 3/4 */ |
| 661 | { .m = { .sec = X, .tb = 1 }, 0x9, {0x1000000, 64 * 256 * 1024} }, /* Upper 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 662 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 663 | { .m = { .sec = X, .tb = X }, 0xa, {0x0000000, 0x0000000} }, /* NONE */ |
| 664 | { .m = { .sec = X, .tb = X }, 0xb, {0x0000000, 0x0000000} }, /* NONE */ |
| 665 | { .m = { .sec = X, .tb = X }, 0xc, {0x0000000, 0x0000000} }, /* NONE */ |
| 666 | { .m = { .sec = X, .tb = X }, 0xd, {0x0000000, 0x0000000} }, /* NONE */ |
| 667 | { .m = { .sec = X, .tb = X }, 0xe, {0x0000000, 0x0000000} }, /* NONE */ |
| 668 | { .m = { .sec = X, .tb = X }, 0xf, {0x0000000, 0x0000000} }, /* NONE */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 669 | }; |
| 670 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 671 | static struct wp_range_descriptor w25x10_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 672 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 673 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x010000, 64 * 1024} }, |
| 674 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 675 | { .m = { .sec = X, .tb = X }, 0x2, {0x000000, 128 * 1024} }, |
| 676 | { .m = { .sec = X, .tb = X }, 0x3, {0x000000, 128 * 1024} }, |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 677 | }; |
| 678 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 679 | static struct wp_range_descriptor w25x20_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 680 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 681 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x030000, 64 * 1024} }, |
| 682 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x020000, 128 * 1024} }, |
| 683 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 684 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 685 | { .m = { .sec = 0, .tb = X }, 0x3, {0x000000, 256 * 1024} }, |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 686 | }; |
| 687 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 688 | static struct wp_range_descriptor w25x40_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 689 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 690 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x070000, 64 * 1024} }, |
| 691 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x060000, 128 * 1024} }, |
| 692 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x040000, 256 * 1024} }, |
| 693 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 694 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 695 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 696 | { .m = { .sec = 0, .tb = X }, 0x4, {0x000000, 512 * 1024} }, |
| 697 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 512 * 1024} }, |
| 698 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 512 * 1024} }, |
| 699 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 512 * 1024} }, |
David Hendricks | 470ca95 | 2010-08-13 14:01:53 -0700 | [diff] [blame] | 700 | }; |
| 701 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 702 | static struct wp_range_descriptor w25x80_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 703 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 704 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x0F0000, 64 * 1024} }, |
| 705 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x0E0000, 128 * 1024} }, |
| 706 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x0C0000, 256 * 1024} }, |
| 707 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x080000, 512 * 1024} }, |
| 708 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 709 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 710 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 711 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 712 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 1024 * 1024} }, |
| 713 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 1024 * 1024} }, |
| 714 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 1024 * 1024} }, |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 715 | }; |
| 716 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 717 | static struct wp_range_descriptor gd25q40_cmp0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 718 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* None */ |
| 719 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x070000, 64 * 1024} }, |
| 720 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x060000, 128 * 1024} }, |
| 721 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x040000, 256 * 1024} }, |
| 722 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 723 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 724 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 725 | { .m = { .sec = 0, .tb = X }, 0x4, {0x000000, 512 * 1024} }, /* All */ |
| 726 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 512 * 1024} }, /* All */ |
| 727 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 512 * 1024} }, /* All */ |
| 728 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 512 * 1024} }, /* All */ |
| 729 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x07F000, 4 * 1024} }, |
| 730 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x07E000, 8 * 1024} }, |
| 731 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x07C000, 16 * 1024} }, |
| 732 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x078000, 32 * 1024} }, |
| 733 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x078000, 32 * 1024} }, |
| 734 | { .m = { .sec = 1, .tb = 0 }, 0x6, {0x078000, 32 * 1024} }, |
| 735 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 736 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 737 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 738 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 739 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
| 740 | { .m = { .sec = 1, .tb = 1 }, 0x6, {0x000000, 32 * 1024} }, |
| 741 | { .m = { .sec = 1, .tb = X }, 0x7, {0x000000, 512 * 1024} }, /* All */ |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 742 | }; |
| 743 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 744 | static struct wp_range_descriptor gd25q40_cmp1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 745 | { .m = { .sec = X, .tb = X }, 0x0, {0x000000, 512 * 1024} }, /* ALL */ |
| 746 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 448 * 1024} }, |
| 747 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 384 * 1024} }, |
| 748 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 256 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 749 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 750 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 448 * 1024} }, |
| 751 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 384 * 1024} }, |
| 752 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 256 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 753 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 754 | { .m = { .sec = 0, .tb = X }, 0x4, {0x000000, 0} }, /* None */ |
| 755 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 0} }, /* None */ |
| 756 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 0} }, /* None */ |
| 757 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 0} }, /* None */ |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 758 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 759 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x000000, 508 * 1024} }, |
| 760 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x000000, 504 * 1024} }, |
| 761 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x000000, 496 * 1024} }, |
| 762 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x000000, 480 * 1024} }, |
| 763 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x000000, 480 * 1024} }, |
| 764 | { .m = { .sec = 1, .tb = 0 }, 0x6, {0x000000, 480 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 765 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 766 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x001000, 508 * 1024} }, |
| 767 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x002000, 504 * 1024} }, |
| 768 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x004000, 496 * 1024} }, |
| 769 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x008000, 480 * 1024} }, |
| 770 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x008000, 480 * 1024} }, |
| 771 | { .m = { .sec = 1, .tb = 1 }, 0x6, {0x008000, 480 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 772 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 773 | { .m = { .sec = 1, .tb = X }, 0x7, {0x000000, 0} }, /* None */ |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 774 | }; |
| 775 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 776 | static struct wp_range_descriptor gd25q64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 777 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 778 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7e0000, 128 * 1024} }, |
| 779 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7c0000, 256 * 1024} }, |
| 780 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x780000, 512 * 1024} }, |
| 781 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x700000, 1024 * 1024} }, |
| 782 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x600000, 2048 * 1024} }, |
| 783 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x400000, 4096 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 784 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 785 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 128 * 1024} }, |
| 786 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 256 * 1024} }, |
| 787 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 512 * 1024} }, |
| 788 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 1024 * 1024} }, |
| 789 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 2048 * 1024} }, |
| 790 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 4096 * 1024} }, |
| 791 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 8192 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 792 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 793 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x7ff000, 4 * 1024} }, |
| 794 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x7fe000, 8 * 1024} }, |
| 795 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x7fc000, 16 * 1024} }, |
| 796 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x7f8000, 32 * 1024} }, |
| 797 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x7f8000, 32 * 1024} }, |
| 798 | { .m = { .sec = 1, .tb = 0 }, 0x6, {0x7f8000, 32 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 799 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 800 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 801 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 802 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 803 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 804 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
| 805 | { .m = { .sec = 1, .tb = 1 }, 0x6, {0x000000, 32 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 806 | }; |
| 807 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 808 | static struct wp_range_descriptor a25l040_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 809 | { .m = { .sec = X, .tb = X }, 0x0, {0, 0} }, /* none */ |
| 810 | { .m = { .sec = X, .tb = X }, 0x1, {0x70000, 64 * 1024} }, |
| 811 | { .m = { .sec = X, .tb = X }, 0x2, {0x60000, 128 * 1024} }, |
| 812 | { .m = { .sec = X, .tb = X }, 0x3, {0x40000, 256 * 1024} }, |
| 813 | { .m = { .sec = X, .tb = X }, 0x4, {0x00000, 512 * 1024} }, |
| 814 | { .m = { .sec = X, .tb = X }, 0x5, {0x00000, 512 * 1024} }, |
| 815 | { .m = { .sec = X, .tb = X }, 0x6, {0x00000, 512 * 1024} }, |
| 816 | { .m = { .sec = X, .tb = X }, 0x7, {0x00000, 512 * 1024} }, |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame] | 817 | }; |
| 818 | |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 819 | struct wp *get_wp_for_flashchip(const struct flashchip *chip) { |
| 820 | // FIXME: The .wp field should be deleted from from struct flashchip |
| 821 | // completly, but linux_mtd and cros_ec still assign their own values |
| 822 | // to it. When they are cleaned up we can delete this. |
| 823 | if(chip->wp) return chip->wp; |
| 824 | |
| 825 | switch (chip->manufacture_id) { |
| 826 | case WINBOND_NEX_ID: |
| 827 | switch(chip->model_id) { |
| 828 | case WINBOND_NEX_W25X10: |
| 829 | case WINBOND_NEX_W25X20: |
| 830 | case WINBOND_NEX_W25X40: |
| 831 | case WINBOND_NEX_W25X80: |
| 832 | case WINBOND_NEX_W25Q128_V_M: |
| 833 | return &wp_w25; |
| 834 | case WINBOND_NEX_W25Q80_V: |
| 835 | case WINBOND_NEX_W25Q16_V: |
| 836 | case WINBOND_NEX_W25Q32_V: |
| 837 | case WINBOND_NEX_W25Q32_W: |
| 838 | case WINBOND_NEX_W25Q32JW: |
| 839 | case WINBOND_NEX_W25Q64_V: |
| 840 | case WINBOND_NEX_W25Q64_W: |
| 841 | // W25Q64JW does not have a range table entry, but the flashchip |
| 842 | // set .wp to wp_25q, so keep it here until the issue is resolved |
| 843 | case WINBOND_NEX_W25Q64JW: |
| 844 | case WINBOND_NEX_W25Q128_DTR: |
| 845 | case WINBOND_NEX_W25Q128_V: |
| 846 | case WINBOND_NEX_W25Q128_W: |
| 847 | return &wp_w25q; |
| 848 | case WINBOND_NEX_W25Q256_V: |
| 849 | case WINBOND_NEX_W25Q256JV_M: |
| 850 | return &wp_w25q_large; |
| 851 | } |
| 852 | break; |
| 853 | case EON_ID_NOPREFIX: |
| 854 | switch (chip->model_id) { |
| 855 | case EON_EN25F40: |
| 856 | case EON_EN25Q40: |
| 857 | case EON_EN25Q80: |
| 858 | case EON_EN25Q32: |
| 859 | case EON_EN25Q64: |
| 860 | case EON_EN25Q128: |
| 861 | case EON_EN25QH128: |
| 862 | case EON_EN25S64: |
| 863 | return &wp_w25; |
| 864 | } |
| 865 | break; |
| 866 | case MACRONIX_ID: |
| 867 | switch (chip->model_id) { |
| 868 | case MACRONIX_MX25L1005: |
| 869 | case MACRONIX_MX25L2005: |
| 870 | case MACRONIX_MX25L4005: |
| 871 | case MACRONIX_MX25L8005: |
| 872 | case MACRONIX_MX25L1605: |
| 873 | case MACRONIX_MX25L3205: |
| 874 | case MACRONIX_MX25U3235E: |
| 875 | case MACRONIX_MX25U6435E: |
| 876 | return &wp_w25; |
| 877 | case MACRONIX_MX25U12835E: |
| 878 | return &wp_w25q_large; |
| 879 | case MACRONIX_MX25L6405: |
| 880 | case MACRONIX_MX25L6495F: |
| 881 | case MACRONIX_MX25L25635F: |
| 882 | return &wp_generic; |
| 883 | } |
| 884 | break; |
| 885 | case ST_ID: |
| 886 | switch(chip->model_id) { |
| 887 | case ST_N25Q064__1E: |
| 888 | case ST_N25Q064__3E: |
| 889 | return &wp_w25; |
| 890 | } |
| 891 | break; |
| 892 | case GIGADEVICE_ID: |
| 893 | switch(chip->model_id) { |
| 894 | case GIGADEVICE_GD25LQ32: |
| 895 | // GD25Q40 does not have a .wp field in flashchips.c, but |
| 896 | // it is in the w25 range table function, so note it here |
| 897 | // until the issue is resolved: |
| 898 | // case GIGADEVICE_GD25Q40: |
| 899 | case GIGADEVICE_GD25Q64: |
| 900 | case GIGADEVICE_GD25LQ64: |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 901 | case GIGADEVICE_GD25Q128: |
| 902 | return &wp_w25; |
| 903 | case GIGADEVICE_GD25Q256D: |
| 904 | return &wp_w25q_large; |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 905 | case GIGADEVICE_GD25LQ128CD: |
| 906 | case GIGADEVICE_GD25Q32: |
| 907 | return &wp_generic; |
| 908 | } |
| 909 | break; |
| 910 | case AMIC_ID_NOPREFIX: |
| 911 | switch(chip->model_id) { |
| 912 | case AMIC_A25L040: |
| 913 | return &wp_w25; |
| 914 | } |
| 915 | break; |
| 916 | case ATMEL_ID: |
| 917 | switch(chip->model_id) { |
| 918 | case ATMEL_AT25SF128A: |
| 919 | case ATMEL_AT25SL128A: |
| 920 | return &wp_w25q; |
| 921 | } |
| 922 | break; |
| 923 | case PROGMANUF_ID: |
| 924 | switch(chip->model_id) { |
| 925 | case PROGDEV_ID: |
| 926 | return &wp_w25; |
| 927 | } |
| 928 | break; |
| 929 | case SPANSION_ID: |
| 930 | switch (chip->model_id) { |
| 931 | case SPANSION_S25FS128S_L: |
| 932 | case SPANSION_S25FS128S_S: |
| 933 | case SPANSION_S25FL256S_UL: |
| 934 | case SPANSION_S25FL256S_US: |
| 935 | // SPANSION_S25FL128S_UL does not have a range table entry, |
| 936 | // but its flashchip set .wp to wp_generic, so keep it here |
| 937 | // until the issue resolved |
| 938 | case SPANSION_S25FL128S_UL: |
| 939 | // SPANSION_S25FL128S_US does not have a range table entry, |
| 940 | // but its flashchip set .wp to wp_generic, so keep it here |
| 941 | // until the issue resolved |
| 942 | case SPANSION_S25FL128S_US: |
| 943 | return &wp_generic; |
| 944 | } |
| 945 | break; |
| 946 | } |
| 947 | |
| 948 | |
| 949 | return NULL; |
| 950 | } |
| 951 | |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 952 | /* FIXME: Move to spi25.c if it's a JEDEC standard opcode */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 953 | static uint8_t w25q_read_status_register_2(const struct flashctx *flash) |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 954 | { |
| 955 | static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { 0x35 }; |
| 956 | unsigned char readarr[2]; |
| 957 | int ret; |
| 958 | |
Edward O'Callaghan | 70f3e8f | 2020-12-21 12:50:52 +1100 | [diff] [blame] | 959 | if (flash->chip->read_status) { |
| 960 | msg_cdbg("RDSR2 failed! cmd=0x35 unimpl for opaque chips\n"); |
| 961 | return 0; |
| 962 | } |
| 963 | |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 964 | /* Read Status Register */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 965 | ret = spi_send_command(flash, sizeof(cmd), sizeof(readarr), cmd, readarr); |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 966 | if (ret) { |
| 967 | /* |
| 968 | * FIXME: make this a benign failure for now in case we are |
| 969 | * unable to execute the opcode |
| 970 | */ |
| 971 | msg_cdbg("RDSR2 failed!\n"); |
| 972 | readarr[0] = 0x00; |
| 973 | } |
| 974 | |
| 975 | return readarr[0]; |
| 976 | } |
| 977 | |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 978 | /* FIXME: Move to spi25.c if it's a JEDEC standard opcode */ |
Edward O'Callaghan | df43e90 | 2020-11-13 23:08:26 +1100 | [diff] [blame] | 979 | static uint8_t mx25l_read_config_register(const struct flashctx *flash) |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 980 | { |
| 981 | static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { 0x15 }; |
| 982 | unsigned char readarr[2]; /* leave room for dummy byte */ |
| 983 | int ret; |
| 984 | |
Edward O'Callaghan | 70f3e8f | 2020-12-21 12:50:52 +1100 | [diff] [blame] | 985 | if (flash->chip->read_status) { |
| 986 | msg_cdbg("RDCR failed! cmd=0x15 unimpl for opaque chips\n"); |
| 987 | return 0; |
| 988 | } |
| 989 | |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 990 | ret = spi_send_command(flash, sizeof(cmd), sizeof(readarr), cmd, readarr); |
| 991 | if (ret) { |
| 992 | msg_cdbg("RDCR failed!\n"); |
| 993 | readarr[0] = 0x00; |
| 994 | } |
| 995 | |
| 996 | return readarr[0]; |
| 997 | } |
| 998 | |
Nikolai Artemiev | 06afe3e | 2021-04-06 16:40:29 +1000 | [diff] [blame] | 999 | static int generic_range_table(const struct flashctx *flash, |
| 1000 | struct wp_range_descriptor **descrs, |
| 1001 | int *num_entries); |
| 1002 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1003 | /* Given a flash chip, this function returns its range table. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1004 | static int w25_range_table(const struct flashctx *flash, |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1005 | struct wp_range_descriptor **descrs, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1006 | int *num_entries) |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1007 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1008 | *descrs = 0; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1009 | *num_entries = 0; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1010 | |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1011 | switch (flash->chip->manufacture_id) { |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1012 | case WINBOND_NEX_ID: |
David Hendricks | 57566ed | 2010-08-16 18:24:45 -0700 | [diff] [blame] | 1013 | case EON_ID_NOPREFIX: |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 1014 | case MACRONIX_ID: |
Nikolai Artemiev | 0e560ae | 2021-04-06 16:45:00 +1000 | [diff] [blame^] | 1015 | return generic_range_table(flash, descrs, num_entries); |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 1016 | case ST_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1017 | switch(flash->chip->model_id) { |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 1018 | case ST_N25Q064__1E: |
| 1019 | case ST_N25Q064__3E: |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1020 | *descrs = n25q064_ranges; |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 1021 | *num_entries = ARRAY_SIZE(n25q064_ranges); |
| 1022 | break; |
| 1023 | default: |
| 1024 | msg_cerr("%s() %d: Micron flash chip mismatch" |
| 1025 | " (0x%04x), aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1026 | flash->chip->model_id); |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 1027 | return -1; |
| 1028 | } |
| 1029 | break; |
Bryan Freed | 9a0051f | 2012-05-22 16:06:09 -0700 | [diff] [blame] | 1030 | case GIGADEVICE_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1031 | switch(flash->chip->model_id) { |
Bryan Freed | 9a0051f | 2012-05-22 16:06:09 -0700 | [diff] [blame] | 1032 | case GIGADEVICE_GD25LQ32: |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1033 | *descrs = w25q32_ranges; |
Bryan Freed | 9a0051f | 2012-05-22 16:06:09 -0700 | [diff] [blame] | 1034 | *num_entries = ARRAY_SIZE(w25q32_ranges); |
| 1035 | break; |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 1036 | case GIGADEVICE_GD25Q40: |
| 1037 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 1038 | /* CMP == 1 */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1039 | *descrs = gd25q40_cmp1_ranges; |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 1040 | *num_entries = ARRAY_SIZE(gd25q40_cmp1_ranges); |
| 1041 | } else { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1042 | *descrs = gd25q40_cmp0_ranges; |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 1043 | *num_entries = ARRAY_SIZE(gd25q40_cmp0_ranges); |
| 1044 | } |
| 1045 | break; |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 1046 | case GIGADEVICE_GD25Q64: |
Marc Jones | b18734f | 2014-04-03 16:19:47 -0600 | [diff] [blame] | 1047 | case GIGADEVICE_GD25LQ64: |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1048 | *descrs = gd25q64_ranges; |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 1049 | *num_entries = ARRAY_SIZE(gd25q64_ranges); |
| 1050 | break; |
Martin Roth | 1fd87ed | 2017-02-27 20:50:50 -0700 | [diff] [blame] | 1051 | case GIGADEVICE_GD25Q128: |
| 1052 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 1053 | /* CMP == 1 */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1054 | *descrs = w25rq128_cmp1_ranges; |
Martin Roth | 1fd87ed | 2017-02-27 20:50:50 -0700 | [diff] [blame] | 1055 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 1056 | } else { |
| 1057 | /* CMP == 0 */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1058 | *descrs = w25rq128_cmp0_ranges; |
Martin Roth | 1fd87ed | 2017-02-27 20:50:50 -0700 | [diff] [blame] | 1059 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 1060 | } |
| 1061 | break; |
Duncan Laurie | 0c38355 | 2019-03-16 12:35:16 -0700 | [diff] [blame] | 1062 | case GIGADEVICE_GD25Q256D: |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1063 | *descrs = w25rq256_cmp0_ranges; |
Duncan Laurie | 0c38355 | 2019-03-16 12:35:16 -0700 | [diff] [blame] | 1064 | *num_entries = ARRAY_SIZE(w25rq256_cmp0_ranges); |
| 1065 | break; |
Bryan Freed | 9a0051f | 2012-05-22 16:06:09 -0700 | [diff] [blame] | 1066 | default: |
| 1067 | msg_cerr("%s() %d: GigaDevice flash chip mismatch" |
| 1068 | " (0x%04x), aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1069 | flash->chip->model_id); |
Bryan Freed | 9a0051f | 2012-05-22 16:06:09 -0700 | [diff] [blame] | 1070 | return -1; |
| 1071 | } |
| 1072 | break; |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame] | 1073 | case AMIC_ID_NOPREFIX: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1074 | switch(flash->chip->model_id) { |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame] | 1075 | case AMIC_A25L040: |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1076 | *descrs = a25l040_ranges; |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame] | 1077 | *num_entries = ARRAY_SIZE(a25l040_ranges); |
| 1078 | break; |
| 1079 | default: |
| 1080 | msg_cerr("%s() %d: AMIC flash chip mismatch" |
| 1081 | " (0x%04x), aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1082 | flash->chip->model_id); |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame] | 1083 | return -1; |
| 1084 | } |
| 1085 | break; |
Furquan Shaikh | b4df8ef | 2017-01-05 15:05:35 -0800 | [diff] [blame] | 1086 | case ATMEL_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1087 | switch(flash->chip->model_id) { |
Edward O'Callaghan | 1fa87e0 | 2019-05-03 02:27:24 -0400 | [diff] [blame] | 1088 | case ATMEL_AT25SF128A: |
Furquan Shaikh | b4df8ef | 2017-01-05 15:05:35 -0800 | [diff] [blame] | 1089 | case ATMEL_AT25SL128A: |
| 1090 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 1091 | /* CMP == 1 */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1092 | *descrs = w25rq128_cmp1_ranges; |
Furquan Shaikh | b4df8ef | 2017-01-05 15:05:35 -0800 | [diff] [blame] | 1093 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 1094 | } else { |
| 1095 | /* CMP == 0 */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1096 | *descrs = w25rq128_cmp0_ranges; |
Furquan Shaikh | b4df8ef | 2017-01-05 15:05:35 -0800 | [diff] [blame] | 1097 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 1098 | } |
| 1099 | break; |
| 1100 | default: |
| 1101 | msg_cerr("%s() %d: Atmel flash chip mismatch" |
| 1102 | " (0x%04x), aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1103 | flash->chip->model_id); |
Furquan Shaikh | b4df8ef | 2017-01-05 15:05:35 -0800 | [diff] [blame] | 1104 | return -1; |
| 1105 | } |
| 1106 | break; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1107 | default: |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1108 | msg_cerr("%s: flash vendor (0x%x) not found, aborting\n", |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 1109 | __func__, flash->chip->manufacture_id); |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1110 | return -1; |
| 1111 | } |
| 1112 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1113 | return 0; |
| 1114 | } |
| 1115 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1116 | int w25_range_to_status(const struct flashctx *flash, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1117 | unsigned int start, unsigned int len, |
| 1118 | struct w25q_status *status) |
| 1119 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1120 | struct wp_range_descriptor *descrs; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1121 | int i, range_found = 0; |
| 1122 | int num_entries; |
| 1123 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1124 | if (w25_range_table(flash, &descrs, &num_entries)) |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1125 | return -1; |
| 1126 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1127 | for (i = 0; i < num_entries; i++) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1128 | struct wp_range *r = &descrs[i].range; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1129 | |
| 1130 | msg_cspew("comparing range 0x%x 0x%x / 0x%x 0x%x\n", |
| 1131 | start, len, r->start, r->len); |
| 1132 | if ((start == r->start) && (len == r->len)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1133 | status->bp0 = descrs[i].bp & 1; |
| 1134 | status->bp1 = descrs[i].bp >> 1; |
| 1135 | status->bp2 = descrs[i].bp >> 2; |
| 1136 | status->tb = descrs[i].m.tb; |
| 1137 | status->sec = descrs[i].m.sec; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1138 | |
| 1139 | range_found = 1; |
| 1140 | break; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | if (!range_found) { |
Edward O'Callaghan | 3be63e0 | 2020-03-27 14:44:24 +1100 | [diff] [blame] | 1145 | msg_cerr("%s: matching range not found\n", __func__); |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1146 | return -1; |
| 1147 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1148 | |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1149 | return 0; |
| 1150 | } |
| 1151 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1152 | int w25_status_to_range(const struct flashctx *flash, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1153 | const struct w25q_status *status, |
| 1154 | unsigned int *start, unsigned int *len) |
| 1155 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1156 | struct wp_range_descriptor *descrs; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1157 | int i, status_found = 0; |
| 1158 | int num_entries; |
| 1159 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1160 | if (w25_range_table(flash, &descrs, &num_entries)) |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1161 | return -1; |
| 1162 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1163 | for (i = 0; i < num_entries; i++) { |
| 1164 | int bp; |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 1165 | int table_bp, table_tb, table_sec; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1166 | |
| 1167 | bp = status->bp0 | (status->bp1 << 1) | (status->bp2 << 2); |
| 1168 | msg_cspew("comparing 0x%x 0x%x / 0x%x 0x%x / 0x%x 0x%x\n", |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1169 | bp, descrs[i].bp, |
| 1170 | status->tb, descrs[i].m.tb, |
| 1171 | status->sec, descrs[i].m.sec); |
| 1172 | table_bp = descrs[i].bp; |
| 1173 | table_tb = descrs[i].m.tb; |
| 1174 | table_sec = descrs[i].m.sec; |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 1175 | if ((bp == table_bp || table_bp == X) && |
| 1176 | (status->tb == table_tb || table_tb == X) && |
| 1177 | (status->sec == table_sec || table_sec == X)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1178 | *start = descrs[i].range.start; |
| 1179 | *len = descrs[i].range.len; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1180 | |
| 1181 | status_found = 1; |
| 1182 | break; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | if (!status_found) { |
| 1187 | msg_cerr("matching status not found\n"); |
| 1188 | return -1; |
| 1189 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1190 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1191 | return 0; |
| 1192 | } |
| 1193 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1194 | /* Given a [start, len], this function calls w25_range_to_status() to convert |
| 1195 | * it to flash-chip-specific range bits, then sets into status register. |
| 1196 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1197 | static int w25_set_range(const struct flashctx *flash, |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1198 | unsigned int start, unsigned int len) |
| 1199 | { |
| 1200 | struct w25q_status status; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1201 | int tmp = 0; |
| 1202 | int expected = 0; |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1203 | |
| 1204 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1205 | tmp = spi_read_status_register(flash); |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1206 | memcpy(&status, &tmp, 1); |
| 1207 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 1208 | |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1209 | if (w25_range_to_status(flash, start, len, &status)) |
| 1210 | return -1; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1211 | |
| 1212 | msg_cdbg("status.busy: %x\n", status.busy); |
| 1213 | msg_cdbg("status.wel: %x\n", status.wel); |
| 1214 | msg_cdbg("status.bp0: %x\n", status.bp0); |
| 1215 | msg_cdbg("status.bp1: %x\n", status.bp1); |
| 1216 | msg_cdbg("status.bp2: %x\n", status.bp2); |
| 1217 | msg_cdbg("status.tb: %x\n", status.tb); |
| 1218 | msg_cdbg("status.sec: %x\n", status.sec); |
| 1219 | msg_cdbg("status.srp0: %x\n", status.srp0); |
| 1220 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1221 | memcpy(&expected, &status, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1222 | spi_write_status_register(flash, expected); |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1223 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1224 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1225 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1226 | if ((tmp & MASK_WP_AREA) != (expected & MASK_WP_AREA)) { |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 1227 | msg_cerr("expected=0x%02x, but actual=0x%02x.\n", |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1228 | expected, tmp); |
| 1229 | return 1; |
| 1230 | } |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1231 | |
| 1232 | return 0; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1235 | /* Print out the current status register value with human-readable text. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1236 | static int w25_wp_status(const struct flashctx *flash) |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1237 | { |
| 1238 | struct w25q_status status; |
| 1239 | int tmp; |
David Hendricks | ce8ded3 | 2010-10-08 11:23:38 -0700 | [diff] [blame] | 1240 | unsigned int start, len; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1241 | int ret = 0; |
| 1242 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1243 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1244 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1245 | memcpy(&status, &tmp, 1); |
| 1246 | msg_cinfo("WP: status: 0x%02x\n", tmp); |
| 1247 | msg_cinfo("WP: status.srp0: %x\n", status.srp0); |
| 1248 | msg_cinfo("WP: write protect is %s.\n", |
| 1249 | status.srp0 ? "enabled" : "disabled"); |
| 1250 | |
| 1251 | msg_cinfo("WP: write protect range: "); |
| 1252 | if (w25_status_to_range(flash, &status, &start, &len)) { |
| 1253 | msg_cinfo("(cannot resolve the range)\n"); |
| 1254 | ret = -1; |
| 1255 | } else { |
| 1256 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 1257 | } |
| 1258 | |
| 1259 | return ret; |
| 1260 | } |
| 1261 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1262 | static int w25q_large_range_to_status(const struct flashctx *flash, |
| 1263 | unsigned int start, unsigned int len, |
| 1264 | struct w25q_status_large *status) |
| 1265 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1266 | struct wp_range_descriptor *descrs; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1267 | int i, range_found = 0; |
| 1268 | int num_entries; |
| 1269 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1270 | if (w25_range_table(flash, &descrs, &num_entries)) |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1271 | return -1; |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1272 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1273 | for (i = 0; i < num_entries; i++) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1274 | struct wp_range *r = &descrs[i].range; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1275 | |
| 1276 | msg_cspew("comparing range 0x%x 0x%x / 0x%x 0x%x\n", |
| 1277 | start, len, r->start, r->len); |
| 1278 | if ((start == r->start) && (len == r->len)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1279 | status->bp0 = descrs[i].bp & 1; |
| 1280 | status->bp1 = descrs[i].bp >> 1; |
| 1281 | status->bp2 = descrs[i].bp >> 2; |
| 1282 | status->bp3 = descrs[i].bp >> 3; |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 1283 | /* |
| 1284 | * For MX25U12835E chip, Top/Bottom (T/B) bit is not |
| 1285 | * part of status register and in that bit position is |
| 1286 | * Quad Enable (QE) |
| 1287 | */ |
| 1288 | if (flash->chip->manufacture_id != MACRONIX_ID || |
| 1289 | flash->chip->model_id != MACRONIX_MX25U12835E) |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1290 | status->tb = descrs[i].m.tb; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1291 | |
| 1292 | range_found = 1; |
| 1293 | break; |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | if (!range_found) { |
Edward O'Callaghan | 3be63e0 | 2020-03-27 14:44:24 +1100 | [diff] [blame] | 1298 | msg_cerr("%s: matching range not found\n", __func__); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1299 | return -1; |
| 1300 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1301 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1302 | return 0; |
| 1303 | } |
| 1304 | |
| 1305 | static int w25_large_status_to_range(const struct flashctx *flash, |
| 1306 | const struct w25q_status_large *status, |
| 1307 | unsigned int *start, unsigned int *len) |
| 1308 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1309 | struct wp_range_descriptor *descrs; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1310 | int i, status_found = 0; |
| 1311 | int num_entries; |
| 1312 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1313 | if (w25_range_table(flash, &descrs, &num_entries)) |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1314 | return -1; |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1315 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1316 | for (i = 0; i < num_entries; i++) { |
| 1317 | int bp; |
| 1318 | int table_bp, table_tb; |
| 1319 | |
| 1320 | bp = status->bp0 | (status->bp1 << 1) | (status->bp2 << 2) | |
| 1321 | (status->bp3 << 3); |
| 1322 | msg_cspew("comparing 0x%x 0x%x / 0x%x 0x%x\n", |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1323 | bp, descrs[i].bp, |
| 1324 | status->tb, descrs[i].m.tb); |
| 1325 | table_bp = descrs[i].bp; |
| 1326 | table_tb = descrs[i].m.tb; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1327 | if ((bp == table_bp || table_bp == X) && |
| 1328 | (status->tb == table_tb || table_tb == X)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1329 | *start = descrs[i].range.start; |
| 1330 | *len = descrs[i].range.len; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1331 | |
| 1332 | status_found = 1; |
| 1333 | break; |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | if (!status_found) { |
| 1338 | msg_cerr("matching status not found\n"); |
| 1339 | return -1; |
| 1340 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1341 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1342 | return 0; |
| 1343 | } |
| 1344 | |
| 1345 | /* Given a [start, len], this function calls w25_range_to_status() to convert |
| 1346 | * it to flash-chip-specific range bits, then sets into status register. |
| 1347 | * Returns 0 if successful, -1 on error, and 1 if reading back was different. |
| 1348 | */ |
| 1349 | static int w25q_large_set_range(const struct flashctx *flash, |
| 1350 | unsigned int start, unsigned int len) |
| 1351 | { |
| 1352 | struct w25q_status_large status; |
| 1353 | int tmp; |
| 1354 | int expected = 0; |
| 1355 | |
| 1356 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1357 | tmp = spi_read_status_register(flash); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1358 | memcpy(&status, &tmp, 1); |
| 1359 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 1360 | |
| 1361 | if (w25q_large_range_to_status(flash, start, len, &status)) |
| 1362 | return -1; |
| 1363 | |
| 1364 | msg_cdbg("status.busy: %x\n", status.busy); |
| 1365 | msg_cdbg("status.wel: %x\n", status.wel); |
| 1366 | msg_cdbg("status.bp0: %x\n", status.bp0); |
| 1367 | msg_cdbg("status.bp1: %x\n", status.bp1); |
| 1368 | msg_cdbg("status.bp2: %x\n", status.bp2); |
| 1369 | msg_cdbg("status.bp3: %x\n", status.bp3); |
| 1370 | msg_cdbg("status.tb: %x\n", status.tb); |
| 1371 | msg_cdbg("status.srp0: %x\n", status.srp0); |
| 1372 | |
| 1373 | memcpy(&expected, &status, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1374 | spi_write_status_register(flash, expected); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1375 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1376 | tmp = spi_read_status_register(flash); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1377 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1378 | if ((tmp & MASK_WP_AREA_LARGE) != (expected & MASK_WP_AREA_LARGE)) { |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1379 | msg_cerr("expected=0x%02x, but actual=0x%02x.\n", |
| 1380 | expected, tmp); |
| 1381 | return 1; |
| 1382 | } |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1383 | |
| 1384 | return 0; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | static int w25q_large_wp_status(const struct flashctx *flash) |
| 1388 | { |
| 1389 | struct w25q_status_large sr1; |
| 1390 | struct w25q_status_2 sr2; |
| 1391 | uint8_t tmp[2]; |
| 1392 | unsigned int start, len; |
| 1393 | int ret = 0; |
| 1394 | |
| 1395 | memset(&sr1, 0, sizeof(sr1)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1396 | tmp[0] = spi_read_status_register(flash); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1397 | memcpy(&sr1, &tmp[0], 1); |
| 1398 | |
| 1399 | memset(&sr2, 0, sizeof(sr2)); |
| 1400 | tmp[1] = w25q_read_status_register_2(flash); |
| 1401 | memcpy(&sr2, &tmp[1], 1); |
| 1402 | |
| 1403 | msg_cinfo("WP: status: 0x%02x%02x\n", tmp[1], tmp[0]); |
| 1404 | msg_cinfo("WP: status.srp0: %x\n", sr1.srp0); |
| 1405 | msg_cinfo("WP: status.srp1: %x\n", sr2.srp1); |
| 1406 | msg_cinfo("WP: write protect is %s.\n", |
| 1407 | (sr1.srp0 || sr2.srp1) ? "enabled" : "disabled"); |
| 1408 | |
| 1409 | msg_cinfo("WP: write protect range: "); |
| 1410 | if (w25_large_status_to_range(flash, &sr1, &start, &len)) { |
| 1411 | msg_cinfo("(cannot resolve the range)\n"); |
| 1412 | ret = -1; |
| 1413 | } else { |
| 1414 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 1415 | } |
| 1416 | |
| 1417 | return ret; |
| 1418 | } |
| 1419 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1420 | /* Set/clear the SRP0 bit in the status register. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1421 | static int w25_set_srp0(const struct flashctx *flash, int enable) |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1422 | { |
| 1423 | struct w25q_status status; |
| 1424 | int tmp = 0; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1425 | int expected = 0; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1426 | |
| 1427 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1428 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1429 | /* FIXME: this is NOT endian-free copy. */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1430 | memcpy(&status, &tmp, 1); |
| 1431 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 1432 | |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1433 | status.srp0 = enable ? 1 : 0; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1434 | memcpy(&expected, &status, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1435 | spi_write_status_register(flash, expected); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1436 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1437 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1438 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
| 1439 | if ((tmp & MASK_WP_AREA) != (expected & MASK_WP_AREA)) |
| 1440 | return 1; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1441 | |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1445 | static int w25_enable_writeprotect(const struct flashctx *flash, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1446 | enum wp_mode wp_mode) |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1447 | { |
| 1448 | int ret; |
| 1449 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 1450 | if (wp_mode != WP_MODE_HARDWARE) { |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1451 | msg_cerr("%s(): unsupported write-protect mode\n", __func__); |
| 1452 | return 1; |
| 1453 | } |
| 1454 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 1455 | ret = w25_set_srp0(flash, 1); |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 1456 | if (ret) |
| 1457 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1458 | return ret; |
| 1459 | } |
| 1460 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1461 | static int w25_disable_writeprotect(const struct flashctx *flash) |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1462 | { |
| 1463 | int ret; |
| 1464 | |
| 1465 | ret = w25_set_srp0(flash, 0); |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 1466 | if (ret) |
| 1467 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1468 | |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1469 | return ret; |
| 1470 | } |
| 1471 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1472 | static int w25_list_ranges(const struct flashctx *flash) |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1473 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1474 | struct wp_range_descriptor *descrs; |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1475 | int i, num_entries; |
| 1476 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1477 | if (w25_range_table(flash, &descrs, &num_entries)) |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1478 | return -1; |
| 1479 | |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1480 | for (i = 0; i < num_entries; i++) { |
| 1481 | msg_cinfo("start: 0x%06x, length: 0x%06x\n", |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1482 | descrs[i].range.start, |
| 1483 | descrs[i].range.len); |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1489 | static int w25q_wp_status(const struct flashctx *flash) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1490 | { |
| 1491 | struct w25q_status sr1; |
| 1492 | struct w25q_status_2 sr2; |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1493 | uint8_t tmp[2]; |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1494 | unsigned int start, len; |
| 1495 | int ret = 0; |
| 1496 | |
| 1497 | memset(&sr1, 0, sizeof(sr1)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1498 | tmp[0] = spi_read_status_register(flash); |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1499 | memcpy(&sr1, &tmp[0], 1); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1500 | |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1501 | memset(&sr2, 0, sizeof(sr2)); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1502 | tmp[1] = w25q_read_status_register_2(flash); |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1503 | memcpy(&sr2, &tmp[1], 1); |
| 1504 | |
| 1505 | msg_cinfo("WP: status: 0x%02x%02x\n", tmp[1], tmp[0]); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1506 | msg_cinfo("WP: status.srp0: %x\n", sr1.srp0); |
| 1507 | msg_cinfo("WP: status.srp1: %x\n", sr2.srp1); |
| 1508 | msg_cinfo("WP: write protect is %s.\n", |
| 1509 | (sr1.srp0 || sr2.srp1) ? "enabled" : "disabled"); |
| 1510 | |
| 1511 | msg_cinfo("WP: write protect range: "); |
| 1512 | if (w25_status_to_range(flash, &sr1, &start, &len)) { |
| 1513 | msg_cinfo("(cannot resolve the range)\n"); |
| 1514 | ret = -1; |
| 1515 | } else { |
| 1516 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 1517 | } |
| 1518 | |
| 1519 | return ret; |
| 1520 | } |
| 1521 | |
| 1522 | /* |
| 1523 | * W25Q adds an optional byte to the standard WRSR opcode. If /CS is |
| 1524 | * de-asserted after the first byte, then it acts like a JEDEC-standard |
| 1525 | * WRSR command. if /CS is asserted, then the next data byte is written |
| 1526 | * into status register 2. |
| 1527 | */ |
| 1528 | #define W25Q_WRSR_OUTSIZE 0x03 |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1529 | static int w25q_write_status_register_WREN(const struct flashctx *flash, uint8_t s1, uint8_t s2) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1530 | { |
| 1531 | int result; |
| 1532 | struct spi_command cmds[] = { |
| 1533 | { |
| 1534 | /* FIXME: WRSR requires either EWSR or WREN depending on chip type. */ |
| 1535 | .writecnt = JEDEC_WREN_OUTSIZE, |
| 1536 | .writearr = (const unsigned char[]){ JEDEC_WREN }, |
| 1537 | .readcnt = 0, |
| 1538 | .readarr = NULL, |
| 1539 | }, { |
| 1540 | .writecnt = W25Q_WRSR_OUTSIZE, |
| 1541 | .writearr = (const unsigned char[]){ JEDEC_WRSR, s1, s2 }, |
| 1542 | .readcnt = 0, |
| 1543 | .readarr = NULL, |
| 1544 | }, { |
| 1545 | .writecnt = 0, |
| 1546 | .writearr = NULL, |
| 1547 | .readcnt = 0, |
| 1548 | .readarr = NULL, |
| 1549 | }}; |
| 1550 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1551 | result = spi_send_multicommand(flash, cmds); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1552 | if (result) { |
| 1553 | msg_cerr("%s failed during command execution\n", |
| 1554 | __func__); |
| 1555 | } |
| 1556 | |
| 1557 | /* WRSR performs a self-timed erase before the changes take effect. */ |
David Hendricks | 6082404 | 2014-12-11 17:22:06 -0800 | [diff] [blame] | 1558 | programmer_delay(100 * 1000); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1559 | |
| 1560 | return result; |
| 1561 | } |
| 1562 | |
| 1563 | /* |
| 1564 | * Set/clear the SRP1 bit in status register 2. |
| 1565 | * FIXME: make this more generic if other chips use the same SR2 layout |
| 1566 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1567 | static int w25q_set_srp1(const struct flashctx *flash, int enable) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1568 | { |
| 1569 | struct w25q_status sr1; |
| 1570 | struct w25q_status_2 sr2; |
| 1571 | uint8_t tmp, expected; |
| 1572 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1573 | tmp = spi_read_status_register(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1574 | memcpy(&sr1, &tmp, 1); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1575 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1576 | memcpy(&sr2, &tmp, 1); |
| 1577 | |
| 1578 | msg_cdbg("%s: old status 2: 0x%02x\n", __func__, tmp); |
| 1579 | |
| 1580 | sr2.srp1 = enable ? 1 : 0; |
| 1581 | |
| 1582 | memcpy(&expected, &sr2, 1); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1583 | w25q_write_status_register_WREN(flash, *((uint8_t *)&sr1), *((uint8_t *)&sr2)); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1584 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1585 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1586 | msg_cdbg("%s: new status 2: 0x%02x\n", __func__, tmp); |
| 1587 | if ((tmp & MASK_WP2_AREA) != (expected & MASK_WP2_AREA)) |
| 1588 | return 1; |
| 1589 | |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
| 1593 | enum wp_mode get_wp_mode(const char *mode_str) |
| 1594 | { |
| 1595 | enum wp_mode wp_mode = WP_MODE_UNKNOWN; |
| 1596 | |
| 1597 | if (!strcasecmp(mode_str, "hardware")) |
| 1598 | wp_mode = WP_MODE_HARDWARE; |
| 1599 | else if (!strcasecmp(mode_str, "power_cycle")) |
| 1600 | wp_mode = WP_MODE_POWER_CYCLE; |
| 1601 | else if (!strcasecmp(mode_str, "permanent")) |
| 1602 | wp_mode = WP_MODE_PERMANENT; |
| 1603 | |
| 1604 | return wp_mode; |
| 1605 | } |
| 1606 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1607 | static int w25q_disable_writeprotect(const struct flashctx *flash, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1608 | enum wp_mode wp_mode) |
| 1609 | { |
| 1610 | int ret = 1; |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1611 | struct w25q_status_2 sr2; |
| 1612 | uint8_t tmp; |
| 1613 | |
| 1614 | switch (wp_mode) { |
| 1615 | case WP_MODE_HARDWARE: |
| 1616 | ret = w25_set_srp0(flash, 0); |
| 1617 | break; |
| 1618 | case WP_MODE_POWER_CYCLE: |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1619 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1620 | memcpy(&sr2, &tmp, 1); |
| 1621 | if (sr2.srp1) { |
| 1622 | msg_cerr("%s(): must disconnect power to disable " |
| 1623 | "write-protection\n", __func__); |
| 1624 | } else { |
| 1625 | ret = 0; |
| 1626 | } |
| 1627 | break; |
| 1628 | case WP_MODE_PERMANENT: |
| 1629 | msg_cerr("%s(): cannot disable permanent write-protection\n", |
| 1630 | __func__); |
| 1631 | break; |
| 1632 | default: |
| 1633 | msg_cerr("%s(): invalid mode specified\n", __func__); |
| 1634 | break; |
| 1635 | } |
| 1636 | |
| 1637 | if (ret) |
| 1638 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1639 | |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1640 | return ret; |
| 1641 | } |
| 1642 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1643 | static int w25q_disable_writeprotect_default(const struct flashctx *flash) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1644 | { |
| 1645 | return w25q_disable_writeprotect(flash, WP_MODE_HARDWARE); |
| 1646 | } |
| 1647 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1648 | static int w25q_enable_writeprotect(const struct flashctx *flash, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1649 | enum wp_mode wp_mode) |
| 1650 | { |
| 1651 | int ret = 1; |
| 1652 | struct w25q_status sr1; |
| 1653 | struct w25q_status_2 sr2; |
| 1654 | uint8_t tmp; |
| 1655 | |
| 1656 | switch (wp_mode) { |
| 1657 | case WP_MODE_HARDWARE: |
| 1658 | if (w25q_disable_writeprotect(flash, WP_MODE_POWER_CYCLE)) { |
| 1659 | msg_cerr("%s(): cannot disable power cycle WP mode\n", |
| 1660 | __func__); |
| 1661 | break; |
| 1662 | } |
| 1663 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1664 | tmp = spi_read_status_register(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1665 | memcpy(&sr1, &tmp, 1); |
| 1666 | if (sr1.srp0) |
| 1667 | ret = 0; |
| 1668 | else |
| 1669 | ret = w25_set_srp0(flash, 1); |
| 1670 | |
| 1671 | break; |
| 1672 | case WP_MODE_POWER_CYCLE: |
| 1673 | if (w25q_disable_writeprotect(flash, WP_MODE_HARDWARE)) { |
| 1674 | msg_cerr("%s(): cannot disable hardware WP mode\n", |
| 1675 | __func__); |
| 1676 | break; |
| 1677 | } |
| 1678 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1679 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1680 | memcpy(&sr2, &tmp, 1); |
| 1681 | if (sr2.srp1) |
| 1682 | ret = 0; |
| 1683 | else |
| 1684 | ret = w25q_set_srp1(flash, 1); |
| 1685 | |
| 1686 | break; |
| 1687 | case WP_MODE_PERMANENT: |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1688 | tmp = spi_read_status_register(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1689 | memcpy(&sr1, &tmp, 1); |
| 1690 | if (sr1.srp0 == 0) { |
| 1691 | ret = w25_set_srp0(flash, 1); |
| 1692 | if (ret) { |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1693 | msg_perr("%s(): cannot enable SRP0 for " |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1694 | "permanent WP\n", __func__); |
| 1695 | break; |
| 1696 | } |
| 1697 | } |
| 1698 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1699 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1700 | memcpy(&sr2, &tmp, 1); |
| 1701 | if (sr2.srp1 == 0) { |
| 1702 | ret = w25q_set_srp1(flash, 1); |
| 1703 | if (ret) { |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1704 | msg_perr("%s(): cannot enable SRP1 for " |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1705 | "permanent WP\n", __func__); |
| 1706 | break; |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | break; |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1711 | default: |
| 1712 | msg_perr("%s(): invalid mode %d\n", __func__, wp_mode); |
| 1713 | break; |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | if (ret) |
| 1717 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
| 1718 | return ret; |
| 1719 | } |
| 1720 | |
| 1721 | /* W25P, W25X, and many flash chips from various vendors */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1722 | struct wp wp_w25 = { |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1723 | .list_ranges = w25_list_ranges, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1724 | .set_range = w25_set_range, |
| 1725 | .enable = w25_enable_writeprotect, |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1726 | .disable = w25_disable_writeprotect, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1727 | .wp_status = w25_wp_status, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1728 | |
| 1729 | }; |
| 1730 | |
| 1731 | /* W25Q series has features such as a second status register and SFDP */ |
| 1732 | struct wp wp_w25q = { |
| 1733 | .list_ranges = w25_list_ranges, |
| 1734 | .set_range = w25_set_range, |
| 1735 | .enable = w25q_enable_writeprotect, |
| 1736 | /* |
| 1737 | * By default, disable hardware write-protection. We may change |
| 1738 | * this later if we want to add fine-grained write-protect disable |
| 1739 | * as a command-line option. |
| 1740 | */ |
| 1741 | .disable = w25q_disable_writeprotect_default, |
| 1742 | .wp_status = w25q_wp_status, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1743 | }; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 1744 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1745 | /* W25Q large series has 4 block-protect bits */ |
| 1746 | struct wp wp_w25q_large = { |
| 1747 | .list_ranges = w25_list_ranges, |
| 1748 | .set_range = w25q_large_set_range, |
| 1749 | .enable = w25q_enable_writeprotect, |
| 1750 | /* |
| 1751 | * By default, disable hardware write-protection. We may change |
| 1752 | * this later if we want to add fine-grained write-protect disable |
| 1753 | * as a command-line option. |
| 1754 | */ |
| 1755 | .disable = w25q_disable_writeprotect_default, |
| 1756 | .wp_status = w25q_large_wp_status, |
| 1757 | }; |
| 1758 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 1759 | static struct wp_range_descriptor gd25q32_cmp0_ranges[] = { |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1760 | /* none, bp4 and bp3 => don't care */ |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1761 | { { }, 0x00, {0, 0} }, |
| 1762 | { { }, 0x08, {0, 0} }, |
| 1763 | { { }, 0x10, {0, 0} }, |
| 1764 | { { }, 0x18, {0, 0} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1765 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1766 | { { }, 0x01, {0x3f0000, 64 * 1024} }, |
| 1767 | { { }, 0x02, {0x3e0000, 128 * 1024} }, |
| 1768 | { { }, 0x03, {0x3c0000, 256 * 1024} }, |
| 1769 | { { }, 0x04, {0x380000, 512 * 1024} }, |
| 1770 | { { }, 0x05, {0x300000, 1024 * 1024} }, |
| 1771 | { { }, 0x06, {0x200000, 2048 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1772 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1773 | { { }, 0x09, {0x000000, 64 * 1024} }, |
| 1774 | { { }, 0x0a, {0x000000, 128 * 1024} }, |
| 1775 | { { }, 0x0b, {0x000000, 256 * 1024} }, |
| 1776 | { { }, 0x0c, {0x000000, 512 * 1024} }, |
| 1777 | { { }, 0x0d, {0x000000, 1024 * 1024} }, |
| 1778 | { { }, 0x0e, {0x000000, 2048 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1779 | |
| 1780 | /* all, bp4 and bp3 => don't care */ |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1781 | { { }, 0x07, {0x000000, 4096 * 1024} }, |
| 1782 | { { }, 0x0f, {0x000000, 4096 * 1024} }, |
| 1783 | { { }, 0x17, {0x000000, 4096 * 1024} }, |
| 1784 | { { }, 0x1f, {0x000000, 4096 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1785 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1786 | { { }, 0x11, {0x3ff000, 4 * 1024} }, |
| 1787 | { { }, 0x12, {0x3fe000, 8 * 1024} }, |
| 1788 | { { }, 0x13, {0x3fc000, 16 * 1024} }, |
| 1789 | { { }, 0x14, {0x3f8000, 32 * 1024} }, /* bp0 => don't care */ |
| 1790 | { { }, 0x15, {0x3f8000, 32 * 1024} }, /* bp0 => don't care */ |
| 1791 | { { }, 0x16, {0x3f8000, 32 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1792 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1793 | { { }, 0x19, {0x000000, 4 * 1024} }, |
| 1794 | { { }, 0x1a, {0x000000, 8 * 1024} }, |
| 1795 | { { }, 0x1b, {0x000000, 16 * 1024} }, |
| 1796 | { { }, 0x1c, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 1797 | { { }, 0x1d, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 1798 | { { }, 0x1e, {0x000000, 32 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1799 | }; |
| 1800 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 1801 | static struct wp_range_descriptor gd25q32_cmp1_ranges[] = { |
Martin Roth | 563a1fe | 2017-04-18 14:26:27 -0600 | [diff] [blame] | 1802 | /* All, bp4 and bp3 => don't care */ |
| 1803 | { { }, 0x00, {0x000000, 4096 * 1024} }, /* All */ |
| 1804 | { { }, 0x08, {0x000000, 4096 * 1024} }, |
| 1805 | { { }, 0x10, {0x000000, 4096 * 1024} }, |
| 1806 | { { }, 0x18, {0x000000, 4096 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1807 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1808 | { { }, 0x01, {0x000000, 4032 * 1024} }, |
| 1809 | { { }, 0x02, {0x000000, 3968 * 1024} }, |
| 1810 | { { }, 0x03, {0x000000, 3840 * 1024} }, |
| 1811 | { { }, 0x04, {0x000000, 3584 * 1024} }, |
| 1812 | { { }, 0x05, {0x000000, 3 * 1024 * 1024} }, |
| 1813 | { { }, 0x06, {0x000000, 2 * 1024 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1814 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1815 | { { }, 0x09, {0x010000, 4032 * 1024} }, |
| 1816 | { { }, 0x0a, {0x020000, 3968 * 1024} }, |
| 1817 | { { }, 0x0b, {0x040000, 3840 * 1024} }, |
| 1818 | { { }, 0x0c, {0x080000, 3584 * 1024} }, |
| 1819 | { { }, 0x0d, {0x100000, 3 * 1024 * 1024} }, |
| 1820 | { { }, 0x0e, {0x200000, 2 * 1024 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1821 | |
Martin Roth | 563a1fe | 2017-04-18 14:26:27 -0600 | [diff] [blame] | 1822 | /* None, bp4 and bp3 => don't care */ |
| 1823 | { { }, 0x07, {0, 0} }, /* None */ |
| 1824 | { { }, 0x0f, {0, 0} }, |
| 1825 | { { }, 0x17, {0, 0} }, |
| 1826 | { { }, 0x1f, {0, 0} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1827 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1828 | { { }, 0x11, {0x000000, 4092 * 1024} }, |
| 1829 | { { }, 0x12, {0x000000, 4088 * 1024} }, |
| 1830 | { { }, 0x13, {0x000000, 4080 * 1024} }, |
| 1831 | { { }, 0x14, {0x000000, 4064 * 1024} }, /* bp0 => don't care */ |
| 1832 | { { }, 0x15, {0x000000, 4064 * 1024} }, /* bp0 => don't care */ |
| 1833 | { { }, 0x16, {0x000000, 4064 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1834 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1835 | { { }, 0x19, {0x001000, 4092 * 1024} }, |
| 1836 | { { }, 0x1a, {0x002000, 4088 * 1024} }, |
| 1837 | { { }, 0x1b, {0x040000, 4080 * 1024} }, |
| 1838 | { { }, 0x1c, {0x080000, 4064 * 1024} }, /* bp0 => don't care */ |
| 1839 | { { }, 0x1d, {0x080000, 4064 * 1024} }, /* bp0 => don't care */ |
| 1840 | { { }, 0x1e, {0x080000, 4064 * 1024} }, |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1841 | }; |
| 1842 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1843 | static struct status_register_layout gd25q32_sr1 = { |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1844 | /* TODO: map second status register */ |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1845 | .bp0_pos = 2, .bp_bits = 5, .srp_pos = 7 |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 1846 | }; |
| 1847 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 1848 | static struct wp_range_descriptor gd25q128_cmp0_ranges[] = { |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 1849 | /* none, bp4 and bp3 => don't care, others = 0 */ |
| 1850 | { { .tb = 0 }, 0x00, {0, 0} }, |
| 1851 | { { .tb = 0 }, 0x08, {0, 0} }, |
| 1852 | { { .tb = 0 }, 0x10, {0, 0} }, |
| 1853 | { { .tb = 0 }, 0x18, {0, 0} }, |
| 1854 | |
| 1855 | { { .tb = 0 }, 0x01, {0xfc0000, 256 * 1024} }, |
| 1856 | { { .tb = 0 }, 0x02, {0xf80000, 512 * 1024} }, |
| 1857 | { { .tb = 0 }, 0x03, {0xf00000, 1024 * 1024} }, |
| 1858 | { { .tb = 0 }, 0x04, {0xe00000, 2048 * 1024} }, |
| 1859 | { { .tb = 0 }, 0x05, {0xc00000, 4096 * 1024} }, |
| 1860 | { { .tb = 0 }, 0x06, {0x800000, 8192 * 1024} }, |
| 1861 | |
| 1862 | { { .tb = 0 }, 0x09, {0x000000, 256 * 1024} }, |
| 1863 | { { .tb = 0 }, 0x0a, {0x000000, 512 * 1024} }, |
| 1864 | { { .tb = 0 }, 0x0b, {0x000000, 1024 * 1024} }, |
| 1865 | { { .tb = 0 }, 0x0c, {0x000000, 2048 * 1024} }, |
| 1866 | { { .tb = 0 }, 0x0d, {0x000000, 4096 * 1024} }, |
| 1867 | { { .tb = 0 }, 0x0e, {0x000000, 8192 * 1024} }, |
| 1868 | |
| 1869 | /* all, bp4 and bp3 => don't care, others = 1 */ |
| 1870 | { { .tb = 0 }, 0x07, {0x000000, 16384 * 1024} }, |
| 1871 | { { .tb = 0 }, 0x0f, {0x000000, 16384 * 1024} }, |
| 1872 | { { .tb = 0 }, 0x17, {0x000000, 16384 * 1024} }, |
| 1873 | { { .tb = 0 }, 0x1f, {0x000000, 16384 * 1024} }, |
| 1874 | |
| 1875 | { { .tb = 0 }, 0x11, {0xfff000, 4 * 1024} }, |
| 1876 | { { .tb = 0 }, 0x12, {0xffe000, 8 * 1024} }, |
| 1877 | { { .tb = 0 }, 0x13, {0xffc000, 16 * 1024} }, |
| 1878 | { { .tb = 0 }, 0x14, {0xff8000, 32 * 1024} }, /* bp0 => don't care */ |
| 1879 | { { .tb = 0 }, 0x15, {0xff8000, 32 * 1024} }, /* bp0 => don't care */ |
| 1880 | |
| 1881 | { { .tb = 0 }, 0x19, {0x000000, 4 * 1024} }, |
| 1882 | { { .tb = 0 }, 0x1a, {0x000000, 8 * 1024} }, |
| 1883 | { { .tb = 0 }, 0x1b, {0x000000, 16 * 1024} }, |
| 1884 | { { .tb = 0 }, 0x1c, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 1885 | { { .tb = 0 }, 0x1d, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 1886 | { { .tb = 0 }, 0x1e, {0x000000, 32 * 1024} }, |
| 1887 | }; |
| 1888 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 1889 | static struct wp_range_descriptor gd25q128_cmp1_ranges[] = { |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 1890 | /* none, bp4 and bp3 => don't care, others = 0 */ |
| 1891 | { { .tb = 1 }, 0x00, {0x000000, 16384 * 1024} }, |
| 1892 | { { .tb = 1 }, 0x08, {0x000000, 16384 * 1024} }, |
| 1893 | { { .tb = 1 }, 0x10, {0x000000, 16384 * 1024} }, |
| 1894 | { { .tb = 1 }, 0x18, {0x000000, 16384 * 1024} }, |
| 1895 | |
| 1896 | { { .tb = 1 }, 0x01, {0x000000, 16128 * 1024} }, |
| 1897 | { { .tb = 1 }, 0x02, {0x000000, 15872 * 1024} }, |
| 1898 | { { .tb = 1 }, 0x03, {0x000000, 15360 * 1024} }, |
| 1899 | { { .tb = 1 }, 0x04, {0x000000, 14336 * 1024} }, |
| 1900 | { { .tb = 1 }, 0x05, {0x000000, 12288 * 1024} }, |
| 1901 | { { .tb = 1 }, 0x06, {0x000000, 8192 * 1024} }, |
| 1902 | |
| 1903 | { { .tb = 1 }, 0x09, {0x000000, 16128 * 1024} }, |
| 1904 | { { .tb = 1 }, 0x0a, {0x000000, 15872 * 1024} }, |
| 1905 | { { .tb = 1 }, 0x0b, {0x000000, 15360 * 1024} }, |
| 1906 | { { .tb = 1 }, 0x0c, {0x000000, 14336 * 1024} }, |
| 1907 | { { .tb = 1 }, 0x0d, {0x000000, 12288 * 1024} }, |
| 1908 | { { .tb = 1 }, 0x0e, {0x000000, 8192 * 1024} }, |
| 1909 | |
| 1910 | /* none, bp4 and bp3 => don't care, others = 1 */ |
| 1911 | { { .tb = 1 }, 0x07, {0x000000, 16384 * 1024} }, |
| 1912 | { { .tb = 1 }, 0x08, {0x000000, 16384 * 1024} }, |
| 1913 | { { .tb = 1 }, 0x0f, {0x000000, 16384 * 1024} }, |
| 1914 | { { .tb = 1 }, 0x17, {0x000000, 16384 * 1024} }, |
| 1915 | { { .tb = 1 }, 0x1f, {0x000000, 16384 * 1024} }, |
| 1916 | |
| 1917 | { { .tb = 1 }, 0x11, {0x000000, 16380 * 1024} }, |
| 1918 | { { .tb = 1 }, 0x12, {0x000000, 16376 * 1024} }, |
| 1919 | { { .tb = 1 }, 0x13, {0x000000, 16368 * 1024} }, |
| 1920 | { { .tb = 1 }, 0x14, {0x000000, 16352 * 1024} }, /* bp0 => don't care */ |
| 1921 | { { .tb = 1 }, 0x15, {0x000000, 16352 * 1024} }, /* bp0 => don't care */ |
| 1922 | |
| 1923 | { { .tb = 1 }, 0x19, {0x001000, 16380 * 1024} }, |
| 1924 | { { .tb = 1 }, 0x1a, {0x002000, 16376 * 1024} }, |
| 1925 | { { .tb = 1 }, 0x1b, {0x004000, 16368 * 1024} }, |
| 1926 | { { .tb = 1 }, 0x1c, {0x008000, 16352 * 1024} }, /* bp0 => don't care */ |
| 1927 | { { .tb = 1 }, 0x1d, {0x008000, 16352 * 1024} }, /* bp0 => don't care */ |
| 1928 | { { .tb = 1 }, 0x1e, {0x008000, 16352 * 1024} }, |
| 1929 | }; |
| 1930 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1931 | static struct status_register_layout gd25q128_sr1 = { |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 1932 | /* TODO: map second and third status registers */ |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1933 | .bp0_pos = 2, .bp_bits = 5, .srp_pos = 7 |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 1934 | }; |
| 1935 | |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 1936 | /* FIXME: MX25L6406 has same ID as MX25L6405D */ |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 1937 | static struct wp_range_descriptor mx25l6406e_ranges[] = { |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1938 | { { }, 0, {0, 0} }, /* none */ |
| 1939 | { { }, 0x1, {0x7e0000, 64 * 2 * 1024} }, /* blocks 126-127 */ |
| 1940 | { { }, 0x2, {0x7c0000, 64 * 4 * 1024} }, /* blocks 124-127 */ |
| 1941 | { { }, 0x3, {0x7a0000, 64 * 8 * 1024} }, /* blocks 120-127 */ |
| 1942 | { { }, 0x4, {0x700000, 64 * 16 * 1024} }, /* blocks 112-127 */ |
| 1943 | { { }, 0x5, {0x600000, 64 * 32 * 1024} }, /* blocks 96-127 */ |
| 1944 | { { }, 0x6, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 1945 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1946 | { { }, 0x7, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1947 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1948 | { { }, 0x9, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 1949 | { { }, 0xa, {0x000000, 64 * 96 * 1024} }, /* blocks 0-95 */ |
| 1950 | { { }, 0xb, {0x000000, 64 * 112 * 1024} }, /* blocks 0-111 */ |
| 1951 | { { }, 0xc, {0x000000, 64 * 120 * 1024} }, /* blocks 0-119 */ |
| 1952 | { { }, 0xd, {0x000000, 64 * 124 * 1024} }, /* blocks 0-123 */ |
| 1953 | { { }, 0xe, {0x000000, 64 * 126 * 1024} }, /* blocks 0-125 */ |
| 1954 | { { }, 0xf, {0x000000, 64 * 128 * 1024} }, /* all */ |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 1955 | }; |
| 1956 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1957 | static struct status_register_layout mx25l6406e_sr1 = { |
| 1958 | .bp0_pos = 2, .bp_bits = 4, .srp_pos = 7 |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 1959 | }; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 1960 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 1961 | static struct wp_range_descriptor mx25l6495f_tb0_ranges[] = { |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1962 | { { }, 0, {0, 0} }, /* none */ |
| 1963 | { { }, 0x1, {0x7f0000, 64 * 1 * 1024} }, /* block 127 */ |
| 1964 | { { }, 0x2, {0x7e0000, 64 * 2 * 1024} }, /* blocks 126-127 */ |
| 1965 | { { }, 0x3, {0x7c0000, 64 * 4 * 1024} }, /* blocks 124-127 */ |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 1966 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1967 | { { }, 0x4, {0x780000, 64 * 8 * 1024} }, /* blocks 120-127 */ |
| 1968 | { { }, 0x5, {0x700000, 64 * 16 * 1024} }, /* blocks 112-127 */ |
| 1969 | { { }, 0x6, {0x600000, 64 * 32 * 1024} }, /* blocks 96-127 */ |
| 1970 | { { }, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
| 1971 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1972 | { { }, 0x9, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1973 | { { }, 0xa, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1974 | { { }, 0xb, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1975 | { { }, 0xc, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1976 | { { }, 0xd, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1977 | { { }, 0xe, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1978 | { { }, 0xf, {0x000000, 64 * 128 * 1024} }, /* all */ |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 1979 | }; |
| 1980 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 1981 | static struct wp_range_descriptor mx25l6495f_tb1_ranges[] = { |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 1982 | { { }, 0, {0, 0} }, /* none */ |
| 1983 | { { }, 0x1, {0x000000, 64 * 1 * 1024} }, /* block 0 */ |
| 1984 | { { }, 0x2, {0x000000, 64 * 2 * 1024} }, /* blocks 0-1 */ |
| 1985 | { { }, 0x3, {0x000000, 64 * 4 * 1024} }, /* blocks 0-3 */ |
| 1986 | { { }, 0x4, {0x000000, 64 * 8 * 1024} }, /* blocks 0-7 */ |
| 1987 | { { }, 0x5, {0x000000, 64 * 16 * 1024} }, /* blocks 0-15 */ |
| 1988 | { { }, 0x6, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 1989 | { { }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 1990 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1991 | { { }, 0x9, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1992 | { { }, 0xa, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1993 | { { }, 0xb, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1994 | { { }, 0xc, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1995 | { { }, 0xd, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1996 | { { }, 0xe, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1997 | { { }, 0xf, {0x000000, 64 * 128 * 1024} }, /* all */ |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 1998 | }; |
| 1999 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2000 | static struct status_register_layout mx25l6495f_sr1 = { |
| 2001 | .bp0_pos = 2, .bp_bits = 4, .srp_pos = 7 |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2002 | }; |
| 2003 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 2004 | static struct wp_range_descriptor mx25l25635f_tb0_ranges[] = { |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2005 | { { }, 0, {0, 0} }, /* none */ |
| 2006 | { { }, 0x1, {0x1ff0000, 64 * 1 * 1024} }, /* block 511 */ |
| 2007 | { { }, 0x2, {0x1fe0000, 64 * 2 * 1024} }, /* blocks 510-511 */ |
| 2008 | { { }, 0x3, {0x1fc0000, 64 * 4 * 1024} }, /* blocks 508-511 */ |
| 2009 | { { }, 0x4, {0x1f80000, 64 * 8 * 1024} }, /* blocks 504-511 */ |
| 2010 | { { }, 0x5, {0x1f00000, 64 * 16 * 1024} }, /* blocks 496-511 */ |
| 2011 | { { }, 0x6, {0x1e00000, 64 * 32 * 1024} }, /* blocks 480-511 */ |
| 2012 | { { }, 0x7, {0x1c00000, 64 * 64 * 1024} }, /* blocks 448-511 */ |
| 2013 | { { }, 0x8, {0x1800000, 64 * 128 * 1024} }, /* blocks 384-511 */ |
| 2014 | { { }, 0x9, {0x1000000, 64 * 256 * 1024} }, /* blocks 256-511 */ |
| 2015 | { { }, 0xa, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 2016 | { { }, 0xb, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 2017 | { { }, 0xc, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 2018 | { { }, 0xd, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 2019 | { { }, 0xe, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 2020 | { { }, 0xf, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 2021 | }; |
| 2022 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 2023 | static struct wp_range_descriptor mx25l25635f_tb1_ranges[] = { |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2024 | { { }, 0, {0, 0} }, /* none */ |
| 2025 | { { }, 0x1, {0x000000, 64 * 1 * 1024} }, /* block 0 */ |
| 2026 | { { }, 0x2, {0x000000, 64 * 2 * 1024} }, /* blocks 0-1 */ |
| 2027 | { { }, 0x3, {0x000000, 64 * 4 * 1024} }, /* blocks 0-3 */ |
| 2028 | { { }, 0x4, {0x000000, 64 * 8 * 1024} }, /* blocks 0-7 */ |
| 2029 | { { }, 0x5, {0x000000, 64 * 16 * 1024} }, /* blocks 0-15 */ |
| 2030 | { { }, 0x6, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 2031 | { { }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 2032 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* blocks 0-127 */ |
| 2033 | { { }, 0x9, {0x000000, 64 * 256 * 1024} }, /* blocks 0-255 */ |
| 2034 | { { }, 0xa, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 2035 | { { }, 0xb, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 2036 | { { }, 0xc, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 2037 | { { }, 0xd, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 2038 | { { }, 0xe, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 2039 | { { }, 0xf, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 2040 | }; |
| 2041 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2042 | static struct status_register_layout mx25l25635f_sr1 = { |
| 2043 | .bp0_pos = 2, .bp_bits = 4, .srp_pos = 7 |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2044 | }; |
| 2045 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 2046 | static struct wp_range_descriptor s25fs128s_ranges[] = { |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2047 | { { .tb = 1 }, 0, {0, 0} }, /* none */ |
| 2048 | { { .tb = 1 }, 0x1, {0x000000, 256 * 1024} }, /* lower 64th */ |
| 2049 | { { .tb = 1 }, 0x2, {0x000000, 512 * 1024} }, /* lower 32nd */ |
| 2050 | { { .tb = 1 }, 0x3, {0x000000, 1024 * 1024} }, /* lower 16th */ |
| 2051 | { { .tb = 1 }, 0x4, {0x000000, 2048 * 1024} }, /* lower 8th */ |
| 2052 | { { .tb = 1 }, 0x5, {0x000000, 4096 * 1024} }, /* lower 4th */ |
| 2053 | { { .tb = 1 }, 0x6, {0x000000, 8192 * 1024} }, /* lower half */ |
| 2054 | { { .tb = 1 }, 0x7, {0x000000, 16384 * 1024} }, /* all */ |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2055 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2056 | { { .tb = 0 }, 0, {0, 0} }, /* none */ |
| 2057 | { { .tb = 0 }, 0x1, {0xfc0000, 256 * 1024} }, /* upper 64th */ |
| 2058 | { { .tb = 0 }, 0x2, {0xf80000, 512 * 1024} }, /* upper 32nd */ |
| 2059 | { { .tb = 0 }, 0x3, {0xf00000, 1024 * 1024} }, /* upper 16th */ |
| 2060 | { { .tb = 0 }, 0x4, {0xe00000, 2048 * 1024} }, /* upper 8th */ |
| 2061 | { { .tb = 0 }, 0x5, {0xc00000, 4096 * 1024} }, /* upper 4th */ |
| 2062 | { { .tb = 0 }, 0x6, {0x800000, 8192 * 1024} }, /* upper half */ |
| 2063 | { { .tb = 0 }, 0x7, {0x000000, 16384 * 1024} }, /* all */ |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2064 | }; |
| 2065 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2066 | static struct status_register_layout s25fs128s_sr1 = { |
| 2067 | .bp0_pos = 2, .bp_bits = 3, .srp_pos = 7 |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2068 | }; |
| 2069 | |
David Hendricks | c694bb8 | 2015-02-25 14:52:17 -0800 | [diff] [blame] | 2070 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 2071 | static struct wp_range_descriptor s25fl256s_ranges[] = { |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2072 | { { .tb = 1 }, 0, {0, 0} }, /* none */ |
| 2073 | { { .tb = 1 }, 0x1, {0x000000, 512 * 1024} }, /* lower 64th */ |
| 2074 | { { .tb = 1 }, 0x2, {0x000000, 1024 * 1024} }, /* lower 32nd */ |
| 2075 | { { .tb = 1 }, 0x3, {0x000000, 2048 * 1024} }, /* lower 16th */ |
| 2076 | { { .tb = 1 }, 0x4, {0x000000, 4096 * 1024} }, /* lower 8th */ |
| 2077 | { { .tb = 1 }, 0x5, {0x000000, 8192 * 1024} }, /* lower 4th */ |
| 2078 | { { .tb = 1 }, 0x6, {0x000000, 16384 * 1024} }, /* lower half */ |
| 2079 | { { .tb = 1 }, 0x7, {0x000000, 32768 * 1024} }, /* all */ |
| 2080 | |
| 2081 | { { .tb = 0 }, 0, {0, 0} }, /* none */ |
| 2082 | { { .tb = 0 }, 0x1, {0x1f80000, 512 * 1024} }, /* upper 64th */ |
| 2083 | { { .tb = 0 }, 0x2, {0x1f00000, 1024 * 1024} }, /* upper 32nd */ |
| 2084 | { { .tb = 0 }, 0x3, {0x1e00000, 2048 * 1024} }, /* upper 16th */ |
| 2085 | { { .tb = 0 }, 0x4, {0x1c00000, 4096 * 1024} }, /* upper 8th */ |
| 2086 | { { .tb = 0 }, 0x5, {0x1800000, 8192 * 1024} }, /* upper 4th */ |
| 2087 | { { .tb = 0 }, 0x6, {0x1000000, 16384 * 1024} }, /* upper half */ |
| 2088 | { { .tb = 0 }, 0x7, {0x000000, 32768 * 1024} }, /* all */ |
David Hendricks | c694bb8 | 2015-02-25 14:52:17 -0800 | [diff] [blame] | 2089 | }; |
| 2090 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2091 | static struct status_register_layout s25fl256s_sr1 = { |
| 2092 | .bp0_pos = 2, .bp_bits = 3, .srp_pos = 7 |
David Hendricks | c694bb8 | 2015-02-25 14:52:17 -0800 | [diff] [blame] | 2093 | }; |
| 2094 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2095 | static int get_sr1_layout( |
| 2096 | const struct flashctx *flash, struct status_register_layout *sr1) |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2097 | { |
| 2098 | switch (flash->chip->manufacture_id) { |
| 2099 | case GIGADEVICE_ID: |
| 2100 | switch(flash->chip->model_id) { |
| 2101 | |
| 2102 | case GIGADEVICE_GD25Q32: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2103 | *sr1 = gd25q32_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2104 | return 0; |
| 2105 | case GIGADEVICE_GD25LQ128CD: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2106 | *sr1 = gd25q128_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2107 | return 0; |
| 2108 | } |
| 2109 | break; |
| 2110 | case MACRONIX_ID: |
| 2111 | switch (flash->chip->model_id) { |
| 2112 | case MACRONIX_MX25L6405: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2113 | *sr1 = mx25l6406e_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2114 | return 0; |
| 2115 | case MACRONIX_MX25L6495F: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2116 | *sr1 = mx25l6495f_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2117 | return 0; |
| 2118 | case MACRONIX_MX25L25635F: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2119 | *sr1 = mx25l25635f_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2120 | return 0; |
| 2121 | } |
| 2122 | break; |
| 2123 | case SPANSION_ID: |
| 2124 | switch (flash->chip->model_id) { |
| 2125 | case SPANSION_S25FS128S_L: |
| 2126 | case SPANSION_S25FS128S_S: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2127 | *sr1 = s25fs128s_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2128 | return 0; |
| 2129 | case SPANSION_S25FL256S_UL: |
| 2130 | case SPANSION_S25FL256S_US: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2131 | *sr1 = s25fl256s_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2132 | return 0; |
| 2133 | } |
| 2134 | break; |
| 2135 | } |
| 2136 | |
| 2137 | return 1; |
| 2138 | } |
| 2139 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2140 | /* Given a flash chip, this function returns its writeprotect info. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2141 | static int generic_range_table(const struct flashctx *flash, |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2142 | struct wp_range_descriptor **descrs, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2143 | int *num_entries) |
| 2144 | { |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2145 | *num_entries = 0; |
| 2146 | |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2147 | switch (flash->chip->manufacture_id) { |
Nikolai Artemiev | 06afe3e | 2021-04-06 16:40:29 +1000 | [diff] [blame] | 2148 | case WINBOND_NEX_ID: |
| 2149 | switch(flash->chip->model_id) { |
| 2150 | case WINBOND_NEX_W25X10: |
| 2151 | *descrs = w25x10_ranges; |
| 2152 | *num_entries = ARRAY_SIZE(w25x10_ranges); |
| 2153 | break; |
| 2154 | case WINBOND_NEX_W25X20: |
| 2155 | *descrs = w25x20_ranges; |
| 2156 | *num_entries = ARRAY_SIZE(w25x20_ranges); |
| 2157 | break; |
| 2158 | case WINBOND_NEX_W25X40: |
| 2159 | *descrs = w25x40_ranges; |
| 2160 | *num_entries = ARRAY_SIZE(w25x40_ranges); |
| 2161 | break; |
| 2162 | case WINBOND_NEX_W25X80: |
| 2163 | *descrs = w25x80_ranges; |
| 2164 | *num_entries = ARRAY_SIZE(w25x80_ranges); |
| 2165 | break; |
| 2166 | case WINBOND_NEX_W25Q80_V: |
| 2167 | *descrs = w25q80_ranges; |
| 2168 | *num_entries = ARRAY_SIZE(w25q80_ranges); |
| 2169 | break; |
| 2170 | case WINBOND_NEX_W25Q16_V: |
| 2171 | *descrs = w25q16_ranges; |
| 2172 | *num_entries = ARRAY_SIZE(w25q16_ranges); |
| 2173 | break; |
| 2174 | case WINBOND_NEX_W25Q32_V: |
| 2175 | case WINBOND_NEX_W25Q32_W: |
| 2176 | case WINBOND_NEX_W25Q32JW: |
| 2177 | *descrs = w25q32_ranges; |
| 2178 | *num_entries = ARRAY_SIZE(w25q32_ranges); |
| 2179 | break; |
| 2180 | case WINBOND_NEX_W25Q64_V: |
| 2181 | case WINBOND_NEX_W25Q64_W: |
| 2182 | *descrs = w25q64_ranges; |
| 2183 | *num_entries = ARRAY_SIZE(w25q64_ranges); |
| 2184 | break; |
| 2185 | case WINBOND_NEX_W25Q128_DTR: |
| 2186 | case WINBOND_NEX_W25Q128_V_M: |
| 2187 | case WINBOND_NEX_W25Q128_V: |
| 2188 | case WINBOND_NEX_W25Q128_W: |
| 2189 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2190 | /* CMP == 1 */ |
| 2191 | *descrs = w25rq128_cmp1_ranges; |
| 2192 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 2193 | } else { |
| 2194 | /* CMP == 0 */ |
| 2195 | *descrs = w25rq128_cmp0_ranges; |
| 2196 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 2197 | } |
| 2198 | break; |
| 2199 | case WINBOND_NEX_W25Q256_V: |
| 2200 | case WINBOND_NEX_W25Q256JV_M: |
| 2201 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2202 | /* CMP == 1 */ |
| 2203 | *descrs = w25rq256_cmp1_ranges; |
| 2204 | *num_entries = ARRAY_SIZE(w25rq256_cmp1_ranges); |
| 2205 | } else { |
| 2206 | /* CMP == 0 */ |
| 2207 | *descrs = w25rq256_cmp0_ranges; |
| 2208 | *num_entries = ARRAY_SIZE(w25rq256_cmp0_ranges); |
| 2209 | } |
| 2210 | break; |
| 2211 | default: |
| 2212 | msg_cerr("%s() %d: WINBOND flash chip mismatch (0x%04x)" |
| 2213 | ", aborting\n", __func__, __LINE__, |
| 2214 | flash->chip->model_id); |
| 2215 | return -1; |
| 2216 | } |
| 2217 | break; |
| 2218 | |
Nikolai Artemiev | 12a84fa | 2021-04-06 16:41:56 +1000 | [diff] [blame] | 2219 | case EON_ID_NOPREFIX: |
| 2220 | switch (flash->chip->model_id) { |
| 2221 | case EON_EN25F40: |
| 2222 | *descrs = en25f40_ranges; |
| 2223 | *num_entries = ARRAY_SIZE(en25f40_ranges); |
| 2224 | break; |
| 2225 | case EON_EN25Q40: |
| 2226 | *descrs = en25q40_ranges; |
| 2227 | *num_entries = ARRAY_SIZE(en25q40_ranges); |
| 2228 | break; |
| 2229 | case EON_EN25Q80: |
| 2230 | *descrs = en25q80_ranges; |
| 2231 | *num_entries = ARRAY_SIZE(en25q80_ranges); |
| 2232 | break; |
| 2233 | case EON_EN25Q32: |
| 2234 | *descrs = en25q32_ranges; |
| 2235 | *num_entries = ARRAY_SIZE(en25q32_ranges); |
| 2236 | break; |
| 2237 | case EON_EN25Q64: |
| 2238 | *descrs = en25q64_ranges; |
| 2239 | *num_entries = ARRAY_SIZE(en25q64_ranges); |
| 2240 | break; |
| 2241 | case EON_EN25Q128: |
| 2242 | *descrs = en25q128_ranges; |
| 2243 | *num_entries = ARRAY_SIZE(en25q128_ranges); |
| 2244 | break; |
| 2245 | case EON_EN25QH128: |
| 2246 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2247 | /* CMP == 1 */ |
| 2248 | *descrs = w25rq128_cmp1_ranges; |
| 2249 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 2250 | } else { |
| 2251 | /* CMP == 0 */ |
| 2252 | *descrs = w25rq128_cmp0_ranges; |
| 2253 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 2254 | } |
| 2255 | break; |
| 2256 | case EON_EN25S64: |
| 2257 | *descrs = en25s64_ranges; |
| 2258 | *num_entries = ARRAY_SIZE(en25s64_ranges); |
| 2259 | break; |
| 2260 | default: |
| 2261 | msg_cerr("%s():%d: EON flash chip mismatch (0x%04x)" |
| 2262 | ", aborting\n", __func__, __LINE__, |
| 2263 | flash->chip->model_id); |
| 2264 | return -1; |
| 2265 | } |
| 2266 | break; |
| 2267 | |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2268 | case GIGADEVICE_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2269 | switch(flash->chip->model_id) { |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2270 | |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2271 | case GIGADEVICE_GD25Q32: { |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2272 | uint8_t sr1 = w25q_read_status_register_2(flash); |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2273 | |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2274 | if (!(sr1 & (1 << 6))) { /* CMP == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2275 | *descrs = &gd25q32_cmp0_ranges[0]; |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2276 | *num_entries = ARRAY_SIZE(gd25q32_cmp0_ranges); |
| 2277 | } else { /* CMP == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2278 | *descrs = &gd25q32_cmp1_ranges[0]; |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2279 | *num_entries = ARRAY_SIZE(gd25q32_cmp1_ranges); |
| 2280 | } |
| 2281 | |
| 2282 | break; |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2283 | } |
Aaron Durbin | 6c957d7 | 2018-08-20 09:31:01 -0600 | [diff] [blame] | 2284 | case GIGADEVICE_GD25LQ128CD: { |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2285 | uint8_t sr1 = w25q_read_status_register_2(flash); |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2286 | |
| 2287 | if (!(sr1 & (1 << 6))) { /* CMP == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2288 | *descrs = &gd25q128_cmp0_ranges[0]; |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2289 | *num_entries = ARRAY_SIZE(gd25q128_cmp0_ranges); |
| 2290 | } else { /* CMP == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2291 | *descrs = &gd25q128_cmp1_ranges[0]; |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2292 | *num_entries = ARRAY_SIZE(gd25q128_cmp1_ranges); |
| 2293 | } |
| 2294 | |
| 2295 | break; |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2296 | } |
| 2297 | default: |
| 2298 | msg_cerr("%s() %d: GigaDevice flash chip mismatch" |
| 2299 | " (0x%04x), aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2300 | flash->chip->model_id); |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2301 | return -1; |
| 2302 | } |
| 2303 | break; |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2304 | case MACRONIX_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2305 | switch (flash->chip->model_id) { |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2306 | case MACRONIX_MX25L6405: |
| 2307 | /* FIXME: MX25L64* chips have mixed capabilities and |
| 2308 | share IDs */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2309 | *descrs = &mx25l6406e_ranges[0]; |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2310 | *num_entries = ARRAY_SIZE(mx25l6406e_ranges); |
| 2311 | break; |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2312 | case MACRONIX_MX25L6495F: { |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2313 | uint8_t cr = mx25l_read_config_register(flash); |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2314 | |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2315 | if (!(cr & (1 << 3))) { /* T/B == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2316 | *descrs = &mx25l6495f_tb0_ranges[0]; |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2317 | *num_entries = ARRAY_SIZE(mx25l6495f_tb0_ranges); |
| 2318 | } else { /* T/B == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2319 | *descrs = &mx25l6495f_tb1_ranges[0]; |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2320 | *num_entries = ARRAY_SIZE(mx25l6495f_tb1_ranges); |
| 2321 | } |
| 2322 | break; |
| 2323 | } |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2324 | case MACRONIX_MX25L25635F: { |
| 2325 | uint8_t cr = mx25l_read_config_register(flash); |
| 2326 | |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2327 | if (!(cr & (1 << 3))) { /* T/B == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2328 | *descrs = &mx25l25635f_tb0_ranges[0]; |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2329 | *num_entries = ARRAY_SIZE(mx25l25635f_tb0_ranges); |
| 2330 | } else { /* T/B == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2331 | *descrs = &mx25l25635f_tb1_ranges[0]; |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2332 | *num_entries = ARRAY_SIZE(mx25l25635f_tb1_ranges); |
| 2333 | } |
| 2334 | break; |
Nikolai Artemiev | 0e560ae | 2021-04-06 16:45:00 +1000 | [diff] [blame^] | 2335 | } |
| 2336 | case MACRONIX_MX25L1005: |
| 2337 | *descrs = mx25l1005_ranges; |
| 2338 | *num_entries = ARRAY_SIZE(mx25l1005_ranges); |
| 2339 | break; |
| 2340 | case MACRONIX_MX25L2005: |
| 2341 | *descrs = mx25l2005_ranges; |
| 2342 | *num_entries = ARRAY_SIZE(mx25l2005_ranges); |
| 2343 | break; |
| 2344 | case MACRONIX_MX25L4005: |
| 2345 | *descrs = mx25l4005_ranges; |
| 2346 | *num_entries = ARRAY_SIZE(mx25l4005_ranges); |
| 2347 | break; |
| 2348 | case MACRONIX_MX25L8005: |
| 2349 | *descrs = mx25l8005_ranges; |
| 2350 | *num_entries = ARRAY_SIZE(mx25l8005_ranges); |
| 2351 | break; |
| 2352 | case MACRONIX_MX25L1605: |
| 2353 | /* FIXME: MX25L1605 and MX25L1605D have different write |
| 2354 | * protection capabilities, but share IDs */ |
| 2355 | *descrs = mx25l1605d_ranges; |
| 2356 | *num_entries = ARRAY_SIZE(mx25l1605d_ranges); |
| 2357 | break; |
| 2358 | case MACRONIX_MX25L3205: |
| 2359 | *descrs = mx25l3205d_ranges; |
| 2360 | *num_entries = ARRAY_SIZE(mx25l3205d_ranges); |
| 2361 | break; |
| 2362 | case MACRONIX_MX25U3235E: |
| 2363 | *descrs = mx25u3235e_ranges; |
| 2364 | *num_entries = ARRAY_SIZE(mx25u3235e_ranges); |
| 2365 | break; |
| 2366 | case MACRONIX_MX25U6435E: |
| 2367 | *descrs = mx25u6435e_ranges; |
| 2368 | *num_entries = ARRAY_SIZE(mx25u6435e_ranges); |
| 2369 | break; |
| 2370 | case MACRONIX_MX25U12835E: { |
| 2371 | uint8_t cr = mx25l_read_config_register(flash); |
| 2372 | if (cr & MX25U12835E_TB) { /* T/B == 1 */ |
| 2373 | *descrs = mx25u12835e_tb1_ranges; |
| 2374 | *num_entries = ARRAY_SIZE(mx25u12835e_tb1_ranges); |
| 2375 | } else { /* T/B == 0 */ |
| 2376 | *descrs = mx25u12835e_tb0_ranges; |
| 2377 | *num_entries = ARRAY_SIZE(mx25u12835e_tb0_ranges); |
| 2378 | } |
| 2379 | } |
| 2380 | break; |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2381 | default: |
| 2382 | msg_cerr("%s():%d: MXIC flash chip mismatch (0x%04x)" |
| 2383 | ", aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2384 | flash->chip->model_id); |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2385 | return -1; |
| 2386 | } |
| 2387 | break; |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2388 | case SPANSION_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2389 | switch (flash->chip->model_id) { |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2390 | case SPANSION_S25FS128S_L: |
| 2391 | case SPANSION_S25FS128S_S: { |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2392 | *descrs = s25fs128s_ranges; |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2393 | *num_entries = ARRAY_SIZE(s25fs128s_ranges); |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2394 | break; |
| 2395 | } |
David Hendricks | c694bb8 | 2015-02-25 14:52:17 -0800 | [diff] [blame] | 2396 | case SPANSION_S25FL256S_UL: |
| 2397 | case SPANSION_S25FL256S_US: { |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2398 | *descrs = s25fl256s_ranges; |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2399 | *num_entries = ARRAY_SIZE(s25fl256s_ranges); |
David Hendricks | c694bb8 | 2015-02-25 14:52:17 -0800 | [diff] [blame] | 2400 | break; |
| 2401 | } |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2402 | default: |
| 2403 | msg_cerr("%s():%d Spansion flash chip mismatch (0x%04x)" |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2404 | ", aborting\n", __func__, __LINE__, |
| 2405 | flash->chip->model_id); |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2406 | return -1; |
| 2407 | } |
| 2408 | break; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2409 | default: |
| 2410 | msg_cerr("%s: flash vendor (0x%x) not found, aborting\n", |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2411 | __func__, flash->chip->manufacture_id); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2412 | return -1; |
| 2413 | } |
| 2414 | |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2418 | /* Determines if special s25f-specific functions need to be used to access a |
| 2419 | * given chip's modifier bits. Very much a hard-coded special case hack, but it |
| 2420 | * is also very easy to replace once a proper abstraction for accessing |
| 2421 | * specific modifier bits is added. */ |
| 2422 | static int use_s25f_modifier_bits(const struct flashctx *flash) |
| 2423 | { |
| 2424 | bool model_match = |
| 2425 | flash->chip->model_id == SPANSION_S25FS128S_L || |
| 2426 | flash->chip->model_id == SPANSION_S25FS128S_S || |
| 2427 | flash->chip->model_id == SPANSION_S25FL256S_UL || |
| 2428 | flash->chip->model_id == SPANSION_S25FL256S_US; |
| 2429 | return (flash->chip->manufacture_id == SPANSION_ID) && model_match; |
| 2430 | } |
| 2431 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2432 | static uint8_t generic_get_bp_mask(struct status_register_layout sr1) |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2433 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2434 | return ((1 << (sr1.bp0_pos + sr1.bp_bits)) - 1) ^ \ |
| 2435 | ((1 << sr1.bp0_pos) - 1); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2436 | } |
| 2437 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2438 | static uint8_t generic_get_status_check_mask(struct status_register_layout sr1) |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2439 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2440 | return generic_get_bp_mask(sr1) | 1 << sr1.srp_pos; |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2441 | } |
| 2442 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2443 | /* Given a [start, len], this function finds a block protect bit combination |
| 2444 | * (if possible) and sets the corresponding bits in "status". Remaining bits |
| 2445 | * are preserved. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2446 | static int generic_range_to_status(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2447 | unsigned int start, unsigned int len, |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2448 | uint8_t *status, uint8_t *check_mask) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2449 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2450 | struct status_register_layout sr1; |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 2451 | struct wp_range_descriptor *r; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2452 | int i, range_found = 0, num_entries; |
| 2453 | uint8_t bp_mask; |
| 2454 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2455 | if (get_sr1_layout(flash, &sr1)) |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2456 | return -1; |
| 2457 | |
| 2458 | if (generic_range_table(flash, &r, &num_entries)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2459 | return -1; |
| 2460 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2461 | bp_mask = generic_get_bp_mask(sr1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2462 | |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2463 | for (i = 0; i < num_entries; i++, r++) { |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2464 | msg_cspew("comparing range 0x%x 0x%x / 0x%x 0x%x\n", |
| 2465 | start, len, r->range.start, r->range.len); |
| 2466 | if ((start == r->range.start) && (len == r->range.len)) { |
| 2467 | *status &= ~(bp_mask); |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2468 | *status |= r->bp << (sr1.bp0_pos); |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2469 | |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2470 | if (use_s25f_modifier_bits(flash)) { |
| 2471 | if (s25f_set_modifier_bits(flash, &r->m) < 0) { |
Edward O'Callaghan | 0b662c1 | 2021-01-22 00:30:24 +1100 | [diff] [blame] | 2472 | msg_cerr("error setting modifier bits for range.\n"); |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2473 | return -1; |
| 2474 | } |
| 2475 | } |
| 2476 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2477 | range_found = 1; |
| 2478 | break; |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | if (!range_found) { |
Edward O'Callaghan | 3be63e0 | 2020-03-27 14:44:24 +1100 | [diff] [blame] | 2483 | msg_cerr("%s: matching range not found\n", __func__); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2484 | return -1; |
| 2485 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 2486 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2487 | *check_mask = generic_get_status_check_mask(sr1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2488 | return 0; |
| 2489 | } |
| 2490 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2491 | static int generic_status_to_range(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2492 | const uint8_t sr1, unsigned int *start, unsigned int *len) |
| 2493 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2494 | struct status_register_layout sr1_layout; |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 2495 | struct wp_range_descriptor *r; |
Duncan Laurie | 04ca117 | 2015-03-12 09:25:34 -0700 | [diff] [blame] | 2496 | int num_entries, i, status_found = 0; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2497 | uint8_t sr1_bp; |
Edward O'Callaghan | 9c4c9a5 | 2019-12-04 18:18:01 +1100 | [diff] [blame] | 2498 | struct modifier_bits m; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2499 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2500 | if (get_sr1_layout(flash, &sr1_layout)) |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2501 | return -1; |
| 2502 | |
| 2503 | if (generic_range_table(flash, &r, &num_entries)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2504 | return -1; |
| 2505 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2506 | /* modifier bits may be compared more than once, so get them here */ |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2507 | if (use_s25f_modifier_bits(flash) && s25f_get_modifier_bits(flash, &m) < 0) |
| 2508 | return -1; |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2509 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2510 | sr1_bp = (sr1 >> sr1_layout.bp0_pos) & ((1 << sr1_layout.bp_bits) - 1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2511 | |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2512 | for (i = 0; i < num_entries; i++, r++) { |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2513 | if (use_s25f_modifier_bits(flash)) { |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2514 | if (memcmp(&m, &r->m, sizeof(m))) |
| 2515 | continue; |
| 2516 | } |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2517 | msg_cspew("comparing 0x%02x 0x%02x\n", sr1_bp, r->bp); |
| 2518 | if (sr1_bp == r->bp) { |
| 2519 | *start = r->range.start; |
| 2520 | *len = r->range.len; |
| 2521 | status_found = 1; |
| 2522 | break; |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | if (!status_found) { |
| 2527 | msg_cerr("matching status not found\n"); |
| 2528 | return -1; |
| 2529 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 2530 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2531 | return 0; |
| 2532 | } |
| 2533 | |
| 2534 | /* Given a [start, len], this function calls generic_range_to_status() to |
| 2535 | * convert it to flash-chip-specific range bits, then sets into status register. |
| 2536 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2537 | static int generic_set_range(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2538 | unsigned int start, unsigned int len) |
| 2539 | { |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2540 | uint8_t status, expected, check_mask; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2541 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2542 | status = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2543 | msg_cdbg("%s: old status: 0x%02x\n", __func__, status); |
| 2544 | |
| 2545 | expected = status; /* preserve non-bp bits */ |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2546 | if (generic_range_to_status(flash, start, len, &expected, &check_mask)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2547 | return -1; |
| 2548 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2549 | spi_write_status_register(flash, expected); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2550 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2551 | status = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2552 | msg_cdbg("%s: new status: 0x%02x\n", __func__, status); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2553 | if ((status & check_mask) != (expected & check_mask)) { |
| 2554 | msg_cerr("expected=0x%02x, but actual=0x%02x. check mask=0x%02x\n", |
| 2555 | expected, status, check_mask); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2556 | return 1; |
| 2557 | } |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2558 | return 0; |
| 2559 | } |
| 2560 | |
| 2561 | /* Set/clear the status regsiter write protect bit in SR1. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2562 | static int generic_set_srp0(const struct flashctx *flash, int enable) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2563 | { |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2564 | uint8_t status, expected, check_mask; |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2565 | struct status_register_layout sr1; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2566 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2567 | if (get_sr1_layout(flash, &sr1)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2568 | return -1; |
| 2569 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2570 | expected = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2571 | msg_cdbg("%s: old status: 0x%02x\n", __func__, expected); |
| 2572 | |
| 2573 | if (enable) |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2574 | expected |= 1 << sr1.srp_pos; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2575 | else |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2576 | expected &= ~(1 << sr1.srp_pos); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2577 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2578 | spi_write_status_register(flash, expected); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2579 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2580 | status = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2581 | msg_cdbg("%s: new status: 0x%02x\n", __func__, status); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2582 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2583 | check_mask = generic_get_status_check_mask(sr1); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2584 | msg_cdbg("%s: check mask: 0x%02x\n", __func__, check_mask); |
| 2585 | if ((status & check_mask) != (expected & check_mask)) { |
| 2586 | msg_cerr("expected=0x%02x, but actual=0x%02x. check mask=0x%02x\n", |
| 2587 | expected, status, check_mask); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2588 | return -1; |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2589 | } |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2590 | |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2594 | static int generic_enable_writeprotect(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2595 | enum wp_mode wp_mode) |
| 2596 | { |
| 2597 | int ret; |
| 2598 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 2599 | if (wp_mode != WP_MODE_HARDWARE) { |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2600 | msg_cerr("%s(): unsupported write-protect mode\n", __func__); |
| 2601 | return 1; |
| 2602 | } |
| 2603 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 2604 | ret = generic_set_srp0(flash, 1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2605 | if (ret) |
| 2606 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 2607 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2608 | return ret; |
| 2609 | } |
| 2610 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2611 | static int generic_disable_writeprotect(const struct flashctx *flash) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2612 | { |
| 2613 | int ret; |
| 2614 | |
| 2615 | ret = generic_set_srp0(flash, 0); |
| 2616 | if (ret) |
| 2617 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 2618 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2619 | return ret; |
| 2620 | } |
| 2621 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2622 | static int generic_list_ranges(const struct flashctx *flash) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2623 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 2624 | struct wp_range_descriptor *r; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2625 | int i, num_entries; |
| 2626 | |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2627 | if (generic_range_table(flash, &r, &num_entries)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2628 | return -1; |
| 2629 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2630 | for (i = 0; i < num_entries; i++) { |
| 2631 | msg_cinfo("start: 0x%06x, length: 0x%06x\n", |
| 2632 | r->range.start, r->range.len); |
| 2633 | r++; |
| 2634 | } |
| 2635 | |
| 2636 | return 0; |
| 2637 | } |
| 2638 | |
Edward O'Callaghan | a3edcb2 | 2019-12-05 14:30:50 +1100 | [diff] [blame] | 2639 | static int wp_context_status(const struct flashctx *flash) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2640 | { |
| 2641 | uint8_t sr1; |
| 2642 | unsigned int start, len; |
| 2643 | int ret = 0; |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2644 | struct status_register_layout sr1_layout; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2645 | int wp_en; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2646 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2647 | if (get_sr1_layout(flash, &sr1_layout)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2648 | return -1; |
| 2649 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2650 | sr1 = spi_read_status_register(flash); |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2651 | wp_en = (sr1 >> sr1_layout.srp_pos) & 1; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2652 | |
| 2653 | msg_cinfo("WP: status: 0x%04x\n", sr1); |
| 2654 | msg_cinfo("WP: status.srp0: %x\n", wp_en); |
| 2655 | /* FIXME: SRP1 is not really generic, but we probably should print |
| 2656 | * it anyway to have consistent output. #legacycruft */ |
| 2657 | msg_cinfo("WP: status.srp1: %x\n", 0); |
| 2658 | msg_cinfo("WP: write protect is %s.\n", |
| 2659 | wp_en ? "enabled" : "disabled"); |
| 2660 | |
| 2661 | msg_cinfo("WP: write protect range: "); |
| 2662 | if (generic_status_to_range(flash, sr1, &start, &len)) { |
| 2663 | msg_cinfo("(cannot resolve the range)\n"); |
| 2664 | ret = -1; |
| 2665 | } else { |
| 2666 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 2667 | } |
| 2668 | |
| 2669 | return ret; |
| 2670 | } |
| 2671 | |
| 2672 | struct wp wp_generic = { |
| 2673 | .list_ranges = generic_list_ranges, |
| 2674 | .set_range = generic_set_range, |
| 2675 | .enable = generic_enable_writeprotect, |
| 2676 | .disable = generic_disable_writeprotect, |
Edward O'Callaghan | a3edcb2 | 2019-12-05 14:30:50 +1100 | [diff] [blame] | 2677 | .wp_status = wp_context_status, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2678 | }; |