Stefan Tauner | 4404f73 | 2013-09-12 08:28:56 +0000 | [diff] [blame] | 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 | * Copyright (C) 2013 Stefan Tauner |
| 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. |
Stefan Tauner | 4404f73 | 2013-09-12 08:28:56 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * All ST M50 chips are locked on startup. Most of them have a uniform 64 kB block layout, but some have |
| 21 | * a non-uniform block/sector segmentation which has to be handled with more care. Some of the non-uniform |
| 22 | * chips support erasing of the 4 kB sectors with another command. |
| 23 | */ |
| 24 | |
| 25 | #include "flash.h" |
Stefan Tauner | 4404f73 | 2013-09-12 08:28:56 +0000 | [diff] [blame] | 26 | #include "chipdrivers.h" |
| 27 | |
Stefan Tauner | beaffd8 | 2013-09-12 08:29:06 +0000 | [diff] [blame] | 28 | static int stm50_erase_sector(struct flashctx *flash, unsigned int addr) |
Stefan Tauner | 4404f73 | 2013-09-12 08:28:56 +0000 | [diff] [blame] | 29 | { |
Stefan Tauner | beaffd8 | 2013-09-12 08:29:06 +0000 | [diff] [blame] | 30 | chipaddr bios = flash->virtual_memory + addr; |
Stefan Tauner | 4404f73 | 2013-09-12 08:28:56 +0000 | [diff] [blame] | 31 | |
| 32 | // clear status register |
| 33 | chip_writeb(flash, 0x50, bios); |
| 34 | // now start it |
| 35 | chip_writeb(flash, 0x32, bios); |
| 36 | chip_writeb(flash, 0xd0, bios); |
| 37 | programmer_delay(10); |
| 38 | |
Stefan Tauner | beaffd8 | 2013-09-12 08:29:06 +0000 | [diff] [blame] | 39 | uint8_t status = wait_82802ab(flash); |
| 40 | print_status_82802ab(status); |
Stefan Tauner | 4404f73 | 2013-09-12 08:28:56 +0000 | [diff] [blame] | 41 | |
Stefan Tauner | beaffd8 | 2013-09-12 08:29:06 +0000 | [diff] [blame] | 42 | return status == 0x80; |
| 43 | } |
| 44 | |
| 45 | /* Some ST M50* chips do support erasing of sectors. This function will derive the erase function to use from |
| 46 | * the length of the of the block. For calls that apparently do not address a sector (but a block) we just call |
| 47 | * the block erase function instead. FIXME: This duplicates the behavior of the remaining erasers for blocks and |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame^] | 48 | * might be fixed when flashprog supports multiple functions per eraser or erasers that do erase parts of the |
Stefan Tauner | beaffd8 | 2013-09-12 08:29:06 +0000 | [diff] [blame] | 49 | * chip only. */ |
| 50 | int erase_sector_stm50(struct flashctx *flash, unsigned int addr, unsigned int len) |
| 51 | { |
| 52 | if (len == 4096) |
| 53 | return stm50_erase_sector(flash, addr); |
| 54 | else |
| 55 | return erase_block_82802ab(flash, addr, len); |
Stefan Tauner | 4404f73 | 2013-09-12 08:28:56 +0000 | [diff] [blame] | 56 | } |