Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | int erase_m29f002(struct flashchip *flash) { |
| 24 | volatile uint8_t *bios = flash->virtual_memory; |
Carl-Daniel Hailfinger | 61a8bd2 | 2009-03-05 19:24:22 +0000 | [diff] [blame^] | 25 | writeb(0xaa, bios + 0x555); |
| 26 | writeb(0x55, bios + 0xaaa); |
| 27 | writeb(0x80, bios + 0x555); |
| 28 | writeb(0xaa, bios + 0x555); |
| 29 | writeb(0x55, bios + 0xaaa); |
| 30 | writeb(0x10, bios + 0x555); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 31 | myusec_delay(10); |
| 32 | toggle_ready_jedec(bios); |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static void rewrite_block(volatile uint8_t *bios, uint8_t *src, volatile uint8_t *dst, int size) { |
| 37 | /* erase */ |
Carl-Daniel Hailfinger | 61a8bd2 | 2009-03-05 19:24:22 +0000 | [diff] [blame^] | 38 | writeb(0xaa, bios + 0x555); |
| 39 | writeb(0x55, bios + 0xaaa); |
| 40 | writeb(0x80, bios + 0x555); |
| 41 | writeb(0xaa, bios + 0x555); |
| 42 | writeb(0x55, bios + 0xaaa); |
| 43 | writeb(0x30, dst); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 44 | myusec_delay(10); |
| 45 | toggle_ready_jedec(bios); |
| 46 | |
| 47 | /* program */ |
| 48 | while (size--) { |
Carl-Daniel Hailfinger | 61a8bd2 | 2009-03-05 19:24:22 +0000 | [diff] [blame^] | 49 | writeb(0xaa, bios + 0x555); |
| 50 | writeb(0x55, bios + 0xaaa); |
| 51 | writeb(0xa0, bios + 0x555); |
| 52 | writeb(*src, dst); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 53 | toggle_ready_jedec(dst); |
| 54 | dst++; |
| 55 | src++; |
| 56 | } |
| 57 | } |
| 58 | |
| 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"); |
| 63 | } |
| 64 | |
| 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; |
| 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 Stuge | b219ba3 | 2009-01-26 15:19:43 +0000 | [diff] [blame] | 80 | do_block(bios, buf, i, 0x3c000, 16*1024); |
Peter Stuge | af8ffac | 2009-01-26 06:42:02 +0000 | [diff] [blame] | 81 | |
| 82 | printf("\n"); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 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; |
| 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 | } |