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 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 25 | chipaddr 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); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 32 | programmer_delay(10); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 33 | toggle_ready_jedec(bios); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 34 | if (check_erased_range(flash, 0, flash->total_size * 1024)) { |
| 35 | fprintf(stderr, "ERASE FAILED!\n"); |
| 36 | return -1; |
| 37 | } |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 38 | return 0; |
| 39 | } |
| 40 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 41 | static int rewrite_block(struct flashchip *flash, uint8_t *src, |
| 42 | unsigned long start, int size) |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame] | 43 | { |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 44 | chipaddr bios = flash->virtual_memory; |
| 45 | chipaddr dst = bios + start; |
| 46 | |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 47 | /* erase */ |
Michael Karcher | 1c296ca | 2009-11-27 17:49:42 +0000 | [diff] [blame] | 48 | /* FIXME: use erase_sector_jedec? */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 49 | chip_writeb(0xaa, bios + 0x555); |
| 50 | chip_writeb(0x55, bios + 0xaaa); |
| 51 | chip_writeb(0x80, bios + 0x555); |
| 52 | chip_writeb(0xaa, bios + 0x555); |
| 53 | chip_writeb(0x55, bios + 0xaaa); |
| 54 | chip_writeb(0x30, dst); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 55 | programmer_delay(10); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 56 | toggle_ready_jedec(bios); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 57 | if (check_erased_range(flash, start, size)) { |
| 58 | fprintf(stderr, "ERASE FAILED!\n"); |
| 59 | return -1; |
| 60 | } |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 61 | |
| 62 | /* program */ |
Michael Karcher | 1c296ca | 2009-11-27 17:49:42 +0000 | [diff] [blame] | 63 | /* FIXME: use write_sector_jedec? */ |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 64 | while (size--) { |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 65 | chip_writeb(0xaa, bios + 0x555); |
| 66 | chip_writeb(0x55, bios + 0xaaa); |
| 67 | chip_writeb(0xa0, bios + 0x555); |
| 68 | chip_writeb(*src, dst); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 69 | toggle_ready_jedec(dst); |
| 70 | dst++; |
| 71 | src++; |
| 72 | } |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 73 | return 0; |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 76 | static int do_block(struct flashchip *flash, uint8_t *src, int i, |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame] | 77 | unsigned long start, int size) |
| 78 | { |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 79 | int ret; |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 80 | printf("%d at address: 0x%08lx", i, start); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 81 | ret = rewrite_block(flash, src + start, start, size); |
| 82 | if (ret) |
| 83 | return ret; |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 84 | 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 Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 85 | return 0; |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame] | 88 | int write_m29f002t(struct flashchip *flash, uint8_t *buf) |
| 89 | { |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 90 | int i, page_size = flash->page_size; |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 91 | |
| 92 | /* M29F002(N)T has 7 blocks. From bottom to top their sizes are: |
| 93 | * 64k 64k 64k 32k 8k 8k 16k |
| 94 | * flash->page_size is set to 64k in flashchips.c |
| 95 | */ |
| 96 | |
| 97 | printf("Programming block: "); |
| 98 | for (i = 0; i < 3; i++) |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 99 | do_block(flash, buf, i, i * page_size, page_size); |
| 100 | do_block(flash, buf, i++, 0x30000, 32 * 1024); |
| 101 | do_block(flash, buf, i++, 0x38000, 8 * 1024); |
| 102 | do_block(flash, buf, i++, 0x3a000, 8 * 1024); |
| 103 | do_block(flash, buf, i, 0x3c000, 16 * 1024); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 104 | |
| 105 | printf("\n"); |
| 106 | return 0; |
| 107 | } |
| 108 | |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame] | 109 | int write_m29f002b(struct flashchip *flash, uint8_t *buf) |
| 110 | { |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 111 | int i = 0, page_size = flash->page_size; |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 112 | |
| 113 | /* M29F002B has 7 blocks. From bottom to top their sizes are: |
| 114 | * 16k 8k 8k 32k 64k 64k 64k |
| 115 | * flash->page_size is set to 64k in flashchips.c |
| 116 | */ |
| 117 | |
| 118 | printf("Programming block: "); |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 119 | do_block(flash, buf, i++, 0x00000, 16 * 1024); |
| 120 | do_block(flash, buf, i++, 0x04000, 8 * 1024); |
| 121 | do_block(flash, buf, i++, 0x06000, 8 * 1024); |
| 122 | do_block(flash, buf, i++, 0x08000, 32 * 1024); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 123 | for (; i < 7; i++) |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 124 | do_block(flash, buf, i, (i - 3) * page_size, page_size); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 125 | |
| 126 | printf("\n"); |
| 127 | return 0; |
| 128 | } |