Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2004 Tyan Corporation |
| 5 | * Copyright (C) 2007 Nikolay Petukhov <nikolay.petukhov@gmail.com> |
| 6 | * Copyright (C) 2007 Reinder E.N. de Haan <lb_reha@mveas.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | */ |
| 22 | |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 23 | #include "flash.h" |
| 24 | |
| 25 | extern int exclude_start_page, exclude_end_page; |
| 26 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 27 | void write_lockbits_49fl00x(chipaddr bios, int size, |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 28 | unsigned char bits, int block_size) |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 29 | { |
| 30 | int i, left = size; |
| 31 | |
| 32 | for (i = 0; left >= block_size; i++, left -= block_size) { |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 33 | /* pm49fl002 */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 34 | if (block_size == 16384 && i % 2) |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 35 | continue; |
| 36 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 37 | chip_writeb(bits, bios + (i * block_size) + 2); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | int probe_49fl00x(struct flashchip *flash) |
| 42 | { |
| 43 | int ret = probe_jedec(flash); |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 44 | |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 45 | if (ret == 1) |
| 46 | map_flash_registers(flash); |
| 47 | |
| 48 | return ret; |
| 49 | } |
| 50 | |
| 51 | int erase_49fl00x(struct flashchip *flash) |
| 52 | { |
| 53 | int i; |
| 54 | int total_size = flash->total_size * 1024; |
| 55 | int page_size = flash->page_size; |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 56 | |
| 57 | /* unprotected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 58 | write_lockbits_49fl00x(flash->virtual_registers, |
| 59 | total_size, 0, page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 60 | |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 61 | /* |
| 62 | * erase_chip_jedec() will not work... Datasheet says |
| 63 | * "Chip erase is available in A/A Mux Mode only". |
| 64 | */ |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 65 | printf("Erasing page: "); |
| 66 | for (i = 0; i < total_size / page_size; i++) { |
| 67 | if ((i >= exclude_start_page) && (i < exclude_end_page)) |
| 68 | continue; |
| 69 | |
| 70 | /* erase the page */ |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 71 | if (erase_block_jedec(flash, i * page_size, page_size)) { |
| 72 | fprintf(stderr, "ERASE FAILED!\n"); |
| 73 | return -1; |
| 74 | } |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 75 | printf("%04d at address: 0x%08x", i, i * page_size); |
| 76 | 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"); |
| 77 | fflush(stdout); |
| 78 | } |
| 79 | printf("\n"); |
| 80 | |
| 81 | /* protected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 82 | write_lockbits_49fl00x(flash->virtual_registers, |
| 83 | total_size, 1, page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | int write_49fl00x(struct flashchip *flash, uint8_t *buf) |
| 89 | { |
| 90 | int i; |
| 91 | int total_size = flash->total_size * 1024; |
| 92 | int page_size = flash->page_size; |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 93 | chipaddr bios = flash->virtual_memory; |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 94 | |
| 95 | /* unprotected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 96 | write_lockbits_49fl00x(flash->virtual_registers, total_size, 0, |
| 97 | page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 98 | |
| 99 | printf("Programming page: "); |
| 100 | for (i = 0; i < total_size / page_size; i++) { |
| 101 | if ((i >= exclude_start_page) && (i < exclude_end_page)) |
| 102 | continue; |
| 103 | |
| 104 | /* erase the page before programming */ |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 105 | if (erase_block_jedec(flash, i * page_size, page_size)) { |
| 106 | fprintf(stderr, "ERASE FAILED!\n"); |
| 107 | return -1; |
| 108 | } |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 109 | |
| 110 | /* write to the sector */ |
| 111 | printf("%04d at address: 0x%08x", i, i * page_size); |
| 112 | write_sector_jedec(bios, buf + i * page_size, |
| 113 | bios + i * page_size, page_size); |
| 114 | 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"); |
| 115 | fflush(stdout); |
| 116 | } |
| 117 | printf("\n"); |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 118 | |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 119 | /* protected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 120 | write_lockbits_49fl00x(flash->virtual_registers, total_size, 1, |
| 121 | page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |