Create an MTD driver for SPIFI
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4951 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
4a44aa0ab9
commit
c61de9ca3a
@ -903,22 +903,20 @@ Where <subdir> is one of the following:
|
||||
This configuration has some special options that can be used to
|
||||
create a block device on the SPIFI FLASH. NOTE: CONFIG_LPC43_SPIFI=y
|
||||
must also be defined to enable SPIFI setup support:
|
||||
|
||||
CONFIG_SPIFI_BLKDRVR - Enable to create a block driver on the SPFI
|
||||
device.
|
||||
CONFIG_SPIFI_DEVNO - SPIFI minor device number. The SPFI device will
|
||||
be at /dev/ramN, where N is the value of CONFIG_SPIFI_DEVNO.
|
||||
Default: 0.
|
||||
CONFIG_SPIFI_RDONLY - Create a read only device on SPIFI.
|
||||
CONFIG_SPIFI_OFFSET - Offset the beginning of the block driver this
|
||||
many bytes into the device address space. Default 0.
|
||||
CONFIG_SPIFI_BLKSIZE - The size of one block. SPIFI is not block
|
||||
oriented, so most any size of the block used in the SPIFI block
|
||||
device can be used. NOTE: FAT will support only sector sizes of
|
||||
512, 1024, 2048, or 4096. Default: 512
|
||||
CONFIG_SPIFI_NBLOCKS - The number of blocks in the file system,
|
||||
each of size CONFIG_SPIFI_BLKSIZE. The end of the file system
|
||||
will be at device offset:
|
||||
CONFIG_SPIFI_OFFSET + CONFIG_SPIFI_BLKSIZE*CONFIG_SPIFI_NBLOCKS
|
||||
The must assure that this does offset does not go beyond the end
|
||||
of the FLASH memory.
|
||||
|
||||
SPIFI device geometry:
|
||||
|
||||
CONFIG_SPIFI_OFFSET - Offset the beginning of the block driver this many
|
||||
bytes into the device address space. This offset must be an exact
|
||||
multiple of the erase block size (CONFIG_SPIFI_BLKSIZE). Default 0.
|
||||
CONFIG_SPIFI_BLKSIZE - The size of one device erase block. If not defined
|
||||
then the driver will try to determine the correct erase block size by
|
||||
examining that data returned from spifi_initialize (which sometimes
|
||||
seems bad).
|
||||
|
||||
Other SPIFI options
|
||||
|
||||
CONFIG_SPIFI_SECTOR512 - If defined, then the driver will report a more
|
||||
FAT friendly 512 byte sector size and will manage the read-modify-write
|
||||
operations on the larger erase block.
|
||||
CONFIG_SPIFI_READONLY - Define to support only read-only operations.
|
||||
|
@ -658,35 +658,31 @@ CONFIG_MMCSD_MMCSUPPORT=n
|
||||
CONFIG_MMCSD_HAVECARDDETECT=n
|
||||
|
||||
#
|
||||
# This configuration has some special options that can be used to
|
||||
# create a block device on the SPIFI FLASH. NOTE: CONFIG_LPC43_SPIFI=y
|
||||
# The SPIFI drvier has some special options that can be used to
|
||||
# create an MTD device on the SPIFI FLASH. NOTE: CONFIG_LPC43_SPIFI=y
|
||||
# must also be defined to enable SPIFI setup support:
|
||||
#
|
||||
# CONFIG_SPIFI_BLKDRVR - Enable to create a block driver on the SPFI
|
||||
# device.
|
||||
# CONFIG_SPIFI_DEVNO - SPIFI minor device number. The SPFI device will
|
||||
# be at /dev/rdN, where N is the value of CONFIG_SPIFI_DEVNO.
|
||||
# Default: 0.
|
||||
# CONFIG_SPIFI_RDONLY - Create a read only device on SPIFI.
|
||||
# CONFIG_SPIFI_OFFSET - Offset the beginning of the block driver this
|
||||
# many bytes into the device address space. Default 0.
|
||||
# CONFIG_SPIFI_BLKSIZE - The size of one block. SPIFI is not block
|
||||
# oriented, so most any size of the block used in the SPIFI block
|
||||
# device can be used. NOTE: FAT will support only sector sizes of 512,
|
||||
# 1024, 2048, or 4096. Default: 512
|
||||
# CONFIG_SPIFI_NBLOCKS - The number of blocks in the file system,
|
||||
# each of size CONFIG_SPIFI_BLKSIZE. The end of the file system
|
||||
# will be at device offset:
|
||||
# CONFIG_SPIFI_OFFSET + CONFIG_SPIFI_BLKSIZE*CONFIG_SPIFI_NBLOCKS
|
||||
# The must assure that this does offset does not go beyond the end
|
||||
# of the FLASH memory.
|
||||
# SPIFI device geometry:
|
||||
#
|
||||
# CONFIG_SPIFI_OFFSET - Offset the beginning of the block driver this many
|
||||
# bytes into the device address space. This offset must be an exact
|
||||
# multiple of the erase block size (CONFIG_SPIFI_BLKSIZE). Default 0.
|
||||
# CONFIG_SPIFI_BLKSIZE - The size of one device erase block. If not defined
|
||||
# then the driver will try to determine the correct erase block size by
|
||||
# examining that data returned from spifi_initialize (which sometimes
|
||||
# seems bad).
|
||||
#
|
||||
# Other SPIFI options
|
||||
#
|
||||
# CONFIG_SPIFI_SECTOR512 - If defined, then the driver will report a more
|
||||
# FAT friendly 512 byte sector size and will manage the read-modify-write
|
||||
# operations on the larger erase block.
|
||||
# CONFIG_SPIFI_READONLY - Define to support only read-only operations.
|
||||
#
|
||||
CONFIG_SPIFI_BLKDRVR=n
|
||||
CONFIG_SPIFI_DEVNO=0
|
||||
CONFIG_SPIFI_RDONLY=n
|
||||
CONFIG_SPIFI_OFFSET=0
|
||||
CONFIG_SPIFI_BLKSIZE=512
|
||||
CONFIG_SPIFI_NBLOCKS=(1024*1024/512)
|
||||
CONFIG_SPIFI_BLKSIZE=4096
|
||||
CONFIG_SPIFI_SECTOR512=y
|
||||
CONFIG_SPIFI_RDONLY=n
|
||||
|
||||
# TCP/IP and UDP support via uIP
|
||||
# CONFIG_NET - Enable or disable all network features
|
||||
|
@ -44,89 +44,25 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/ramdisk.h>
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
#ifdef CONFIG_SPIFI_BLKDRVR
|
||||
#ifdef CONFIG_LPC43_SPIFI
|
||||
# include <nuttx/mtd.h>
|
||||
# include "lpc43_spifi.h"
|
||||
|
||||
/* This should be removed someday when we are confident in SPIFI */
|
||||
|
||||
# ifdef CONFIG_DEBUG_FS
|
||||
# include "up_arch.h"
|
||||
# include "chip/lpc43_cgu.h"
|
||||
# include "chip/lpc43_ccu.h"
|
||||
# ifdef CONFIG_SPFI_NXFFS
|
||||
# include <sys/mount.h>
|
||||
# include <nuttx/fs/nxffs.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
/* SPIFI Configuration ******************************************************/
|
||||
/* This logic supports some special options that can be used to create a
|
||||
* block device on the SPIFI FLASH. NOTE: CONFIG_LPC43_SPIFI=y must also
|
||||
* be defined to enable SPIFI setup support:
|
||||
*
|
||||
* CONFIG_SPIFI_BLKDRVR - Enable to create a block driver on the SPFI device.
|
||||
* CONFIG_SPIFI_DEVNO - SPIFI minor device number. The SPFI device will be
|
||||
* at /dev/ramN, where N is the value of CONFIG_SPIFI_DEVNO. Default: 0.
|
||||
* CONFIG_SPIFI_RDONLY - Create a read only device on SPIFI.
|
||||
* CONFIG_SPIFI_OFFSET - Offset the beginning of the block driver this many
|
||||
* bytes into the device address space. Default 0.
|
||||
* CONFIG_SPIFI_BLKSIZE - The size of one block. SPIFI is not block oriented,
|
||||
* so most any size of the block used in the SPIFI block device can be
|
||||
* used. NOTE: FAT will support only sector sizes of 512, 1024, 2048, or
|
||||
* 4096. Default: 512
|
||||
* CONFIG_SPIFI_NBLOCKS - The number of blocks in the file system, each of
|
||||
* size CONFIG_SPIFI_BLKSIZE. The end of the file system will be at
|
||||
* device offset:
|
||||
* CONFIG_SPIFI_OFFSET + CONFIG_SPIFI_BLKSIZE*CONFIG_SPIFI_NBLOCKS
|
||||
* The must assure that this does offset does not go beyond the end of
|
||||
* the FLASH memory.
|
||||
*/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifdef CONFIG_SPIFI_BLKDRVR
|
||||
|
||||
# ifndef CONFIG_LPC43_SPIFI
|
||||
# error "SPIFI support is not enabled (CONFIG_LPC43_SPIFI)"
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_SPIFI_DEVNO
|
||||
# define CONFIG_SPIFI_DEVNO 0
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_SPIFI_OFFSET
|
||||
# define CONFIG_SPIFI_OFFSET 0
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_SPIFI_BLKSIZE
|
||||
# define CONFIG_SPIFI_BLKSIZE 512
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_SPIFI_NBLOCKS
|
||||
# error "Need number of SPIFI blocks (CONFIG_SPIFI_NBLOCKS)"
|
||||
# endif
|
||||
|
||||
# define SPIFI_BUFFER \
|
||||
(FAR uint8_t *)(LPC43_LOCSRAM_SPIFI_BASE + CONFIG_SPIFI_OFFSET)
|
||||
|
||||
#endif
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# else
|
||||
# define message printf
|
||||
# endif
|
||||
#ifndef CONFIG_SPIFI_DEVNO
|
||||
# define CONFIG_SPIFI_DEVNO 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@ -140,56 +76,53 @@
|
||||
* Make the SPIFI (or part of it) into a block driver that can hold a
|
||||
* file system.
|
||||
*
|
||||
* SPIFI AHB register clock:
|
||||
* Base clock = BASE_M4_CLK
|
||||
* Branch clock = CLK_M4_SPIFI
|
||||
* SPIFI serial clock input:
|
||||
* Base clock = BASE_SPIFI_CLK
|
||||
* Branch clock = SPIFI_CLK
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SPIFI_BLKDRVR
|
||||
#ifdef CONFIG_LPC43_SPIFI
|
||||
static int nsh_spifi_initialize(void)
|
||||
{
|
||||
FAR struct mtd_dev_s *mtd;
|
||||
int ret;
|
||||
|
||||
/* Initialize the SPIFI interface */
|
||||
/* Initialize the SPIFI interface and create the MTD driver instance */
|
||||
|
||||
ret = lpc43_spifi_initialize();
|
||||
mtd = lpc43_spifi_initialize();
|
||||
if (!mtd)
|
||||
{
|
||||
fdbg("ERROR: lpc43_spifi_initialize failed\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_SPFI_NXFFS
|
||||
/* And finally, use the FTL layer to wrap the MTD driver as a block driver */
|
||||
|
||||
ret = ftl_initialize(CONFIG_SPIFI_DEVNO, mtd);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("ERROR: lpc43_spifi_initialize failed: %d\n", ret);
|
||||
fdbg("ERROR: Initializing the FTL layer: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
/* Initialize to provide NXFFS on the MTD interface */1G
|
||||
|
||||
ret = nxffs_initialize(mtd);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("ERROR: NXFFS initialization failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This should be removed someday when we are confident in SPIFI */
|
||||
/* Mount the file system at /mnt/spifi */
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
fdbg("BASE_SPIFI_CLK=%08x\n",
|
||||
getreg32(LPC43_BASE_SPIFI_CLK));
|
||||
fdbg("SPFI CFG=%08x STAT=%08x\n",
|
||||
getreg32(LPC43_CCU1_SPIFI_CFG), getreg32(LPC43_CCU1_SPIFI_STAT));
|
||||
fdbg("M4 SPFI CFG=%08x STAT=%08x\n",
|
||||
getreg32(LPC43_CCU1_M4_SPIFI_CFG), getreg32(LPC43_CCU1_M4_SPIFI_STAT));
|
||||
ret = mount(NULL, "/mnt/spifi", "nxffs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SPIFI_RDONLY
|
||||
/* Register a read-only SPIFI RAM disk at /dev/ramN, where N is the
|
||||
* value of CONFIG_SPIFI_DEVNO.
|
||||
*/
|
||||
|
||||
return romdisk_register(CONFIG_SPIFI_DEVNO, SPIFI_BUFFER,
|
||||
CONFIG_SPIFI_NBLOCKS, CONFIG_SPIFI_BLKSIZE);
|
||||
#else
|
||||
/* Register a write-able SPIFI RAM disk at /dev/ramN, where N is the
|
||||
* value of CONFIG_SPIFI_DEVNO.
|
||||
*/
|
||||
|
||||
return ramdisk_register(CONFIG_SPIFI_DEVNO, SPIFI_BUFFER,
|
||||
CONFIG_SPIFI_NBLOCKS, CONFIG_SPIFI_BLKSIZE,
|
||||
true);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
#else
|
||||
# define nsh_spifi_initialize() (OK)
|
||||
|
Loading…
Reference in New Issue
Block a user