Author: stefanct Date: Thu Sep 12 10:28:56 2013 New Revision: 1736 URL: http://flashrom.org/trac/flashrom/changeset/1736
Log: Cleanup ST M50 driver.
There are two locking strategies used by this umbrella family, one uniform and one that matches the sector layout of the chip. Refactor the functions involved and rename the overly complicated file to just stm50.c and the functions accordingly.
This fixes unlocking of some of the non-uniform chips and gets rid of the abuse of page_size.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at
Added: trunk/stm50.c (contents, props changed) Deleted: trunk/stm50flw0x0x.c Modified: trunk/82802ab.c trunk/Makefile trunk/chipdrivers.h trunk/flashchips.c
Modified: trunk/82802ab.c ============================================================================== --- trunk/82802ab.c Thu Sep 12 01:35:03 2013 (r1735) +++ trunk/82802ab.c Thu Sep 12 10:28:56 2013 (r1736) @@ -89,6 +89,7 @@ return 1; }
+/* FIXME: needs timeout */ uint8_t wait_82802ab(struct flashctx *flash) { uint8_t status;
Modified: trunk/Makefile ============================================================================== --- trunk/Makefile Thu Sep 12 01:35:03 2013 (r1735) +++ trunk/Makefile Thu Sep 12 10:28:56 2013 (r1736) @@ -320,7 +320,7 @@ ############################################################################### # Flash chip drivers and bus support infrastructure.
-CHIP_OBJS = jedec.o stm50flw0x0x.o w39.o w29ee011.o \ +CHIP_OBJS = jedec.o stm50.o w39.o w29ee011.o \ sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \ sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o spi25_statusreg.o \ opaque.o sfdp.o en29lv640b.o at45db.o
Modified: trunk/chipdrivers.h ============================================================================== --- trunk/chipdrivers.h Thu Sep 12 01:35:03 2013 (r1735) +++ trunk/chipdrivers.h Thu Sep 12 10:28:56 2013 (r1736) @@ -193,9 +193,10 @@ /* w29ee011.c */ int probe_w29ee011(struct flashctx *flash);
-/* stm50flw0x0x.c */ -int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int block, unsigned int blocksize); -int unlock_stm50flw0x0x(struct flashctx *flash); +/* stm50.c */ +int erase_sector_stm50(struct flashctx *flash, unsigned int block, unsigned int blocksize); +int unlock_stm50_uniform(struct flashctx *flash); +int unlock_stm50_nonuniform(struct flashctx *flash);
/* en29lv640b.c */ int probe_en29lv640b(struct flashctx *flash);
Modified: trunk/flashchips.c ============================================================================== --- trunk/flashchips.c Thu Sep 12 01:35:03 2013 (r1735) +++ trunk/flashchips.c Thu Sep 12 10:28:56 2013 (r1736) @@ -11008,7 +11008,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FLW040A, .total_size = 512, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, @@ -11028,8 +11028,8 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, .write = write_82802ab, + .unlock = unlock_stm50_uniform, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ }, @@ -11041,7 +11041,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FLW040B, .total_size = 512, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, @@ -11061,8 +11061,8 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, .write = write_82802ab, + .unlock = unlock_stm50_uniform, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ }, @@ -11074,7 +11074,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FLW080A, .total_size = 1024, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_OK_PRE, .probe = probe_82802ab, @@ -11094,7 +11094,7 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, + .unlock = unlock_stm50_nonuniform, .write = write_82802ab, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ @@ -11107,7 +11107,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FLW080B, .total_size = 1024, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, @@ -11127,7 +11127,7 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, + .unlock = unlock_stm50_nonuniform, .write = write_82802ab, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ @@ -11140,7 +11140,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FW002, .total_size = 256, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, @@ -11157,7 +11157,7 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, + .unlock = unlock_stm50_nonuniform, .write = write_82802ab, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ @@ -11170,7 +11170,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FW016, .total_size = 2048, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, @@ -11182,7 +11182,7 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, + .unlock = unlock_stm50_uniform, .write = write_82802ab, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ @@ -11195,7 +11195,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FW040, .total_size = 512, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_OK_PR, .probe = probe_82802ab, @@ -11207,7 +11207,7 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, + .unlock = unlock_stm50_uniform, .write = write_82802ab, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ @@ -11220,7 +11220,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50FW080, .total_size = 1024, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_OK_PREW, .probe = probe_82802ab, @@ -11232,7 +11232,7 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, + .unlock = unlock_stm50_uniform, .write = write_82802ab, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */ @@ -11245,7 +11245,7 @@ .manufacture_id = ST_ID, .model_id = ST_M50LPW116, .total_size = 2048, - .page_size = 64 * 1024, + .page_size = 0, .feature_bits = FEATURE_REGISTERMAP, .tested = TEST_UNTESTED, .probe = probe_82802ab, @@ -11263,7 +11263,7 @@ .block_erase = erase_block_82802ab, } }, - .unlock = unlock_stm50flw0x0x, + .unlock = unlock_stm50_nonuniform, .write = write_82802ab, .read = read_memmapped, .voltage = {3000, 3600}, /* Also has 12V fast program & erase */
Added: trunk/stm50.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/stm50.c Thu Sep 12 10:28:56 2013 (r1736) @@ -0,0 +1,103 @@ +/* + * This file is part of the flashrom project. + * + * Copyright (C) 2008 Claus Gindhart claus.gindhart@kontron.com + * Copyright (C) 2009 Sean Nelson audiohacked@gmail.com + * Copyright (C) 2013 Stefan Tauner + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * All ST M50 chips are locked on startup. Most of them have a uniform 64 kB block layout, but some have + * a non-uniform block/sector segmentation which has to be handled with more care. Some of the non-uniform + * chips support erasing of the 4 kB sectors with another command. + */ + +#include "flash.h" +#include "flashchips.h" +#include "chipdrivers.h" + +static int stm50_unlock_address(struct flashctx *flash, int offset) +{ + chipaddr wrprotect = flash->virtual_registers + 2; + static const uint8_t unlock_sector = 0x00; + msg_cdbg("unlocking at 0x%x\n", offset); + chip_writeb(flash, unlock_sector, wrprotect + offset); + if (chip_readb(flash, wrprotect + offset) != unlock_sector) { + msg_cerr("Cannot unlock address 0x%x\n", offset); + return -1; + } + return 0; +} + +/* Chips known to use a non-uniform block and sector layout for locking (as well as for erasing): + * Name Size Address range of lock registers + * M50FLW080A 1MB FFB00002 - FFBFF002 + * M50FLW080B 1MB FFB00002 - FFBFF002 + * M50FW002 256k FFBC0002 - FFBFC002 + * M50LPW116 2MB FFA00002 - FFBFC002 + */ +int unlock_stm50_nonuniform(struct flashctx *flash) +{ + int i; + struct eraseblock *eraseblocks = flash->chip->block_erasers[0].eraseblocks; + unsigned int done = 0; + for (i = 0; i < NUM_ERASEREGIONS && eraseblocks[i].count != 0; i++) { + unsigned int block_size = eraseblocks[i].size; + unsigned int block_count = eraseblocks[i].count; + + int j; + for (j = 0; j < block_count; j++) { + if (stm50_unlock_address(flash, done)) { + msg_cerr("UNLOCK FAILED!\n"); + return -1; + } + done += block_count * block_size; + } + } + return 0; +} + +/* Unlocking for uniform 64 kB blocks starting at offset 2 of the feature registers. */ +int unlock_stm50_uniform(struct flashctx *flash) +{ + int i; + for (i = 0; i < flash->chip->total_size * 1024; i+= 64 * 1024) { + if (stm50_unlock_address(flash, i)) { + msg_cerr("UNLOCK FAILED!\n"); + return -1; + } + } + return 0; +} + +/* This function is unused. */ +int erase_sector_stm50(struct flashctx *flash, unsigned int sector, unsigned int sectorsize) +{ + chipaddr bios = flash->virtual_memory + sector; + + // clear status register + chip_writeb(flash, 0x50, bios); + // now start it + chip_writeb(flash, 0x32, bios); + chip_writeb(flash, 0xd0, bios); + programmer_delay(10); + + wait_82802ab(flash); + + /* FIXME: Check the status register for errors. */ + return 0; +}