SAMA5: Add logic to auto-mount a file system on AT25 SPI FLASH for NSH

This commit is contained in:
Gregory Nutt 2013-08-05 08:24:39 -06:00
parent 854df0ef8d
commit 94d84d74b0
6 changed files with 242 additions and 13 deletions

View File

@ -42,4 +42,33 @@ config SAMA5_NOR_START
option: If SAMA5_NOR_START is defined, then it will not wait but option: If SAMA5_NOR_START is defined, then it will not wait but
will, instead, immediately start the program in NOR FLASH. will, instead, immediately start the program in NOR FLASH.
config SAMA5_AT25_AUTOMOUNT
bool "AT25 auto-mount"
default n
depends on NSH_ARCHINIT && SAMA5_SPI0 && MTD_AT25
---help---
Automatically initialize the AT25 SPI FLASH driver when NSH starts.
choice
prompt "AT25 configuration"
default SAMA5_AT25_FTL
depends on SAMA5_AT25_AUTOMOUNT
config SAMA5_AT25_FTL
bool "Create AT25 block driver"
---help---
Create the MTD driver for the AT25 and "wrap" the AT25 is a standard
block driver that could then, for example, be mounted using FAT or
any other file system. Any file system may be used, but there will
be no wear-leveling.
config SAMA5_AT25_NXFFS
bool "Create AT25 NXFFS file system"
depends on FS_NXFFS
---help---
Create the MTD driver for the AT25 and and mount the AT25 device as
a wear-leveling, NuttX FLASH file system (NXFFS). The downside of
NXFFS is that it can be very slow.
endchoice
endif endif

View File

@ -857,7 +857,11 @@ Configurations
4. This configuration has support for NSH built-in applications enabled. 4. This configuration has support for NSH built-in applications enabled.
However, no built-in applications are selected in the base configuration. However, no built-in applications are selected in the base configuration.
5. SDRAM support can be enabled by adding the following to your NuttX 5. This configuration has support for the FAT file system built in. However,
by default, there are no block drivers intialized. The FAT file system can
still be used to create RAM disks.
6. SDRAM support can be enabled by adding the following to your NuttX
configuration file: configuration file:
System Type->ATSAMA5 Peripheral Support System Type->ATSAMA5 Peripheral Support
@ -881,7 +885,7 @@ Configurations
Another thing you could do is to enable the RAM test built-in Another thing you could do is to enable the RAM test built-in
application: application:
6. You can enable the NuttX RAM test that may be used to verify the 7. You can enable the NuttX RAM test that may be used to verify the
external SDAM. To do this, keep the SDRAM out of the heap so that external SDAM. To do this, keep the SDRAM out of the heap so that
it can be tested without crashing programs using the memory: it can be tested without crashing programs using the memory:
@ -921,15 +925,7 @@ Configurations
RAMTest: Pattern test: 20000000 268435456 33333333 cccccccc RAMTest: Pattern test: 20000000 268435456 33333333 cccccccc
RAMTest: Address-in-address test: 20000000 268435456 RAMTest: Address-in-address test: 20000000 268435456
STATUS: 8. The Embest or Ronetix CPU module includes an Atmel AT25DF321A,
2013-7-19: This configuration (as do the others) run at 396MHz.
The SAMA5D3 can run at 536MHz. I still need to figure out the
PLL settings to get that speed.
If the CPU speed changes, then so must the NOR and SDRAM
initialization!
7. The Embest or Ronetix CPU module includes an Atmel AT25DF321A,
32-megabit, 2.7-volt SPI serial flash. Support for that serial 32-megabit, 2.7-volt SPI serial flash. Support for that serial
FLASH can be enabled by modifying the NuttX configuration as FLASH can be enabled by modifying the NuttX configuration as
follows: follows:
@ -947,6 +943,24 @@ Configurations
CONFIG_AT25_SPIMODE=0 : Use SPI mode 0 CONFIG_AT25_SPIMODE=0 : Use SPI mode 0
CONFIG_AT25_SPIFREQUENCY=20000000 : Use SPI frequency 20MHz CONFIG_AT25_SPIFREQUENCY=20000000 : Use SPI frequency 20MHz
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : NSH board-initialization
Board Selection
CONFIG_SAMA5_AT25_AUTOMOUNT=y : Mounts AT25 for NSH
CONFIG_SAMA5_AT25_FTL=y : Create block driver for FAT
NOTE that you must close JP1 on the Embest/Ronetix board in
order to enable the AT25 FLASH chip select.
STATUS:
2013-7-19: This configuration (as do the others) run at 396MHz.
The SAMA5D3 can run at 536MHz. I still need to figure out the
PLL settings to get that speed.
If the CPU speed changes, then so must the NOR and SDRAM
initialization!
2013-7-31: I have been unable to execute this configuration from NOR 2013-7-31: I have been unable to execute this configuration from NOR
FLASH by closing the BMS jumper (J9). As far as I can tell, this FLASH by closing the BMS jumper (J9). As far as I can tell, this
jumper does nothing on my board??? I have been using the norboot jumper does nothing on my board??? I have been using the norboot

View File

@ -164,6 +164,10 @@ CONFIG_SAMA5_USART1=y
# CONFIG_SAMA5_MPDDRC is not set # CONFIG_SAMA5_MPDDRC is not set
# CONFIG_PIO_IRQ is not set # CONFIG_PIO_IRQ is not set
#
# SPI device driver options
#
# #
# External Memory Configuration # External Memory Configuration
# #
@ -392,8 +396,17 @@ CONFIG_USART1_2STOP=0
# #
# File system configuration # File system configuration
# #
CONFIG_DISABLE_MOUNTPOINT=y # CONFIG_DISABLE_MOUNTPOINT is not set
# CONFIG_FS_RAMMAP is not set # CONFIG_FS_RAMMAP is not set
CONFIG_FS_FAT=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FAT_MAXFNAME=32
# CONFIG_FS_FATTIME is not set
# CONFIG_FAT_DMAMEMORY is not set
# CONFIG_FS_NXFFS is not set
# CONFIG_FS_ROMFS is not set
# CONFIG_FS_SMARTFS is not set
# CONFIG_FS_BINFS is not set # CONFIG_FS_BINFS is not set
# #

View File

@ -66,6 +66,10 @@ ifeq ($(CONFIG_SAMA5_NOR_MAIN),y)
CSRCS += nor_main.c CSRCS += nor_main.c
endif endif
ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += sam_nsh.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y) ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c CSRCS += sam_autoleds.c
else else

View File

@ -0,0 +1,169 @@
/****************************************************************************
* config/sama5d3x-ek/src/sam_nsh.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/mount.h>
#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
#include <debug.h>
#ifdef CONFIG_SAMA5_SPI0
# include <nuttx/spi/spi.h>
# include <nuttx/mtd.h>
# include <nuttx/fs/nxffs.h>
# include "sam_spi.h"
#endif
#include "sama5d3x-ek.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Can't support the AT25 device if it SPI0 or AT25 support are not enabled */
#define HAVE_AT25 1
#if !defined(CONFIG_SAMA5_SPI0) || !defined(CONFIG_MTD_AT25)
# undef HAVE_AT25
#endif
/* Can't support AT25 features if mountpoints are disabled or if we were not
* asked to mount the AT25 part
*/
#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_SAMA5_AT25_AUTOMOUNT)
# undef HAVE_AT25
#endif
/* If we are going to mount the AT25, then they user must also have told
* us what to do with it by setting one of these.
*/
#if !defined(CONFIG_SAMA5_AT25_FTL) && !defined(CONFIG_SAMA5_AT25_NXFFS)
# undef HAVE_AT25
#endif
#if defined(CONFIG_SAMA5_AT25_FTL) && defined(CONFIG_SAMA5_AT25_NXFFS)
# warning Both CONFIG_SAMA5_AT25_FTL and CONFIG_SAMA5_AT25_NXFFS are set
# warning Ignoring CONFIG_SAMA5_AT25_NXFFS
# undef CONFIG_SAMA5_AT25_NXFFS
#endif
/* Use minor device number 0 is not is provided */
#ifndef CONFIG_NSH_MMCSDMINOR
# define CONFIG_NSH_MMCSDMINOR 0
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_archinitialize
*
* Description:
* Perform architecture specific initialization
*
****************************************************************************/
int nsh_archinitialize(void)
{
#ifdef HAVE_AT25
FAR struct spi_dev_s *spi;
FAR struct mtd_dev_s *mtd;
int ret;
/* Get the SPI port driver */
spi = up_spiinitialize(AT25_PORT);
if (!spi)
{
fdbg("ERROR: Failed to initialize SPI port %d\n", AT25_PORT);
return -ENODEV;
}
/* Now bind the SPI interface to the AT25 SPI FLASH driver */
mtd = at25_initialize(spi);
if (!mtd)
{
fdbg("ERROR: Failed to bind SPI port %d to the AT25 FLASH driver\n");
return -ENODEV;
}
#if defined(CONFIG_SAMA5_AT25_FTL)
/* And finally, use the FTL layer to wrap the MTD driver as a block driver */
ret = ftl_initialize(CONFIG_NSH_MMCSDMINOR, mtd);
if (ret < 0)
{
fdbg("ERROR: Initialize the FTL layer\n");
return ret;
}
#elif defined(CONFIG_SAMA5_AT25_NXFFS)
/* Initialize to provide NXFFS on the MTD interface */
ret = nxffs_initialize(mtd);
if (ret < 0)
{
fdbg("ERROR: NXFFS initialization failed: %d\n", -ret);
return ret;
}
/* Mount the file system at /mnt/at25 */
ret = mount(NULL, "/mnt/at25", "nxffs", 0, NULL);
if (ret < 0)
{
fdbg("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
return ret;
}
#endif
#endif
return OK;
}

View File

@ -114,7 +114,7 @@
#define GPIO_AT25_NPCS0 (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \ #define GPIO_AT25_NPCS0 (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \
GPIO_PORT_PIOD | GPIO_PIN13) GPIO_PORT_PIOD | GPIO_PIN13)
#define AT25_CSNUM 0 #define AT25_PORT SPI0_CS0
/************************************************************************************ /************************************************************************************
* Public Types * Public Types