From d5c888e4eb96f7e781d2ab5079d462d19a63a882 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 18 Jul 2012 18:38:49 +0000 Subject: Create an MTD driver for SPIFI git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4951 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/configs/lpc4330-xplorer/README.txt | 36 ++++--- nuttx/configs/lpc4330-xplorer/nsh/defconfig | 48 +++++---- nuttx/configs/lpc4330-xplorer/src/up_nsh.c | 147 ++++++++-------------------- 3 files changed, 79 insertions(+), 152 deletions(-) (limited to 'nuttx/configs') diff --git a/nuttx/configs/lpc4330-xplorer/README.txt b/nuttx/configs/lpc4330-xplorer/README.txt index 68fe3f396..cf60ca0ec 100644 --- a/nuttx/configs/lpc4330-xplorer/README.txt +++ b/nuttx/configs/lpc4330-xplorer/README.txt @@ -903,22 +903,20 @@ Where 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. diff --git a/nuttx/configs/lpc4330-xplorer/nsh/defconfig b/nuttx/configs/lpc4330-xplorer/nsh/defconfig index de4d3ff09..e6db818ca 100644 --- a/nuttx/configs/lpc4330-xplorer/nsh/defconfig +++ b/nuttx/configs/lpc4330-xplorer/nsh/defconfig @@ -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. -# -CONFIG_SPIFI_BLKDRVR=n -CONFIG_SPIFI_DEVNO=0 -CONFIG_SPIFI_RDONLY=n +# 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_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 diff --git a/nuttx/configs/lpc4330-xplorer/src/up_nsh.c b/nuttx/configs/lpc4330-xplorer/src/up_nsh.c index 4656a43f8..a09acd771 100644 --- a/nuttx/configs/lpc4330-xplorer/src/up_nsh.c +++ b/nuttx/configs/lpc4330-xplorer/src/up_nsh.c @@ -44,89 +44,25 @@ #include #include -#include - #include "chip.h" -#ifdef CONFIG_SPIFI_BLKDRVR +#ifdef CONFIG_LPC43_SPIFI +# include # 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 +# include # 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. - */ - -#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 +/* Configuration ************************************************************/ -# 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(); - if (ret < 0) + mtd = lpc43_spifi_initialize(); + if (!mtd) { - fdbg("ERROR: lpc43_spifi_initialize failed: %d\n", ret); - return ret; + fdbg("ERROR: lpc43_spifi_initialize failed\n"); + return -ENODEV; } - /* This should be removed someday when we are confident in SPIFI */ +#ifndef CONFIG_SPFI_NXFFS + /* And finally, use the FTL layer to wrap the MTD driver as a block driver */ -#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)); -#endif + ret = ftl_initialize(CONFIG_SPIFI_DEVNO, mtd); + if (ret < 0) + { + fdbg("ERROR: Initializing the FTL layer: %d\n", ret); + return ret; + } +#else + /* Initialize to provide NXFFS on the MTD interface */1G -#ifdef CONFIG_SPIFI_RDONLY - /* Register a read-only SPIFI RAM disk at /dev/ramN, where N is the - * value of CONFIG_SPIFI_DEVNO. - */ + ret = nxffs_initialize(mtd); + if (ret < 0) + { + fdbg("ERROR: NXFFS initialization failed: %d\n", ret); + return ret; + } - 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. - */ + /* Mount the file system at /mnt/spifi */ - return ramdisk_register(CONFIG_SPIFI_DEVNO, SPIFI_BUFFER, - CONFIG_SPIFI_NBLOCKS, CONFIG_SPIFI_BLKSIZE, - true); + 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 + + return OK; } #else # define nsh_spifi_initialize() (OK) -- cgit v1.2.3