static void up_init_smartfs(void)
{
  FAR struct mtd_dev_s *mtd;
  FAR struct spi_dev_s *spi;

  /* Initialize a simulated SPI FLASH block device m25p MTD driver */

  spi = up_spiflashinitialize();
  mtd = m25p_initialize(spi);

  /* Now initialize a SMART Flash block device and bind it to the MTD device */

  smart_initialize(0, mtd, NULL);
}
int smart_main(int argc, char *argv[])
{
  FAR struct mtd_dev_s *mtd;
  unsigned int i;
  int ret;

  /* Seed the random number generated */

  srand(0x93846);

  /* Create and initialize a RAM MTD device instance */

#ifdef CONFIG_EXAMPLES_SMART_ARCHINIT
  mtd = smart_archinitialize();
#else
  mtd = rammtd_initialize(g_simflash, EXAMPLES_SMART_BUFSIZE);
#endif
  if (!mtd)
    {
      message("ERROR: Failed to create RAM MTD instance\n");
      msgflush();
      exit(1);
    }

  /* Initialize to provide SMART on an MTD interface */

  MTD_IOCTL(mtd, MTDIOC_BULKERASE, 0);
  ret = smart_initialize(1, mtd);
  if (ret < 0)
    {
      message("ERROR: SMART initialization failed: %d\n", -ret);
      msgflush();
      exit(2);
    }

  /* Creaet a SMARTFS filesystem */

  ret = mksmartfs("/dev/smart1");

  /* Mount the file system */

  ret = mount("/dev/smart1", CONFIG_EXAMPLES_SMART_MOUNTPT, "smartfs", 0, NULL);
  if (ret < 0)
    {
      message("ERROR: Failed to mount the SMART volume: %d\n", errno);
      msgflush();
      exit(3);
    }

  /* Set up memory monitoring */

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_mmbefore = mallinfo();
  g_mmprevious = g_mmbefore;
#else
  (void)mallinfo(&g_mmbefore);
  memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo));
#endif

  /* Loop a few times ... file the file system with some random, files,
   * delete some files randomly, fill the file system with more random file,
   * delete, etc.  This beats the FLASH very hard!
   */

#if CONFIG_EXAMPLES_SMART_NLOOPS == 0
  for (i = 0; ; i++)
#else
  for (i = 1; i <= CONFIG_EXAMPLES_SMART_NLOOPS; i++)
#endif
    {
      /* Write a files to the SMART file system until either (1) all of the
       * open file structures are utilized or until (2) SMART reports an error
       * (hopefully that the file system is full)
       */

      message("\n=== FILLING %d =============================\n", i);
      ret = smart_fillfs();
      message("Filled file system\n");
      message("  Number of files: %d\n", g_nfiles);
      message("  Number deleted:  %d\n", g_ndeleted);

      /* Directory listing */

      smart_directory();

      /* Verify all files written to FLASH */

      ret = smart_verifyfs();
      if (ret < 0)
        {
          message("ERROR: Failed to verify files\n");
          message("  Number of files: %d\n", g_nfiles);
          message("  Number deleted:  %d\n", g_ndeleted);
        }
      else
        {
#if CONFIG_EXAMPLES_SMART_VERBOSE != 0
          message("Verified!\n");
          message("  Number of files: %d\n", g_nfiles);
          message("  Number deleted:  %d\n", g_ndeleted);
#endif
        }

      /* Delete some files */

      message("\n=== DELETING %d ============================\n", i);
      ret = smart_delfiles();
      if (ret < 0)
        {
          message("ERROR: Failed to delete files\n");
          message("  Number of files: %d\n", g_nfiles);
          message("  Number deleted:  %d\n", g_ndeleted);
        }
      else
        {
          message("Deleted some files\n");
          message("  Number of files: %d\n", g_nfiles);
          message("  Number deleted:  %d\n", g_ndeleted);
        }

      /* Directory listing */

      smart_directory();

      /* Verify all files written to FLASH */

      ret = smart_verifyfs();
      if (ret < 0)
        {
          message("ERROR: Failed to verify files\n");
          message("  Number of files: %d\n", g_nfiles);
          message("  Number deleted:  %d\n", g_ndeleted);
        }
      else
        {
#if CONFIG_EXAMPLES_SMART_VERBOSE != 0
          message("Verified!\n");
          message("  Number of files: %d\n", g_nfiles);
          message("  Number deleted:  %d\n", g_ndeleted);
#endif
        }

      /* Show memory usage */

      smart_loopmemusage();
      msgflush();
    }

  /* Delete all files then show memory usage again */

  smart_delallfiles();
  smart_endmemusage();
  msgflush();
  return 0;
}
int nsh_archinitialize(void)
{
#if defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR)
    int ret;
#endif
#ifdef CONFIG_STM32_SPI3
    FAR struct spi_dev_s *spi;
    FAR struct mtd_dev_s *mtd;
#endif
    int ret;

    /* Configure SPI-based devices */

#ifdef CONFIG_STM32_SPI3
    /* Get the SPI port */

    message("nsh_archinitialize: Initializing SPI port 3\n");
    spi = up_spiinitialize(3);
    if (!spi)
    {
        message("nsh_archinitialize: Failed to initialize SPI port 3\n");
        return -ENODEV;
    }

    message("nsh_archinitialize: Successfully initialized SPI port 3\n");

    /* Now bind the SPI interface to the M25P8 SPI FLASH driver */

#if defined(CONFIG_MTD) && defined(CONFIG_MIKROE_FLASH)
    message("nsh_archinitialize: Bind SPI to the SPI flash driver\n");
    mtd = m25p_initialize(spi);
    if (!mtd)
    {
        message("nsh_archinitialize: Failed to bind SPI port 3 to the SPI FLASH driver\n");
    }
    else
    {
        message("nsh_archinitialize: Successfully bound SPI port 3 to the SPI FLASH driver\n");

#ifdef CONFIG_MIKROE_FLASH_PART
        {
            int partno;
            int partsize;
            int partoffset;
            const char *partstring = CONFIG_MIKROE_FLASH_PART_LIST;
            const char *ptr;
            FAR struct mtd_dev_s *mtd_part;
            char  partname[4];

            /* Now create a partition on the FLASH device */

            partno = 0;
            ptr = partstring;
            partoffset = 0;

            while (*ptr != '\0')
            {
                /* Get the partition size */

                partsize = atoi(ptr);
                mtd_part = mtd_partition(mtd, partoffset, (partsize>>2)*16);
                partoffset += (partsize >> 2) * 16;

#ifdef CONFIG_MIKROE_FLASH_CONFIG_PART
                /* Test if this is the config partition */

                if (CONFIG_MIKROE_FLASH_CONFIG_PART_NUMBER == partno)
                {
                    /* Register the partition as the config device */

                    mtdconfig_register(mtd_part);
                }
                else
#endif
                {
                    /* Now initialize a SMART Flash block device and bind it
                     * to the MTD device.
                     */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
                    sprintf(partname, "p%d", partno);
                    smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd_part, partname);
#endif
                }

                /* Update the pointer to point to the next size in the list */

                while ((*ptr >= '0') && (*ptr <= '9'))
                {
                    ptr++;
                }

                if (*ptr == ',')
                {
                    ptr++;
                }

                /* Increment the part number */

                partno++;
            }
#else /* CONFIG_MIKROE_FLASH_PART */

        /* Configure the device with no partition support */

        smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd, NULL);

#endif /* CONFIG_MIKROE_FLASH_PART */
        }
    }

    /* Create a RAM MTD device if configured */

#if defined(CONFIG_RAMMTD) && defined(CONFIG_MIKROE_RAMMTD)
    {
        uint8_t *start = (uint8_t *) kmalloc(CONFIG_MIKROE_RAMMTD_SIZE * 1024);
        mtd = rammtd_initialize(start, CONFIG_MIKROE_RAMMTD_SIZE * 1024);
        mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);

        /* Now initialize a SMART Flash block device and bind it to the MTD device */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
        smart_initialize(CONFIG_MIKROE_RAMMTD_MINOR, mtd, NULL);
#endif
    }

#endif /* CONFIG_RAMMTD && CONFIG_MIKROE_RAMMTD */

#endif /* CONFIG_MTD */
#endif /* CONFIG_STM32_SPI3 */

    /* Create the SPI FLASH MTD instance */
    /* The M25Pxx is not a good media to implement a file system..
     * its block sizes are too large
     */

    /* Mount the SDIO-based MMC/SD block driver */

#ifdef NSH_HAVEMMCSD
    /* Bind the spi interface to the MMC/SD driver */

    message("nsh_archinitialize: Bind SDIO to the MMC/SD driver, minor=%d\n",
            CONFIG_NSH_MMCSDMINOR);
    ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi);
    if (ret != OK)
    {
        message("nsh_archinitialize: Failed to bind SPI to the MMC/SD driver: %d\n", ret);
    }
    else
    {
        message("nsh_archinitialize: Successfully bound SPI to the MMC/SD driver\n");
    }
#endif

#ifdef HAVE_USBHOST
    /* Initialize USB host operation.  stm32_usbhost_initialize() starts a thread
     * will monitor for USB connection and disconnection events.
     */

    ret = stm32_usbhost_initialize();
    if (ret != OK)
    {
        message("nsh_archinitialize: Failed to initialize USB host: %d\n", ret);
        return ret;
    }
#endif

#ifdef HAVE_USBMONITOR
    /* Start the USB Monitor */

    ret = usbmonitor_start(0, NULL);
    if (ret != OK)
    {
        message("nsh_archinitialize: Start USB monitor: %d\n", ret);
    }
#endif

#ifdef CONFIG_LCD_MIO283QT2
    /* Configure the TFT LCD module */

    message("nsh_archinitialize: Initializing TFT LCD module\n");

    ret = up_lcdinitialize();
    if (ret != OK)
    {
        message("nsh_archinitialize: Failed to initialize TFT LCD module\n");
    }

#endif

    /* Configure the Audio sub-system if enabled and bind it to SPI 3 */

#ifdef CONFIG_AUDIO

    up_vs1053initialize(spi);

#endif

    return OK;
}
Beispiel #4
0
int board_app_initialize(void)
{
#if defined(CONFIG_STM32_SPI4)
  FAR struct spi_dev_s *spi;
  FAR struct mtd_dev_s *mtd;
  FAR struct mtd_geometry_s geo;
#endif

#if defined(CONFIG_MTD_PARTITION_NAMES)
  FAR const char *partname = CONFIG_STM32F429I_DISCO_FLASH_PART_NAMES;
#endif

#if defined(CONFIG_MTD) && defined(CONFIG_MTD_SST25XX)
  int ret;
#elif defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR)
  int ret;
#endif

  /* Configure SPI-based devices */

#ifdef CONFIG_STM32_SPI4
  /* Get the SPI port */

  syslog(LOG_INFO, "Initializing SPI port 4\n");

  spi = stm32_spibus_initialize(4);
  if (!spi)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize SPI port 4\n");
      return -ENODEV;
    }

  syslog(LOG_INFO, "Successfully initialized SPI port 4\n");

  /* Now bind the SPI interface to the SST25F064 SPI FLASH driver.  This
   * is a FLASH device that has been added external to the board (i.e.
   * the board does not ship from STM with any on-board FLASH.
   */

#if defined(CONFIG_MTD) && defined(CONFIG_MTD_SST25XX)
  syslog(LOG_INFO, "Bind SPI to the SPI flash driver\n");

  mtd = sst25xx_initialize(spi);
  if (!mtd)
    {
      syslog(LOG_ERR, "ERROR: Failed to bind SPI port 4 to the SPI FLASH driver\n");
    }
  else
    {
      syslog(LOG_INFO, "Successfully bound SPI port 4 to the SPI FLASH driver\n");

      /* Get the geometry of the FLASH device */

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

#ifdef CONFIG_STM32F429I_DISCO_FLASH_PART
      {
        int partno;
        int partsize;
        int partoffset;
        int partszbytes;
        int erasesize;
        const char *partstring = CONFIG_STM32F429I_DISCO_FLASH_PART_LIST;
        const char *ptr;
        FAR struct mtd_dev_s *mtd_part;
        char  partref[4];

        /* Now create a partition on the FLASH device */

        partno = 0;
        ptr = partstring;
        partoffset = 0;

        /* Get the Flash erase size */

        erasesize = geo.erasesize;

        while (*ptr != '\0')
          {
            /* Get the partition size */

            partsize = atoi(ptr);
            partszbytes = (partsize << 10); /* partsize is defined in KB */

            /* Check if partition size is bigger then erase block */

            if (partszbytes < erasesize)
              {
                fdbg("ERROR: Partition size is lesser than erasesize!\n");
                return -1;
              }

            /* Check if partition size is multiple of erase block */

            if ((partszbytes % erasesize) != 0)
              {
                fdbg("ERROR: Partition size is not multiple of erasesize!\n");
                return -1;
              }

            mtd_part    = mtd_partition(mtd, partoffset, partszbytes / erasesize);
            partoffset += partszbytes / erasesize;

#ifdef CONFIG_STM32F429I_DISCO_FLASH_CONFIG_PART
            /* Test if this is the config partition */

            if (CONFIG_STM32F429I_DISCO_FLASH_CONFIG_PART_NUMBER == partno)
              {
                /* Register the partition as the config device */

                mtdconfig_register(mtd_part);
              }
            else
#endif
              {
                /* Now initialize a SMART Flash block device and bind it
                 * to the MTD device.
                 */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
                sprintf(partref, "p%d", partno);
                smart_initialize(CONFIG_STM32F429I_DISCO_FLASH_MINOR, mtd_part, partref);
#endif
              }

#if defined(CONFIG_MTD_PARTITION_NAMES)
            /* Set the partition name */

            if (mtd_part == NULL)
              {
                dbg("Error: failed to create partition %s\n", partname);
                return -1;
              }

            mtd_setpartitionname(mtd_part, partname);

            /* Now skip to next name.  We don't need to split the string here
             * because the MTD partition logic will only display names up to
             * the comma, thus allowing us to use a single static name
             * in the code.
             */

            while (*partname != ',' && *partname != '\0')
              {
                /* Skip to next ',' */

                partname++;
              }

            if (*partname == ',')
              {
                partname++;
              }
#endif

            /* Update the pointer to point to the next size in the list */

            while ((*ptr >= '0') && (*ptr <= '9'))
              {
                ptr++;
              }

            if (*ptr == ',')
              {
                ptr++;
              }

            /* Increment the part number */

            partno++;
          }
      }
#else /* CONFIG_STM32F429I_DISCO_FLASH_PART */

      /* Configure the device with no partition support */

      smart_initialize(CONFIG_STM32F429I_DISCO_FLASH_MINOR, mtd, NULL);

#endif /* CONFIG_STM32F429I_DISCO_FLASH_PART */
    }

#endif /* CONFIG_MTD */
#endif /* CONFIG_STM32_SPI4 */

  /* Create a RAM MTD device if configured */

#if defined(CONFIG_RAMMTD) && defined(CONFIG_STM32F429I_DISCO_RAMMTD)
  {
    uint8_t *start = (uint8_t *) kmm_malloc(CONFIG_STM32F429I_DISCO_RAMMTD_SIZE * 1024);
    mtd = rammtd_initialize(start, CONFIG_STM32F429I_DISCO_RAMMTD_SIZE * 1024);
    mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);

    /* Now initialize a SMART Flash block device and bind it to the MTD device */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
    smart_initialize(CONFIG_STM32F429I_DISCO_RAMMTD_MINOR, mtd, NULL);
#endif
  }

#endif /* CONFIG_RAMMTD && CONFIG_STM32F429I_DISCO_RAMMTD */

#ifdef HAVE_USBHOST
  /* Initialize USB host operation.  stm32_usbhost_initialize() starts a thread
   * will monitor for USB connection and disconnection events.
   */

  ret = stm32_usbhost_initialize();
  if (ret != OK)
    {
      syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", ret);
      return ret;
    }
#endif

#ifdef HAVE_USBMONITOR
  /* Start the USB Monitor */

  ret = usbmonitor_start(0, NULL);
  if (ret != OK)
    {
      syslog(LOG_ERR, "ERROR: Failed to start USB monitor: %d\n", ret);
    }
#endif

  return OK;
}
Beispiel #5
0
static void up_init_smartfs(void)
{
  FAR struct mtd_dev_s *mtd;
  int minor = 0;
#if defined(CONFIG_MTD_M25P) || defined(CONFIG_MTD_W25) || defined(CONFIG_MTD_SST26)
  FAR struct spi_dev_s *spi;
#endif
#ifdef CONFIG_MTD_N25QXXX
  FAR struct qspi_dev_s *qspi;
#endif

#ifdef CONFIG_SIM_SPIFLASH
#ifdef CONFIG_MTD_M25P
  /* Initialize a simulated SPI FLASH block device m25p MTD driver */

  spi = up_spiflashinitialize("m25p");
  if (spi != NULL)
    {
      mtd = m25p_initialize(spi);

      /* Now initialize a SMART Flash block device and bind it to the MTD device */

      if (mtd != NULL)
        {
          smart_initialize(minor++, mtd, "_m25p");
        }
    }
#endif

#ifdef CONFIG_MTD_SST26
  /* Initialize a simulated SPI FLASH block device sst26 MTD driver */

  spi = up_spiflashinitialize("sst26");
  if (spi != NULL)
    {
      mtd = sst26_initialize_spi(spi);

      /* Now initialize a SMART Flash block device and bind it to the MTD device */

      if (mtd != NULL)
        {
          smart_initialize(minor++, mtd, "_sst26");
        }
    }
#endif

#ifdef CONFIG_MTD_W25
  /* Initialize a simulated SPI FLASH block device w25 MTD driver */

  spi = up_spiflashinitialize("w25");
  if (spi != NULL)
    {
      mtd = w25_initialize(spi);

      /* Now initialize a SMART Flash block device and bind it to the MTD device */

      if (mtd != NULL)
        {
          smart_initialize(minor++, mtd, "_w25");
        }
    }
#endif
#endif      /* CONFIG_SIM_SPIFLASH */

#if defined(CONFIG_MTD_N25QXXX) && defined(CONFIG_SIM_QSPIFLASH)
  /* Initialize a simulated SPI FLASH block device n25qxxx MTD driver */

  qspi = up_qspiflashinitialize();
  if (qspi != NULL)
    {
      mtd = n25qxxx_initialize(qspi, 0);

      /* Now initialize a SMART Flash block device and bind it to the MTD device */

      if (mtd != NULL)
        {
          smart_initialize(minor++, mtd, "_n25q");
        }
    }
#endif
}
Beispiel #6
0
int board_app_initialize(uintptr_t arg)
{
#ifdef HAVE_RTC_DRIVER
  FAR struct rtc_lowerhalf_s *rtclower;
#endif
#if defined(HAVE_N25QXXX)
FAR struct mtd_dev_s *mtd_temp;
#endif
#if defined(HAVE_N25QXXX_CHARDEV)
  char blockdev[18];
  char chardev[12];
#endif
  int ret;

  (void)ret;

#ifdef HAVE_PROC
  /* mount the proc filesystem */

  syslog(LOG_INFO, "Mounting procfs to /proc\n");

  ret = mount(NULL, CONFIG_NSH_PROC_MOUNTPOINT, "procfs", 0, NULL);
  if (ret < 0)
    {
      syslog(LOG_ERR,
             "ERROR: Failed to mount the PROC filesystem: %d (%d)\n",
             ret, errno);
      return ret;
    }
#endif

#ifdef HAVE_RTC_DRIVER
  /* Instantiate the STM32 lower-half RTC driver */

  rtclower = stm32l4_rtc_lowerhalf();
  if (!rtclower)
    {
      serr("ERROR: Failed to instantiate the RTC lower-half driver\n");
      return -ENOMEM;
    }
  else
    {
      /* Bind the lower half driver and register the combined RTC driver
       * as /dev/rtc0
       */

      ret = rtc_initialize(0, rtclower);
      if (ret < 0)
        {
          serr("ERROR: Failed to bind/register the RTC driver: %d\n", ret);
          return ret;
        }
    }
#endif

#ifdef HAVE_N25QXXX
  /* Create an instance of the STM32L4 QSPI device driver */

  g_qspi = stm32l4_qspi_initialize(0);
  if (!g_qspi)
    {
      _err("ERROR: stm32l4_qspi_initialize failed\n");
      return ret;
    }
  else
    {
      /* Use the QSPI device instance to initialize the
       * N25QXXX device.
       */

      mtd_temp = n25qxxx_initialize(g_qspi, true);
      if (!mtd_temp)
        {
          _err("ERROR: n25qxxx_initialize failed\n");
          return ret;
        }
      g_mtd_fs = mtd_temp;

#ifdef CONFIG_MTD_PARTITION
      {
        FAR struct mtd_geometry_s geo;
        off_t nblocks;

        /* Setup a partition of 256KiB for our file system. */

        ret = MTD_IOCTL(g_mtd_fs, MTDIOC_GEOMETRY, (unsigned long)(uintptr_t)&geo);
        if (ret < 0)
          {
            _err("ERROR: MTDIOC_GEOMETRY failed\n");
            return ret;
          }

        nblocks = (256*1024) / geo.blocksize;

        mtd_temp = mtd_partition(g_mtd_fs, 0, nblocks);
        if (!mtd_temp)
          {
            _err("ERROR: mtd_partition failed\n");
            return ret;
          }

        g_mtd_fs = mtd_temp;
      }
#endif

#ifdef HAVE_N25QXXX_SMARTFS
      /* Configure the device with no partition support */

      ret = smart_initialize(N25QXXX_SMART_MINOR, g_mtd_fs, NULL);
      if (ret != OK)
        {
          _err("ERROR: Failed to initialize SmartFS: %d\n", ret);
        }

#elif defined(HAVE_N25QXXX_NXFFS)
      /* Initialize to provide NXFFS on the N25QXXX MTD interface */

      ret = nxffs_initialize(g_mtd_fs);
      if (ret < 0)
        {
         _err("ERROR: NXFFS initialization failed: %d\n", ret);
        }

      /* Mount the file system at /mnt/nxffs */

      ret = mount(NULL, "/mnt/nxffs", "nxffs", 0, NULL);
      if (ret < 0)
        {
          _err("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
          return ret;
        }

#else /* if  defined(HAVE_N25QXXX_CHARDEV) */
      /* Use the FTL layer to wrap the MTD driver as a block driver */

      ret = ftl_initialize(N25QXXX_MTD_MINOR, g_mtd_fs);
      if (ret < 0)
        {
          _err("ERROR: Failed to initialize the FTL layer: %d\n", ret);
          return ret;
        }

      /* Use the minor number to create device paths */

      snprintf(blockdev, 18, "/dev/mtdblock%d", N25QXXX_MTD_MINOR);
      snprintf(chardev, 12, "/dev/mtd%d", N25QXXX_MTD_MINOR);

      /* Now create a character device on the block device */

      /* NOTE:  for this to work, you will need to make sure that
       * CONFIG_FS_WRITABLE is set in the config.  It's not a user-
       * visible setting, but you can make it set by selecting an
       * arbitrary writable file system (you don't have to actually
       * use it, just select it so that the block device created via
       * ftl_initialize() will be writable).
       */

      ret = bchdev_register(blockdev, chardev, false);
      if (ret < 0)
        {
          _err("ERROR: bchdev_register %s failed: %d\n", chardev, ret);
          return ret;
        }
#endif
    }
#endif

#ifdef HAVE_USBHOST
  /* Initialize USB host operation.  stm32l4_usbhost_initialize() starts a thread
   * will monitor for USB connection and disconnection events.
   */

  ret = stm32l4_usbhost_initialize();
  if (ret != OK)
    {
      udbg("ERROR: Failed to initialize USB host: %d\n", ret);
      return ret;
    }
#endif

#ifdef HAVE_USBMONITOR
  /* Start the USB Monitor */

  ret = usbmonitor_start(0, NULL);
  if (ret != OK)
    {
      udbg("ERROR: Failed to start USB monitor: %d\n", ret);
      return ret;
    }
#endif

  return OK;
}
Beispiel #7
0
int board_initialize(void)
{
	int ret;
	char partref[4];
	char devname[16];
#ifdef CONFIG_MTD
	FAR struct mtd_dev_s *mtd;
	FAR struct mtd_geometry_s geo;
	FAR struct mtd_dev_s *mtd_part;
#endif
	int partno = QEMU_SMARTFS_PARTITION_PARTNO;
	int minorno = QEMU_SMARTFS_PARTITION_MINORNO;
	int partoffset = QEMU_SMARTFS_PARTITION_START;
	int partsize = QEMU_SMARTFS_PARTITION_SIZE;

#ifdef CONFIG_MTD
	mtd = up_flashinitialize();

	if (!mtd) {
		lldbg("ERROR : up_flashinitializ failed\n");
		return ERROR;
	}

	if (mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)&geo) < 0) {
		lldbg("ERROR: mtd->ioctl failed\n");
		return ERROR;
	}

#ifdef CONFIG_MTD_PARTITION
	mtd_part = mtd_partition(mtd, partoffset, partsize / geo.blocksize, partno);
	if (!mtd_part) {
		lldbg("ERROR: failed to create partition.\n");
		return ERROR;
	}
#endif /* CONFIG_MTD_PARTITION */

	ret = snprintf(partref, sizeof(partref), "p%d", partno);
	if (ret < 0) {
		lldbg("ERROR: snprintf failed while constructing partref, ret = %d\n", ret);
		return ERROR;
	}

	if (ret >= sizeof(partref)) {
		lldbg("WARNING: snprintf output might have truncated, ret = %d\n", ret);
	}

	ret = snprintf(devname, sizeof(devname), "/dev/smart%d%s", minorno, partref);
	if (ret < 0) {
		lldbg("ERROR: snprintf failed while constructing devname, ret = %d\n", ret);
		return ERROR;
	}

	if (ret >= sizeof(devname)) {
		lldbg("WARNING: snprintf output might have truncated, ret = %d\n", ret);
	}


#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
	smart_initialize(minorno, mtd_part, partref);
#endif /* defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS) */

#endif /* CONFIG_MTD */

	ret = mksmartfs(devname, false);

	if (ret != OK) {
		lldbg("ERROR: mksmartfs on %s failed, ret = %d\n", devname, ret);
	} else {
		ret = mount(devname, QEMU_SMARTFS_MOUNT_POINT, "smartfs", 0, NULL);
		if (ret != OK) {
			lldbg("ERROR: mounting '%s' failed, ret = %d\n", devname, ret);
		} else {
			lldbg("%s is mounted successfully at %s \n", devname, QEMU_SMARTFS_MOUNT_POINT);
		}
	}

	return OK;
}
int sam_bringup(void)
{
#ifdef HAVE_S25FL1
  FAR struct qspi_dev_s *qspi;
#endif
#if defined(HAVE_S25FL1) || defined(HAVE_PROGMEM_CHARDEV)
  FAR struct mtd_dev_s *mtd;
#endif
#if defined(HAVE_RTC_DSXXXX) || defined(HAVE_RTC_PCF85263)
  FAR struct i2c_master_s *i2c;
#endif
#if defined(HAVE_S25FL1_CHARDEV) || defined(HAVE_PROGMEM_CHARDEV)
  char blockdev[18];
  char chardev[12];
#endif
  int ret;

  /* Register I2C drivers on behalf of the I2C tool */

  sam_i2ctool();

#if defined(HAVE_RTC_PCF85263)
  /* Get an instance of the TWIHS0 I2C interface */

  i2c = sam_i2cbus_initialize(PCF85263_TWI_BUS);
  if (i2c == NULL)
    {
      SYSLOG("ERROR: sam_i2cbus_initialize(%d) failed\n", PCF85263_TWI_BUS);
    }
  else
    {
      /* Use the I2C interface to initialize the PCF2863 timer */

      ret = pcf85263_rtc_initialize(i2c);
      if (ret < 0)
        {
          SYSLOG("ERROR: pcf85263_rtc_initialize() failed: %d\n", ret);
        }
      else
        {
          /* Synchronize the system time to the RTC time */

          clock_synchronize();
        }
    }

#elif defined(HAVE_RTC_DSXXXX)
  /* Get an instance of the TWIHS0 I2C interface */

  i2c = sam_i2cbus_initialize(DSXXXX_TWI_BUS);
  if (i2c == NULL)
    {
      SYSLOG("ERROR: sam_i2cbus_initialize(%d) failed\n", DSXXXX_TWI_BUS);
    }
  else
    {
      /* Use the I2C interface to initialize the DSXXXX timer */

      ret = dsxxxx_rtc_initialize(i2c);
      if (ret < 0)
        {
          SYSLOG("ERROR: dsxxxx_rtc_initialize() failed: %d\n", ret);
        }
      else
        {
          /* Synchronize the system time to the RTC time */

          clock_synchronize();
        }
    }
#endif

#ifdef HAVE_MACADDR
  /* Read the Ethernet MAC address from the AT24 FLASH and configure the
   * Ethernet driver with that address.
    */

  ret = sam_emac0_setmac();
  if (ret < 0)
    {
      SYSLOG("ERROR: sam_emac0_setmac() failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_FS_PROCFS
  /* Mount the procfs file system */

  ret = mount(NULL, SAMV71_PROCFS_MOUNTPOINT, "procfs", 0, NULL);
  if (ret < 0)
    {
      SYSLOG("ERROR: Failed to mount procfs at %s: %d\n",
             SAMV71_PROCFS_MOUNTPOINT, ret);
    }
#endif

#ifdef HAVE_MTDCONFIG
  /* Create an AT24xx-based MTD configuration device for storage device
   * configuration information.
   */

  ret = sam_at24config();
  if (ret < 0)
    {
      SYSLOG("ERROR: sam_at24config() failed: %d\n", ret);
    }
#endif

#ifdef HAVE_HSMCI
  /* Initialize the HSMCI0 driver */

  ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR);
  if (ret < 0)
    {
      SYSLOG("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
             HSMCI0_SLOTNO, HSMCI0_MINOR, ret);
    }

#ifdef CONFIG_SAMV71XULT_HSMCI0_MOUNT
  else
    {
      /* REVISIT:  A delay seems to be required here or the mount will fail. */
      /* Mount the volume on HSMCI0 */

      ret = mount(CONFIG_SAMV71XULT_HSMCI0_MOUNT_BLKDEV,
                  CONFIG_SAMV71XULT_HSMCI0_MOUNT_MOUNTPOINT,
                  CONFIG_SAMV71XULT_HSMCI0_MOUNT_FSTYPE,
                  0, NULL);

      if (ret < 0)
        {
          SYSLOG("ERROR: Failed to mount %s: %d\n",
                 CONFIG_SAMV71XULT_HSMCI0_MOUNT_MOUNTPOINT, errno);
        }
    }

#endif /* CONFIG_SAMV71XULT_HSMCI0_MOUNT */
#endif /* HAVE_HSMCI */

#ifdef HAVE_AUTOMOUNTER
  /* Initialize the auto-mounter */

  sam_automount_initialize();
#endif

#ifdef HAVE_ROMFS
  /* Create a ROM disk for the /etc filesystem */

  ret = romdisk_register(CONFIG_SAMV71XULT_ROMFS_ROMDISK_MINOR, romfs_img,
                         NSECTORS(romfs_img_len),
                         CONFIG_SAMV71XULT_ROMFS_ROMDISK_SECTSIZE);
  if (ret < 0)
    {
      SYSLOG("ERROR: romdisk_register failed: %d\n", -ret);
    }
  else
    {
      /* Mount the file system */

      ret = mount(CONFIG_SAMV71XULT_ROMFS_ROMDISK_DEVNAME,
                  CONFIG_SAMV71XULT_ROMFS_MOUNT_MOUNTPOINT,
                  "romfs", MS_RDONLY, NULL);
      if (ret < 0)
        {
          SYSLOG("ERROR: mount(%s,%s,romfs) failed: %d\n",
                 CONFIG_SAMV71XULT_ROMFS_ROMDISK_DEVNAME,
                 CONFIG_SAMV71XULT_ROMFS_MOUNT_MOUNTPOINT, errno);
        }
    }
#endif

#ifdef HAVE_S25FL1
  /* Create an instance of the SAMV71 QSPI device driver */

  qspi = sam_qspi_initialize(0);
  if (!qspi)
    {
      SYSLOG("ERROR: sam_qspi_initialize failed\n");
    }
  else
    {
      /* Use the QSPI device instance to initialize the
       * S25FL1 device.
       */

      mtd = s25fl1_initialize(qspi, true);
      if (!mtd)
        {
          SYSLOG("ERROR: s25fl1_initialize failed\n");
        }

#ifdef HAVE_S25FL1_SMARTFS
      /* Configure the device with no partition support */

      ret = smart_initialize(S25FL1_SMART_MINOR, mtd, NULL);
      if (ret != OK)
        {
          SYSLOG("ERROR: Failed to initialize SmartFS: %d\n", ret);
        }

#elif defined(HAVE_S25FL1_NXFFS)
      /* Initialize to provide NXFFS on the S25FL1 MTD interface */

      ret = nxffs_initialize(mtd);
      if (ret < 0)
        {
         SYSLOG("ERROR: NXFFS initialization failed: %d\n", ret);
        }

      /* Mount the file system at /mnt/s25fl1 */

      ret = mount(NULL, "/mnt/s25fl1", "nxffs", 0, NULL);
      if (ret < 0)
        {
          SYSLOG("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
          return ret;
        }

#else /* if  defined(HAVE_S25FL1_CHARDEV) */
      /* Use the FTL layer to wrap the MTD driver as a block driver */

      ret = ftl_initialize(S25FL1_MTD_MINOR, mtd);
      if (ret < 0)
        {
          SYSLOG("ERROR: Failed to initialize the FTL layer: %d\n", ret);
          return ret;
        }

      /* Use the minor number to create device paths */

      snprintf(blockdev, 18, "/dev/mtdblock%d", S25FL1_MTD_MINOR);
      snprintf(chardev, 12, "/dev/mtd%d", S25FL1_MTD_MINOR);

      /* Now create a character device on the block device */

      ret = bchdev_register(blockdev, chardev, false);
      if (ret < 0)
        {
          SYSLOG("ERROR: bchdev_register %s failed: %d\n", chardev, ret);
          return ret;
        }
#endif
    }
#endif

#ifdef HAVE_PROGMEM_CHARDEV
  /* Initialize the SAMV71 FLASH programming memory library */

  sam_progmem_initialize();

  /* Create an instance of the SAMV71 FLASH program memory device driver */

  mtd = progmem_initialize();
  if (!mtd)
    {
      SYSLOG("ERROR: progmem_initialize failed\n");
    }

  /* Use the FTL layer to wrap the MTD driver as a block driver */

  ret = ftl_initialize(PROGMEM_MTD_MINOR, mtd);
  if (ret < 0)
    {
      SYSLOG("ERROR: Failed to initialize the FTL layer: %d\n", ret);
      return ret;
    }

  /* Use the minor number to create device paths */

  snprintf(blockdev, 18, "/dev/mtdblock%d", PROGMEM_MTD_MINOR);
  snprintf(chardev, 12, "/dev/mtd%d", PROGMEM_MTD_MINOR);

  /* Now create a character device on the block device */

  ret = bchdev_register(blockdev, chardev, false);
  if (ret < 0)
    {
      SYSLOG("ERROR: bchdev_register %s failed: %d\n", chardev, ret);
      return ret;
    }
#endif

#ifdef HAVE_USBHOST
  /* Initialize USB host operation.  sam_usbhost_initialize() starts a thread
   * will monitor for USB connection and disconnection events.
   */

  ret = sam_usbhost_initialize();
  if (ret != OK)
    {
      SYSLOG("ERROR: Failed to initialize USB host: %d\n", ret);
    }
#endif

#ifdef HAVE_USBMONITOR
  /* Start the USB Monitor */

  ret = usbmonitor_start(0, NULL);
  if (ret != OK)
    {
      SYSLOG("ERROR: Failed to start the USB monitor: %d\n", ret);
    }
#endif

#ifdef HAVE_WM8904
  /* Configure WM8904 audio */

  ret = sam_wm8904_initialize(0);
  if (ret != OK)
    {
      SYSLOG("ERROR: Failed to initialize WM8904 audio: %d\n", ret);
    }
#endif

#ifdef HAVE_AUDIO_NULL
  /* Configure the NULL audio device */

  ret = sam_audio_null_initialize(0);
  if (ret != OK)
    {
      SYSLOG("ERROR: Failed to initialize the NULL audio device: %d\n", ret);
    }
#endif

#ifdef HAVE_ELF
  /* Initialize the ELF binary loader */

  SYSLOG("Initializing the ELF binary loader\n");
  ret = elf_initialize();
  if (ret < 0)
    {
      SYSLOG("ERROR: Initialization of the ELF loader failed: %d\n", ret);
    }
#endif

  /* If we got here then perhaps not all initialization was successful, but
   * at least enough succeeded to bring-up NSH with perhaps reduced
   * capabilities.
   */

  UNUSED(ret);
  return OK;
}
int nsh_archinitialize(void)
{
#if defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR)
  int ret;
#endif
#if defined(CONFIG_STM32_SPI5) || defined(CONFIG_STM32_SPI4)
  FAR struct spi_dev_s *spi;
  FAR struct mtd_dev_s *mtd;
#endif
#if defined(CONFIG_MTD_PARTITION_NAMES)
  FAR const char *partname = CONFIG_STM32F429I_DISCO_FLASH_PART_NAMES;
#endif

  /* Configure SPI-based devices */

#ifdef CONFIG_STM32_SPI4
  /* Get the SPI port */

  message("nsh_archinitialize: Initializing SPI port 4\n");
  spi = up_spiinitialize(4);
  if (!spi)
    {
      message("nsh_archinitialize: Failed to initialize SPI port 4\n");
      return -ENODEV;
    }

  message("nsh_archinitialize: Successfully initialized SPI port 4\n");

  /* Now bind the SPI interface to the SST25F064 SPI FLASH driver.  This
   * is a FLASH device that has been added external to the board (i.e.
   * the board does not ship from STM with any on-board FLASH.
   */

#if defined(CONFIG_MTD) && defined(CONFIG_MTD_SST25XX)
  message("nsh_archinitialize: Bind SPI to the SPI flash driver\n");
  mtd = sst25xx_initialize(spi);
  if (!mtd)
    {
      message("nsh_archinitialize: Failed to bind SPI port 4 to the SPI FLASH driver\n");
    }
  else
    {
      message("nsh_archinitialize: Successfully bound SPI port 4 to the SPI FLASH driver\n");

#ifdef CONFIG_STM32F429I_DISCO_FLASH_PART
      {
        int partno;
        int partsize;
        int partoffset;
        const char *partstring = CONFIG_STM32F429I_DISCO_FLASH_PART_LIST;
        const char *ptr;
        FAR struct mtd_dev_s *mtd_part;
        char  partref[4];

        /* Now create a partition on the FLASH device */

        partno = 0;
        ptr = partstring;
        partoffset = 0;

        while (*ptr != '\0')
          {
            /* Get the partition size */

            partsize = atoi(ptr);
            mtd_part = mtd_partition(mtd, partoffset, (partsize>>2) * 16);
            partoffset += (partsize >> 2) * 16;

#ifdef CONFIG_STM32F429I_DISCO_FLASH_CONFIG_PART
            /* Test if this is the config partition */

            if (CONFIG_STM32F429I_DISCO_FLASH_CONFIG_PART_NUMBER == partno)
              {
                /* Register the partition as the config device */

                mtdconfig_register(mtd_part);
              }
            else
#endif
              {
                /* Now initialize a SMART Flash block device and bind it
                 * to the MTD device.
                 */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
                sprintf(partref, "p%d", partno);
                smart_initialize(CONFIG_STM32F429I_DISCO_FLASH_MINOR, mtd_part, partref);
#endif
              }

            /* Set the partition name */

#if defined(CONFIG_MTD_PARTITION_NAMES)
            mtd_setpartitionname(mtd_part, partname);

            /* Now skip to next name.  We don't need to split the string here
             * because the MTD partition logic will only display names up to
             * the comma, thus allowing us to use a single static name
             * in the code.
             */

            while (*partname != ',' && *partname != '\0')
              {
                /* Skip to next ',' */

                partname++;
              }
            if (*partname == ',')
              {
                partname++;
              }
#endif

            /* Update the pointer to point to the next size in the list */

            while ((*ptr >= '0') && (*ptr <= '9'))
              {
                ptr++;
              }

            if (*ptr == ',')
              {
                ptr++;
              }

            /* Increment the part number */

            partno++;
          }
      }
#else /* CONFIG_STM32F429I_DISCO_FLASH_PART */

      /* Configure the device with no partition support */

      smart_initialize(CONFIG_STM32F429I_DISCO_FLASH_MINOR, mtd, NULL);

#endif /* CONFIG_STM32F429I_DISCO_FLASH_PART */
    }

#endif /* CONFIG_MTD */
#endif /* CONFIG_STM32_SPI4 */

  /* Create a RAM MTD device if configured */

#if defined(CONFIG_RAMMTD) && defined(CONFIG_STM32F429I_DISCO_RAMMTD)
  {
    uint8_t *start = (uint8_t *) kmalloc(CONFIG_STM32F429I_DISCO_RAMMTD_SIZE * 1024);
    mtd = rammtd_initialize(start, CONFIG_STM32F429I_DISCO_RAMMTD_SIZE * 1024);
    mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);

    /* Now initialize a SMART Flash block device and bind it to the MTD device */

#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
    smart_initialize(CONFIG_STM32F429I_DISCO_RAMMTD_MINOR, mtd, NULL);
#endif
  }

#endif /* CONFIG_RAMMTD && CONFIG_STM32F429I_DISCO_RAMMTD */

#ifdef HAVE_USBHOST
  /* Initialize USB host operation.  stm32_usbhost_initialize() starts a thread
   * will monitor for USB connection and disconnection events.
   */

  ret = stm32_usbhost_initialize();
  if (ret != OK)
    {
      message("nsh_archinitialize: Failed to initialize USB host: %d\n", ret);
      return ret;
    }

#ifdef CONFIG_USBHOST_MSC
  /* Initialize the USB storage class */

  ret = usbhost_storageinit();
  if (ret != OK)
    {
      message("nsh_archinitialize: Failed to initialize USB host storage: %d\n", ret);
      return ret;
    }

#endif

#endif

#ifdef HAVE_USBMONITOR
  /* Start the USB Monitor */

  ret = usbmonitor_start(0, NULL);
  if (ret != OK)
    {
      message("nsh_archinitialize: Start USB monitor: %d\n", ret);
    }
#endif

  return OK;
}