Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2008 coresystems GmbH |
| 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 | |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 21 | #include "flash.h" |
| 22 | |
| 23 | int probe_winbond_fwhub(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 | 2ad267d | 2009-05-27 11:40:08 +0000 | [diff] [blame] | 26 | uint8_t id1, id2; |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 27 | |
| 28 | /* Product Identification Entry */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 29 | chip_writeb(0xAA, bios + 0x5555); |
| 30 | chip_writeb(0x55, bios + 0x2AAA); |
| 31 | chip_writeb(0x90, bios + 0x5555); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 32 | programmer_delay(10); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 33 | |
| 34 | /* Read product ID */ |
Carl-Daniel Hailfinger | 2ad267d | 2009-05-27 11:40:08 +0000 | [diff] [blame] | 35 | id1 = chip_readb(bios); |
| 36 | id2 = chip_readb(bios + 0x01); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 37 | |
| 38 | /* Product Identifixation Exit */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 39 | chip_writeb(0xAA, bios + 0x5555); |
| 40 | chip_writeb(0x55, bios + 0x2AAA); |
| 41 | chip_writeb(0xF0, bios + 0x5555); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 42 | programmer_delay(10); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 43 | |
Carl-Daniel Hailfinger | 2ad267d | 2009-05-27 11:40:08 +0000 | [diff] [blame] | 44 | printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 45 | |
Carl-Daniel Hailfinger | 2ad267d | 2009-05-27 11:40:08 +0000 | [diff] [blame] | 46 | if (id1 != flash->manufacture_id || id2 != flash->model_id) |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 47 | return 0; |
| 48 | |
| 49 | map_flash_registers(flash); |
| 50 | |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | static int unlock_block_winbond_fwhub(struct flashchip *flash, int offset) |
| 55 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 56 | chipaddr wrprotect = flash->virtual_registers + offset + 2; |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 57 | uint8_t locking; |
| 58 | |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 59 | printf_debug("Trying to unlock block @0x%08x = 0x%02x\n", offset, |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 60 | chip_readb(wrprotect)); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 61 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 62 | locking = chip_readb(wrprotect); |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 63 | switch (locking & 0x7) { |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 64 | case 0: |
| 65 | printf_debug("Full Access.\n"); |
| 66 | return 0; |
| 67 | case 1: |
| 68 | printf_debug("Write Lock (Default State).\n"); |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 69 | chip_writeb(0, wrprotect); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 70 | return 0; |
| 71 | case 2: |
| 72 | printf_debug("Locked Open (Full Access, Lock Down).\n"); |
| 73 | return 0; |
| 74 | case 3: |
| 75 | fprintf(stderr, "Error: Write Lock, Locked Down.\n"); |
| 76 | return -1; |
| 77 | case 4: |
| 78 | printf_debug("Read Lock.\n"); |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 79 | chip_writeb(0, wrprotect); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 80 | return 0; |
| 81 | case 5: |
| 82 | printf_debug("Read/Write Lock.\n"); |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 83 | chip_writeb(0, wrprotect); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 84 | return 0; |
| 85 | case 6: |
| 86 | fprintf(stderr, "Error: Read Lock, Locked Down.\n"); |
| 87 | return -1; |
| 88 | case 7: |
| 89 | fprintf(stderr, "Error: Read/Write Lock, Locked Down.\n"); |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | /* We will never reach this point, but GCC doesn't know */ |
| 94 | return -1; |
| 95 | } |
| 96 | |
| 97 | int unlock_winbond_fwhub(struct flashchip *flash) |
| 98 | { |
| 99 | int i, total_size = flash->total_size * 1024; |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 100 | chipaddr bios = flash->virtual_memory; |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 101 | uint8_t locking; |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 102 | |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 103 | /* Are there any hardware restrictions that we can't overcome? |
| 104 | * If flashrom fail here, someone's got to check all those GPIOs. |
| 105 | */ |
| 106 | |
| 107 | /* Product Identification Entry */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 108 | chip_writeb(0xAA, bios + 0x5555); |
| 109 | chip_writeb(0x55, bios + 0x2AAA); |
| 110 | chip_writeb(0x90, bios + 0x5555); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 111 | programmer_delay(10); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 112 | |
| 113 | /* Read Hardware Lock Bits */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 114 | locking = chip_readb(bios + 0xffff2); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 115 | |
| 116 | /* Product Identification Exit */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 117 | chip_writeb(0xAA, bios + 0x5555); |
| 118 | chip_writeb(0x55, bios + 0x2AAA); |
| 119 | chip_writeb(0xF0, bios + 0x5555); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 120 | programmer_delay(10); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 121 | |
| 122 | printf_debug("Lockout bits:\n"); |
| 123 | |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 124 | if (locking & (1 << 2)) |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 125 | fprintf(stderr, "Error: hardware bootblock locking (#TBL).\n"); |
| 126 | else |
| 127 | printf_debug("No hardware bootblock locking (good!)\n"); |
| 128 | |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 129 | if (locking & (1 << 3)) |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 130 | fprintf(stderr, "Error: hardware block locking (#WP).\n"); |
| 131 | else |
| 132 | printf_debug("No hardware block locking (good!)\n"); |
| 133 | |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 134 | if (locking & ((1 << 2) | (1 << 3))) |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 135 | return -1; |
| 136 | |
| 137 | /* Unlock the complete chip */ |
| 138 | for (i = 0; i < total_size; i += flash->page_size) |
| 139 | if (unlock_block_winbond_fwhub(flash, i)) |
| 140 | return -1; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 145 | static int erase_sector_winbond_fwhub(struct flashchip *flash, |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 146 | unsigned int sector) |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 147 | { |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 148 | chipaddr bios = flash->virtual_memory; |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 149 | /* Remember: too much sleep can waste your day. */ |
| 150 | |
| 151 | printf("0x%08x\b\b\b\b\b\b\b\b\b\b", sector); |
| 152 | |
| 153 | /* Sector Erase */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 154 | chip_writeb(0xAA, bios + 0x5555); |
| 155 | chip_writeb(0x55, bios + 0x2AAA); |
| 156 | chip_writeb(0x80, bios + 0x5555); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 157 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 158 | chip_writeb(0xAA, bios + 0x5555); |
| 159 | chip_writeb(0x55, bios + 0x2AAA); |
| 160 | chip_writeb(0x30, bios + sector); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 161 | |
| 162 | /* wait for Toggle bit ready */ |
| 163 | toggle_ready_jedec(bios); |
| 164 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 165 | if (check_erased_range(flash, sector, flash->page_size)) { |
| 166 | fprintf(stderr, "ERASE FAILED!\n"); |
| 167 | return -1; |
| 168 | } |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | int erase_winbond_fwhub(struct flashchip *flash) |
| 173 | { |
| 174 | int i, total_size = flash->total_size * 1024; |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 175 | |
Stefan Reinauer | 4c390c8 | 2008-07-02 13:33:09 +0000 | [diff] [blame] | 176 | unlock_winbond_fwhub(flash); |
| 177 | |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 178 | printf("Erasing: "); |
| 179 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 180 | for (i = 0; i < total_size; i += flash->page_size) { |
| 181 | if (erase_sector_winbond_fwhub(flash, i)) { |
| 182 | fprintf(stderr, "ERASE FAILED!\n"); |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 183 | return -1; |
| 184 | } |
| 185 | } |
| 186 | |
Carl-Daniel Hailfinger | 30f7cb2 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 187 | printf("\n"); |
| 188 | |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | int write_winbond_fwhub(struct flashchip *flash, uint8_t *buf) |
| 193 | { |
| 194 | int i; |
| 195 | int total_size = flash->total_size * 1024; |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 196 | chipaddr bios = flash->virtual_memory; |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 197 | |
| 198 | if (erase_winbond_fwhub(flash)) |
| 199 | return -1; |
| 200 | |
| 201 | printf("Programming: "); |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 202 | for (i = 0; i < total_size; i += flash->page_size) { |
Stefan Reinauer | c34ce2e | 2008-03-18 00:36:18 +0000 | [diff] [blame] | 203 | printf("0x%08x\b\b\b\b\b\b\b\b\b\b", i); |
| 204 | write_sector_jedec(bios, buf + i, bios + i, flash->page_size); |
| 205 | } |
| 206 | printf("\n"); |
| 207 | |
| 208 | return 0; |
| 209 | } |