blob: 87cbc6149e5c308952dde21ede3871e73fb2d476 [file] [log] [blame]
hailfinger336d3c32008-03-14 00:02:25 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
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 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * Datasheet:
23 * - Name: Intel 82802AB/82802AC Firmware Hub (FWH)
24 * - URL: http://www.intel.com/design/chipsets/datashts/290658.htm
25 * - PDF: http://download.intel.com/design/chipsets/datashts/29065804.pdf
26 * - Order number: 290658-004
27 */
28
hailfinger336d3c32008-03-14 00:02:25 +000029#include "flash.h"
snelson8913d082010-02-26 05:48:29 +000030#include "chipdrivers.h"
hailfinger336d3c32008-03-14 00:02:25 +000031
snelsonc0acbeb2010-03-19 18:47:06 +000032void print_status_82802ab(uint8_t status)
hailfinger336d3c32008-03-14 00:02:25 +000033{
snelsonfc007bb2010-03-24 23:14:32 +000034 msg_cdbg("%s", status & 0x80 ? "Ready:" : "Busy:");
35 msg_cdbg("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
36 msg_cdbg("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
37 msg_cdbg("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
38 msg_cdbg("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
39 msg_cdbg("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
40 msg_cdbg("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
hailfinger336d3c32008-03-14 00:02:25 +000041}
42
Souvik Ghoshd75cd672016-06-17 14:21:39 -070043int probe_82802ab(struct flashctx *flash)
hailfinger336d3c32008-03-14 00:02:25 +000044{
hailfinger82719632009-05-16 21:22:56 +000045 chipaddr bios = flash->virtual_memory;
uwe8d342eb2011-07-28 08:13:25 +000046 uint8_t id1, id2, flashcontent1, flashcontent2;
Patrick Georgif3fa2992017-02-02 16:24:44 +010047 int shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED) != 0;
hailfinger336d3c32008-03-14 00:02:25 +000048
hailfinger2fc3c402009-09-05 01:16:30 +000049 /* Reset to get a clean state */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070050 chip_writeb(flash, 0xFF, bios);
hailfingere5829f62009-06-05 17:48:08 +000051 programmer_delay(10);
hailfinger2fc3c402009-09-05 01:16:30 +000052
53 /* Enter ID mode */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070054 chip_writeb(flash, 0x90, bios);
hailfingere5829f62009-06-05 17:48:08 +000055 programmer_delay(10);
hailfinger336d3c32008-03-14 00:02:25 +000056
Souvik Ghoshd75cd672016-06-17 14:21:39 -070057 id1 = chip_readb(flash, bios + (0x00 << shifted));
58 id2 = chip_readb(flash, bios + (0x01 << shifted));
hailfinger336d3c32008-03-14 00:02:25 +000059
60 /* Leave ID mode */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070061 chip_writeb(flash, 0xFF, bios);
hailfinger336d3c32008-03-14 00:02:25 +000062
hailfingere5829f62009-06-05 17:48:08 +000063 programmer_delay(10);
hailfinger336d3c32008-03-14 00:02:25 +000064
snelsonfc007bb2010-03-24 23:14:32 +000065 msg_cdbg("%s: id1 0x%02x, id2 0x%02x", __func__, id1, id2);
hailfinger336d3c32008-03-14 00:02:25 +000066
hailfingercbc09f92010-03-22 23:47:38 +000067 if (!oddparity(id1))
snelsonfc007bb2010-03-24 23:14:32 +000068 msg_cdbg(", id1 parity violation");
hailfingercbc09f92010-03-22 23:47:38 +000069
uwe8d342eb2011-07-28 08:13:25 +000070 /*
71 * Read the product ID location again. We should now see normal
72 * flash contents.
73 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070074 flashcontent1 = chip_readb(flash, bios + (0x00 << shifted));
75 flashcontent2 = chip_readb(flash, bios + (0x01 << shifted));
hailfingercbc09f92010-03-22 23:47:38 +000076
77 if (id1 == flashcontent1)
snelsonfc007bb2010-03-24 23:14:32 +000078 msg_cdbg(", id1 is normal flash content");
hailfingercbc09f92010-03-22 23:47:38 +000079 if (id2 == flashcontent2)
snelsonfc007bb2010-03-24 23:14:32 +000080 msg_cdbg(", id2 is normal flash content");
hailfingercbc09f92010-03-22 23:47:38 +000081
snelsonfc007bb2010-03-24 23:14:32 +000082 msg_cdbg("\n");
Patrick Georgif3fa2992017-02-02 16:24:44 +010083 if (id1 != flash->chip->manufacture_id || id2 != flash->chip->model_id)
hailfinger336d3c32008-03-14 00:02:25 +000084 return 0;
85
Patrick Georgif3fa2992017-02-02 16:24:44 +010086 if (flash->chip->feature_bits & FEATURE_REGISTERMAP)
hailfingerb8e4e212010-03-15 03:48:42 +000087 map_flash_registers(flash);
hailfinger336d3c32008-03-14 00:02:25 +000088
89 return 1;
90}
91
Souvik Ghoshd75cd672016-06-17 14:21:39 -070092uint8_t wait_82802ab(struct flashctx *flash)
hailfinger336d3c32008-03-14 00:02:25 +000093{
94 uint8_t status;
hailfingera10a6072010-10-10 14:02:27 +000095 chipaddr bios = flash->virtual_memory;
hailfinger336d3c32008-03-14 00:02:25 +000096
Souvik Ghoshd75cd672016-06-17 14:21:39 -070097 chip_writeb(flash, 0x70, bios);
98 if ((chip_readb(flash, bios) & 0x80) == 0) { // it's busy
99 while ((chip_readb(flash, bios) & 0x80) == 0) ;
hailfinger336d3c32008-03-14 00:02:25 +0000100 }
101
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700102 status = chip_readb(flash, bios);
hailfinger336d3c32008-03-14 00:02:25 +0000103
hailfinger2fc3c402009-09-05 01:16:30 +0000104 /* Reset to get a clean state */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700105 chip_writeb(flash, 0xFF, bios);
hailfinger336d3c32008-03-14 00:02:25 +0000106
107 return status;
108}
109
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700110int unlock_82802ab(struct flashctx *flash)
snelsonc0acbeb2010-03-19 18:47:06 +0000111{
112 int i;
113 //chipaddr wrprotect = flash->virtual_registers + page + 2;
114
Patrick Georgif3fa2992017-02-02 16:24:44 +0100115 for (i = 0; i < flash->chip->total_size * 1024; i+= flash->chip->page_size)
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700116 chip_writeb(flash, 0, flash->virtual_registers + i + 2);
snelsonc0acbeb2010-03-19 18:47:06 +0000117
118 return 0;
119}
120
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700121int erase_block_82802ab(struct flashctx *flash, unsigned int page,
uwe8d342eb2011-07-28 08:13:25 +0000122 unsigned int pagesize)
hailfinger336d3c32008-03-14 00:02:25 +0000123{
snelson2d471072010-01-09 05:30:14 +0000124 chipaddr bios = flash->virtual_memory;
hailfinger336d3c32008-03-14 00:02:25 +0000125 uint8_t status;
126
127 // clear status register
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700128 chip_writeb(flash, 0x50, bios + page);
stepana5807bf2009-09-16 08:26:59 +0000129
hailfinger336d3c32008-03-14 00:02:25 +0000130 // now start it
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700131 chip_writeb(flash, 0x20, bios + page);
132 chip_writeb(flash, 0xd0, bios + page);
hailfingere5829f62009-06-05 17:48:08 +0000133 programmer_delay(10);
stepana5807bf2009-09-16 08:26:59 +0000134
hailfinger336d3c32008-03-14 00:02:25 +0000135 // now let's see what the register is
hailfingera10a6072010-10-10 14:02:27 +0000136 status = wait_82802ab(flash);
snelsonc0acbeb2010-03-19 18:47:06 +0000137 print_status_82802ab(status);
stepana5807bf2009-09-16 08:26:59 +0000138
hailfingerac8e3182011-06-26 17:04:16 +0000139 /* FIXME: Check the status register for errors. */
hailfinger336d3c32008-03-14 00:02:25 +0000140 return 0;
141}
142
hailfinger71e1bd42010-10-13 22:26:56 +0000143/* chunksize is 1 */
Patrick Georgiab8353e2017-02-03 18:32:01 +0100144int write_82802ab(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
hailfinger336d3c32008-03-14 00:02:25 +0000145{
146 int i;
hailfingera10a6072010-10-10 14:02:27 +0000147 chipaddr dst = flash->virtual_memory + start;
hailfinger336d3c32008-03-14 00:02:25 +0000148
hailfingera10a6072010-10-10 14:02:27 +0000149 for (i = 0; i < len; i++) {
hailfinger336d3c32008-03-14 00:02:25 +0000150 /* transfer data from source to destination */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700151 chip_writeb(flash, 0x40, dst);
152 chip_writeb(flash, *src++, dst++);
hailfingera10a6072010-10-10 14:02:27 +0000153 wait_82802ab(flash);
hailfinger336d3c32008-03-14 00:02:25 +0000154 }
hailfingera10a6072010-10-10 14:02:27 +0000155
156 /* FIXME: Ignore errors for now. */
157 return 0;
hailfinger336d3c32008-03-14 00:02:25 +0000158}
159
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700160int unlock_28f004s5(struct flashctx *flash)
snelsona013bf62010-03-22 04:39:31 +0000161{
162 chipaddr bios = flash->virtual_memory;
snelson6cfa2392010-03-22 07:03:26 +0000163 uint8_t mcfg, bcfg, need_unlock = 0, can_unlock = 0;
164 int i;
snelsona013bf62010-03-22 04:39:31 +0000165
166 /* Clear status register */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700167 chip_writeb(flash, 0x50, bios);
snelsona013bf62010-03-22 04:39:31 +0000168
169 /* Read identifier codes */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700170 chip_writeb(flash, 0x90, bios);
snelsona013bf62010-03-22 04:39:31 +0000171
172 /* Read master lock-bit */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700173 mcfg = chip_readb(flash, bios + 0x3);
snelsonfc007bb2010-03-24 23:14:32 +0000174 msg_cdbg("master lock is ");
snelsona013bf62010-03-22 04:39:31 +0000175 if (mcfg) {
176 msg_cdbg("locked!\n");
177 } else {
178 msg_cdbg("unlocked!\n");
179 can_unlock = 1;
180 }
uwe8d342eb2011-07-28 08:13:25 +0000181
snelsona013bf62010-03-22 04:39:31 +0000182 /* Read block lock-bits */
Patrick Georgif3fa2992017-02-02 16:24:44 +0100183 for (i = 0; i < flash->chip->total_size * 1024; i+= (64 * 1024)) {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700184 bcfg = chip_readb(flash, bios + i + 2); // read block lock config
snelsona013bf62010-03-22 04:39:31 +0000185 msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un");
186 if (bcfg) {
187 need_unlock = 1;
188 }
189 }
190
191 /* Reset chip */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700192 chip_writeb(flash, 0xFF, bios);
snelsona013bf62010-03-22 04:39:31 +0000193
194 /* Unlock: clear block lock-bits, if needed */
195 if (can_unlock && need_unlock) {
snelsonfc007bb2010-03-24 23:14:32 +0000196 msg_cdbg("Unlock: ");
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700197 chip_writeb(flash, 0x60, bios);
198 chip_writeb(flash, 0xD0, bios);
199 chip_writeb(flash, 0xFF, bios);
snelsonfc007bb2010-03-24 23:14:32 +0000200 msg_cdbg("Done!\n");
snelsona013bf62010-03-22 04:39:31 +0000201 }
202
203 /* Error: master locked or a block is locked */
204 if (!can_unlock && need_unlock) {
205 msg_cerr("At least one block is locked and lockdown is active!\n");
206 return -1;
207 }
208
209 return 0;
210}
uwe8e0cff52011-08-25 22:44:11 +0000211
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700212int unlock_lh28f008bjt(struct flashctx *flash)
uwe8e0cff52011-08-25 22:44:11 +0000213{
214 chipaddr bios = flash->virtual_memory;
215 uint8_t mcfg, bcfg;
216 uint8_t need_unlock = 0, can_unlock = 0;
217 int i;
218
219 /* Wait if chip is busy */
220 wait_82802ab(flash);
221
222 /* Read identifier codes */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700223 chip_writeb(flash, 0x90, bios);
uwe8e0cff52011-08-25 22:44:11 +0000224
225 /* Read master lock-bit */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700226 mcfg = chip_readb(flash, bios + 0x3);
uwe8e0cff52011-08-25 22:44:11 +0000227 msg_cdbg("master lock is ");
228 if (mcfg) {
229 msg_cdbg("locked!\n");
230 } else {
231 msg_cdbg("unlocked!\n");
232 can_unlock = 1;
233 }
234
235 /* Read block lock-bits, 8 * 8 KB + 15 * 64 KB */
Patrick Georgif3fa2992017-02-02 16:24:44 +0100236 for (i = 0; i < flash->chip->total_size * 1024;
uwe8e0cff52011-08-25 22:44:11 +0000237 i += (i >= (64 * 1024) ? 64 * 1024 : 8 * 1024)) {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700238 bcfg = chip_readb(flash, bios + i + 2); /* read block lock config */
uwe8e0cff52011-08-25 22:44:11 +0000239 msg_cdbg("block lock at %06x is %slocked!\n", i,
240 bcfg ? "" : "un");
241 if (bcfg)
242 need_unlock = 1;
243 }
244
245 /* Reset chip */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700246 chip_writeb(flash, 0xFF, bios);
uwe8e0cff52011-08-25 22:44:11 +0000247
248 /* Unlock: clear block lock-bits, if needed */
249 if (can_unlock && need_unlock) {
250 msg_cdbg("Unlock: ");
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700251 chip_writeb(flash, 0x60, bios);
252 chip_writeb(flash, 0xD0, bios);
253 chip_writeb(flash, 0xFF, bios);
uwe8e0cff52011-08-25 22:44:11 +0000254 wait_82802ab(flash);
255 msg_cdbg("Done!\n");
256 }
257
258 /* Error: master locked or a block is locked */
259 if (!can_unlock && need_unlock) {
260 msg_cerr("At least one block is locked and lockdown is active!\n");
261 return -1;
262 }
263
264 return 0;
265}