Index: mx25l.c =================================================================== --- mx25l.c (revision 210201) +++ mx25l.c (working copy) @@ -45,6 +45,10 @@ #include +/* block erase flags */ +#define FL_ERASE_32K 0x02 +#define FL_ERASE_64K 0x04 + struct mx25l_flash_ident { const char *name; @@ -52,6 +56,7 @@ uint16_t device_id; unsigned int sectorsize; unsigned int sectorcount; + unsigned int flags; }; struct mx25l_softc @@ -59,7 +64,7 @@ device_t sc_dev; uint8_t sc_manufacturer_id; uint16_t sc_device_id; - unsigned int sc_sectorsize; + unsigned int sc_sectorsize; /* for "sector erase" operations */ struct mtx sc_mtx; struct disk *sc_disk; struct proc *sc_p; @@ -83,10 +88,10 @@ static void mx25l_task(void *arg); struct mx25l_flash_ident flash_devices[] = { - { "mx25ll32", 0xc2, 0x2016, 64 * 1024, 64 }, - { "mx25ll64", 0xc2, 0x2017, 64 * 1024, 128 }, - { "mx25ll128", 0xc2, 0x2018, 64 * 1024, 256 }, - { "s25fl128", 0x01, 0x2018, 64 * 1024, 256 }, + { "mx25ll32", 0xc2, 0x2016, 64 * 1024, 64, 0 }, + { "mx25ll64", 0xc2, 0x2017, 64 * 1024, 128, 0 }, + { "mx25ll128", 0xc2, 0x2018, 4 * 1024, 4096, FL_ERASE_32K | FL_ERASE_64K }, + { "s25fl128", 0x01, 0x2018, 64 * 1024, 256, 0 }, }; static uint8_t @@ -178,7 +183,7 @@ } static void -mx25l_erase_sector(device_t dev, off_t sector) +mx25l_erase_sector(device_t dev, off_t sector, uint8_t ecmd) { uint8_t txBuf[4], rxBuf[4]; struct spi_command cmd; @@ -191,7 +196,7 @@ memset(txBuf, 0, sizeof(txBuf)); memset(rxBuf, 0, sizeof(rxBuf)); - txBuf[0] = CMD_SECTOR_ERASE; + txBuf[0] = ecmd; cmd.tx_cmd = txBuf; cmd.rx_cmd = rxBuf; cmd.rx_cmd_sz = 4; @@ -222,6 +227,14 @@ bytes_writen = 0; write_offset = offset; + /* Writes, for now, must begin on a sector size boundary */ + if ((offset % sc->sc_sectorsize) != 0) + return EIO; + + /* And they must be a multiple of sector size */ + if ((count % sc->sc_sectorsize) != 0) + return EIO; + /* * Sanity checks */ @@ -252,7 +265,7 @@ * If we crossed sector boundary - erase next sector */ if (((offset + bytes_writen) % sc->sc_sectorsize) == 0) - mx25l_erase_sector(dev, offset + bytes_writen); + mx25l_erase_sector(dev, offset + bytes_writen, CMD_SECTOR_ERASE); txBuf[0] = CMD_PAGE_PROGRAM; txBuf[1] = ((write_offset >> 16) & 0xff); @@ -299,17 +312,6 @@ 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)); - - 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; @@ -363,15 +365,15 @@ 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 = 512; /* Read/write IO size */ 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 */ - /* Sectorsize for erase operations */ - sc->sc_sectorsize = ident->sectorsize; + /* Sector size for erase operations - fixed at the moment */ + sc->sc_sectorsize = ident->sectorsize; /* NB: use stripesize to hold the erase/region size for RedBoot */ - sc->sc_disk->d_stripesize = ident->sectorsize; + sc->sc_disk->d_stripesize = 65536; disk_create(sc->sc_disk, DISK_VERSION); bioq_init(&sc->sc_bio_queue); Index: mx25lreg.h =================================================================== --- mx25lreg.h (revision 210201) +++ mx25lreg.h (working copy) @@ -39,8 +39,10 @@ #define CMD_READ 0x03 #define CMD_FAST_READ 0x0B #define CMD_PAGE_PROGRAM 0x02 -#define CMD_SECTOR_ERASE 0xD8 +#define CMD_SECTOR_ERASE 0x20 #define CMD_BULK_ERASE 0xC7 +#define CMD_BLOCK_ERASE_32K 0x52 +#define CMD_BLOCK_ERASE_64K 0xD8 /* * Status register flags