Flashrom

Flashrom Svn Source Tree

Root/trunk/w39.c

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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "flash.h"
23
24static int printlock_w39_fwh_block(struct flashctx *flash, unsigned int offset)
25{
26chipaddr wrprotect = flash->virtual_registers + offset + 2;
27uint8_t locking;
28
29locking = chip_readb(flash, wrprotect);
30msg_cdbg("Lock status of block at 0x%08x is ", offset);
31switch (locking & 0x7) {
32case 0:
33msg_cdbg("Full Access.\n");
34break;
35case 1:
36msg_cdbg("Write Lock (Default State).\n");
37break;
38case 2:
39msg_cdbg("Locked Open (Full Access, Lock Down).\n");
40break;
41case 3:
42msg_cerr("Error: Write Lock, Locked Down.\n");
43break;
44case 4:
45msg_cdbg("Read Lock.\n");
46break;
47case 5:
48msg_cdbg("Read/Write Lock.\n");
49break;
50case 6:
51msg_cerr("Error: Read Lock, Locked Down.\n");
52break;
53case 7:
54msg_cerr("Error: Read/Write Lock, Locked Down.\n");
55break;
56}
57
58/* Read or write lock present? */
59return (locking & ((1 << 2) | (1 << 0))) ? -1 : 0;
60}
61
62static int unlock_w39_fwh_block(struct flashctx *flash, unsigned int offset)
63{
64chipaddr wrprotect = flash->virtual_registers + offset + 2;
65uint8_t locking;
66
67locking = chip_readb(flash, wrprotect);
68/* Read or write lock present? */
69if (locking & ((1 << 2) | (1 << 0))) {
70/* Lockdown active? */
71if (locking & (1 << 1)) {
72msg_cerr("Can't unlock block at 0x%08x!\n", offset);
73return -1;
74} else {
75msg_cdbg("Unlocking block at 0x%08x\n", offset);
76chip_writeb(flash, 0, wrprotect);
77}
78}
79
80return 0;
81}
82
83static uint8_t w39_idmode_readb(struct flashctx *flash, unsigned int offset)
84{
85chipaddr bios = flash->virtual_memory;
86uint8_t val;
87
88/* Product Identification Entry */
89chip_writeb(flash, 0xAA, bios + 0x5555);
90chip_writeb(flash, 0x55, bios + 0x2AAA);
91chip_writeb(flash, 0x90, bios + 0x5555);
92programmer_delay(10);
93
94/* Read something, maybe hardware lock bits */
95val = chip_readb(flash, bios + offset);
96
97/* Product Identification Exit */
98chip_writeb(flash, 0xAA, bios + 0x5555);
99chip_writeb(flash, 0x55, bios + 0x2AAA);
100chip_writeb(flash, 0xF0, bios + 0x5555);
101programmer_delay(10);
102
103return val;
104}
105
106static int printlock_w39_tblwp(uint8_t lock)
107{
108msg_cdbg("Hardware bootblock locking (#TBL) is %sactive.\n",
109 (lock & (1 << 2)) ? "" : "not ");
110msg_cdbg("Hardware remaining chip locking (#WP) is %sactive..\n",
111(lock & (1 << 3)) ? "" : "not ");
112if (lock & ((1 << 2) | (1 << 3)))
113return -1;
114
115return 0;
116}
117
118static int printlock_w39_bootblock_64k16k(uint8_t lock)
119{
120msg_cdbg("Software 64 kB bootblock locking is %sactive.\n",
121 (lock & (1 << 0)) ? "" : "not ");
122msg_cdbg("Software 16 kB bootblock locking is %sactive.\n",
123 (lock & (1 << 1)) ? "" : "not ");
124if (lock & ((1 << 1) | (1 << 0)))
125return -1;
126
127return 0;
128}
129
130static int printlock_w39_common(struct flashctx *flash, unsigned int offset)
131{
132uint8_t lock;
133
134lock = w39_idmode_readb(flash, offset);
135msg_cdbg("Lockout bits:\n");
136return printlock_w39_tblwp(lock);
137}
138
139static int printlock_w39_fwh(struct flashctx *flash)
140{
141unsigned int i, total_size = flash->total_size * 1024;
142int ret = 0;
143
144/* Print lock status of the complete chip */
145for (i = 0; i < total_size; i += flash->page_size)
146ret |= printlock_w39_fwh_block(flash, i);
147
148return ret;
149}
150
151static int unlock_w39_fwh(struct flashctx *flash)
152{
153unsigned int i, total_size = flash->total_size * 1024;
154
155/* Unlock the complete chip */
156for (i = 0; i < total_size; i += flash->page_size)
157if (unlock_w39_fwh_block(flash, i))
158return -1;
159
160return 0;
161}
162
163int printlock_w39l040(struct flashctx *flash)
164{
165uint8_t lock;
166int ret;
167
168lock = w39_idmode_readb(flash, 0x00002);
169msg_cdbg("Bottom boot block:\n");
170ret = printlock_w39_bootblock_64k16k(lock);
171
172lock = w39_idmode_readb(flash, 0x7fff2);
173msg_cdbg("Top boot block:\n");
174ret |= printlock_w39_bootblock_64k16k(lock);
175
176return ret;
177}
178
179int printlock_w39v040a(struct flashctx *flash)
180{
181uint8_t lock;
182int ret = 0;
183
184/* The W39V040A datasheet contradicts itself on the lock register
185 * location: 0x00002 and 0x7fff2 are both mentioned. Pick the one
186 * which is similar to the other chips of the same family.
187 */
188lock = w39_idmode_readb(flash, 0x7fff2);
189msg_cdbg("Lockout bits:\n");
190
191ret = printlock_w39_tblwp(lock);
192ret |= printlock_w39_bootblock_64k16k(lock);
193
194return ret;
195}
196
197int printlock_w39v040b(struct flashctx *flash)
198{
199return printlock_w39_common(flash, 0x7fff2);
200}
201
202int printlock_w39v040c(struct flashctx *flash)
203{
204/* Typo in the datasheet? The other chips use 0x7fff2. */
205return printlock_w39_common(flash, 0xfff2);
206}
207
208int printlock_w39v040fa(struct flashctx *flash)
209{
210int ret = 0;
211
212ret = printlock_w39v040a(flash);
213ret |= printlock_w39_fwh(flash);
214
215return ret;
216}
217
218int printlock_w39v040fb(struct flashctx *flash)
219{
220int ret = 0;
221
222ret = printlock_w39v040b(flash);
223ret |= printlock_w39_fwh(flash);
224
225return ret;
226}
227
228int printlock_w39v040fc(struct flashctx *flash)
229{
230int ret = 0;
231
232/* W39V040C and W39V040FC use different WP/TBL offsets. */
233ret = printlock_w39_common(flash, 0x7fff2);
234ret |= printlock_w39_fwh(flash);
235
236return ret;
237}
238
239int printlock_w39v080a(struct flashctx *flash)
240{
241return printlock_w39_common(flash, 0xffff2);
242}
243
244int printlock_w39v080fa(struct flashctx *flash)
245{
246int ret = 0;
247
248ret = printlock_w39v080a(flash);
249ret |= printlock_w39_fwh(flash);
250
251return ret;
252}
253
254int printlock_w39v080fa_dual(struct flashctx *flash)
255{
256msg_cinfo("Block locking for W39V080FA in dual mode is "
257 "undocumented.\n");
258/* Better safe than sorry. */
259return -1;
260}
261
262int unlock_w39v040fb(struct flashctx *flash)
263{
264if (unlock_w39_fwh(flash))
265return -1;
266if (printlock_w39_common(flash, 0x7fff2))
267return -1;
268
269return 0;
270}
271
272int unlock_w39v080fa(struct flashctx *flash)
273{
274if (unlock_w39_fwh(flash))
275return -1;
276if (printlock_w39_common(flash, 0xffff2))
277return -1;
278
279return 0;
280}
281
282int printlock_at49f(struct flashctx *flash)
283{
284uint8_t lock = w39_idmode_readb(flash, 0x00002);
285msg_cdbg("Hardware bootblock lockout is %sactive.\n",
286 (lock & 0x01) ? "" : "not ");
287return 0;
288}
289

Archive Download this file

Revision: HEAD