2 * This file is part of flashrom.
4 * Copyright (C) 2009 Peter Stuge <peter@stuge.se>
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.
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.
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
23 int erase_m29f002(struct flashchip *flash) {
24 volatile uint8_t *bios = flash->virtual_memory;
25 *(volatile uint8_t *)(bios + 0x555) = 0xaa;
26 *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
27 *(volatile uint8_t *)(bios + 0x555) = 0x80;
28 *(volatile uint8_t *)(bios + 0x555) = 0xaa;
29 *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
30 *(volatile uint8_t *)(bios + 0x555) = 0x10;
32 toggle_ready_jedec(bios);
36 static void rewrite_block(volatile uint8_t *bios, uint8_t *src, volatile uint8_t *dst, int size) {
38 *(volatile uint8_t *)(bios + 0x555) = 0xaa;
39 *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
40 *(volatile uint8_t *)(bios + 0x555) = 0x80;
41 *(volatile uint8_t *)(bios + 0x555) = 0xaa;
42 *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
45 toggle_ready_jedec(bios);
49 *(volatile uint8_t *)(bios + 0x555) = 0xaa;
50 *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
51 *(volatile uint8_t *)(bios + 0x555) = 0xa0;
53 toggle_ready_jedec(dst);
59 static void do_block(volatile uint8_t *bios, uint8_t *src, int i, unsigned long start, int size) {
60 printf("%d at address: 0x%08lx", i, start);
61 rewrite_block(bios, src + start, bios + start, size);
62 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");
65 int write_m29f002t(struct flashchip *flash, uint8_t *buf) {
66 int i, page_size = flash->page_size;
67 volatile uint8_t *bios = flash->virtual_memory;
69 /* M29F002(N)T has 7 blocks. From bottom to top their sizes are:
70 * 64k 64k 64k 32k 8k 8k 16k
71 * flash->page_size is set to 64k in flashchips.c
74 printf("Programming block: ");
75 for (i = 0; i < 3; i++)
76 do_block(bios, buf, i, i*page_size, page_size);
77 do_block(bios, buf, i++, 0x30000, 32*1024);
78 do_block(bios, buf, i++, 0x38000, 8*1024);
79 do_block(bios, buf, i++, 0x3a000, 8*1024);
80 do_block(bios, buf, i, 0x3c000, 16*1024);
86 int write_m29f002b(struct flashchip *flash, uint8_t *buf) {
87 int i = 0, page_size = flash->page_size;
88 volatile uint8_t *bios = flash->virtual_memory;
90 /* M29F002B has 7 blocks. From bottom to top their sizes are:
91 * 16k 8k 8k 32k 64k 64k 64k
92 * flash->page_size is set to 64k in flashchips.c
95 printf("Programming block: ");
96 do_block(bios, buf, i++, 0x00000, 16*1024);
97 do_block(bios, buf, i++, 0x04000, 8*1024);
98 do_block(bios, buf, i++, 0x06000, 8*1024);
99 do_block(bios, buf, i++, 0x08000, 32*1024);
101 do_block(bios, buf, i, (i-3)*page_size, page_size);