Esempio n. 1
0
static void nor_init()
{
	if(!nor_device_init(&nor_device))
	{
		mtd_register(&nor_device.mtd);

#ifdef S5L8900
		images_setup();
#endif
		nvram_setup();
		syscfg_setup();
	}
}
Esempio n. 2
0
FAR struct mtd_dev_s *mtd_rwb_initialize(FAR struct mtd_dev_s *mtd)
{
  FAR struct mtd_rwbuffer_s *priv;
  struct mtd_geometry_s geo;
  int ret;

  fvdbg("mtd: %p\n", mtd);
  DEBUGASSERT(mtd && mtd->ioctl);

  /* Get the device geometry */

  ret = mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
  if (ret < 0)
    {
      fdbg("ERROR: MTDIOC_GEOMETRY ioctl failed: %d\n", ret);
      return NULL;
    }

  /* Allocate a state structure (we allocate the structure instead of using
   * a fixed, static allocation so that we can handle multiple FLASH devices.
   * The current implementation would handle only one FLASH part per SPI
   * device (only because of the SPIDEV_FLASH definition) and so would have
   * to be extended to handle multiple FLASH parts on the same SPI bus.
   */

  priv = (FAR struct mtd_rwbuffer_s *)kmm_zalloc(sizeof(struct mtd_rwbuffer_s));
  if (priv)
    {
      /* Initialize the allocated structure. (unsupported methods/fields
       * were already nullified by kmm_zalloc).
       */

      priv->mtd.erase    = mtd_erase;  /* Our MTD erase method */
      priv->mtd.bread    = mtd_bread;  /* Our MTD bread method */
      priv->mtd.bwrite   = mtd_bwrite; /* Our MTD bwrite method */
      priv->mtd.read     = mtd_read;   /* Our MTD read method */
      priv->mtd.ioctl    = mtd_ioctl;  /* Our MTD ioctl method */

      priv->dev          = mtd;        /* The contained MTD instance */

      /* Sectors per block.  The erase block size must be an even multiple
       * of the sector size.
       */

      priv->spb          = geo.erasesize / geo.blocksize;
      DEBUGASSERT((size_t)priv->spb * geo_blocksize = geo.erasesize);

      /* Values must be provided to rwb_initialize() */
      /* Supported geometry */

      priv->rwb.blocksize = geo.blocksize;
      priv->rwb.nblocks   = geo.neraseblocks * priv->spb;

      /* Buffer setup */

#ifdef CONFIG_DRVR_WRITEBUFFER
      priv->rwb.wrmaxblocks = CONFIG_MTD_NWRBLOCKS;
#endif
#ifdef CONFIG_DRVR_READAHEAD
      priv->rwb.rhmaxblocks = CONFIG_MTD_NRDBLOCKS;
#endif

      /* Callouts */

      priv->rwb.dev       = priv;             /* Device state passed to callouts */
      priv->rwb.wrflush   = mtd_flush;        /* Callout to flush buffer */
      priv->rwb.rhreload  = mtd_reload;       /* Callout to reload buffer */

      /* Initialize read-ahead/write buffering */

      ret = rwb_initialize(&priv->rwb);
      if (ret < 0)
        {
          fdbg("ERROR: rwb_initialize failed: %d\n", ret);
          kmm_free(priv);
          return NULL;
        }
    }

  /* Register the MTD with the procfs system if enabled */

#ifdef CONFIG_MTD_REGISTRATION
  mtd_register(&priv->mtd, "rwbuffer");
#endif

  /* Return the implementation-specific state structure as the MTD device */

  fvdbg("Return %p\n", priv);
  return &priv->mtd;
}
Esempio n. 3
0
FAR struct mtd_dev_s *blockmtd_initialize(FAR const char *path, size_t offset,
                                          size_t mtdlen, int16_t sectsize,
                                          int32_t erasesize)
{
  FAR struct file_dev_s *priv;
  size_t nblocks;
  int mode;
  int ret;
  int fd;

  /* Create an instance of the FILE MTD device state structure */

  priv = (FAR struct file_dev_s *)kmm_zalloc(sizeof(struct file_dev_s));
  if (!priv)
    {
      ferr("ERROR: Failed to allocate the FILE MTD state structure\n");
      return NULL;
    }

  /* Determine the file open mode */

  mode  = O_RDOK;
#ifdef CONFIG_FS_WRITABLE
  mode |= O_WROK;
#endif

  /* Try to open the file.  NOTE that block devices will use a character
   * driver proxy.
   */

  fd = open(path, mode);
  if (fd <0)
    {
      ferr("ERROR: Failed to open the FILE MTD file %s\n", path);
      kmm_free(priv);
      return NULL;
    }

  /* Detach the file descriptor from the open file */

  ret = file_detach(fd, &priv->mtdfile);
  if (ret < 0)
    {
      ferr("ERROR: Failed to detail the FILE MTD file %s\n", path);
      close(fd);
      kmm_free(priv);
      return NULL;
    }

  /* Set the block size based on the provided sectsize parameter */

  if (sectsize <= 0)
    {
      priv->blocksize = CONFIG_FILEMTD_BLOCKSIZE;
    }
  else
    {
      priv->blocksize = sectsize;
    }

  /* Set the erase size based on the provided erasesize parameter */

  if (erasesize <= 0)
    {
      priv->erasesize = CONFIG_FILEMTD_ERASESIZE;
    }
  else
    {
      priv->erasesize = erasesize;
    }

  /* Force the size to be an even number of the erase block size */

  nblocks = mtdlen / priv->erasesize;
  if (nblocks < 3)
    {
      ferr("ERROR: Need to provide at least three full erase block\n");
      file_close_detached(&priv->mtdfile);
      kmm_free(priv);
      return NULL;
    }

  /* Perform initialization as necessary. (unsupported methods were
   * nullified by kmm_zalloc).
   */

  priv->mtd.erase  = filemtd_erase;
  priv->mtd.bread  = filemtd_bread;
  priv->mtd.bwrite = filemtd_bwrite;
  priv->mtd.read   = filemtd_byteread;
#ifdef CONFIG_MTD_BYTE_WRITE
  priv->mtd.write  = file_bytewrite;
#endif
  priv->mtd.ioctl  = filemtd_ioctl;
  priv->offset     = offset;
  priv->nblocks    = nblocks;

#ifdef CONFIG_MTD_REGISTRATION
  /* Register the MTD with the procfs system if enabled */

  mtd_register(&priv->mtd, "filemtd");
#endif

  return &priv->mtd;
}