blob: 8afef796ee457287e13c1140cb76297e65a68ff0 [file] [log] [blame]
Peter Stugeaf8ffac2009-01-26 06:42:02 +00001/*
2 * This file is part of flashrom.
3 *
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
23int 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;
31 myusec_delay(10);
32 toggle_ready_jedec(bios);
33 return 0;
34}
35
36static void rewrite_block(volatile uint8_t *bios, uint8_t *src, volatile uint8_t *dst, int size) {
37 /* erase */
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;
43 *dst = 0x30;
44 myusec_delay(10);
45 toggle_ready_jedec(bios);
46
47 /* program */
48 while (size--) {
49 *(volatile uint8_t *)(bios + 0x555) = 0xaa;
50 *(volatile uint8_t *)(bios + 0xaaa) = 0x55;
51 *(volatile uint8_t *)(bios + 0x555) = 0xa0;
52 *dst = *src;
53 toggle_ready_jedec(dst);
54 dst++;
55 src++;
56 }
57}
58
59static 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");
63}
64
65int write_m29f002t(struct flashchip *flash, uint8_t *buf) {
66 int i, page_size = flash->page_size;
67 volatile uint8_t *bios = flash->virtual_memory;
68
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
72 */
73
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);
Peter Stugeb219ba32009-01-26 15:19:43 +000080 do_block(bios, buf, i, 0x3c000, 16*1024);
Peter Stugeaf8ffac2009-01-26 06:42:02 +000081
82 printf("\n");
83 return 0;
84}
85
86int 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;
89
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
93 */
94
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);
100 for (; i < 7; i++)
101 do_block(bios, buf, i, (i-3)*page_size, page_size);
102
103 printf("\n");
104 return 0;
105}