Add Wistron RPAA-82 board support

View: New views
9 Messages — Rating Filter:   Alert me  

Add Wistron RPAA-82 board support

by Eric L. Chen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
I added my ar7161 board support last weekend.
It's flash is come from Spansion.

--
Best Regards,
Eric L. Chen <lihong@...>

[patch-mips-spiflash.diff]

Index: src-mips/sys/dev/flash/mx25l.c
===================================================================
--- src-mips/sys/dev/flash/mx25l.c (revision 198476)
+++ src-mips/sys/dev/flash/mx25l.c (working copy)
@@ -59,6 +59,8 @@
  device_t sc_dev;
  uint8_t sc_manufacturer_id;
  uint16_t sc_device_id;
+ unsigned int sc_sectorsize;
+ unsigned int sc_sectorcount;
  struct mtx sc_mtx;
  struct disk *sc_disk;
  struct proc *sc_p;
@@ -85,6 +87,7 @@
  { "mx25ll32",  0xc2, 0x2016, 64 * 1024,  64 },
  { "mx25ll64",  0xc2, 0x2017, 64 * 1024, 128 },
  { "mx25ll128", 0xc2, 0x2018, 64 * 1024, 256 },
+ { "s25fl128",  0x01, 0x2018, 64 * 1024, 256 },
 };
 
 static uint8_t
@@ -172,6 +175,7 @@
  cmd.rx_cmd = rxBuf;
  cmd.rx_cmd_sz = 1;
  cmd.tx_cmd_sz = 1;
+ mx25l_wait_for_device_ready(dev);
  err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
 }
 
@@ -182,7 +186,6 @@
  struct spi_command cmd;
  int err;
 
- mx25l_wait_for_device_ready(dev);
  mx25l_set_writable(dev, 1);
 
  memset(&cmd, 0, sizeof(cmd));
@@ -197,10 +200,134 @@
  txBuf[1] = ((sector >> 16) & 0xff);
  txBuf[2] = ((sector >> 8) & 0xff);
  txBuf[3] = (sector & 0xff);
+ mx25l_wait_for_device_ready(dev);
  err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
 }
 
+static void
+mx25l_write_sector(device_t dev, off_t offset, caddr_t data)
+{
+ struct mx25l_softc *sc = device_get_softc(dev);
+ uint8_t txBuf[4], rxBuf[4];
+ struct spi_command cmd;
+ uint8_t *ptr = (uint8_t*)data;
+ long n;
+ int err;
+
+ for (n = 0; n < sc->sc_sectorsize; n += FLASH_PAGE_SIZE) {
+ bzero(&cmd, sizeof(cmd));
+ bzero(txBuf, sizeof(txBuf));
+ bzero(rxBuf, sizeof(rxBuf));
+
+ cmd.tx_cmd_sz = 4;
+ cmd.rx_cmd_sz = 4;
+ cmd.tx_cmd = txBuf;
+ cmd.rx_cmd = rxBuf;
+
+ txBuf[0] = CMD_PAGE_PROGRAM;
+ txBuf[1] = (((offset + n) >> 16) & 0xff);
+ txBuf[2] = (((offset + n) >> 8) & 0xff);
+ txBuf[3] = ((offset + n) & 0xff);
+
+ cmd.tx_data = ptr + n;
+ cmd.tx_data_sz = FLASH_PAGE_SIZE;
+ cmd.rx_data = ptr + n;
+ cmd.rx_data_sz = FLASH_PAGE_SIZE;
+
+ mx25l_set_writable(dev, 1);
+ mx25l_wait_for_device_ready(dev);
+ err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
+ }
+}
+
 static int
+mx25l_read(device_t dev, off_t offset, long count, caddr_t data)
+{
+ uint8_t txBuf[8], rxBuf[8];
+ struct spi_command cmd;
+ int ret;
+
+ bzero(&cmd, sizeof(cmd));
+ bzero(txBuf, sizeof(txBuf));
+ bzero(rxBuf, sizeof(rxBuf));
+
+ cmd.tx_cmd_sz = 5;
+ cmd.rx_cmd_sz = 5;
+
+ txBuf[0] = CMD_FAST_READ;
+ txBuf[1] = ((offset >> 16) & 0xff);
+ txBuf[2] = ((offset >> 8) & 0xff);
+ txBuf[3] = (offset & 0xff);
+ txBuf[4] = 0; /* Dummy byte required by fast read */
+
+ cmd.tx_cmd = txBuf;
+ cmd.rx_cmd = rxBuf;
+ cmd.tx_data = data;
+ cmd.tx_data_sz = count;
+ cmd.rx_data = data;
+ cmd.rx_data_sz = count;
+ mx25l_wait_for_device_ready(dev);
+ ret = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
+
+ return ret;
+}
+
+static int
+mx25l_write(device_t dev, off_t offset, long count, caddr_t data)
+{
+ struct mx25l_softc *sc = device_get_softc(dev);
+ off_t sector;
+ int sector_offset, sector_remain, i, n;
+ uint8_t *temp, *ptr = (uint8_t*)data;
+
+ temp = malloc(sc->sc_sectorsize, M_TEMP, M_WAITOK);
+ if (NULL == temp){
+ printf("%s: failed to alloc.\n", __func__);
+ return -1;
+ }
+
+ sector_offset = offset % sc->sc_sectorsize;
+ sector_remain = sc->sc_sectorsize - sector_offset;
+ sector = offset - sector_offset;
+
+ if (sector_remain >= count) {
+ /* in sector */
+ mx25l_read(dev, sector, sc->sc_sectorsize, temp);
+ bcopy(ptr, temp + sector_offset, count);
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, temp);
+ } else {
+ /* cross sectoer, first */
+ mx25l_read(dev, sector, sc->sc_sectorsize, temp);
+ bcopy(ptr, temp + sector_offset, sector_remain);
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, temp);
+ count -= sector_remain;
+ ptr += sector_remain;
+
+ /* inter */
+ n = count / sc->sc_sectorsize;
+ for (i = 0; i < n; i++) {
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, ptr);
+ count -= sc->sc_sectorsize;
+ sector += sc->sc_sectorsize;
+ ptr += sc->sc_sectorsize;
+ }
+ /* last */
+ if (count > 0) {
+ mx25l_read(dev, sector, sc->sc_sectorsize, temp);
+ bcopy(ptr, temp, count);
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, temp);
+ }
+
+ }
+ free(temp, M_TEMP);
+ return 0;
+}
+
+static int
 mx25l_probe(device_t dev)
 {
  device_set_desc(dev, "M25Pxx Flash Family");
@@ -223,6 +350,11 @@
 
  mx25l_wait_for_device_ready(sc->sc_dev);
 
+ sc->sc_manufacturer_id = ident->manufacturer_id;
+ sc->sc_device_id = ident->device_id;
+ sc->sc_sectorsize = ident->sectorsize;
+ sc->sc_sectorcount = ident->sectorcount;
+
  sc->sc_disk = disk_alloc();
  sc->sc_disk->d_open = mx25l_open;
  sc->sc_disk->d_close = mx25l_close;
@@ -231,7 +363,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 = 512;
  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 */
@@ -294,15 +426,10 @@
 {
  struct mx25l_softc *sc = (struct mx25l_softc*)arg;
  struct bio *bp;
- uint8_t txBuf[8], rxBuf[8];
- struct spi_command cmd;
- device_t dev, pdev;
- off_t write_offset;
- long bytes_to_write, bytes_writen;
+ device_t dev;
 
+ dev = sc->sc_dev;
  for (;;) {
- dev = sc->sc_dev;
- pdev = device_get_parent(dev);
  M25PXX_LOCK(sc);
  do {
  bp = bioq_first(&sc->sc_bio_queue);
@@ -312,84 +439,16 @@
  bioq_remove(&sc->sc_bio_queue, bp);
  M25PXX_UNLOCK(sc);
 
- if (bp->bio_cmd == BIO_READ) {
- txBuf[0] = CMD_FAST_READ;
- cmd.tx_cmd_sz = 5;
- cmd.rx_cmd_sz = 5;
-
- txBuf[1] = (((bp->bio_offset) >> 16) & 0xff);
- txBuf[2] = (((bp->bio_offset) >> 8) & 0xff);
- txBuf[3] = ((bp->bio_offset) & 0xff);
- /* Dummy byte */
- txBuf[4] = 0;
-
- cmd.tx_cmd = txBuf;
- cmd.rx_cmd = rxBuf;
- cmd.tx_data = bp->bio_data;
- cmd.tx_data_sz = bp->bio_bcount;
- cmd.rx_data = bp->bio_data;
- cmd.rx_data_sz = bp->bio_bcount;
-
- bp->bio_error = SPIBUS_TRANSFER(pdev, dev, &cmd);
+ switch(bp->bio_cmd) {
+ case BIO_READ:
+ bp->bio_error = mx25l_read(dev, bp->bio_offset, bp->bio_bcount, bp->bio_data);
+ bp->bio_resid = 0;
+ break;
+ case BIO_WRITE:
+ bp->bio_error = mx25l_write(dev, bp->bio_offset, bp->bio_bcount, bp->bio_data);
+ bp->bio_resid = 0;
+ break;
  }
- else if (bp->bio_cmd == BIO_WRITE) {
- mx25l_erase_sector(dev, bp->bio_offset);
-
- cmd.tx_cmd_sz = 4;
- cmd.rx_cmd_sz = 4;
-
- bytes_writen = 0;
- write_offset = bp->bio_offset;
-
- /*
- * I assume here that we write per-sector only
- * and sector size should be 256 bytes aligned
- */
- KASSERT(write_offset % FLASH_PAGE_SIZE == 0,
-    ("offset for BIO_WRITE is not %d bytes aliIgned",
- FLASH_PAGE_SIZE));
-
- /*
- * Maximum write size for CMD_PAGE_PROGRAM is
- * FLASH_PAGE_SIZE, so split data to chunks
- * FLASH_PAGE_SIZE bytes eash and write them
- * one by one
- */
- while (bytes_writen < bp->bio_bcount) {
- txBuf[0] = CMD_PAGE_PROGRAM;
- txBuf[1] = ((write_offset >> 16) & 0xff);
- txBuf[2] = ((write_offset >> 8) & 0xff);
- txBuf[3] = (write_offset & 0xff);
-
- bytes_to_write = MIN(FLASH_PAGE_SIZE,
-    bp->bio_bcount - bytes_writen);
- cmd.tx_cmd = txBuf;
- cmd.rx_cmd = rxBuf;
- cmd.tx_data = bp->bio_data + bytes_writen;
- cmd.tx_data_sz = bytes_to_write;
- cmd.rx_data = bp->bio_data + bytes_writen;
- cmd.rx_data_sz = bytes_to_write;
-
- /*
- * Eash completed write operation resets WEL
- * (write enable latch) to disabled state,
- * so we re-enable it here
- */
- mx25l_wait_for_device_ready(dev);
- mx25l_set_writable(dev, 1);
-
- bp->bio_error = SPIBUS_TRANSFER(pdev, dev, &cmd);
- if (bp->bio_error)
- break;
-
- bytes_writen += bytes_to_write;
- write_offset += bytes_to_write;
- }
- }
- else
- bp->bio_error = EINVAL;
-
-
  biodone(bp);
  }
 }
Index: src-mips/sys/dev/flash/mx25lreg.h
===================================================================
--- src-mips/sys/dev/flash/mx25lreg.h (revision 198476)
+++ src-mips/sys/dev/flash/mx25lreg.h (working copy)
@@ -46,6 +46,7 @@
  * Status register flags
  */
 #define STATUS_SRWD (1 << 7)
+#define STATUS_BP3 (1 << 5)
 #define STATUS_BP2 (1 << 4)
 #define STATUS_BP1 (1 << 3)
 #define STATUS_BP0 (1 << 2)
Index: src-mips/sys/geom/geom_redboot.c
===================================================================
--- src-mips/sys/geom/geom_redboot.c (revision 198476)
+++ src-mips/sys/geom/geom_redboot.c (working copy)
@@ -366,16 +366,23 @@
  return (NULL);
  g_topology_unlock();
  head = NULL;
- offset = cp->provider->mediasize - blksize;
-again:
- buf = g_read_data(cp, offset, blksize, NULL);
+ /*
+ * Find out FIS Directory block by block
+ */
+ buf = g_read_data(cp, 0, blksize, NULL);
  if (buf != NULL)
- head = parse_fis_directory(buf, blksize, offset, offmask);
- if (head == NULL && offset != 0) {
- if (buf != NULL)
- g_free(buf);
- offset = 0; /* check the front */
- goto again;
+ head = parse_fis_directory(buf, blksize, 0, offmask);
+ if (head == NULL) {
+ g_free(buf);
+ for (offset = cp->provider->mediasize - blksize; offset > 0; offset -= blksize) {
+ buf = g_read_data(cp, offset, blksize, NULL);
+ if (buf != NULL)
+ head = parse_fis_directory(buf, blksize, offset, offmask);
+ if (head)
+ break;
+ if (buf != NULL)
+ g_free(buf);
+ }
  }
  g_topology_lock();
  if (head == NULL) {


_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by Andrew Thompson-24 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 26, 2009 at 11:37:52AM +0800, Eric wrote:
> Hi
> I added my ar7161 board support last weekend.
> It's flash is come from Spansion.

This is great. Oleksandr has also just added write support which will
conflict/duplicate some of your changes so have a look and merge any
outstanding changes you have made (s25fl128 support).

http://svn.freebsd.org/viewvc/base?view=revision&revision=198465

cheers,
Andrew
_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by Eric L. Chen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2009-10-26 at 18:11 +1300, Andrew Thompson wrote:

> On Mon, Oct 26, 2009 at 11:37:52AM +0800, Eric wrote:
> > Hi
> > I added my ar7161 board support last weekend.
> > It's flash is come from Spansion.
>
> This is great. Oleksandr has also just added write support which will
> conflict/duplicate some of your changes so have a look and merge any
> outstanding changes you have made (s25fl128 support).
>
> http://svn.freebsd.org/viewvc/base?view=revision&revision=198465
>
> cheers,
> Andrew
At first, I have my own write support, then I saw hit commit today.
So this patch already merged his commit.

--
Best Regards,
Eric L. Chen <lihong@...>

[patch-mips-spiflash.diff]

Index: src-mips/sys/dev/flash/mx25l.c
===================================================================
--- src-mips/sys/dev/flash/mx25l.c (revision 198476)
+++ src-mips/sys/dev/flash/mx25l.c (working copy)
@@ -59,6 +59,8 @@
  device_t sc_dev;
  uint8_t sc_manufacturer_id;
  uint16_t sc_device_id;
+ unsigned int sc_sectorsize;
+ unsigned int sc_sectorcount;
  struct mtx sc_mtx;
  struct disk *sc_disk;
  struct proc *sc_p;
@@ -85,6 +87,7 @@
  { "mx25ll32",  0xc2, 0x2016, 64 * 1024,  64 },
  { "mx25ll64",  0xc2, 0x2017, 64 * 1024, 128 },
  { "mx25ll128", 0xc2, 0x2018, 64 * 1024, 256 },
+ { "s25fl128",  0x01, 0x2018, 64 * 1024, 256 },
 };
 
 static uint8_t
@@ -172,6 +175,7 @@
  cmd.rx_cmd = rxBuf;
  cmd.rx_cmd_sz = 1;
  cmd.tx_cmd_sz = 1;
+ mx25l_wait_for_device_ready(dev);
  err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
 }
 
@@ -182,7 +186,6 @@
  struct spi_command cmd;
  int err;
 
- mx25l_wait_for_device_ready(dev);
  mx25l_set_writable(dev, 1);
 
  memset(&cmd, 0, sizeof(cmd));
@@ -197,10 +200,134 @@
  txBuf[1] = ((sector >> 16) & 0xff);
  txBuf[2] = ((sector >> 8) & 0xff);
  txBuf[3] = (sector & 0xff);
+ mx25l_wait_for_device_ready(dev);
  err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
 }
 
+static void
+mx25l_write_sector(device_t dev, off_t offset, caddr_t data)
+{
+ struct mx25l_softc *sc = device_get_softc(dev);
+ uint8_t txBuf[4], rxBuf[4];
+ struct spi_command cmd;
+ uint8_t *ptr = (uint8_t*)data;
+ long n;
+ int err;
+
+ for (n = 0; n < sc->sc_sectorsize; n += FLASH_PAGE_SIZE) {
+ bzero(&cmd, sizeof(cmd));
+ bzero(txBuf, sizeof(txBuf));
+ bzero(rxBuf, sizeof(rxBuf));
+
+ cmd.tx_cmd_sz = 4;
+ cmd.rx_cmd_sz = 4;
+ cmd.tx_cmd = txBuf;
+ cmd.rx_cmd = rxBuf;
+
+ txBuf[0] = CMD_PAGE_PROGRAM;
+ txBuf[1] = (((offset + n) >> 16) & 0xff);
+ txBuf[2] = (((offset + n) >> 8) & 0xff);
+ txBuf[3] = ((offset + n) & 0xff);
+
+ cmd.tx_data = ptr + n;
+ cmd.tx_data_sz = FLASH_PAGE_SIZE;
+ cmd.rx_data = ptr + n;
+ cmd.rx_data_sz = FLASH_PAGE_SIZE;
+
+ mx25l_set_writable(dev, 1);
+ mx25l_wait_for_device_ready(dev);
+ err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
+ }
+}
+
 static int
+mx25l_read(device_t dev, off_t offset, long count, caddr_t data)
+{
+ uint8_t txBuf[8], rxBuf[8];
+ struct spi_command cmd;
+ int ret;
+
+ bzero(&cmd, sizeof(cmd));
+ bzero(txBuf, sizeof(txBuf));
+ bzero(rxBuf, sizeof(rxBuf));
+
+ cmd.tx_cmd_sz = 5;
+ cmd.rx_cmd_sz = 5;
+
+ txBuf[0] = CMD_FAST_READ;
+ txBuf[1] = ((offset >> 16) & 0xff);
+ txBuf[2] = ((offset >> 8) & 0xff);
+ txBuf[3] = (offset & 0xff);
+ txBuf[4] = 0; /* Dummy byte required by fast read */
+
+ cmd.tx_cmd = txBuf;
+ cmd.rx_cmd = rxBuf;
+ cmd.tx_data = data;
+ cmd.tx_data_sz = count;
+ cmd.rx_data = data;
+ cmd.rx_data_sz = count;
+ mx25l_wait_for_device_ready(dev);
+ ret = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
+
+ return ret;
+}
+
+static int
+mx25l_write(device_t dev, off_t offset, long count, caddr_t data)
+{
+ struct mx25l_softc *sc = device_get_softc(dev);
+ off_t sector;
+ int sector_offset, sector_remain, i, n;
+ uint8_t *temp, *ptr = (uint8_t*)data;
+
+ temp = malloc(sc->sc_sectorsize, M_TEMP, M_WAITOK);
+ if (NULL == temp){
+ printf("%s: failed to alloc.\n", __func__);
+ return -1;
+ }
+
+ sector_offset = offset % sc->sc_sectorsize;
+ sector_remain = sc->sc_sectorsize - sector_offset;
+ sector = offset - sector_offset;
+
+ if (sector_remain >= count) {
+ /* in sector */
+ mx25l_read(dev, sector, sc->sc_sectorsize, temp);
+ bcopy(ptr, temp + sector_offset, count);
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, temp);
+ } else {
+ /* cross sectoer, first */
+ mx25l_read(dev, sector, sc->sc_sectorsize, temp);
+ bcopy(ptr, temp + sector_offset, sector_remain);
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, temp);
+ count -= sector_remain;
+ ptr += sector_remain;
+
+ /* inter */
+ n = count / sc->sc_sectorsize;
+ for (i = 0; i < n; i++) {
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, ptr);
+ count -= sc->sc_sectorsize;
+ sector += sc->sc_sectorsize;
+ ptr += sc->sc_sectorsize;
+ }
+ /* last */
+ if (count > 0) {
+ mx25l_read(dev, sector, sc->sc_sectorsize, temp);
+ bcopy(ptr, temp, count);
+ mx25l_erase_sector(dev, sector);
+ mx25l_write_sector(dev, sector, temp);
+ }
+
+ }
+ free(temp, M_TEMP);
+ return 0;
+}
+
+static int
 mx25l_probe(device_t dev)
 {
  device_set_desc(dev, "M25Pxx Flash Family");
@@ -223,6 +350,11 @@
 
  mx25l_wait_for_device_ready(sc->sc_dev);
 
+ sc->sc_manufacturer_id = ident->manufacturer_id;
+ sc->sc_device_id = ident->device_id;
+ sc->sc_sectorsize = ident->sectorsize;
+ sc->sc_sectorcount = ident->sectorcount;
+
  sc->sc_disk = disk_alloc();
  sc->sc_disk->d_open = mx25l_open;
  sc->sc_disk->d_close = mx25l_close;
@@ -231,7 +363,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 = 512;
  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 */
@@ -294,15 +426,10 @@
 {
  struct mx25l_softc *sc = (struct mx25l_softc*)arg;
  struct bio *bp;
- uint8_t txBuf[8], rxBuf[8];
- struct spi_command cmd;
- device_t dev, pdev;
- off_t write_offset;
- long bytes_to_write, bytes_writen;
+ device_t dev;
 
+ dev = sc->sc_dev;
  for (;;) {
- dev = sc->sc_dev;
- pdev = device_get_parent(dev);
  M25PXX_LOCK(sc);
  do {
  bp = bioq_first(&sc->sc_bio_queue);
@@ -312,84 +439,16 @@
  bioq_remove(&sc->sc_bio_queue, bp);
  M25PXX_UNLOCK(sc);
 
- if (bp->bio_cmd == BIO_READ) {
- txBuf[0] = CMD_FAST_READ;
- cmd.tx_cmd_sz = 5;
- cmd.rx_cmd_sz = 5;
-
- txBuf[1] = (((bp->bio_offset) >> 16) & 0xff);
- txBuf[2] = (((bp->bio_offset) >> 8) & 0xff);
- txBuf[3] = ((bp->bio_offset) & 0xff);
- /* Dummy byte */
- txBuf[4] = 0;
-
- cmd.tx_cmd = txBuf;
- cmd.rx_cmd = rxBuf;
- cmd.tx_data = bp->bio_data;
- cmd.tx_data_sz = bp->bio_bcount;
- cmd.rx_data = bp->bio_data;
- cmd.rx_data_sz = bp->bio_bcount;
-
- bp->bio_error = SPIBUS_TRANSFER(pdev, dev, &cmd);
+ switch(bp->bio_cmd) {
+ case BIO_READ:
+ bp->bio_error = mx25l_read(dev, bp->bio_offset, bp->bio_bcount, bp->bio_data);
+ bp->bio_resid = 0;
+ break;
+ case BIO_WRITE:
+ bp->bio_error = mx25l_write(dev, bp->bio_offset, bp->bio_bcount, bp->bio_data);
+ bp->bio_resid = 0;
+ break;
  }
- else if (bp->bio_cmd == BIO_WRITE) {
- mx25l_erase_sector(dev, bp->bio_offset);
-
- cmd.tx_cmd_sz = 4;
- cmd.rx_cmd_sz = 4;
-
- bytes_writen = 0;
- write_offset = bp->bio_offset;
-
- /*
- * I assume here that we write per-sector only
- * and sector size should be 256 bytes aligned
- */
- KASSERT(write_offset % FLASH_PAGE_SIZE == 0,
-    ("offset for BIO_WRITE is not %d bytes aliIgned",
- FLASH_PAGE_SIZE));
-
- /*
- * Maximum write size for CMD_PAGE_PROGRAM is
- * FLASH_PAGE_SIZE, so split data to chunks
- * FLASH_PAGE_SIZE bytes eash and write them
- * one by one
- */
- while (bytes_writen < bp->bio_bcount) {
- txBuf[0] = CMD_PAGE_PROGRAM;
- txBuf[1] = ((write_offset >> 16) & 0xff);
- txBuf[2] = ((write_offset >> 8) & 0xff);
- txBuf[3] = (write_offset & 0xff);
-
- bytes_to_write = MIN(FLASH_PAGE_SIZE,
-    bp->bio_bcount - bytes_writen);
- cmd.tx_cmd = txBuf;
- cmd.rx_cmd = rxBuf;
- cmd.tx_data = bp->bio_data + bytes_writen;
- cmd.tx_data_sz = bytes_to_write;
- cmd.rx_data = bp->bio_data + bytes_writen;
- cmd.rx_data_sz = bytes_to_write;
-
- /*
- * Eash completed write operation resets WEL
- * (write enable latch) to disabled state,
- * so we re-enable it here
- */
- mx25l_wait_for_device_ready(dev);
- mx25l_set_writable(dev, 1);
-
- bp->bio_error = SPIBUS_TRANSFER(pdev, dev, &cmd);
- if (bp->bio_error)
- break;
-
- bytes_writen += bytes_to_write;
- write_offset += bytes_to_write;
- }
- }
- else
- bp->bio_error = EINVAL;
-
-
  biodone(bp);
  }
 }
Index: src-mips/sys/dev/flash/mx25lreg.h
===================================================================
--- src-mips/sys/dev/flash/mx25lreg.h (revision 198476)
+++ src-mips/sys/dev/flash/mx25lreg.h (working copy)
@@ -46,6 +46,7 @@
  * Status register flags
  */
 #define STATUS_SRWD (1 << 7)
+#define STATUS_BP3 (1 << 5)
 #define STATUS_BP2 (1 << 4)
 #define STATUS_BP1 (1 << 3)
 #define STATUS_BP0 (1 << 2)
Index: src-mips/sys/geom/geom_redboot.c
===================================================================
--- src-mips/sys/geom/geom_redboot.c (revision 198476)
+++ src-mips/sys/geom/geom_redboot.c (working copy)
@@ -366,16 +366,23 @@
  return (NULL);
  g_topology_unlock();
  head = NULL;
- offset = cp->provider->mediasize - blksize;
-again:
- buf = g_read_data(cp, offset, blksize, NULL);
+ /*
+ * Find out FIS Directory block by block
+ */
+ buf = g_read_data(cp, 0, blksize, NULL);
  if (buf != NULL)
- head = parse_fis_directory(buf, blksize, offset, offmask);
- if (head == NULL && offset != 0) {
- if (buf != NULL)
- g_free(buf);
- offset = 0; /* check the front */
- goto again;
+ head = parse_fis_directory(buf, blksize, 0, offmask);
+ if (head == NULL) {
+ g_free(buf);
+ for (offset = cp->provider->mediasize - blksize; offset > 0; offset -= blksize) {
+ buf = g_read_data(cp, offset, blksize, NULL);
+ if (buf != NULL)
+ head = parse_fis_directory(buf, blksize, offset, offmask);
+ if (head)
+ break;
+ if (buf != NULL)
+ g_free(buf);
+ }
  }
  g_topology_lock();
  if (head == NULL) {


_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by Eric L. Chen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2009-10-26 at 13:34 +0800, Eric wrote:

> On Mon, 2009-10-26 at 18:11 +1300, Andrew Thompson wrote:
> > On Mon, Oct 26, 2009 at 11:37:52AM +0800, Eric wrote:
> > > Hi
> > > I added my ar7161 board support last weekend.
> > > It's flash is come from Spansion.
> >
> > This is great. Oleksandr has also just added write support which will
> > conflict/duplicate some of your changes so have a look and merge any
> > outstanding changes you have made (s25fl128 support).
> >
> > http://svn.freebsd.org/viewvc/base?view=revision&revision=198465
> >
> > cheers,
> > Andrew
>
> At first, I have my own write support, then I saw hit commit today.
> So this patch already merged his commit.
>

It seems work well on my board.
I can put both OpenWrt and FreeBSD on the same board.
The only problem for FreeBSD is that FreeBSD kernel has no dedicated
entry address. OpenWrt put 'j kernel_entry' at load address, so it no
need to change redboot config after firmware upgrade.

===================== RedBoot ==========================
RedBoot(tm) bootstrap and debug environment [ROMRAM]
Non-certified release, version v1.0 - built 12:26:39, May 18 2009

Copyright (C) 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.

Board: RPAA-82
RAM: 0x80000000-0x84000000, [0x80051290-0x80fe1000] available
FLASH: 0xbf000000 - 0xbfff0000, 256 blocks of 0x00010000 bytes each.
== Executing boot script in 3.000 seconds - enter ^C to abort
^C
RedBoot> fis list
Name              FLASH addr  Mem addr    Length      Entry point
RedBoot           0xBF000000  0xBF000000  0x00040000  0x00000000
vmlinux.bin.l7    0xBF040000  0x80060000  0x00100000  0x80060000
rootfs            0xBF140000  0xBF140000  0x00400000  0x00000000
fbsd-kern         0xBF540000  0x80060000  0x00200000  0x800976C0
fbsd-root         0xBF740000  0xBF740000  0x00800000  0x00000000
fbsd-data         0xBFF40000  0xBFF40000  0x000A0000  0x00000000
FIS directory     0xBFFE0000  0xBFFE0000  0x0000F000  0x00000000
RedBoot config    0xBFFEF000  0xBFFEF000  0x00001000  0x00000000

===================== FreeBSD ==========================
Tue Oct 27 01:58:42 UTC 2009

FreeBSD/mips (ar71xx) (ttyu0)

login: root
Oct 27 01:59:09 ar71xx login: ROOT LOGIN (root) ON ttyu0
Copyright (c) 1992-2009 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights
reserved.

# df -h
Filesystem                     Size    Used   Avail Capacity  Mounted on
/dev/redboot/fbsd-root.uzip     48M     30M     14M    69%    /
devfs                          1.0K    1.0K      0B   100%    /dev
/dev/redboot/fbsd-data         528K    7.5K    478K     2%    /flash
/dev/md0                       3.6M    144K    3.2M     4%    /var
# mount
/dev/redboot/fbsd-root.uzip on / (ufs, local, noatime, read-only)
devfs on /dev (devfs, local)
/dev/redboot/fbsd-data on /flash (ufs, local, noatime)
/dev/md0 on /var (ufs, local)









_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by Oleksandr Tymoshenko-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Eric wrote:

> On Mon, 2009-10-26 at 18:11 +1300, Andrew Thompson wrote:
>> On Mon, Oct 26, 2009 at 11:37:52AM +0800, Eric wrote:
>>> Hi
>>> I added my ar7161 board support last weekend.
>>> It's flash is come from Spansion.
>> This is great. Oleksandr has also just added write support which will
>> conflict/duplicate some of your changes so have a look and merge any
>> outstanding changes you have made (s25fl128 support).
>>
>> http://svn.freebsd.org/viewvc/base?view=revision&revision=198465
>>
>> cheers,
>> Andrew
>
> At first, I have my own write support, then I saw hit commit today.
> So this patch already merged his commit.
     There are some excessive code in the patch. e.g. GEOM will take care for
use that data offset and size are sector-size aligned/multiple. So I reworked
your patch a little bit:
     http://people.freebsd.org/~gonzo/mips/mx25.diff

Could you, please, test it and let me know if it works for you.

Thanks!
_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by Eric L. Chen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 2009-10-28 at 22:52 -0700, Oleksandr Tymoshenko wrote:

> Eric wrote:
> > On Mon, 2009-10-26 at 18:11 +1300, Andrew Thompson wrote:
> >> On Mon, Oct 26, 2009 at 11:37:52AM +0800, Eric wrote:
> >>> Hi
> >>> I added my ar7161 board support last weekend.
> >>> It's flash is come from Spansion.
> >> This is great. Oleksandr has also just added write support which will
> >> conflict/duplicate some of your changes so have a look and merge any
> >> outstanding changes you have made (s25fl128 support).
> >>
> >> http://svn.freebsd.org/viewvc/base?view=revision&revision=198465
> >>
> >> cheers,
> >> Andrew
> >
> > At first, I have my own write support, then I saw hit commit today.
> > So this patch already merged his commit.
>      There are some excessive code in the patch. e.g. GEOM will take care for
> use that data offset and size are sector-size aligned/multiple. So I reworked
> your patch a little bit:
>      http://people.freebsd.org/~gonzo/mips/mx25.diff
>
> Could you, please, test it and let me know if it works for you.
>
> Thanks!

It cannot format redboot partition by newfs:
uhub1: 2 ports with 2 removable, self powered
redboot/fbsd-root.uzip: 6144 x 8192 blocks
Trying to mount root from ufs:/dev/redboot/fbsd-root.uzip
warning: no time-of-day clock registered, system time will not be set
accurately
start_init: trying /etc/init
eval: cannot create /flash/hostid: Read-only file system
/etc/rc: WARNING: could not store hostuuid in /flash/hostid.
mount: /dev/ufs/config : No such file or directory
Mounting /etc/fstab filesystems failed,  startup aborted
ERROR: ABORTING BOOT (sending SIGTERM to parent)!
Oct 27 01:58:39 init: /bin/sh on /etc/rc terminated abnormally, going to
single user mode
Enter full pathname of shell or RETURN for /bin/sh:
                                                    #
#
# df
Filesystem                  512-blocks  Used Avail Capacity  Mounted on
/dev/redboot/fbsd-root.uzip      98078 62252 27980    69%    /
devfs                                2     2     0   100%    /dev
# ls /dev/redboot
FIS directory RedBoot config fbsd-kern fbsd-root.uzip vmlinux.bin.l7
RedBoot fbsd-data fbsd-root rootfs
# newfs -n -o space -L config -O 1 -b 4096 -f 512 /dev/redboot/fbsd-data
/dev/redboot/fbsd-data: 0.6MB (1280 sectors) block size 4096, fragment
size 512
        using 4 cylinder groups of 0.16MB, 41 blks, 96 inodes.
super-block backups (for fsck -b #) at:
newfs: wtfs: 20480 bytes at sector 32: Invalid argument
# reboot
Waiting (max 60 seconds) for system process `vnlru' to stop...done
Waiting (max 60 seconds) for system process `bufdaemon' to stop...done
Waiting (max 60 seconds) for system process `syncer' to stop...
Syncing disks, vnodes remaining...0 0 0 0 0 0 0 0 done
All buffers synced.
Uptime: 3m15s
Rebooting...
+phyReg16Val = 1b2b
phyReg20Val = d6d
Ethernet eth0: MAC address 00:03:7f:ff:ff:fe
IP: 192.168.1.81/255.255.255.0, Gateway: 0.0.0.0
Default server: 192.168.1.254

RedBoot(tm) bootstrap and debug environment [ROMRAM]
Non-certified release, version v1.0 - built 12:26:39, May 18 2009

Copyright (C) 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.

Board: RPAA-82
RAM: 0x80000000-0x84000000, [0x80051290-0x80fe1000] available
FLASH: 0xbf000000 - 0xbfff0000, 256 blocks of 0x00010000 bytes each.
== Executing boot script in 3.000 seconds - enter ^C to abort
^C
RedBoot> fis list
Name              FLASH addr  Mem addr    Length      Entry point
RedBoot           0xBF000000  0xBF000000  0x00040000  0x00000000
vmlinux.bin.l7    0xBF040000  0x80060000  0x00100000  0x80060000
rootfs            0xBF140000  0xBF140000  0x00400000  0x00000000
fbsd-kern         0xBF540000  0x80060000  0x00200000  0x800976C0
fbsd-root         0xBF740000  0xBF740000  0x00800000  0x00000000
fbsd-data         0xBFF40000  0xBFF40000  0x000A0000  0x00000000
FIS directory     0xBFFE0000  0xBFFE0000  0x0000F000  0x00000000
RedBoot config    0xBFFEF000  0xBFFEF000  0x00001000  0x00000000
RedBoot>



_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by Andrew Thompson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Nov 02, 2009 at 09:18:45AM +0800, Eric wrote:

> On Wed, 2009-10-28 at 22:52 -0700, Oleksandr Tymoshenko wrote:
> >      There are some excessive code in the patch. e.g. GEOM will take care for
> > use that data offset and size are sector-size aligned/multiple. So I reworked
> > your patch a little bit:
> >      http://people.freebsd.org/~gonzo/mips/mx25.diff
> >
> > Could you, please, test it and let me know if it works for you.
> >
> > Thanks!
>
> It cannot format redboot partition by newfs:
> uhub1: 2 ports with 2 removable, self powered
> redboot/fbsd-root.uzip: 6144 x 8192 blocks
> Trying to mount root from ufs:/dev/redboot/fbsd-root.uzip
> warning: no time-of-day clock registered, system time will not be set
> accurately
> start_init: trying /etc/init
> eval: cannot create /flash/hostid: Read-only file system
> /etc/rc: WARNING: could not store hostuuid in /flash/hostid.
> mount: /dev/ufs/config : No such file or directory
> Mounting /etc/fstab filesystems failed,  startup aborted
> ERROR: ABORTING BOOT (sending SIGTERM to parent)!
> Oct 27 01:58:39 init: /bin/sh on /etc/rc terminated abnormally, going to
> single user mode
> Enter full pathname of shell or RETURN for /bin/sh:
>                                                     #
> #
> # df
> Filesystem                  512-blocks  Used Avail Capacity  Mounted on
> /dev/redboot/fbsd-root.uzip      98078 62252 27980    69%    /
> devfs                                2     2     0   100%    /dev
> # ls /dev/redboot
> FIS directory RedBoot config fbsd-kern fbsd-root.uzip vmlinux.bin.l7
> RedBoot fbsd-data fbsd-root rootfs
> # newfs -n -o space -L config -O 1 -b 4096 -f 512 /dev/redboot/fbsd-data
> /dev/redboot/fbsd-data: 0.6MB (1280 sectors) block size 4096, fragment
> size 512
> using 4 cylinder groups of 0.16MB, 41 blks, 96 inodes.
> super-block backups (for fsck -b #) at:
> newfs: wtfs: 20480 bytes at sector 32: Invalid argument

The problem here is the flash sector size is 64k. Pretending the flash
has a 512b sector isnt the right way, you would be better off having a
geom class to do the transformation+caching.


Andrew
_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by Eric L. Chen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2009-11-02 at 14:23 +1300, Andrew Thompson wrote:

> On Mon, Nov 02, 2009 at 09:18:45AM +0800, Eric wrote:
> > On Wed, 2009-10-28 at 22:52 -0700, Oleksandr Tymoshenko wrote:
> > >      There are some excessive code in the patch. e.g. GEOM will take care for
> > > use that data offset and size are sector-size aligned/multiple. So I reworked
> > > your patch a little bit:
> > >      http://people.freebsd.org/~gonzo/mips/mx25.diff
> > >
> > > Could you, please, test it and let me know if it works for you.
> > >
> > > Thanks!
> >
> > It cannot format redboot partition by newfs:
> > uhub1: 2 ports with 2 removable, self powered
> > redboot/fbsd-root.uzip: 6144 x 8192 blocks
> > Trying to mount root from ufs:/dev/redboot/fbsd-root.uzip
> > warning: no time-of-day clock registered, system time will not be set
> > accurately
> > start_init: trying /etc/init
> > eval: cannot create /flash/hostid: Read-only file system
> > /etc/rc: WARNING: could not store hostuuid in /flash/hostid.
> > mount: /dev/ufs/config : No such file or directory
> > Mounting /etc/fstab filesystems failed,  startup aborted
> > ERROR: ABORTING BOOT (sending SIGTERM to parent)!
> > Oct 27 01:58:39 init: /bin/sh on /etc/rc terminated abnormally, going to
> > single user mode
> > Enter full pathname of shell or RETURN for /bin/sh:
> >                                                     #
> > #
> > # df
> > Filesystem                  512-blocks  Used Avail Capacity  Mounted on
> > /dev/redboot/fbsd-root.uzip      98078 62252 27980    69%    /
> > devfs                                2     2     0   100%    /dev
> > # ls /dev/redboot
> > FIS directory RedBoot config fbsd-kern fbsd-root.uzip vmlinux.bin.l7
> > RedBoot fbsd-data fbsd-root rootfs
> > # newfs -n -o space -L config -O 1 -b 4096 -f 512 /dev/redboot/fbsd-data
> > /dev/redboot/fbsd-data: 0.6MB (1280 sectors) block size 4096, fragment
> > size 512
> > using 4 cylinder groups of 0.16MB, 41 blks, 96 inodes.
> > super-block backups (for fsck -b #) at:
> > newfs: wtfs: 20480 bytes at sector 32: Invalid argument
>
> The problem here is the flash sector size is 64k. Pretending the flash
> has a 512b sector isnt the right way, you would be better off having a
> geom class to do the transformation+caching.
>
>
> Andrew

So, the better way is that add a new geom class to support different
erase and program size?
I referred XOR flash sys/dev/cfi/cfi_disk.c at first. It set disk sector
size to 512 even erase size is 128k.



--
Best Regards,
Eric L. Chen <lihong@...>

_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."

Re: Add Wistron RPAA-82 board support

by M. Warner Losh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In message: <1257126338.3097.7.camel@localhost>
            Eric <lihong@...> writes:
: On Mon, 2009-11-02 at 14:23 +1300, Andrew Thompson wrote:
: > On Mon, Nov 02, 2009 at 09:18:45AM +0800, Eric wrote:
: > > On Wed, 2009-10-28 at 22:52 -0700, Oleksandr Tymoshenko wrote:
: > > >      There are some excessive code in the patch. e.g. GEOM will take care for
: > > > use that data offset and size are sector-size aligned/multiple. So I reworked
: > > > your patch a little bit:
: > > >      http://people.freebsd.org/~gonzo/mips/mx25.diff
: > > >
: > > > Could you, please, test it and let me know if it works for you.
: > > >
: > > > Thanks!
: > >
: > > It cannot format redboot partition by newfs:
: > > uhub1: 2 ports with 2 removable, self powered
: > > redboot/fbsd-root.uzip: 6144 x 8192 blocks
: > > Trying to mount root from ufs:/dev/redboot/fbsd-root.uzip
: > > warning: no time-of-day clock registered, system time will not be set
: > > accurately
: > > start_init: trying /etc/init
: > > eval: cannot create /flash/hostid: Read-only file system
: > > /etc/rc: WARNING: could not store hostuuid in /flash/hostid.
: > > mount: /dev/ufs/config : No such file or directory
: > > Mounting /etc/fstab filesystems failed,  startup aborted
: > > ERROR: ABORTING BOOT (sending SIGTERM to parent)!
: > > Oct 27 01:58:39 init: /bin/sh on /etc/rc terminated abnormally, going to
: > > single user mode
: > > Enter full pathname of shell or RETURN for /bin/sh:
: > >                                                     #
: > > #
: > > # df
: > > Filesystem                  512-blocks  Used Avail Capacity  Mounted on
: > > /dev/redboot/fbsd-root.uzip      98078 62252 27980    69%    /
: > > devfs                                2     2     0   100%    /dev
: > > # ls /dev/redboot
: > > FIS directory RedBoot config fbsd-kern fbsd-root.uzip vmlinux.bin.l7
: > > RedBoot fbsd-data fbsd-root rootfs
: > > # newfs -n -o space -L config -O 1 -b 4096 -f 512 /dev/redboot/fbsd-data
: > > /dev/redboot/fbsd-data: 0.6MB (1280 sectors) block size 4096, fragment
: > > size 512
: > > using 4 cylinder groups of 0.16MB, 41 blks, 96 inodes.
: > > super-block backups (for fsck -b #) at:
: > > newfs: wtfs: 20480 bytes at sector 32: Invalid argument
: >
: > The problem here is the flash sector size is 64k. Pretending the flash
: > has a 512b sector isnt the right way, you would be better off having a
: > geom class to do the transformation+caching.
: >
: >
: > Andrew
:
: So, the better way is that add a new geom class to support different
: erase and program size?
: I referred XOR flash sys/dev/cfi/cfi_disk.c at first. It set disk sector
: size to 512 even erase size is 128k.

Yea.  That's not quite right...  when I did the spi flash, I exported
the actual write sector size.  on SPI flash, however, you don't have
to erase it: the controller will do that for you (it is less
efficient, however).

We do need to have a good geom layer that does this.  We also need a
good flash file system as well...

Warner
_______________________________________________
freebsd-mips@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-mips
To unsubscribe, send any mail to "freebsd-mips-unsubscribe@..."