Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2000 Silicon Integrated System Corporation |
| 5 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 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. |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 10 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 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. |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 15 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 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 |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "flash.h" |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 22 | |
Uwe Hermann | 51582f2 | 2007-08-23 10:20:40 +0000 | [diff] [blame] | 23 | void protect_m29f400bt(volatile uint8_t *bios) |
| 24 | { |
| 25 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 26 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
| 27 | *(volatile uint8_t *)(bios + 0xAAA) = 0xA0; |
| 28 | |
| 29 | usleep(200); |
| 30 | } |
| 31 | |
| 32 | void write_page_m29f400bt(volatile uint8_t *bios, uint8_t *src, |
| 33 | volatile uint8_t *dst, int page_size) |
| 34 | { |
| 35 | int i; |
| 36 | |
| 37 | for (i = 0; i < page_size; i++) { |
| 38 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 39 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
| 40 | *(volatile uint8_t *)(bios + 0xAAA) = 0xA0; |
| 41 | |
| 42 | /* transfer data from source to destination */ |
| 43 | *dst = *src; |
| 44 | //*(volatile char *) (bios) = 0xF0; |
| 45 | //usleep(5); |
Uwe Hermann | fd37414 | 2007-08-23 15:20:38 +0000 | [diff] [blame] | 46 | toggle_ready_jedec(dst); |
Uwe Hermann | 51582f2 | 2007-08-23 10:20:40 +0000 | [diff] [blame] | 47 | printf |
| 48 | ("Value in the flash at address %p = %#x, want %#x\n", |
| 49 | (uint8_t *) (dst - bios), *dst, *src); |
| 50 | dst++; |
| 51 | src++; |
| 52 | } |
| 53 | } |
| 54 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 55 | int probe_m29f400bt(struct flashchip *flash) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 56 | { |
Stefan Reinauer | ce53297 | 2007-05-23 17:20:56 +0000 | [diff] [blame] | 57 | volatile uint8_t *bios = flash->virtual_memory; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 58 | uint8_t id1, id2; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 59 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 60 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 61 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
| 62 | *(volatile uint8_t *)(bios + 0xAAA) = 0x90; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 63 | |
| 64 | myusec_delay(10); |
| 65 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 66 | id1 = *(volatile uint8_t *)bios; |
| 67 | id2 = *(volatile uint8_t *)(bios + 0x02); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 68 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 69 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 70 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
| 71 | *(volatile uint8_t *)(bios + 0xAAA) = 0xF0; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 72 | |
| 73 | myusec_delay(10); |
Ronald G. Minnich | d4228fd | 2003-02-28 17:21:38 +0000 | [diff] [blame] | 74 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 75 | printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2); |
Ronald G. Minnich | d4228fd | 2003-02-28 17:21:38 +0000 | [diff] [blame] | 76 | |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 77 | if (id1 == flash->manufacture_id && id2 == flash->model_id) |
| 78 | return 1; |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 83 | int erase_m29f400bt(struct flashchip *flash) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 84 | { |
Stefan Reinauer | ce53297 | 2007-05-23 17:20:56 +0000 | [diff] [blame] | 85 | volatile uint8_t *bios = flash->virtual_memory; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 86 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 87 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 88 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
| 89 | *(volatile uint8_t *)(bios + 0xAAA) = 0x80; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 90 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 91 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 92 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
| 93 | *(volatile uint8_t *)(bios + 0xAAA) = 0x10; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 94 | |
| 95 | myusec_delay(10); |
Uwe Hermann | fd37414 | 2007-08-23 15:20:38 +0000 | [diff] [blame] | 96 | toggle_ready_jedec(bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 97 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 98 | return 0; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 101 | int block_erase_m29f400bt(volatile uint8_t *bios, volatile uint8_t *dst) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 102 | { |
| 103 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 104 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 105 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
| 106 | *(volatile uint8_t *)(bios + 0xAAA) = 0x80; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 107 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 108 | *(volatile uint8_t *)(bios + 0xAAA) = 0xAA; |
| 109 | *(volatile uint8_t *)(bios + 0x555) = 0x55; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 110 | //*(volatile uint8_t *) (bios + 0xAAA) = 0x10; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 111 | *dst = 0x30; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 112 | |
| 113 | myusec_delay(10); |
Uwe Hermann | fd37414 | 2007-08-23 15:20:38 +0000 | [diff] [blame] | 114 | toggle_ready_jedec(bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 115 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 116 | return 0; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 119 | int write_m29f400bt(struct flashchip *flash, uint8_t *buf) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 120 | { |
| 121 | int i; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 122 | int total_size = flash->total_size * 1024; |
| 123 | int page_size = flash->page_size; |
Stefan Reinauer | ce53297 | 2007-05-23 17:20:56 +0000 | [diff] [blame] | 124 | volatile uint8_t *bios = flash->virtual_memory; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 125 | |
| 126 | //erase_m29f400bt (flash); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 127 | printf("Programming Page:\n "); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 128 | /********************************* |
| 129 | *Pages for M29F400BT: |
| 130 | * 16 0x7c000 0x7ffff TOP |
| 131 | * 8 0x7a000 0x7bfff |
| 132 | * 8 0x78000 0x79fff |
| 133 | * 32 0x70000 0x77fff |
| 134 | * 64 0x60000 0x6ffff |
| 135 | * 64 0x50000 0x5ffff |
| 136 | * 64 0x40000 0x4ffff |
| 137 | *--------------------------------- |
| 138 | * 64 0x30000 0x3ffff |
| 139 | * 64 0x20000 0x2ffff |
| 140 | * 64 0x10000 0x1ffff |
| 141 | * 64 0x00000 0x0ffff BOTTOM |
| 142 | *********************************/ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 143 | printf("total_size/page_size = %d\n", total_size / page_size); |
| 144 | for (i = 0; i < (total_size / page_size) - 1; i++) { |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 145 | printf("%04d at address: 0x%08x\n", i, i * page_size); |
| 146 | block_erase_m29f400bt(bios, bios + i * page_size); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 147 | write_page_m29f400bt(bios, buf + i * page_size, |
| 148 | bios + i * page_size, page_size); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 149 | 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\b\b\b"); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 152 | printf("%04d at address: 0x%08x\n", 7, 0x70000); |
| 153 | block_erase_m29f400bt(bios, bios + 0x70000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 154 | write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 155 | |
| 156 | printf("%04d at address: 0x%08x\n", 8, 0x78000); |
| 157 | block_erase_m29f400bt(bios, bios + 0x78000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 158 | write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 159 | |
| 160 | printf("%04d at address: 0x%08x\n", 9, 0x7a000); |
| 161 | block_erase_m29f400bt(bios, bios + 0x7a000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 162 | write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 163 | |
| 164 | printf("%04d at address: 0x%08x\n", 10, 0x7c000); |
| 165 | block_erase_m29f400bt(bios, bios + 0x7c000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 166 | write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 167 | |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 168 | printf("\n"); |
| 169 | //protect_m29f400bt (bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 170 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 171 | return 0; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 174 | int write_linuxbios_m29f400bt(struct flashchip *flash, uint8_t *buf) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 175 | { |
Stefan Reinauer | ce53297 | 2007-05-23 17:20:56 +0000 | [diff] [blame] | 176 | volatile uint8_t *bios = flash->virtual_memory; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 177 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 178 | printf("Programming Page:\n "); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 179 | /********************************* |
| 180 | *Pages for M29F400BT: |
| 181 | * 16 0x7c000 0x7ffff TOP |
| 182 | * 8 0x7a000 0x7bfff |
| 183 | * 8 0x78000 0x79fff |
| 184 | * 32 0x70000 0x77fff |
| 185 | * 64 0x60000 0x6ffff |
| 186 | * 64 0x50000 0x5ffff |
| 187 | * 64 0x40000 0x4ffff |
| 188 | *--------------------------------- |
| 189 | * 64 0x30000 0x3ffff |
| 190 | * 64 0x20000 0x2ffff |
| 191 | * 64 0x10000 0x1ffff |
| 192 | * 64 0x00000 0x0ffff BOTTOM |
| 193 | *********************************/ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 194 | printf("%04d at address: 0x%08x\n", 7, 0x00000); |
| 195 | block_erase_m29f400bt(bios, bios + 0x00000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 196 | write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, 64 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 197 | |
| 198 | printf("%04d at address: 0x%08x\n", 7, 0x10000); |
| 199 | block_erase_m29f400bt(bios, bios + 0x10000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 200 | write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, 64 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 201 | |
| 202 | printf("%04d at address: 0x%08x\n", 7, 0x20000); |
| 203 | block_erase_m29f400bt(bios, bios + 0x20000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 204 | write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, 64 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 205 | |
| 206 | printf("%04d at address: 0x%08x\n", 7, 0x30000); |
| 207 | block_erase_m29f400bt(bios, bios + 0x30000); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 208 | write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, 64 * 1024); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 209 | |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 210 | printf("\n"); |
| 211 | //protect_m29f400bt (bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 212 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 213 | return 0; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 214 | } |