Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2008 coresystems GmbH |
| 5 | * Copyright (C) 2010 Carl-Daniel Hailfinger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include "flash.h" |
Carl-Daniel Hailfinger | ef3ac8a | 2014-08-03 13:05:34 +0000 | [diff] [blame] | 19 | #include "chipdrivers.h" |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 20 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 21 | static uint8_t w39_idmode_readb(struct flashctx *flash, unsigned int offset) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 22 | { |
| 23 | chipaddr bios = flash->virtual_memory; |
| 24 | uint8_t val; |
| 25 | |
| 26 | /* Product Identification Entry */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 27 | chip_writeb(flash, 0xAA, bios + 0x5555); |
| 28 | chip_writeb(flash, 0x55, bios + 0x2AAA); |
| 29 | chip_writeb(flash, 0x90, bios + 0x5555); |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 30 | programmer_delay(10); |
| 31 | |
| 32 | /* Read something, maybe hardware lock bits */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 33 | val = chip_readb(flash, bios + offset); |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 34 | |
| 35 | /* Product Identification Exit */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 36 | chip_writeb(flash, 0xAA, bios + 0x5555); |
| 37 | chip_writeb(flash, 0x55, bios + 0x2AAA); |
| 38 | chip_writeb(flash, 0xF0, bios + 0x5555); |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 39 | programmer_delay(10); |
| 40 | |
| 41 | return val; |
| 42 | } |
| 43 | |
| 44 | static int printlock_w39_tblwp(uint8_t lock) |
| 45 | { |
| 46 | msg_cdbg("Hardware bootblock locking (#TBL) is %sactive.\n", |
| 47 | (lock & (1 << 2)) ? "" : "not "); |
| 48 | msg_cdbg("Hardware remaining chip locking (#WP) is %sactive..\n", |
| 49 | (lock & (1 << 3)) ? "" : "not "); |
| 50 | if (lock & ((1 << 2) | (1 << 3))) |
| 51 | return -1; |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
Kyösti Mälkki | c31243e | 2012-10-28 01:50:08 +0000 | [diff] [blame] | 56 | static int printlock_w39_single_bootblock(uint8_t lock, uint16_t kB) |
| 57 | { |
| 58 | msg_cdbg("Software %d kB bootblock locking is %sactive.\n", kB, (lock & 0x03) ? "" : "not "); |
| 59 | if (lock & 0x03) |
| 60 | return -1; |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 65 | static int printlock_w39_bootblock_64k16k(uint8_t lock) |
| 66 | { |
| 67 | msg_cdbg("Software 64 kB bootblock locking is %sactive.\n", |
| 68 | (lock & (1 << 0)) ? "" : "not "); |
| 69 | msg_cdbg("Software 16 kB bootblock locking is %sactive.\n", |
| 70 | (lock & (1 << 1)) ? "" : "not "); |
| 71 | if (lock & ((1 << 1) | (1 << 0))) |
| 72 | return -1; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 77 | static int printlock_w39_common(struct flashctx *flash, unsigned int offset) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 78 | { |
| 79 | uint8_t lock; |
| 80 | |
| 81 | lock = w39_idmode_readb(flash, offset); |
| 82 | msg_cdbg("Lockout bits:\n"); |
| 83 | return printlock_w39_tblwp(lock); |
| 84 | } |
| 85 | |
Kyösti Mälkki | c31243e | 2012-10-28 01:50:08 +0000 | [diff] [blame] | 86 | int printlock_w39f010(struct flashctx *flash) |
| 87 | { |
| 88 | uint8_t lock; |
| 89 | int ret; |
| 90 | |
| 91 | lock = w39_idmode_readb(flash, 0x00002); |
| 92 | msg_cdbg("Bottom boot block:\n"); |
| 93 | ret = printlock_w39_single_bootblock(lock, 16); |
| 94 | |
| 95 | lock = w39_idmode_readb(flash, 0x1fff2); |
| 96 | msg_cdbg("Top boot block:\n"); |
| 97 | ret |= printlock_w39_single_bootblock(lock, 16); |
| 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | int printlock_w39l010(struct flashctx *flash) |
| 103 | { |
| 104 | uint8_t lock; |
| 105 | int ret; |
| 106 | |
| 107 | lock = w39_idmode_readb(flash, 0x00002); |
| 108 | msg_cdbg("Bottom boot block:\n"); |
| 109 | ret = printlock_w39_single_bootblock(lock, 8); |
| 110 | |
| 111 | lock = w39_idmode_readb(flash, 0x1fff2); |
| 112 | msg_cdbg("Top boot block:\n"); |
| 113 | ret |= printlock_w39_single_bootblock(lock, 8); |
| 114 | |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | int printlock_w39l020(struct flashctx *flash) |
| 119 | { |
| 120 | uint8_t lock; |
| 121 | int ret; |
| 122 | |
| 123 | lock = w39_idmode_readb(flash, 0x00002); |
| 124 | msg_cdbg("Bottom boot block:\n"); |
| 125 | ret = printlock_w39_bootblock_64k16k(lock); |
| 126 | |
| 127 | lock = w39_idmode_readb(flash, 0x3fff2); |
| 128 | msg_cdbg("Top boot block:\n"); |
| 129 | ret |= printlock_w39_bootblock_64k16k(lock); |
| 130 | |
| 131 | return ret; |
| 132 | } |
| 133 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 134 | int printlock_w39l040(struct flashctx *flash) |
Michael Karcher | 19e0aac | 2011-03-06 17:58:05 +0000 | [diff] [blame] | 135 | { |
| 136 | uint8_t lock; |
| 137 | int ret; |
| 138 | |
| 139 | lock = w39_idmode_readb(flash, 0x00002); |
| 140 | msg_cdbg("Bottom boot block:\n"); |
| 141 | ret = printlock_w39_bootblock_64k16k(lock); |
| 142 | |
| 143 | lock = w39_idmode_readb(flash, 0x7fff2); |
| 144 | msg_cdbg("Top boot block:\n"); |
| 145 | ret |= printlock_w39_bootblock_64k16k(lock); |
| 146 | |
| 147 | return ret; |
| 148 | } |
| 149 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 150 | int printlock_w39v040a(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 151 | { |
| 152 | uint8_t lock; |
| 153 | int ret = 0; |
| 154 | |
| 155 | /* The W39V040A datasheet contradicts itself on the lock register |
| 156 | * location: 0x00002 and 0x7fff2 are both mentioned. Pick the one |
| 157 | * which is similar to the other chips of the same family. |
| 158 | */ |
| 159 | lock = w39_idmode_readb(flash, 0x7fff2); |
| 160 | msg_cdbg("Lockout bits:\n"); |
| 161 | |
| 162 | ret = printlock_w39_tblwp(lock); |
| 163 | ret |= printlock_w39_bootblock_64k16k(lock); |
| 164 | |
| 165 | return ret; |
| 166 | } |
| 167 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 168 | int printlock_w39v040b(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 169 | { |
| 170 | return printlock_w39_common(flash, 0x7fff2); |
| 171 | } |
| 172 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 173 | int printlock_w39v040c(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 174 | { |
| 175 | /* Typo in the datasheet? The other chips use 0x7fff2. */ |
| 176 | return printlock_w39_common(flash, 0xfff2); |
| 177 | } |
| 178 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 179 | int printlock_w39v040fa(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 180 | { |
| 181 | int ret = 0; |
| 182 | |
| 183 | ret = printlock_w39v040a(flash); |
Carl-Daniel Hailfinger | ef3ac8a | 2014-08-03 13:05:34 +0000 | [diff] [blame] | 184 | ret |= printlock_regspace2_uniform_64k(flash); |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 185 | |
| 186 | return ret; |
| 187 | } |
| 188 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 189 | int printlock_w39v040fb(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 190 | { |
| 191 | int ret = 0; |
| 192 | |
| 193 | ret = printlock_w39v040b(flash); |
Carl-Daniel Hailfinger | ef3ac8a | 2014-08-03 13:05:34 +0000 | [diff] [blame] | 194 | ret |= printlock_regspace2_uniform_64k(flash); |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 195 | |
| 196 | return ret; |
| 197 | } |
| 198 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 199 | int printlock_w39v040fc(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 200 | { |
| 201 | int ret = 0; |
| 202 | |
| 203 | /* W39V040C and W39V040FC use different WP/TBL offsets. */ |
| 204 | ret = printlock_w39_common(flash, 0x7fff2); |
Carl-Daniel Hailfinger | ef3ac8a | 2014-08-03 13:05:34 +0000 | [diff] [blame] | 205 | ret |= printlock_regspace2_uniform_64k(flash); |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 206 | |
| 207 | return ret; |
| 208 | } |
| 209 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 210 | int printlock_w39v080a(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 211 | { |
| 212 | return printlock_w39_common(flash, 0xffff2); |
| 213 | } |
| 214 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 215 | int printlock_w39v080fa(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 216 | { |
| 217 | int ret = 0; |
| 218 | |
| 219 | ret = printlock_w39v080a(flash); |
Carl-Daniel Hailfinger | ef3ac8a | 2014-08-03 13:05:34 +0000 | [diff] [blame] | 220 | ret |= printlock_regspace2_uniform_64k(flash); |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 221 | |
| 222 | return ret; |
| 223 | } |
| 224 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 225 | int printlock_w39v080fa_dual(struct flashctx *flash) |
Carl-Daniel Hailfinger | 9188240 | 2010-12-05 16:33:59 +0000 | [diff] [blame] | 226 | { |
| 227 | msg_cinfo("Block locking for W39V080FA in dual mode is " |
| 228 | "undocumented.\n"); |
| 229 | /* Better safe than sorry. */ |
| 230 | return -1; |
| 231 | } |
| 232 | |
David Borg | f5a30f6 | 2012-04-15 13:16:32 +0000 | [diff] [blame] | 233 | int printlock_at49f(struct flashctx *flash) |
| 234 | { |
| 235 | uint8_t lock = w39_idmode_readb(flash, 0x00002); |
| 236 | msg_cdbg("Hardware bootblock lockout is %sactive.\n", |
| 237 | (lock & 0x01) ? "" : "not "); |
| 238 | return 0; |
| 239 | } |