blob: 00cbbc1409f469e15dab9ce3d5765e46ffadfc96 [file] [log] [blame]
Peter Stugeaf8ffac2009-01-26 06:42:02 +00001/*
Uwe Hermann7b2969b2009-04-15 10:52:49 +00002 * This file is part of the flashrom project.
Peter Stugeaf8ffac2009-01-26 06:42:02 +00003 *
4 * Copyright (C) 2009 Peter Stuge <peter@stuge.se>
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#include "flash.h"
22
Uwe Hermann7b2969b2009-04-15 10:52:49 +000023int erase_m29f002(struct flashchip *flash)
24{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000025 chipaddr bios = flash->virtual_memory;
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000026 chip_writeb(0xaa, bios + 0x555);
27 chip_writeb(0x55, bios + 0xaaa);
28 chip_writeb(0x80, bios + 0x555);
29 chip_writeb(0xaa, bios + 0x555);
30 chip_writeb(0x55, bios + 0xaaa);
31 chip_writeb(0x10, bios + 0x555);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000032 programmer_delay(10);
Peter Stugeaf8ffac2009-01-26 06:42:02 +000033 toggle_ready_jedec(bios);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000034 if (check_erased_range(flash, 0, flash->total_size * 1024)) {
35 fprintf(stderr, "ERASE FAILED!\n");
36 return -1;
37 }
Peter Stugeaf8ffac2009-01-26 06:42:02 +000038 return 0;
39}
40
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000041static int rewrite_block(struct flashchip *flash, uint8_t *src,
42 unsigned long start, int size)
Uwe Hermann7b2969b2009-04-15 10:52:49 +000043{
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000044 chipaddr bios = flash->virtual_memory;
45 chipaddr dst = bios + start;
46
Peter Stugeaf8ffac2009-01-26 06:42:02 +000047 /* erase */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000048 chip_writeb(0xaa, bios + 0x555);
49 chip_writeb(0x55, bios + 0xaaa);
50 chip_writeb(0x80, bios + 0x555);
51 chip_writeb(0xaa, bios + 0x555);
52 chip_writeb(0x55, bios + 0xaaa);
53 chip_writeb(0x30, dst);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +000054 programmer_delay(10);
Peter Stugeaf8ffac2009-01-26 06:42:02 +000055 toggle_ready_jedec(bios);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000056 if (check_erased_range(flash, start, size)) {
57 fprintf(stderr, "ERASE FAILED!\n");
58 return -1;
59 }
Peter Stugeaf8ffac2009-01-26 06:42:02 +000060
61 /* program */
62 while (size--) {
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000063 chip_writeb(0xaa, bios + 0x555);
64 chip_writeb(0x55, bios + 0xaaa);
65 chip_writeb(0xa0, bios + 0x555);
66 chip_writeb(*src, dst);
Peter Stugeaf8ffac2009-01-26 06:42:02 +000067 toggle_ready_jedec(dst);
68 dst++;
69 src++;
70 }
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000071 return 0;
Peter Stugeaf8ffac2009-01-26 06:42:02 +000072}
73
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000074static int do_block(struct flashchip *flash, uint8_t *src, int i,
Uwe Hermann7b2969b2009-04-15 10:52:49 +000075 unsigned long start, int size)
76{
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000077 int ret;
Peter Stugeaf8ffac2009-01-26 06:42:02 +000078 printf("%d at address: 0x%08lx", i, start);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000079 ret = rewrite_block(flash, src + start, start, size);
80 if (ret)
81 return ret;
Peter Stugeaf8ffac2009-01-26 06:42:02 +000082 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");
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000083 return 0;
Peter Stugeaf8ffac2009-01-26 06:42:02 +000084}
85
Uwe Hermann7b2969b2009-04-15 10:52:49 +000086int write_m29f002t(struct flashchip *flash, uint8_t *buf)
87{
Peter Stugeaf8ffac2009-01-26 06:42:02 +000088 int i, page_size = flash->page_size;
Peter Stugeaf8ffac2009-01-26 06:42:02 +000089
90 /* M29F002(N)T has 7 blocks. From bottom to top their sizes are:
91 * 64k 64k 64k 32k 8k 8k 16k
92 * flash->page_size is set to 64k in flashchips.c
93 */
94
95 printf("Programming block: ");
96 for (i = 0; i < 3; i++)
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000097 do_block(flash, buf, i, i * page_size, page_size);
98 do_block(flash, buf, i++, 0x30000, 32 * 1024);
99 do_block(flash, buf, i++, 0x38000, 8 * 1024);
100 do_block(flash, buf, i++, 0x3a000, 8 * 1024);
101 do_block(flash, buf, i, 0x3c000, 16 * 1024);
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000102
103 printf("\n");
104 return 0;
105}
106
Uwe Hermann7b2969b2009-04-15 10:52:49 +0000107int write_m29f002b(struct flashchip *flash, uint8_t *buf)
108{
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000109 int i = 0, page_size = flash->page_size;
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000110
111 /* M29F002B has 7 blocks. From bottom to top their sizes are:
112 * 16k 8k 8k 32k 64k 64k 64k
113 * flash->page_size is set to 64k in flashchips.c
114 */
115
116 printf("Programming block: ");
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000117 do_block(flash, buf, i++, 0x00000, 16 * 1024);
118 do_block(flash, buf, i++, 0x04000, 8 * 1024);
119 do_block(flash, buf, i++, 0x06000, 8 * 1024);
120 do_block(flash, buf, i++, 0x08000, 32 * 1024);
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000121 for (; i < 7; i++)
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000122 do_block(flash, buf, i, (i - 3) * page_size, page_size);
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000123
124 printf("\n");
125 return 0;
126}