blob: f58c495d1f6d2cd237a0b384e24a921570f4e14b [file] [log] [blame]
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +00001/*
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 Hailfinger91882402010-12-05 16:33:59 +000016 */
17
18#include "flash.h"
Carl-Daniel Hailfingeref3ac8a2014-08-03 13:05:34 +000019#include "chipdrivers.h"
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +000020
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000021static uint8_t w39_idmode_readb(struct flashctx *flash, unsigned int offset)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +000022{
23 chipaddr bios = flash->virtual_memory;
24 uint8_t val;
25
26 /* Product Identification Entry */
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000027 chip_writeb(flash, 0xAA, bios + 0x5555);
28 chip_writeb(flash, 0x55, bios + 0x2AAA);
29 chip_writeb(flash, 0x90, bios + 0x5555);
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +000030 programmer_delay(10);
31
32 /* Read something, maybe hardware lock bits */
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000033 val = chip_readb(flash, bios + offset);
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +000034
35 /* Product Identification Exit */
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000036 chip_writeb(flash, 0xAA, bios + 0x5555);
37 chip_writeb(flash, 0x55, bios + 0x2AAA);
38 chip_writeb(flash, 0xF0, bios + 0x5555);
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +000039 programmer_delay(10);
40
41 return val;
42}
43
44static 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älkkic31243e2012-10-28 01:50:08 +000056static 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 Hailfinger91882402010-12-05 16:33:59 +000065static 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 Hailfinger63fd9022011-12-14 22:25:15 +000077static int printlock_w39_common(struct flashctx *flash, unsigned int offset)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +000078{
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älkkic31243e2012-10-28 01:50:08 +000086int 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
102int 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
118int 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 Hailfinger8a3c60c2011-12-18 15:01:24 +0000134int printlock_w39l040(struct flashctx *flash)
Michael Karcher19e0aac2011-03-06 17:58:05 +0000135{
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 Hailfinger63fd9022011-12-14 22:25:15 +0000150int printlock_w39v040a(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000151{
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 Hailfinger63fd9022011-12-14 22:25:15 +0000168int printlock_w39v040b(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000169{
170 return printlock_w39_common(flash, 0x7fff2);
171}
172
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000173int printlock_w39v040c(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000174{
175 /* Typo in the datasheet? The other chips use 0x7fff2. */
176 return printlock_w39_common(flash, 0xfff2);
177}
178
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000179int printlock_w39v040fa(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000180{
181 int ret = 0;
182
183 ret = printlock_w39v040a(flash);
Carl-Daniel Hailfingeref3ac8a2014-08-03 13:05:34 +0000184 ret |= printlock_regspace2_uniform_64k(flash);
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000185
186 return ret;
187}
188
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000189int printlock_w39v040fb(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000190{
191 int ret = 0;
192
193 ret = printlock_w39v040b(flash);
Carl-Daniel Hailfingeref3ac8a2014-08-03 13:05:34 +0000194 ret |= printlock_regspace2_uniform_64k(flash);
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000195
196 return ret;
197}
198
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000199int printlock_w39v040fc(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000200{
201 int ret = 0;
202
203 /* W39V040C and W39V040FC use different WP/TBL offsets. */
204 ret = printlock_w39_common(flash, 0x7fff2);
Carl-Daniel Hailfingeref3ac8a2014-08-03 13:05:34 +0000205 ret |= printlock_regspace2_uniform_64k(flash);
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000206
207 return ret;
208}
209
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000210int printlock_w39v080a(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000211{
212 return printlock_w39_common(flash, 0xffff2);
213}
214
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000215int printlock_w39v080fa(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000216{
217 int ret = 0;
218
219 ret = printlock_w39v080a(flash);
Carl-Daniel Hailfingeref3ac8a2014-08-03 13:05:34 +0000220 ret |= printlock_regspace2_uniform_64k(flash);
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000221
222 return ret;
223}
224
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000225int printlock_w39v080fa_dual(struct flashctx *flash)
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000226{
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 Borgf5a30f62012-04-15 13:16:32 +0000233int 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}