patch to sys/dev/flash/ to allow smaller read IO sizes
Adrian Chadd
adrian.chadd at gmail.com
Sun Feb 13 19:02:47 UTC 2011
I've been running a few of my ubiquiti boards out of flash recently
and the default sector size just makes it impossible.
This patch introduces a couple of important changes:
* the GEOM sector size is changed to 512 bytes;
* non-aligned size/offset for read/write is now an IO error, rather
than a KASSERT();
This means that read IO will work fine with smaller IO sizes and the
wrong-sized IO will simply return EIO rather than panicing the kernel.
Writing should still work for IO size+offset as a multiple of the
sector size.
Thanks,
Adrian
====
[root at pcbsd-1294 /data/1/adrian/head/src]# cat /tmp/flash_read_size.diff
Index: sys/dev/flash/mx25l.c
===================================================================
--- sys/dev/flash/mx25l.c (revision 218440)
+++ sys/dev/flash/mx25l.c (working copy)
@@ -49,6 +49,13 @@
#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;
@@ -230,17 +237,10 @@
bytes_writen = 0;
write_offset = offset;
- /*
- * Sanity checks
- */
- KASSERT(count % sc->sc_sectorsize == 0,
- ("count for BIO_WRITE is not sector size (%d bytes) aligned",
- sc->sc_sectorsize));
+ /* Use the erase sectorsize here; since blocks are erased
first before writing */
+ if (count % sc->sc_sectorsize != 0 || offset % sc->sc_sectorsize != 0)
+ return (EIO);
- KASSERT(offset % sc->sc_sectorsize == 0,
- ("offset for BIO_WRITE is not sector size (%d bytes) aligned",
- sc->sc_sectorsize));
-
/*
* Assume here that we write per-sector only
* and sector size should be 256 bytes aligned
@@ -307,17 +307,10 @@
pdev = device_get_parent(dev);
sc = device_get_softc(dev);
- /*
- * Sanity checks
- */
- KASSERT(count % sc->sc_sectorsize == 0,
- ("count for BIO_READ is not sector size (%d bytes) aligned",
- sc->sc_sectorsize));
+ /* Enforce the disk read sectorsize; not the erase sectorsize */
+ if (count % sc->sc_disk->d_sectorsize != 0 || offset %
sc->sc_disk->d_sectorsize != 0)
+ return (EIO);
- KASSERT(offset % sc->sc_sectorsize == 0,
- ("offset for BIO_READ is not sector size (%d bytes) aligned",
- sc->sc_sectorsize));
-
txBuf[0] = CMD_FAST_READ;
cmd.tx_cmd_sz = 5;
cmd.rx_cmd_sz = 5;
@@ -371,7 +364,7 @@
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 */
More information about the freebsd-mips
mailing list