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