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