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 | |
| 23 | #include <stdio.h> |
| 24 | #include "flash.h" |
| 25 | |
| 26 | extern int exclude_start_page, exclude_end_page; |
| 27 | |
| 28 | void write_lockbits_49fl00x(volatile uint8_t *bios, int size, |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 29 | unsigned char bits, int block_size) |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 30 | { |
| 31 | int i, left = size; |
| 32 | |
| 33 | for (i = 0; left >= block_size; i++, left -= block_size) { |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 34 | /* pm49fl002 */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 35 | if (block_size == 16384 && i % 2) |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 36 | continue; |
| 37 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 38 | chip_writeb(bits, bios + (i * block_size) + 2); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | int probe_49fl00x(struct flashchip *flash) |
| 43 | { |
| 44 | int ret = probe_jedec(flash); |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 45 | |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 46 | if (ret == 1) |
| 47 | map_flash_registers(flash); |
| 48 | |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | int erase_49fl00x(struct flashchip *flash) |
| 53 | { |
| 54 | int i; |
| 55 | int total_size = flash->total_size * 1024; |
| 56 | int page_size = flash->page_size; |
| 57 | volatile uint8_t *bios = flash->virtual_memory; |
| 58 | |
| 59 | /* unprotected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 60 | write_lockbits_49fl00x(flash->virtual_registers, |
| 61 | total_size, 0, page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 62 | |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 63 | /* |
| 64 | * erase_chip_jedec() will not work... Datasheet says |
| 65 | * "Chip erase is available in A/A Mux Mode only". |
| 66 | */ |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 67 | printf("Erasing page: "); |
| 68 | for (i = 0; i < total_size / page_size; i++) { |
| 69 | if ((i >= exclude_start_page) && (i < exclude_end_page)) |
| 70 | continue; |
| 71 | |
| 72 | /* erase the page */ |
| 73 | erase_block_jedec(bios, i * page_size); |
| 74 | printf("%04d at address: 0x%08x", i, i * page_size); |
| 75 | 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"); |
| 76 | fflush(stdout); |
| 77 | } |
| 78 | printf("\n"); |
| 79 | |
| 80 | /* protected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 81 | write_lockbits_49fl00x(flash->virtual_registers, |
| 82 | total_size, 1, page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | int write_49fl00x(struct flashchip *flash, uint8_t *buf) |
| 88 | { |
| 89 | int i; |
| 90 | int total_size = flash->total_size * 1024; |
| 91 | int page_size = flash->page_size; |
| 92 | volatile uint8_t *bios = flash->virtual_memory; |
| 93 | |
| 94 | /* unprotected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 95 | write_lockbits_49fl00x(flash->virtual_registers, total_size, 0, |
| 96 | page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 97 | |
| 98 | printf("Programming page: "); |
| 99 | for (i = 0; i < total_size / page_size; i++) { |
| 100 | if ((i >= exclude_start_page) && (i < exclude_end_page)) |
| 101 | continue; |
| 102 | |
| 103 | /* erase the page before programming */ |
| 104 | erase_block_jedec(bios, i * page_size); |
| 105 | |
| 106 | /* write to the sector */ |
| 107 | printf("%04d at address: 0x%08x", i, i * page_size); |
| 108 | write_sector_jedec(bios, buf + i * page_size, |
| 109 | bios + i * page_size, page_size); |
| 110 | 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"); |
| 111 | fflush(stdout); |
| 112 | } |
| 113 | printf("\n"); |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 114 | |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 115 | /* protected */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 116 | write_lockbits_49fl00x(flash->virtual_registers, total_size, 1, |
| 117 | page_size); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |