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#include "chipdrivers.h"
24
25static uint8_t w39_idmode_readb(struct flashctx *flash, unsigned int offset)
26{
27chipaddr bios = flash->virtual_memory;
28uint8_t val;
29
30/* Product Identification Entry */
31chip_writeb(flash, 0xAA, bios + 0x5555);
32chip_writeb(flash, 0x55, bios + 0x2AAA);
33chip_writeb(flash, 0x90, bios + 0x5555);
34programmer_delay(10);
35
36/* Read something, maybe hardware lock bits */
37val = chip_readb(flash, bios + offset);
38
39/* Product Identification Exit */
40chip_writeb(flash, 0xAA, bios + 0x5555);
41chip_writeb(flash, 0x55, bios + 0x2AAA);
42chip_writeb(flash, 0xF0, bios + 0x5555);
43programmer_delay(10);
44
45return val;
46}
47
48static int printlock_w39_tblwp(uint8_t lock)
49{
50msg_cdbg("Hardware bootblock locking (#TBL) is %sactive.\n",
51 (lock & (1 << 2)) ? "" : "not ");
52msg_cdbg("Hardware remaining chip locking (#WP) is %sactive..\n",
53(lock & (1 << 3)) ? "" : "not ");
54if (lock & ((1 << 2) | (1 << 3)))
55return -1;
56
57return 0;
58}
59
60static int printlock_w39_single_bootblock(uint8_t lock, uint16_t kB)
61{
62msg_cdbg("Software %d kB bootblock locking is %sactive.\n", kB, (lock & 0x03) ? "" : "not ");
63if (lock & 0x03)
64return -1;
65
66return 0;
67}
68
69static int printlock_w39_bootblock_64k16k(uint8_t lock)
70{
71msg_cdbg("Software 64 kB bootblock locking is %sactive.\n",
72 (lock & (1 << 0)) ? "" : "not ");
73msg_cdbg("Software 16 kB bootblock locking is %sactive.\n",
74 (lock & (1 << 1)) ? "" : "not ");
75if (lock & ((1 << 1) | (1 << 0)))
76return -1;
77
78return 0;
79}
80
81static int printlock_w39_common(struct flashctx *flash, unsigned int offset)
82{
83uint8_t lock;
84
85lock = w39_idmode_readb(flash, offset);
86msg_cdbg("Lockout bits:\n");
87return printlock_w39_tblwp(lock);
88}
89
90int printlock_w39f010(struct flashctx *flash)
91{
92uint8_t lock;
93int ret;
94
95lock = w39_idmode_readb(flash, 0x00002);
96msg_cdbg("Bottom boot block:\n");
97ret = printlock_w39_single_bootblock(lock, 16);
98
99lock = w39_idmode_readb(flash, 0x1fff2);
100msg_cdbg("Top boot block:\n");
101ret |= printlock_w39_single_bootblock(lock, 16);
102
103return ret;
104}
105
106int printlock_w39l010(struct flashctx *flash)
107{
108uint8_t lock;
109int ret;
110
111lock = w39_idmode_readb(flash, 0x00002);
112msg_cdbg("Bottom boot block:\n");
113ret = printlock_w39_single_bootblock(lock, 8);
114
115lock = w39_idmode_readb(flash, 0x1fff2);
116msg_cdbg("Top boot block:\n");
117ret |= printlock_w39_single_bootblock(lock, 8);
118
119return ret;
120}
121
122int printlock_w39l020(struct flashctx *flash)
123{
124uint8_t lock;
125int ret;
126
127lock = w39_idmode_readb(flash, 0x00002);
128msg_cdbg("Bottom boot block:\n");
129ret = printlock_w39_bootblock_64k16k(lock);
130
131lock = w39_idmode_readb(flash, 0x3fff2);
132msg_cdbg("Top boot block:\n");
133ret |= printlock_w39_bootblock_64k16k(lock);
134
135return ret;
136}
137
138int printlock_w39l040(struct flashctx *flash)
139{
140uint8_t lock;
141int ret;
142
143lock = w39_idmode_readb(flash, 0x00002);
144msg_cdbg("Bottom boot block:\n");
145ret = printlock_w39_bootblock_64k16k(lock);
146
147lock = w39_idmode_readb(flash, 0x7fff2);
148msg_cdbg("Top boot block:\n");
149ret |= printlock_w39_bootblock_64k16k(lock);
150
151return ret;
152}
153
154int printlock_w39v040a(struct flashctx *flash)
155{
156uint8_t lock;
157int ret = 0;
158
159/* The W39V040A datasheet contradicts itself on the lock register
160 * location: 0x00002 and 0x7fff2 are both mentioned. Pick the one
161 * which is similar to the other chips of the same family.
162 */
163lock = w39_idmode_readb(flash, 0x7fff2);
164msg_cdbg("Lockout bits:\n");
165
166ret = printlock_w39_tblwp(lock);
167ret |= printlock_w39_bootblock_64k16k(lock);
168
169return ret;
170}
171
172int printlock_w39v040b(struct flashctx *flash)
173{
174return printlock_w39_common(flash, 0x7fff2);
175}
176
177int printlock_w39v040c(struct flashctx *flash)
178{
179/* Typo in the datasheet? The other chips use 0x7fff2. */
180return printlock_w39_common(flash, 0xfff2);
181}
182
183int printlock_w39v040fa(struct flashctx *flash)
184{
185int ret = 0;
186
187ret = printlock_w39v040a(flash);
188ret |= printlock_regspace2_uniform_64k(flash);
189
190return ret;
191}
192
193int printlock_w39v040fb(struct flashctx *flash)
194{
195int ret = 0;
196
197ret = printlock_w39v040b(flash);
198ret |= printlock_regspace2_uniform_64k(flash);
199
200return ret;
201}
202
203int printlock_w39v040fc(struct flashctx *flash)
204{
205int ret = 0;
206
207/* W39V040C and W39V040FC use different WP/TBL offsets. */
208ret = printlock_w39_common(flash, 0x7fff2);
209ret |= printlock_regspace2_uniform_64k(flash);
210
211return ret;
212}
213
214int printlock_w39v080a(struct flashctx *flash)
215{
216return printlock_w39_common(flash, 0xffff2);
217}
218
219int printlock_w39v080fa(struct flashctx *flash)
220{
221int ret = 0;
222
223ret = printlock_w39v080a(flash);
224ret |= printlock_regspace2_uniform_64k(flash);
225
226return ret;
227}
228
229int printlock_w39v080fa_dual(struct flashctx *flash)
230{
231msg_cinfo("Block locking for W39V080FA in dual mode is "
232 "undocumented.\n");
233/* Better safe than sorry. */
234return -1;
235}
236
237int printlock_at49f(struct flashctx *flash)
238{
239uint8_t lock = w39_idmode_readb(flash, 0x00002);
240msg_cdbg("Hardware bootblock lockout is %sactive.\n",
241 (lock & 0x01) ? "" : "not ");
242return 0;
243}

Archive Download this file

Revision: HEAD