blob: c327f44c1c93a3d3e835272522acf381c92d8a3b [file] [log] [blame]
Ronald G. Minnichb1934902002-06-11 19:15:55 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Ronald G. Minnichb1934902002-06-11 19:15:55 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
Ronald G. Minnichb1934902002-06-11 19:15:55 +00005 *
Uwe Hermannd1107642007-08-29 17:52:32 +00006 * 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.
Ronald G. Minnichb1934902002-06-11 19:15:55 +000010 *
Uwe Hermannd1107642007-08-29 17:52:32 +000011 * 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.
Ronald G. Minnichb1934902002-06-11 19:15:55 +000015 *
Uwe Hermannd1107642007-08-29 17:52:32 +000016 * 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
Ronald G. Minnichb1934902002-06-11 19:15:55 +000019 */
20
21#include "flash.h"
Ronald G. Minnichb1934902002-06-11 19:15:55 +000022
Michael Karcher1c296ca2009-11-27 17:49:42 +000023/* WARNING!
24 This chip uses the standard JEDEC Addresses in 16-bit mode as word
25 addresses. In byte mode, 0xAAA has to be used instead of 0x555 and
26 0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC
27 functions. */
28
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000029void write_page_m29f400bt(chipaddr bios, uint8_t *src,
30 chipaddr dst, int page_size)
Uwe Hermann51582f22007-08-23 10:20:40 +000031{
32 int i;
33
34 for (i = 0; i < page_size; i++) {
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000035 chip_writeb(0xAA, bios + 0xAAA);
36 chip_writeb(0x55, bios + 0x555);
37 chip_writeb(0xA0, bios + 0xAAA);
Uwe Hermann51582f22007-08-23 10:20:40 +000038
39 /* transfer data from source to destination */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000040 chip_writeb(*src, dst);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000041 //chip_writeb(0xF0, bios);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000042 //programmer_delay(5);
Uwe Hermannfd374142007-08-23 15:20:38 +000043 toggle_ready_jedec(dst);
Uwe Hermann51582f22007-08-23 10:20:40 +000044 printf
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000045 ("Value in the flash at address 0x%lx = %#x, want %#x\n",
46 (dst - bios), chip_readb(dst), *src);
Uwe Hermann51582f22007-08-23 10:20:40 +000047 dst++;
48 src++;
49 }
50}
51
Ollie Lho761bf1b2004-03-20 16:46:10 +000052int probe_m29f400bt(struct flashchip *flash)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000053{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000054 chipaddr bios = flash->virtual_memory;
Ollie Lho184a4042005-11-26 21:55:36 +000055 uint8_t id1, id2;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000056
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000057 chip_writeb(0xAA, bios + 0xAAA);
58 chip_writeb(0x55, bios + 0x555);
59 chip_writeb(0x90, bios + 0xAAA);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000060
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000061 programmer_delay(10);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000062
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000063 id1 = chip_readb(bios);
Carl-Daniel Hailfingerc2a18452007-12-31 01:18:26 +000064 /* The data sheet says id2 is at (bios + 0x01) and id2 listed in
65 * flash.h does not match. It should be possible to use JEDEC probe.
66 */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000067 id2 = chip_readb(bios + 0x02);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000068
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000069 chip_writeb(0xAA, bios + 0xAAA);
70 chip_writeb(0x55, bios + 0x555);
71 chip_writeb(0xF0, bios + 0xAAA);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000072
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000073 programmer_delay(10);
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000074
Uwe Hermann04aa59a2009-09-02 22:09:00 +000075 printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2);
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000076
Ronald G. Minnichb1934902002-06-11 19:15:55 +000077 if (id1 == flash->manufacture_id && id2 == flash->model_id)
78 return 1;
79
80 return 0;
81}
82
Ollie Lho761bf1b2004-03-20 16:46:10 +000083int erase_m29f400bt(struct flashchip *flash)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000084{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000085 chipaddr bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000086
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000087 chip_writeb(0xAA, bios + 0xAAA);
88 chip_writeb(0x55, bios + 0x555);
89 chip_writeb(0x80, bios + 0xAAA);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000090
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000091 chip_writeb(0xAA, bios + 0xAAA);
92 chip_writeb(0x55, bios + 0x555);
93 chip_writeb(0x10, bios + 0xAAA);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000094
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000095 programmer_delay(10);
Uwe Hermannfd374142007-08-23 15:20:38 +000096 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000097
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000098 if (check_erased_range(flash, 0, flash->total_size * 1024)) {
99 fprintf(stderr, "ERASE FAILED!\n");
100 return -1;
101 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000102 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000103}
104
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000105int block_erase_m29f400bt(struct flashchip *flash, int start, int len)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000106{
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000107 chipaddr bios = flash->virtual_memory;
108 chipaddr dst = bios + start;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000109
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +0000110 chip_writeb(0xAA, bios + 0xAAA);
111 chip_writeb(0x55, bios + 0x555);
112 chip_writeb(0x80, bios + 0xAAA);
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000113
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +0000114 chip_writeb(0xAA, bios + 0xAAA);
115 chip_writeb(0x55, bios + 0x555);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000116 //chip_writeb(0x10, bios + 0xAAA);
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +0000117 chip_writeb(0x30, dst);
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000118
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000119 programmer_delay(10);
Uwe Hermannfd374142007-08-23 15:20:38 +0000120 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000121
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000122 if (check_erased_range(flash, start, len)) {
123 fprintf(stderr, "ERASE FAILED!\n");
124 return -1;
125 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000126 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000127}
128
Ollie Lho184a4042005-11-26 21:55:36 +0000129int write_m29f400bt(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000130{
131 int i;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000132 int total_size = flash->total_size * 1024;
133 int page_size = flash->page_size;
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000134 chipaddr bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000135
136 //erase_m29f400bt (flash);
Uwe Hermanna502dce2007-10-17 23:55:15 +0000137 printf("Programming page:\n ");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000138 /*********************************
139 *Pages for M29F400BT:
140 * 16 0x7c000 0x7ffff TOP
141 * 8 0x7a000 0x7bfff
142 * 8 0x78000 0x79fff
143 * 32 0x70000 0x77fff
144 * 64 0x60000 0x6ffff
145 * 64 0x50000 0x5ffff
146 * 64 0x40000 0x4ffff
147 *---------------------------------
148 * 64 0x30000 0x3ffff
149 * 64 0x20000 0x2ffff
150 * 64 0x10000 0x1ffff
151 * 64 0x00000 0x0ffff BOTTOM
152 *********************************/
Ollie Lho761bf1b2004-03-20 16:46:10 +0000153 printf("total_size/page_size = %d\n", total_size / page_size);
154 for (i = 0; i < (total_size / page_size) - 1; i++) {
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000155 printf("%04d at address: 0x%08x\n", i, i * page_size);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000156 if (block_erase_m29f400bt(flash, i * page_size, page_size)) {
157 fprintf(stderr, "ERASE FAILED!\n");
158 return -1;
159 }
Ollie Lho761bf1b2004-03-20 16:46:10 +0000160 write_page_m29f400bt(bios, buf + i * page_size,
161 bios + i * page_size, page_size);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000162 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000163 }
164
Ollie Lho761bf1b2004-03-20 16:46:10 +0000165 printf("%04d at address: 0x%08x\n", 7, 0x70000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000166 if (block_erase_m29f400bt(flash, 0x70000, 32 * 1024)) {
167 fprintf(stderr, "ERASE FAILED!\n");
168 return -1;
169 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000170 write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000171
172 printf("%04d at address: 0x%08x\n", 8, 0x78000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000173 if (block_erase_m29f400bt(flash, 0x78000, 8 * 1024)) {
174 fprintf(stderr, "ERASE FAILED!\n");
175 return -1;
176 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000177 write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000178
179 printf("%04d at address: 0x%08x\n", 9, 0x7a000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000180 if (block_erase_m29f400bt(flash, 0x7a000, 8 * 1024)) {
181 fprintf(stderr, "ERASE FAILED!\n");
182 return -1;
183 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000184 write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000185
186 printf("%04d at address: 0x%08x\n", 10, 0x7c000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000187 if (block_erase_m29f400bt(flash, 0x7c000, 16 * 1024)) {
188 fprintf(stderr, "ERASE FAILED!\n");
189 return -1;
190 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000191 write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000192
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000193 printf("\n");
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000194
Uwe Hermannffec5f32007-08-23 16:08:21 +0000195 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000196}
197
Stefan Reinauere3f3e2e2008-01-18 15:33:10 +0000198int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000199{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000200 chipaddr bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000201
Uwe Hermanna502dce2007-10-17 23:55:15 +0000202 printf("Programming page:\n ");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000203 /*********************************
204 *Pages for M29F400BT:
205 * 16 0x7c000 0x7ffff TOP
206 * 8 0x7a000 0x7bfff
207 * 8 0x78000 0x79fff
208 * 32 0x70000 0x77fff
209 * 64 0x60000 0x6ffff
210 * 64 0x50000 0x5ffff
211 * 64 0x40000 0x4ffff
212 *---------------------------------
213 * 64 0x30000 0x3ffff
214 * 64 0x20000 0x2ffff
215 * 64 0x10000 0x1ffff
216 * 64 0x00000 0x0ffff BOTTOM
217 *********************************/
Ollie Lho761bf1b2004-03-20 16:46:10 +0000218 printf("%04d at address: 0x%08x\n", 7, 0x00000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000219 if (block_erase_m29f400bt(flash, 0x00000, 64 * 1024)) {
220 fprintf(stderr, "ERASE FAILED!\n");
221 return -1;
222 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000223 write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000224
225 printf("%04d at address: 0x%08x\n", 7, 0x10000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000226 if (block_erase_m29f400bt(flash, 0x10000, 64 * 1024)) {
227 fprintf(stderr, "ERASE FAILED!\n");
228 return -1;
229 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000230 write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000231
232 printf("%04d at address: 0x%08x\n", 7, 0x20000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000233 if (block_erase_m29f400bt(flash, 0x20000, 64 * 1024)) {
234 fprintf(stderr, "ERASE FAILED!\n");
235 return -1;
236 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000237 write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000238
239 printf("%04d at address: 0x%08x\n", 7, 0x30000);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000240 if (block_erase_m29f400bt(flash, 0x30000, 64 * 1024)) {
241 fprintf(stderr, "ERASE FAILED!\n");
242 return -1;
243 }
Uwe Hermanna7e05482007-05-09 10:17:44 +0000244 write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000245
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000246 printf("\n");
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000247
Uwe Hermannffec5f32007-08-23 16:08:21 +0000248 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000249}