From 917721a49555f247ace4b6ced66a223896b0e84e Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Wed, 16 Feb 2011 20:07:44 +0000 Subject: [PATCH] Modify the spi flash driver to allow smaller read IO sizes, but enforce the larger, aligned write+erase sizes the driver currently implements. This preserves write behaviour but makes the flash driver usable for things like a read-only FFS or a geom_uzip/geom_compress . Note that since GEOM will now return the sector size as being smaller, writes of sector size/alignment will now fail with an EIO. Code which writes to the flash device will have to be (for now) manually taught about the flash write blocksize. --- sys/dev/flash/mx25l.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/sys/dev/flash/mx25l.c b/sys/dev/flash/mx25l.c index 5a84e1b351a3..d5c227091134 100644 --- a/sys/dev/flash/mx25l.c +++ b/sys/dev/flash/mx25l.c @@ -49,6 +49,13 @@ __FBSDID("$FreeBSD$"); #define FL_ERASE_4K 0x01 #define FL_ERASE_32K 0x02 +/* + * Define the sectorsize to be a smaller size rather than the flash + * sector size. Trying to run FFS off of a 64k flash sector size + * results in a completely un-usable system. + */ +#define MX25L_SECTORSIZE 512 + struct mx25l_flash_ident { const char *name; @@ -231,15 +238,11 @@ mx25l_write(device_t dev, off_t offset, caddr_t data, off_t count) write_offset = offset; /* - * Sanity checks + * Use the erase sectorsize here since blocks are fully erased + * first before they're written to. */ - KASSERT(count % sc->sc_sectorsize == 0, - ("count for BIO_WRITE is not sector size (%d bytes) aligned", - sc->sc_sectorsize)); - - KASSERT(offset % sc->sc_sectorsize == 0, - ("offset for BIO_WRITE is not sector size (%d bytes) aligned", - sc->sc_sectorsize)); + if (count % sc->sc_sectorsize != 0 || offset % sc->sc_sectorsize != 0) + return (EIO); /* * Assume here that we write per-sector only @@ -308,15 +311,13 @@ mx25l_read(device_t dev, off_t offset, caddr_t data, off_t count) sc = device_get_softc(dev); /* - * Sanity checks + * Enforce the disk read sectorsize not the erase sectorsize. + * In this way, smaller read IO is possible,dramatically + * speeding up filesystem/geom_compress access. */ - KASSERT(count % sc->sc_sectorsize == 0, - ("count for BIO_READ is not sector size (%d bytes) aligned", - sc->sc_sectorsize)); - - KASSERT(offset % sc->sc_sectorsize == 0, - ("offset for BIO_READ is not sector size (%d bytes) aligned", - sc->sc_sectorsize)); + if (count % sc->sc_disk->d_sectorsize != 0 + || offset % sc->sc_disk->d_sectorsize != 0) + return (EIO); txBuf[0] = CMD_FAST_READ; cmd.tx_cmd_sz = 5; @@ -371,7 +372,7 @@ mx25l_attach(device_t dev) sc->sc_disk->d_name = "flash/spi"; sc->sc_disk->d_drv1 = sc; sc->sc_disk->d_maxsize = DFLTPHYS; - sc->sc_disk->d_sectorsize = ident->sectorsize; + sc->sc_disk->d_sectorsize = MX25L_SECTORSIZE; sc->sc_disk->d_mediasize = ident->sectorsize * ident->sectorcount; sc->sc_disk->d_unit = device_get_unit(sc->sc_dev); sc->sc_disk->d_dump = NULL; /* NB: no dumps */