blob: 40b219cadcd602f5d4549de0773666caced7897b [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
Uwe Hermann51582f22007-08-23 10:20:40 +000023void protect_m29f400bt(volatile uint8_t *bios)
24{
25 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
26 *(volatile uint8_t *)(bios + 0x555) = 0x55;
27 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
28
29 usleep(200);
30}
31
32void write_page_m29f400bt(volatile uint8_t *bios, uint8_t *src,
33 volatile uint8_t *dst, int page_size)
34{
35 int i;
36
37 for (i = 0; i < page_size; i++) {
38 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
39 *(volatile uint8_t *)(bios + 0x555) = 0x55;
40 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
41
42 /* transfer data from source to destination */
43 *dst = *src;
44 //*(volatile char *) (bios) = 0xF0;
45 //usleep(5);
Uwe Hermannfd374142007-08-23 15:20:38 +000046 toggle_ready_jedec(dst);
Uwe Hermann51582f22007-08-23 10:20:40 +000047 printf
48 ("Value in the flash at address %p = %#x, want %#x\n",
49 (uint8_t *) (dst - bios), *dst, *src);
50 dst++;
51 src++;
52 }
53}
54
Ollie Lho761bf1b2004-03-20 16:46:10 +000055int probe_m29f400bt(struct flashchip *flash)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000056{
Stefan Reinauerce532972007-05-23 17:20:56 +000057 volatile uint8_t *bios = flash->virtual_memory;
Ollie Lho184a4042005-11-26 21:55:36 +000058 uint8_t id1, id2;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000059
Uwe Hermanna7e05482007-05-09 10:17:44 +000060 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
61 *(volatile uint8_t *)(bios + 0x555) = 0x55;
62 *(volatile uint8_t *)(bios + 0xAAA) = 0x90;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000063
64 myusec_delay(10);
65
Uwe Hermanna7e05482007-05-09 10:17:44 +000066 id1 = *(volatile uint8_t *)bios;
67 id2 = *(volatile uint8_t *)(bios + 0x02);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000068
Uwe Hermanna7e05482007-05-09 10:17:44 +000069 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
70 *(volatile uint8_t *)(bios + 0x555) = 0x55;
71 *(volatile uint8_t *)(bios + 0xAAA) = 0xF0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000072
73 myusec_delay(10);
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000074
Ollie Lho184a4042005-11-26 21:55:36 +000075 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, 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{
Stefan Reinauerce532972007-05-23 17:20:56 +000085 volatile uint8_t *bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000086
Uwe Hermanna7e05482007-05-09 10:17:44 +000087 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
88 *(volatile uint8_t *)(bios + 0x555) = 0x55;
89 *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000090
Uwe Hermanna7e05482007-05-09 10:17:44 +000091 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
92 *(volatile uint8_t *)(bios + 0x555) = 0x55;
93 *(volatile uint8_t *)(bios + 0xAAA) = 0x10;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000094
95 myusec_delay(10);
Uwe Hermannfd374142007-08-23 15:20:38 +000096 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000097
Uwe Hermannffec5f32007-08-23 16:08:21 +000098 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000099}
100
Ollie Lho184a4042005-11-26 21:55:36 +0000101int block_erase_m29f400bt(volatile uint8_t *bios, volatile uint8_t *dst)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000102{
103
Uwe Hermanna7e05482007-05-09 10:17:44 +0000104 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
105 *(volatile uint8_t *)(bios + 0x555) = 0x55;
106 *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000107
Uwe Hermanna7e05482007-05-09 10:17:44 +0000108 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
109 *(volatile uint8_t *)(bios + 0x555) = 0x55;
Ollie Lho184a4042005-11-26 21:55:36 +0000110 //*(volatile uint8_t *) (bios + 0xAAA) = 0x10;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000111 *dst = 0x30;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000112
113 myusec_delay(10);
Uwe Hermannfd374142007-08-23 15:20:38 +0000114 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000115
Uwe Hermannffec5f32007-08-23 16:08:21 +0000116 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000117}
118
Ollie Lho184a4042005-11-26 21:55:36 +0000119int write_m29f400bt(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000120{
121 int i;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000122 int total_size = flash->total_size * 1024;
123 int page_size = flash->page_size;
Stefan Reinauerce532972007-05-23 17:20:56 +0000124 volatile uint8_t *bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000125
126 //erase_m29f400bt (flash);
Uwe Hermanna502dce2007-10-17 23:55:15 +0000127 printf("Programming page:\n ");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000128 /*********************************
129 *Pages for M29F400BT:
130 * 16 0x7c000 0x7ffff TOP
131 * 8 0x7a000 0x7bfff
132 * 8 0x78000 0x79fff
133 * 32 0x70000 0x77fff
134 * 64 0x60000 0x6ffff
135 * 64 0x50000 0x5ffff
136 * 64 0x40000 0x4ffff
137 *---------------------------------
138 * 64 0x30000 0x3ffff
139 * 64 0x20000 0x2ffff
140 * 64 0x10000 0x1ffff
141 * 64 0x00000 0x0ffff BOTTOM
142 *********************************/
Ollie Lho761bf1b2004-03-20 16:46:10 +0000143 printf("total_size/page_size = %d\n", total_size / page_size);
144 for (i = 0; i < (total_size / page_size) - 1; i++) {
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000145 printf("%04d at address: 0x%08x\n", i, i * page_size);
146 block_erase_m29f400bt(bios, bios + i * page_size);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000147 write_page_m29f400bt(bios, buf + i * page_size,
148 bios + i * page_size, page_size);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000149 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 +0000150 }
151
Ollie Lho761bf1b2004-03-20 16:46:10 +0000152 printf("%04d at address: 0x%08x\n", 7, 0x70000);
153 block_erase_m29f400bt(bios, bios + 0x70000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000154 write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000155
156 printf("%04d at address: 0x%08x\n", 8, 0x78000);
157 block_erase_m29f400bt(bios, bios + 0x78000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000158 write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000159
160 printf("%04d at address: 0x%08x\n", 9, 0x7a000);
161 block_erase_m29f400bt(bios, bios + 0x7a000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000162 write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000163
164 printf("%04d at address: 0x%08x\n", 10, 0x7c000);
165 block_erase_m29f400bt(bios, bios + 0x7c000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000166 write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000167
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000168 printf("\n");
169 //protect_m29f400bt (bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000170
Uwe Hermannffec5f32007-08-23 16:08:21 +0000171 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000172}
173
Ollie Lho184a4042005-11-26 21:55:36 +0000174int write_linuxbios_m29f400bt(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000175{
Stefan Reinauerce532972007-05-23 17:20:56 +0000176 volatile uint8_t *bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000177
Uwe Hermanna502dce2007-10-17 23:55:15 +0000178 printf("Programming page:\n ");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000179 /*********************************
180 *Pages for M29F400BT:
181 * 16 0x7c000 0x7ffff TOP
182 * 8 0x7a000 0x7bfff
183 * 8 0x78000 0x79fff
184 * 32 0x70000 0x77fff
185 * 64 0x60000 0x6ffff
186 * 64 0x50000 0x5ffff
187 * 64 0x40000 0x4ffff
188 *---------------------------------
189 * 64 0x30000 0x3ffff
190 * 64 0x20000 0x2ffff
191 * 64 0x10000 0x1ffff
192 * 64 0x00000 0x0ffff BOTTOM
193 *********************************/
Ollie Lho761bf1b2004-03-20 16:46:10 +0000194 printf("%04d at address: 0x%08x\n", 7, 0x00000);
195 block_erase_m29f400bt(bios, bios + 0x00000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000196 write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000197
198 printf("%04d at address: 0x%08x\n", 7, 0x10000);
199 block_erase_m29f400bt(bios, bios + 0x10000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000200 write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000201
202 printf("%04d at address: 0x%08x\n", 7, 0x20000);
203 block_erase_m29f400bt(bios, bios + 0x20000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000204 write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000205
206 printf("%04d at address: 0x%08x\n", 7, 0x30000);
207 block_erase_m29f400bt(bios, bios + 0x30000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000208 write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000209
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000210 printf("\n");
211 //protect_m29f400bt (bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000212
Uwe Hermannffec5f32007-08-23 16:08:21 +0000213 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000214}