Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 2 | * This file is part of the flashrom project. |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 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 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 23 | int erase_m29f002(struct flashchip *flash) |
| 24 | { |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 25 | volatile uint8_t *bios = flash->virtual_memory; |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 26 | 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); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 32 | myusec_delay(10); |
| 33 | toggle_ready_jedec(bios); |
| 34 | return 0; |
| 35 | } |
| 36 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 37 | static void rewrite_block(volatile uint8_t *bios, uint8_t *src, |
| 38 | volatile uint8_t *dst, int size) |
| 39 | { |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 40 | /* erase */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 41 | chip_writeb(0xaa, bios + 0x555); |
| 42 | chip_writeb(0x55, bios + 0xaaa); |
| 43 | chip_writeb(0x80, bios + 0x555); |
| 44 | chip_writeb(0xaa, bios + 0x555); |
| 45 | chip_writeb(0x55, bios + 0xaaa); |
| 46 | chip_writeb(0x30, dst); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 47 | myusec_delay(10); |
| 48 | toggle_ready_jedec(bios); |
| 49 | |
| 50 | /* program */ |
| 51 | while (size--) { |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 52 | chip_writeb(0xaa, bios + 0x555); |
| 53 | chip_writeb(0x55, bios + 0xaaa); |
| 54 | chip_writeb(0xa0, bios + 0x555); |
| 55 | chip_writeb(*src, dst); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 56 | toggle_ready_jedec(dst); |
| 57 | dst++; |
| 58 | src++; |
| 59 | } |
| 60 | } |
| 61 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 62 | static void do_block(volatile uint8_t *bios, uint8_t *src, int i, |
| 63 | unsigned long start, int size) |
| 64 | { |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 65 | printf("%d at address: 0x%08lx", i, start); |
| 66 | rewrite_block(bios, src + start, bios + start, size); |
| 67 | 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"); |
| 68 | } |
| 69 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 70 | int write_m29f002t(struct flashchip *flash, uint8_t *buf) |
| 71 | { |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 72 | int i, page_size = flash->page_size; |
| 73 | volatile uint8_t *bios = flash->virtual_memory; |
| 74 | |
| 75 | /* M29F002(N)T has 7 blocks. From bottom to top their sizes are: |
| 76 | * 64k 64k 64k 32k 8k 8k 16k |
| 77 | * flash->page_size is set to 64k in flashchips.c |
| 78 | */ |
| 79 | |
| 80 | printf("Programming block: "); |
| 81 | for (i = 0; i < 3; i++) |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 82 | do_block(bios, buf, i, i * page_size, page_size); |
| 83 | do_block(bios, buf, i++, 0x30000, 32 * 1024); |
| 84 | do_block(bios, buf, i++, 0x38000, 8 * 1024); |
| 85 | do_block(bios, buf, i++, 0x3a000, 8 * 1024); |
| 86 | do_block(bios, buf, i, 0x3c000, 16 * 1024); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 87 | |
| 88 | printf("\n"); |
| 89 | return 0; |
| 90 | } |
| 91 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 92 | int write_m29f002b(struct flashchip *flash, uint8_t *buf) |
| 93 | { |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 94 | int i = 0, page_size = flash->page_size; |
| 95 | volatile uint8_t *bios = flash->virtual_memory; |
| 96 | |
| 97 | /* M29F002B has 7 blocks. From bottom to top their sizes are: |
| 98 | * 16k 8k 8k 32k 64k 64k 64k |
| 99 | * flash->page_size is set to 64k in flashchips.c |
| 100 | */ |
| 101 | |
| 102 | printf("Programming block: "); |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 103 | do_block(bios, buf, i++, 0x00000, 16 * 1024); |
| 104 | do_block(bios, buf, i++, 0x04000, 8 * 1024); |
| 105 | do_block(bios, buf, i++, 0x06000, 8 * 1024); |
| 106 | do_block(bios, buf, i++, 0x08000, 32 * 1024); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 107 | for (; i < 7; i++) |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame^] | 108 | do_block(bios, buf, i, (i - 3) * page_size, page_size); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 109 | |
| 110 | printf("\n"); |
| 111 | return 0; |
| 112 | } |