| 1 | /* |
|---|
| 2 | * This file is part of the flashrom project. |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2008 Claus Gindhart <claus.gindhart@kontron.com> |
|---|
| 5 | * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com> |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | /* |
|---|
| 23 | * This module is designed for supporting the devices |
|---|
| 24 | * ST M50FLW040A (not yet tested) |
|---|
| 25 | * ST M50FLW040B (not yet tested) |
|---|
| 26 | * ST M50FLW080A |
|---|
| 27 | * ST M50FLW080B (not yet tested) |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #include "flash.h" |
|---|
| 31 | #include "flashchips.h" |
|---|
| 32 | #include "chipdrivers.h" |
|---|
| 33 | |
|---|
| 34 | /* |
|---|
| 35 | * claus.gindhart@kontron.com |
|---|
| 36 | * The ST M50FLW080B and STM50FLW080B chips have to be unlocked, |
|---|
| 37 | * before you can erase them or write to them. |
|---|
| 38 | */ |
|---|
| 39 | static int unlock_block_stm50flw0x0x(struct flashctx *flash, int offset) |
|---|
| 40 | { |
|---|
| 41 | chipaddr wrprotect = flash->virtual_registers + 2; |
|---|
| 42 | static const uint8_t unlock_sector = 0x00; |
|---|
| 43 | int j; |
|---|
| 44 | |
|---|
| 45 | /* |
|---|
| 46 | * These chips have to be unlocked before you can erase them or write |
|---|
| 47 | * to them. The size of the locking sectors depends on the type |
|---|
| 48 | * of chip. |
|---|
| 49 | * |
|---|
| 50 | * Sometimes, the BIOS does this for you; so you probably |
|---|
| 51 | * don't need to worry about that. |
|---|
| 52 | */ |
|---|
| 53 | |
|---|
| 54 | /* Check, if it's is a top/bottom-block with 4k-sectors. */ |
|---|
| 55 | /* TODO: What about the other types? */ |
|---|
| 56 | if ((offset == 0) || |
|---|
| 57 | (offset == (flash->chip->model_id == ST_M50FLW080A ? 0xE0000 : 0x10000)) |
|---|
| 58 | || (offset == 0xF0000)) { |
|---|
| 59 | |
|---|
| 60 | // unlock each 4k-sector |
|---|
| 61 | for (j = 0; j < 0x10000; j += 0x1000) { |
|---|
| 62 | msg_cdbg("unlocking at 0x%x\n", offset + j); |
|---|
| 63 | chip_writeb(flash, unlock_sector, |
|---|
| 64 | wrprotect + offset + j); |
|---|
| 65 | if (chip_readb(flash, wrprotect + offset + j) != |
|---|
| 66 | unlock_sector) { |
|---|
| 67 | msg_cerr("Cannot unlock sector @ 0x%x\n", |
|---|
| 68 | offset + j); |
|---|
| 69 | return -1; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | } else { |
|---|
| 73 | msg_cdbg("unlocking at 0x%x\n", offset); |
|---|
| 74 | chip_writeb(flash, unlock_sector, wrprotect + offset); |
|---|
| 75 | if (chip_readb(flash, wrprotect + offset) != unlock_sector) { |
|---|
| 76 | msg_cerr("Cannot unlock sector @ 0x%x\n", offset); |
|---|
| 77 | return -1; |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | return 0; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | int unlock_stm50flw0x0x(struct flashctx *flash) |
|---|
| 85 | { |
|---|
| 86 | int i; |
|---|
| 87 | |
|---|
| 88 | for (i = 0; i < flash->chip->total_size * 1024; i+= flash->chip->page_size) { |
|---|
| 89 | if(unlock_block_stm50flw0x0x(flash, i)) { |
|---|
| 90 | msg_cerr("UNLOCK FAILED!\n"); |
|---|
| 91 | return -1; |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return 0; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | /* This function is unused. */ |
|---|
| 99 | int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int sector, |
|---|
| 100 | unsigned int sectorsize) |
|---|
| 101 | { |
|---|
| 102 | chipaddr bios = flash->virtual_memory + sector; |
|---|
| 103 | |
|---|
| 104 | // clear status register |
|---|
| 105 | chip_writeb(flash, 0x50, bios); |
|---|
| 106 | // now start it |
|---|
| 107 | chip_writeb(flash, 0x32, bios); |
|---|
| 108 | chip_writeb(flash, 0xd0, bios); |
|---|
| 109 | programmer_delay(10); |
|---|
| 110 | |
|---|
| 111 | wait_82802ab(flash); |
|---|
| 112 | |
|---|
| 113 | /* FIXME: Check the status register for errors. */ |
|---|
| 114 | return 0; |
|---|
| 115 | } |
|---|