summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-04-29 20:59:40 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-04-29 20:59:40 +0000
commit1b8b1bef4170c92bd7c49b458d73386b466a4cb6 (patch)
tree45065cb6115a2b4b0f957ea0347a396add2f01a4
parentecf739cee8363fbcac042f001520e0fe9ce46681 (diff)
Add beginning of a test for NXFFS
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3540 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rw-r--r--apps/examples/README.txt8
-rw-r--r--apps/examples/nxffs/Makefile93
-rw-r--r--apps/examples/nxffs/nxffs_main.c111
-rw-r--r--nuttx/ChangeLog7
-rw-r--r--nuttx/configs/sim/nxffs/Make.defs110
-rw-r--r--nuttx/configs/sim/nxffs/appconfig39
-rw-r--r--nuttx/configs/sim/nxffs/defconfig396
-rwxr-xr-xnuttx/configs/sim/nxffs/setenv.sh45
-rw-r--r--nuttx/drivers/mtd/rammtd.c20
-rw-r--r--nuttx/fs/nxffs/Make.defs3
-rwxr-xr-xnuttx/fs/nxffs/README.txt6
-rw-r--r--nuttx/fs/nxffs/nxffs.h70
-rw-r--r--nuttx/fs/nxffs/nxffs_blockstats.c2
-rw-r--r--nuttx/fs/nxffs/nxffs_cache.c32
-rw-r--r--nuttx/fs/nxffs/nxffs_initialize.c90
-rw-r--r--nuttx/fs/nxffs/nxffs_open.c8
-rw-r--r--nuttx/fs/nxffs/nxffs_read.c174
-rw-r--r--nuttx/fs/nxffs/nxffs_reformat.c10
-rw-r--r--nuttx/fs/nxffs/nxffs_write.c147
-rw-r--r--nuttx/include/nuttx/mtd.h2
-rw-r--r--nuttx/include/nuttx/nxffs.h104
21 files changed, 1431 insertions, 46 deletions
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index 7f000dd5a7..d342814c2d 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -228,6 +228,14 @@ examples/nx
CONFIG_DISABLE_PTHREAD=n
CONFIG_NX_BLOCKING=y
+examples/nxffs
+^^^^^^^^^^^^^^
+
+ This is a test of the NuttX NXFFS FLASH file system. This is an NXFFS
+ stress test and beats on the file system very hard. It should only
+ be used in a simulation environment! Putting this NXFFS test on real
+ hardware will most likely destroy your FLASH. You have been warned.
+
examples/nxflat
^^^^^^^^^^^^^^^
diff --git a/apps/examples/nxffs/Makefile b/apps/examples/nxffs/Makefile
new file mode 100644
index 0000000000..1021bfc6d1
--- /dev/null
+++ b/apps/examples/nxffs/Makefile
@@ -0,0 +1,93 @@
+############################################################################
+# apps/examples/nxffs/Makefile
+#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# Hello, World! Example
+
+ASRCS =
+CSRCS = nxffs_main.c
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+ifeq ($(WINTOOL),y)
+ BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+else
+ BIN = "$(APPDIR)/libapps$(LIBEXT)"
+endif
+
+ROOTDEPPATH = --dep-path .
+
+# Common build
+
+VPATH =
+
+all: .built
+.PHONY: clean depend distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+.built: $(OBJS)
+ @( for obj in $(OBJS) ; do \
+ $(call ARCHIVE, $(BIN), $${obj}); \
+ done ; )
+ @touch .built
+
+context:
+
+.depend: Makefile $(SRCS)
+ @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @touch $@
+
+depend: .depend
+
+clean:
+ @rm -f *.o *~ .*.swp .built
+ $(call CLEAN)
+
+distclean: clean
+ @rm -f Make.dep .depend
+
+-include Make.dep
diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c
new file mode 100644
index 0000000000..2e046a26f6
--- /dev/null
+++ b/apps/examples/nxffs/nxffs_main.c
@@ -0,0 +1,111 @@
+/****************************************************************************
+ * examples/nxffs/nxffs_main.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <nuttx/mtd.h>
+#include <nuttx/nxffs.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+/* This must exactly match the default configuration in drivers/mtd/rammtd.c */
+
+#ifndef CONFIG_RAMMTD_BLOCKSIZE
+# define CONFIG_RAMMTD_BLOCKSIZE 512
+#endif
+
+#ifndef CONFIG_RAMMTD_ERASESIZE
+# define CONFIG_RAMMTD_ERASESIZE 4096
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXFFS_NEBLOCKS
+# define CONFIG_EXAMPLES_NXFFS_NEBLOCKS (32)
+#endif
+
+#undef CONFIG_EXAMPLES_NXFFS_BUFSIZE
+#define CONFIG_EXAMPLES_NXFFS_BUFSIZE \
+ (CONFIG_RAMMTD_ERASESIZE * CONFIG_EXAMPLES_NXFFS_NEBLOCKS)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+/* Pre-allocated simulated flash */
+
+static uint8_t g_simflash[CONFIG_EXAMPLES_NXFFS_BUFSIZE];
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * user_start
+ ****************************************************************************/
+
+int user_start(int argc, char *argv[])
+{
+ FAR struct mtd_dev_s *mtd;
+ int ret;
+
+ /* Create and initialize a RAM MTD device instance */
+
+ mtd = rammtd_initialize(g_simflash, CONFIG_EXAMPLES_NXFFS_BUFSIZE);
+ if (!mtd)
+ {
+ fprintf(stderr, "ERROR: Failed to create RAM MTD instance\n");
+ exit(1);
+ }
+
+ /* Initialize to provide NXFFS on an MTD interface */
+
+ ret = nxffs_initialize(mtd);
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: NXFFS initialization failed: %d\n", -ret);
+ exit(2);
+ }
+
+ return 0;
+}
+
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 2b914e30e7..a0ade81662 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -1715,7 +1715,6 @@
any other ARM9 build.
* fs/nxffs: Adding a tiny, wear-leveling FLASH file system for NuttX. This
file system is intended to be small and will have some limitations. The
- implementation is incomplete on initial checkin.
-
-
-
+ implementation is incomplete on initial checkin.
+ * apps/examples/nxffs and configs/sim/nxffs: Add a test a a configuration that
+ will be used to verify NXFFS.
diff --git a/nuttx/configs/sim/nxffs/Make.defs b/nuttx/configs/sim/nxffs/Make.defs
new file mode 100644
index 0000000000..d137dd83c9
--- /dev/null
+++ b/nuttx/configs/sim/nxffs/Make.defs
@@ -0,0 +1,110 @@
+############################################################################
+# configs/sim/nxffs/Make.defs
+#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+
+include ${TOPDIR}/.config
+
+HOSTOS = ${shell uname -o 2>/dev/null || echo "Other"}
+
+ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
+ ARCHOPTIMIZATION = -g
+else
+ ARCHOPTIMIZATION = -O2
+endif
+
+ARCHCPUFLAGS = -fno-builtin
+ARCHPICFLAGS = -fpic
+ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
+ARCHDEFINES =
+ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
+ARCHSCRIPT =
+
+CROSSDEV =
+CC = $(CROSSDEV)gcc
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+AR = $(CROSSDEV)ar rcs
+NM = $(CROSSDEV)nm
+OBJCOPY = $(CROSSDEV)objcopy
+OBJDUMP = $(CROSSDEV)objdump
+
+CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
+ $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
+CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES)
+AFLAGS = $(CFLAGS) -D__ASSEMBLY__
+
+OBJEXT = .o
+LIBEXT = .a
+
+ifeq ($(HOSTOS),Cygwin)
+ EXEEXT = .exe
+else
+ EXEEXT =
+endif
+
+ifeq ("${CONFIG_DEBUG_SYMBOLS}","y")
+ LDFLAGS += -g
+endif
+
+define PREPROCESS
+ @echo "CPP: $1->$2"
+ @$(CPP) $(CPPFLAGS) $1 -o $2
+endef
+
+define COMPILE
+ @echo "CC: $1"
+ @$(CC) -c $(CFLAGS) $1 -o $2
+endef
+
+define ASSEMBLE
+ @echo "AS: $1"
+ @$(CC) -c $(AFLAGS) $1 -o $2
+endef
+
+define ARCHIVE
+ echo "AR: $2"; \
+ $(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; }
+endef
+
+define CLEAN
+ @rm -f *.o *.a
+endef
+
+MKDEP = $(TOPDIR)/tools/mkdeps.sh
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
+ $(ARCHCPUFLAGS) $(HOSTINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
+HOSTLDFLAGS =
diff --git a/nuttx/configs/sim/nxffs/appconfig b/nuttx/configs/sim/nxffs/appconfig
new file mode 100644
index 0000000000..8170a0edd8
--- /dev/null
+++ b/nuttx/configs/sim/nxffs/appconfig
@@ -0,0 +1,39 @@
+############################################################################
+# configs/sim/nxffs/appconfig
+#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+
+# Path to example in apps/examples containing the user_start entry point
+
+CONFIGURED_APPS += examples/nxffs
+
diff --git a/nuttx/configs/sim/nxffs/defconfig b/nuttx/configs/sim/nxffs/defconfig
new file mode 100644
index 0000000000..c3edcfc155
--- /dev/null
+++ b/nuttx/configs/sim/nxffs/defconfig
@@ -0,0 +1,396 @@
+############################################################################
+# configs/sim/nxffs/defconfig
+#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+#
+# Architecture selection
+#
+# CONFIG_ARCH - identifies the arch subdirectory and, hence, the
+# processor architecture.
+# CONFIG_ARCH_name - for use in C code. This identifies the particular
+# processor architecture (CONFIG_ARCH_SIM).
+# CONFIG_ARCH_BOARD - identifies the configs subdirectory and, hence,
+# the board that supports the particular chip or SoC.
+# CONFIG_ARCH_BOARD_name - for use in C code
+# CONFIG_ENDIAN_BIG - define if big endian (default is little endian)
+#
+CONFIG_ARCH=sim
+CONFIG_ARCH_SIM=y
+CONFIG_ARCH_BOARD=sim
+CONFIG_ARCH_BOARD_SIM=y
+
+#
+# General OS setup
+#
+# CONFIG_APPS_DIR - Identifies the relative path to the directory
+# that builds the application to link with NuttX. Default: ../apps
+# CONFIG_DEBUG - enables built-in debug options
+# CONFIG_DEBUG_VERBOSE - enables verbose debug output
+# CONFIG_DEBUG_SYMBOLS - build without optimization and with
+# debug symbols (needed for use with a debugger).
+# CONFIG_MM_REGIONS - If the architecture includes multiple
+# regions of memory to allocate from, this specifies the
+# number of memory regions that the memory manager must
+# handle and enables the API mm_addregion(start, end);
+# CONFIG_ARCH_LOWPUTC - architecture supports low-level, boot
+# time console output
+# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz
+# or TICKS_PER_MSEC=10. This setting may be defined to
+# inform NuttX that the processor hardware is providing
+# system timer interrupts at some interrupt interval other
+# than 10 msec.
+# CONFIG_RR_INTERVAL - The round robin timeslice will be set
+# this number of milliseconds; Round robin scheduling can
+# be disabled by setting this value to zero.
+# CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
+# scheduler to monitor system performance
+# CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
+# task name to save in the TCB. Useful if scheduler
+# instrumentation is selected. Set to zero to disable.
+# CONFIG_JULIAN_TIME - Enables Julian time conversions
+# CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
+# Used to initialize the internal time logic.
+# CONFIG_DEV_CONSOLE - Set if architecture-specific logic
+# provides /dev/console. Enables stdout, stderr, stdin.
+# CONFIG_DEV_LOWCONSOLE - Use the simple, low-level serial console
+# driver (minimul support)
+# CONFIG_MUTEX_TYPES: Set to enable support for recursive and
+# errorcheck mutexes. Enables pthread_mutexattr_settype().
+# CONFIG_PRIORITY_INHERITANCE : Set to enable support for priority
+# inheritance on mutexes and semaphores.
+# CONFIG_SEM_PREALLOCHOLDERS: This setting is only used if priority
+# inheritance is enabled. It defines the maximum number of
+# different threads (minus one) that can take counts on a
+# semaphore with priority inheritance support. This may be
+# set to zero if priority inheritance is disabled OR if you
+# are only using semaphores as mutexes (only one holder) OR
+# if no more than two threads participate using a counting
+# semaphore.
+# CONFIG_SEM_NNESTPRIO. If priority inheritance is enabled,
+# then this setting is the maximum number of higher priority
+# threads (minus 1) than can be waiting for another thread
+# to release a count on a semaphore. This value may be set
+# to zero if no more than one thread is expected to wait for
+# a semaphore.
+# CONFIG_FDCLONE_DISABLE. Disable cloning of all file descriptors
+# by task_create() when a new task is started. If set, all
+# files/drivers will appear to be closed in the new task.
+# CONFIG_FDCLONE_STDIO. Disable cloning of all but the first
+# three file descriptors (stdin, stdout, stderr) by task_create()
+# when a new task is started. If set, all files/drivers will
+# appear to be closed in the new task except for stdin, stdout,
+# and stderr.
+# CONFIG_SDCLONE_DISABLE. Disable cloning of all socket
+# desciptors by task_create() when a new task is started. If
+# set, all sockets will appear to be closed in the new task.
+#
+#CONFIG_APPS_DIR=
+CONFIG_DEBUG=y
+CONFIG_DEBUG_VERBOSE=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DEBUG_FS=y
+CONFIG_MM_REGIONS=1
+CONFIG_ARCH_LOWPUTC=y
+CONFIG_RR_INTERVAL=0
+CONFIG_SCHED_INSTRUMENTATION=n
+CONFIG_TASK_NAME_SIZE=32
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=4
+CONFIG_START_DAY=29
+CONFIG_JULIAN_TIME=n
+CONFIG_DEV_CONSOLE=y
+CONFIG_DEV_LOWCONSOLE=n
+CONFIG_MUTEX_TYPES=y
+CONFIG_PRIORITY_INHERITANCE=n
+CONFIG_SEM_PREALLOCHOLDERS=0
+CONFIG_SEM_NNESTPRIO=0
+CONFIG_FDCLONE_DISABLE=n
+CONFIG_FDCLONE_STDIO=n
+CONFIG_SDCLONE_DISABLE=y
+
+#
+# The following can be used to disable categories of
+# APIs supported by the OS. If the compiler supports
+# weak functions, then it should not be necessary to
+# disable functions unless you want to restrict usage
+# of those APIs.
+#
+# There are certain dependency relationships in these
+# features.
+#
+# o mq_notify logic depends on signals to awaken tasks
+# waiting for queues to become full or empty.
+# o pthread_condtimedwait() depends on signals to wake
+# up waiting tasks.
+#
+CONFIG_DISABLE_CLOCK=n
+CONFIG_DISABLE_POSIX_TIMERS=y
+CONFIG_DISABLE_PTHREAD=y
+CONFIG_DISABLE_SIGNALS=y
+CONFIG_DISABLE_MQUEUE=y
+CONFIG_DISABLE_MOUNTPOINT=n
+CONFIG_DISABLE_ENVIRON=n
+CONFIG_DISABLE_POLL=y
+
+#
+# Misc libc settings
+#
+# CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a
+# little smaller if we do not support fieldwidthes
+#
+CONFIG_NOPRINTF_FIELDWIDTH=n
+
+#
+# Allow for architecture optimized implementations
+#
+# The architecture can provide optimized versions of the
+# following to improve sysem performance
+#
+CONFIG_ARCH_MEMCPY=n
+CONFIG_ARCH_MEMCMP=n
+CONFIG_ARCH_MEMMOVE=n
+CONFIG_ARCH_MEMSET=n
+CONFIG_ARCH_STRCMP=n
+CONFIG_ARCH_STRCPY=n
+CONFIG_ARCH_STRNCPY=n
+CONFIG_ARCH_STRLEN=n
+CONFIG_ARCH_STRNLEN=n
+CONFIG_ARCH_BZERO=n
+
+##
+# General build options
+#
+# CONFIG_RRLOAD_BINARY - make the rrload binary format used with
+# BSPs from www.ridgerun.com using the tools/mkimage.sh script
+# CONFIG_INTELHEX_BINARY - make the Intel HEX binary format
+# used with many different loaders using the GNU objcopy program
+# Should not be selected if you are not using the GNU toolchain.
+# CONFIG_RAW_BINARY - make a raw binary format file used with many
+# different loaders using the GNU objcopy program. This option
+# should not be selected if you are not using the GNU toolchain.
+# CONFIG_HAVE_LIBM - toolchain supports libm.a
+#
+CONFIG_RRLOAD_BINARY=n
+CONFIG_INTELHEX_BINARY=n
+CONFIG_RAW_BINARY=n
+CONFIG_HAVE_LIBM=y
+
+#
+# Sizes of configurable things (0 disables)
+#
+# CONFIG_MAX_TASKS - The maximum number of simultaneously
+# active tasks. This value must be a power of two.
+# CONFIG_MAX_TASK_ARGS - This controls the maximum number of
+# of parameters that a task may receive (i.e., maxmum value
+# of 'argc')
+# CONFIG_NPTHREAD_KEYS - The number of items of thread-
+# specific data that can be retained
+# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
+# descriptors (one for each open)
+# CONFIG_NFILE_STREAMS - The maximum number of streams that
+# can be fopen'ed
+# CONFIG_NAME_MAX - The maximum size of a file name.
+# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
+# on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_NUNGET_CHARS - Number of characters that can be
+# buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
+# structures. The system manages a pool of preallocated
+# message structures to minimize dynamic allocations
+# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
+# a fixed payload size given by this settin (does not include
+# other message structure overhead.
+# CONFIG_MAX_WDOGPARMS - Maximum number of parameters that
+# can be passed to a watchdog handler
+# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
+# structures. The system manages a pool of preallocated
+# watchdog structures to minimize dynamic allocations
+# CONFIG_PREALLOC_TIMERS - The number of pre-allocated POSIX
+# timer structures. The system manages a pool of preallocated
+# timer structures to minimize dynamic allocations. Set to
+# zero for all dynamic allocations.
+#
+CONFIG_MAX_TASKS=64
+CONFIG_MAX_TASK_ARGS=4
+CONFIG_NPTHREAD_KEYS=4
+CONFIG_NFILE_DESCRIPTORS=32
+CONFIG_NFILE_STREAMS=16
+CONFIG_NAME_MAX=32
+CONFIG_STDIO_BUFFER_SIZE=1024
+CONFIG_NUNGET_CHARS=2
+CONFIG_PREALLOC_MQ_MSGS=32
+CONFIG_MQ_MAXMSGSIZE=32
+CONFIG_MAX_WDOGPARMS=4
+CONFIG_PREALLOC_WDOGS=32
+CONFIG_PREALLOC_TIMERS=8
+
+#
+# FAT filesystem configuration
+# CONFIG_FS_FAT - Enable FAT filesystem support
+# CONFIG_FAT_SECTORSIZE - Max supported sector size
+# CONFIG_FS_ROMFS - Enable ROMFS filesystem support
+CONFIG_FS_FAT=y
+CONFIG_FS_ROMFS=n
+
+#
+# TCP/IP and UDP support via uIP
+# CONFIG_NET - Enable or disable all network features
+# CONFIG_NET_IPv6 - Build in support for IPv6
+# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread.
+# CONFIG_NET_SOCKOPTS - Enable or disable support for socket options
+# CONFIG_NET_BUFSIZE - uIP buffer size
+# CONFIG_NET_TCP - TCP support on or off
+# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks)
+# CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers
+# CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero)
+# CONFIG_NET_TCPBACKLOG - Incoming connections pend in a backlog until
+# accept() is called. The size of the backlog is selected when listen() is called.
+# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks)
+# CONFIG_NET_UDP - UDP support on or off
+# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off
+# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections
+# CONFIG_NET_ICMP - ICMP ping response support on or off
+# CONFIG_NET_ICMP_PING - ICMP ping request support on or off
+# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address
+# CONFIG_NET_STATISTICS - uIP statistics on or off
+# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window
+# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table
+# CONFIG_NET_BROADCAST - Broadcast support
+# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates
+#
+CONFIG_NET=n
+CONFIG_NET_IPv6=n
+CONFIG_NSOCKET_DESCRIPTORS=0
+CONFIG_NET_SOCKOPTS=y
+CONFIG_NET_BUFSIZE=420
+CONFIG_NET_TCP=n
+CONFIG_NET_TCP_CONNS=40
+CONFIG_NET_MAX_LISTENPORTS=40
+CONFIG_NET_UDP=n
+CONFIG_NET_UDP_CHECKSUMS=y
+#CONFIG_NET_UDP_CONNS=10
+CONFIG_NET_ICMP=n
+CONFIG_NET_ICMP_PING=n
+#CONFIG_NET_PINGADDRCONF=0
+CONFIG_NET_STATISTICS=y
+#CONFIG_NET_RECEIVE_WINDOW=
+#CONFIG_NET_ARPTAB_SIZE=8
+CONFIG_NET_BROADCAST=n
+#CONFIG_NET_FWCACHE_SIZE=2
+
+#
+# UIP Network Utilities
+# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP
+# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries
+CONFIG_NET_DHCP_LIGHT=n
+CONFIG_NET_RESOLV_ENTRIES=4
+
+#
+# Settings for examples/uip
+CONFIG_EXAMPLE_UIP_IPADDR=(192<<24|168<<16|0<<8|128)
+CONFIG_EXAMPLE_UIP_DRIPADDR=(192<<24|168<<16|0<<8|1)
+CONFIG_EXAMPLE_UIP_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLE_UIP_DHCPC=n
+
+#
+# Settings for examples/nettest
+CONFIG_EXAMPLE_NETTEST_SERVER=n
+CONFIG_EXAMPLE_NETTEST_PERFORMANCE=n
+CONFIG_EXAMPLE_NETTEST_NOMAC=n
+CONFIG_EXAMPLE_NETTEST_IPADDR=(192<<24|168<<16|0<<8|128)
+CONFIG_EXAMPLE_NETTEST_DRIPADDR=(192<<24|168<<16|0<<8|1)
+CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLE_NETTEST_CLIENTIP=(192<<24|168<<16|0<<8|106)
+
+#
+# Settings for examples/ostest
+#
+CONFIG_EXAMPLES_OSTEST_LOOPS=100
+CONFIG_EXAMPLES_OSTEST_STACKSIZE=8192
+
+#
+# Settings for apps/nshlib
+CONFIG_NSH_CONSOLE=y
+CONFIG_NSH_TELNET=n
+CONFIG_NSH_IOBUFFER_SIZE=512
+CONFIG_NSH_CMD_SIZE=40
+CONFIG_NSH_STACKSIZE=4096
+CONFIG_NSH_DHCPC=n
+CONFIG_NSH_NOMAC=n
+CONFIG_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
+CONFIG_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
+CONFIG_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
+
+#
+# Various FS, NXFFS, RAMMTD and other settings needed for
+# apps/examples/nxffs
+#
+CONFIG_FS_NXFFS=y
+CONFIG_NXFFS_ERASEDSTATE=0xff
+CONFIG_NXFSS_PREALLOCATED=y
+CONFIG_RAMMTD_BLOCKSIZE=512
+CONFIG_RAMMTD_ERASESIZE=4096
+CONFIG_RAMMTD_ERASESTATE=0xff
+CONFIG_EXAMPLES_NXFFS_NEBLOCKS=32
+
+#
+# Stack and heap information
+#
+# CONFIG_BOOT_RUNFROMFLASH - Some configurations support XIP
+# operation from FLASH but must copy initialized .data sections to RAM.
+# CONFIG_BOOT_COPYTORAM - Some configurations boot in FLASH
+# but copy themselves entirely into RAM for better performance.
+# CONFIG_CUSTOM_STACK - The up_ implementation will handle
+# all stack operations outside of the nuttx model.
+# CONFIG_STACK_POINTER - The initial stack pointer
+# CONFIG_IDLETHREAD_STACKSIZE - The size of the initial stack.
+# This is the thread that (1) performs the inital boot of the system up
+# to the point where user_start() is spawned, and (2) there after is the
+# IDLE thread that executes only when there is no other thread ready to
+# run.
+# CONFIG_USERMAIN_STACKSIZE - The size of the stack to allocate
+# for the main user thread that begins at the user_start() entry point.
+# CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size
+# CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
+# CONFIG_HEAP_BASE - The beginning of the heap
+# CONFIG_HEAP_SIZE - The size of the heap
+#
+CONFIG_BOOT_RUNFROMFLASH=n
+CONFIG_BOOT_COPYTORAM=n
+CONFIG_CUSTOM_STACK=n
+CONFIG_IDLETHREAD_STACKSIZE=4096
+CONFIG_USERMAIN_STACKSIZE=4096
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=8192
+CONFIG_HEAP_BASE=
+CONFIG_HEAP_SIZE=
diff --git a/nuttx/configs/sim/nxffs/setenv.sh b/nuttx/configs/sim/nxffs/setenv.sh
new file mode 100755
index 0000000000..2733778439
--- /dev/null
+++ b/nuttx/configs/sim/nxffs/setenv.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+# confisgs/sim/nxffs/setenv.sh
+#
+# Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+
+if [ "$(basename $0)" = "setenv.sh" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+if [ -z ${PATH_ORIG} ]; then export PATH_ORIG=${PATH}; fi
+
+#export NUTTX_BIN=
+#export PATH=${NUTTX_BIN}:/sbin:/usr/sbin:${PATH_ORIG}
+
+echo "PATH : ${PATH}"
diff --git a/nuttx/drivers/mtd/rammtd.c b/nuttx/drivers/mtd/rammtd.c
index 5bdfa50179..6a2e1f4c20 100644
--- a/nuttx/drivers/mtd/rammtd.c
+++ b/nuttx/drivers/mtd/rammtd.c
@@ -168,20 +168,22 @@ static ssize_t ram_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nbl
{
FAR struct ram_dev_s *priv = (FAR struct ram_dev_s *)dev;
off_t offset;
+ off_t maxblock;
size_t nbytes;
DEBUGASSERT(dev && buf);
/* Don't let the read exceed the size of the ram buffer */
- if (startblock >= priv->nblocks)
+ maxblock = priv->nblocks * CONFIG_RAMMTD_BLKPER;
+ if (startblock >= maxblock)
{
return 0;
}
- if (startblock + nblocks >= priv->nblocks)
+ if (startblock + nblocks > maxblock)
{
- nblocks = priv->nblocks - nblocks;
+ nblocks = maxblock - startblock;
}
/* Get the offset corresponding to the first block and the size
@@ -201,25 +203,27 @@ static ssize_t ram_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nbl
* Name: ram_bwrite
****************************************************************************/
-static ssize_t ram_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
- FAR const uint8_t *buf)
+static ssize_t ram_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
+ size_t nblocks, FAR const uint8_t *buf)
{
FAR struct ram_dev_s *priv = (FAR struct ram_dev_s *)dev;
off_t offset;
+ off_t maxblock;
size_t nbytes;
DEBUGASSERT(dev && buf);
/* Don't let the write exceed the size of the ram buffer */
- if (startblock >= priv->nblocks)
+ maxblock = priv->nblocks * CONFIG_RAMMTD_BLKPER;
+ if (startblock >= maxblock)
{
return 0;
}
- if (startblock + nblocks >= priv->nblocks)
+ if (startblock + nblocks > maxblock)
{
- nblocks = priv->nblocks - nblocks;
+ nblocks = maxblock - startblock;
}
/* Get the offset corresponding to the first block and the size
diff --git a/nuttx/fs/nxffs/Make.defs b/nuttx/fs/nxffs/Make.defs
index 88c3d9cee9..6409c23bcf 100644
--- a/nuttx/fs/nxffs/Make.defs
+++ b/nuttx/fs/nxffs/Make.defs
@@ -37,7 +37,8 @@ ifeq ($(CONFIG_FS_NXFFS),y)
ASRCS +=
CSRCS += nxffs_block.c nxffs_blockstats.c nxffs_cache.c nxffs_dirent.c \
nxffs_initialize.c nxffs_inode.c nxffs_ioctl.c nxffs_open.c \
- nxffs_reformat.c nxffs_stat.c nxffs_unlink.c nxffs_util.c
+ nxffs_read.c nxffs_reformat.c nxffs_stat.c nxffs_unlink.c \
+ nxffs_util.c nxffs_write.c
# Argument for dependency checking
diff --git a/nuttx/fs/nxffs/README.txt b/nuttx/fs/nxffs/README.txt
index a2577e1f8e..cdbea34ca6 100755
--- a/nuttx/fs/nxffs/README.txt
+++ b/nuttx/fs/nxffs/README.txt
@@ -92,3 +92,9 @@ that you should be aware before opting to use NXFFS:
6. The clean-up process occurs only during a write when the free FLASH
memory at the end of the FLASH is exhausted. Thus, occasionally, file
writing may take a long time.
+
+7. Another limitation is that there can be only a single NXFFS volume
+ mounted at any time. This has to do with the fact that we bind to
+ an MTD driver (instead of a block driver) and bypass all of the normal
+ mount operations.
+
diff --git a/nuttx/fs/nxffs/nxffs.h b/nuttx/fs/nxffs/nxffs.h
index 4f903a072e..5b1809ebc9 100644
--- a/nuttx/fs/nxffs/nxffs.h
+++ b/nuttx/fs/nxffs/nxffs.h
@@ -50,19 +50,11 @@
#include <semaphore.h>
#include <nuttx/mtd.h>
+#include <nuttx/nxffs.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-/* Configuration ************************************************************/
-#ifndef CONFIG_NXFFS_ERASEDSTATE
-# define CONFIG_NXFFS_ERASEDSTATE 0xff
-#endif
-
-#if CONFIG_NXFFS_ERASEDSTATE != 0xff && CONFIG_NXFFS_ERASEDSTATE != 0x00
-# error "CONFIG_NXFFS_ERASEDSTATE must be either 0x00 or 0xff"
-#endif
-
/* NXFFS Definitions ********************************************************/
/* General NXFFS organization. The following example assumes 4 logical
* blocks per FLASH erase block. The actual relationship is determined by
@@ -141,6 +133,10 @@
* 6. The clean-up process occurs only during a write when the free FLASH
* memory at the end of the FLASH is exhausted. Thus, occasionally, file
* writing may take a long time.
+ * 7. Another limitation is that there can be only a single NXFFS volume
+ * mounted at any time. This has to do with the fact that we bind to
+ * an MTD driver (instead of a block driver) and bypass all of the normal
+ * mount operations.
*/
/* Values for logical block state. Basically, there are only two, perhaps
@@ -149,19 +145,25 @@
* BLOCK_STATE_GOOD - The block is not known to be bad.
* BLOCK_STATE_BAD - An error was found on the block and it is marked bad.
* Other values - The block is bad and has an invalid state.
+ *
+ * Care is taken so that the GOOD to BAD transition only involves burning
+ * bits from the erased to non-erased state.
*/
-#define BLOCK_STATE_GOOD CONFIG_NXFFS_ERASEDSTATE
-#define BLOCK_STATE_BAD 0xaa
+#define BLOCK_STATE_GOOD (CONFIG_NXFFS_ERASEDSTATE ^ 0x44)
+#define BLOCK_STATE_BAD (CONFIG_NXFFS_ERASEDSTATE ^ 0x55)
/* Values for NXFFS inode state. Similar there are 2 (maybe 3) inode states:
*
* INODE_STATE_FILE - The inode is a valid usuable, file
* INODE_STATE_DELETED - The inode has been deleted.
+ *
+ * Care is taken so that the GOOD to BAD transition only involves burning
+ * bits from the erased to non-erased state.
*/
-#define INODE_STATE_FILE CONFIG_NXFFS_ERASEDSTATE
-#define INODE_STATE_DELETED 0x55
+#define INODE_STATE_FILE (CONFIG_NXFFS_ERASEDSTATE ^ 0x22)
+#define INODE_STATE_DELETED (CONFIG_NXFFS_ERASEDSTATE ^ 0xaa)
/* Number of bytes in an the NXFFS magic sequences */
@@ -316,6 +318,18 @@ extern const uint8_t g_inodemagic[NXFFS_MAGICSIZE];
extern const uint8_t g_datamagic[NXFFS_MAGICSIZE];
+/* If CONFIG_NXFSS_PREALLOCATED is defined, then this is the single, pre-
+ * allocated NXFFS volume instance.
+ */
+
+#ifdef CONFIG_NXFSS_PREALLOCATED
+extern struct nxffs_volume_s g_volume;
+#endif
+
+/* A singly-linked list of open files */
+
+extern struct nxffs_ofile_s *g_ofiles;
+
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -474,12 +488,14 @@ extern int nxffs_getc(FAR struct nxffs_volume_s *volume);
*
* Description:
* Read a sequence of data bytes from the FLASH memory. This function
- * allows the data in the formatted FLASH blocks to be read as a continuous\
+ * allows the data in the formatted FLASH blocks to be read as a continuous
* byte stream, skipping over bad blocks and block headers as necessary.
*
* Input Parameters:
* volume - Describes the NXFFS volume. The paramters ioblock and iooffset
* in the volume structure determine the behavior of nxffs_getc().
+ * buffer - A pointer to memory to receive the data read from FLASH.
+ * buflen - The maximum number of bytes to read from FLASH.
*
* Returned Value:
* The number of bytes read is returned on success. Otherwise, a negated
@@ -493,6 +509,29 @@ extern ssize_t nxffs_rddata(FAR struct nxffs_volume_s *volume,
FAR uint8_t *buffer, size_t buflen);
/****************************************************************************
+ * Name: nxffs_wrdata
+ *
+ * Description:
+ * Write a sequence of data bytes into volume cache memory. Nothing is
+ * actually written to FLASH! This function allows the data in the formatted
+ * FLASH blocks to be read as a continuous byte stream, skipping over bad
+ * blocks and block headers as necessary.
+ *
+ * Input Parameters:
+ * volume - Describes the NXFFS volume.
+ * buffer - A pointer to memory to containing the data to write to FLASH.
+ * buflen - The maximum number of bytes to write to FLASH.
+ *
+ * Returned Value:
+ * The number of bytes written is returned on success. Otherwise, a negated
+ * errno indicating the nature of the failure.
+ *
+ ****************************************************************************/
+
+extern ssize_t nxffs_wrdata(FAR struct nxffs_volume_s *volume,
+ FAR const uint8_t *buffer, size_t buflen);
+
+/****************************************************************************
* Name: nxffs_freeentry
*
* Description:
@@ -700,9 +739,12 @@ extern int nxffs_rminode(FAR struct nxffs_volume_s *volume, FAR const char *name
* See include/nuttx/fs.h
*
* - nxffs_open() and nxffs_close() are defined in nxffs_open.c
+ * - nxffs_read() is defined in nxffs_read.c
+ * - nxffs_write() is defined in nxffs_write.c
* - nxffs_ioctl() is defined in nxffs_ioctl.c
* - nxffs_opendir(), nxffs_readdir(), and nxffs_rewindir() are defined in
* nxffs_dirent.c
+ * - nxffs_bind() and nxffs_unbind() are defined in nxffs_initialize.c
* - nxffs_stat() and nxffs_statfs() are defined in nxffs_stat.c
* - nxffs_unlink() is defined nxffs_unlink.c
*
diff --git a/nuttx/fs/nxffs/nxffs_blockstats.c b/nuttx/fs/nxffs/nxffs_blockstats.c
index 8ad6f09787..9f7ca3af7f 100644
--- a/nuttx/fs/nxffs/nxffs_blockstats.c
+++ b/nuttx/fs/nxffs/nxffs_blockstats.c
@@ -116,7 +116,7 @@ int nxffs_blockstats(FAR struct nxffs_volume_s *volume,
for (bptr = volume->cache, lblock = 0;
lblock < volume->blkper;
- bptr += SIZEOF_NXFFS_BLOCK_HDR, lblock++)
+ bptr += volume->geo.blocksize, lblock++)
{
FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s*)bptr;
diff --git a/nuttx/fs/nxffs/nxffs_cache.c b/nuttx/fs/nxffs/nxffs_cache.c
index a2774ddfd6..f149de7cb3 100644
--- a/nuttx/fs/nxffs/nxffs_cache.c
+++ b/nuttx/fs/nxffs/nxffs_cache.c
@@ -95,7 +95,7 @@ int nxffs_rdcache(FAR struct nxffs_volume_s *volume, off_t block,
/* Check if the requested data is already in the cache */
- if (block != volume->cblock || nblocks <= volume->ncached)
+ if (block != volume->cblock || nblocks > volume->ncached)
{
/* Read the specified blocks into cache */
@@ -229,12 +229,14 @@ int nxffs_getc(FAR struct nxffs_volume_s *volume)
*
* Description:
* Read a sequence of data bytes from the FLASH memory. This function
- * allows the data in the formatted FLASH blocks to be read as a continuous\
+ * allows the data in the formatted FLASH blocks to be read as a continuous
* byte stream, skipping over bad blocks and block headers as necessary.
*
* Input Parameters:
* volume - Describes the NXFFS volume. The paramters ioblock and iooffset
* in the volume structure determine the behavior of nxffs_getc().
+ * buffer - A pointer to memory to receive the data read from FLASH.
+ * buflen - The maximum number of bytes to read from FLASH.
*
* Returned Value:
* The number of bytes read is returned on success. Otherwise, a negated
@@ -267,3 +269,29 @@ ssize_t nxffs_rddata(FAR struct nxffs_volume_s *volume,
return buflen;
}
+/****************************************************************************
+ * Name: nxffs_wrdata
+ *
+ * Description:
+ * Write a sequence of data bytes into volume cache memory. Nothing is
+ * actually written to FLASH! This function allows the data in the formatted
+ * FLASH blocks to be read as a continuous byte stream, skipping over bad
+ * blocks and block headers as necessary.
+ *
+ * Input Parameters:
+ * volume - Describes the NXFFS volume.
+ * buffer - A pointer to memory to containing the data to write to FLASH.
+ * buflen - The maximum number of bytes to write to FLASH.
+ *
+ * Returned Value:
+ * The number of bytes written is returned on success. Otherwise, a negated
+ * errno indicating the nature of the failure.
+ *
+ ****************************************************************************/
+
+ssize_t nxffs_wrdata(FAR struct nxffs_volume_s *volume,
+ FAR const uint8_t *buffer, size_t buflen)
+{
+#warning "Missing Logic"
+ return -ENOSYS;
+}
diff --git a/nuttx/fs/nxffs/nxffs_initialize.c b/nuttx/fs/nxffs/nxffs_initialize.c
index 8d96ffa158..fc2d97b658 100644
--- a/nuttx/fs/nxffs/nxffs_initialize.c
+++ b/nuttx/fs/nxffs/nxffs_initialize.c
@@ -41,6 +41,7 @@
#include <nuttx/config.h>
+#include <string.h>
#include <errno.h>
#include <assert.h>
#include <debug.h>
@@ -119,6 +120,14 @@ const uint8_t g_inodemagic[NXFFS_MAGICSIZE] = { 'I', 'n', 'o', 'd' };
const uint8_t g_datamagic[NXFFS_MAGICSIZE] = { 'D', 'a', 't', 'a' };
+/* If CONFIG_NXFSS_PREALLOCATED is defined, then this is the single, pre-
+ * allocated NXFFS volume instance.
+ */
+
+#ifdef CONFIG_NXFSS_PREALLOCATED
+struct nxffs_volume_s g_volume;
+#endif
+
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -135,19 +144,31 @@ const uint8_t g_datamagic[NXFFS_MAGICSIZE] = { 'D', 'a', 't', 'a' };
*
* Input Parameters:
* mtd - The MTD device that supports the FLASH interface.
- * start - The first block of the file system begins at this block number
- * in the FLASH
- * nblocks - This number of blocks is set aside for the file system.
+ *
+ * Returned Value:
+ * Zero is returned on success. Otherwise, a negated errno value is
+ * returned to indicate the nature of the failure.
*
****************************************************************************/
-int nxffs_initialize(FAR struct mtd_dev_s *mtd, off_t start, off_t nblocks)
+int nxffs_initialize(FAR struct mtd_dev_s *mtd)
{
FAR struct nxffs_volume_s *volume;
struct nxffs_blkstats_s stats;
off_t threshold;
int ret;
+ /* If CONFIG_NXFSS_PREALLOCATED is defined, then this is the single, pre-
+ * allocated NXFFS volume instance.
+ */
+
+#ifdef CONFIG_NXFSS_PREALLOCATED
+
+ volume = &g_volume;
+ memset(volume, 0, sizeof(struct nxffs_volume_s));
+
+#else
+
/* Allocate a NXFFS volume structure */
volume = (FAR struct nxffs_volume_s *)kzalloc(sizeof(struct nxffs_volume_s));
@@ -156,6 +177,7 @@ int nxffs_initialize(FAR struct mtd_dev_s *mtd, off_t start, off_t nblocks)
ret = -ENOMEM;
goto errout;
}
+#endif
/* Initialize the NXFFS volume structure */
@@ -175,7 +197,7 @@ int nxffs_initialize(FAR struct mtd_dev_s *mtd, off_t start, off_t nblocks)
/* Allocate one, in-memory erase block buffer */
- volume->cache = (FAR uint8_t *)kmalloc(volume->geo.erasesize);
+ volume->cache = (FAR uint8_t *)kmalloc(volume->geo.erasesize);
if (!volume->cache)
{
fdbg("Failed to allocate an erase block buffer\n");
@@ -238,7 +260,6 @@ errout_with_iobuffer:
kfree(volume->cache);
errout_with_volume:
kfree(volume);
-errout:
return ret;
}
@@ -400,3 +421,60 @@ int nxffs_limits(FAR struct nxffs_volume_s *volume)
return OK;
}
+/****************************************************************************
+ * Name: nxffs_bind
+ *
+ * Description:
+ * This function implements a portion of the mount operation. Normmally,
+ * the bind() method allocates and initializes the mountpoint private data
+ * then binds the blockdriver inode to the filesystem private data. The
+ * final binding of the private data (containing the blockdriver) to the
+ * mountpoint is performed by mount().
+ *
+ * For the NXFFS, this sequence is quite different for the following
+ * reasons:
+ *
+ * 1. A block driver is not used. Instead, an MTD instance was provided
+ * to nxfs_initialize prior to mounting. So, in this sense, the NXFFS
+ * file system is already bound.
+ *
+ * 2. Since the volume was already bound to the MTD driver, all allocations
+ * and initializations have already been performed. Essentially, all
+ * mount operations have been bypassed and now we just need to provide
+ * the pre-allocated volume instance.
+ *
+ * 3. The tricky thing is that there is no mechanism to associate multiple
+ * NXFFS volumes to the multiple volumes bound to different MTD drivers.
+ * Hence, the limitation of a single NXFFS volume.
+ *
+ ****************************************************************************/
+
+int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
+ FAR void **handle)
+{
+#ifndef CONFIG_NXFSS_PREALLOCATED
+# error "No design to support dynamic allocation of volumes"
+#else
+
+ /* If CONFIG_NXFSS_PREALLOCATED is defined, then this is the single, pre-
+ * allocated NXFFS volume instance.
+ */
+
+ DEBUGASSERT(g_volume.cache);
+ *handle = &g_volume;
+#endif
+ return OK;
+}
+
+/****************************************************************************
+ * Name: nxffs_unbind
+ *
+ * Description: This implements the filesystem portion of the umount
+ * operation.
+ *
+ ****************************************************************************/
+
+int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver)
+{
+ return g_ofiles ? -EBUSY : OK;
+}
diff --git a/nuttx/fs/nxffs/nxffs_open.c b/nuttx/fs/nxffs/nxffs_open.c
index 88bfbf3ff6..f057ab4bc7 100644
--- a/nuttx/fs/nxffs/nxffs_open.c
+++ b/nuttx/fs/nxffs/nxffs_open.c
@@ -65,14 +65,14 @@
* Public Variables
****************************************************************************/
+/* A singly-linked list of open files */
+
+struct nxffs_ofile_s *g_ofiles;
+
/****************************************************************************
* Private Variables
****************************************************************************/
-/* A singly-linked list of open files */
-
-static struct nxffs_ofile_s *g_ofiles;
-
/****************************************************************************
* Private Functions
****************************************************************************/
diff --git a/nuttx/fs/nxffs/nxffs_read.c b/nuttx/fs/nxffs/nxffs_read.c
new file mode 100644
index 0000000000..d8c2e95672
--- /dev/null
+++ b/nuttx/fs/nxffs/nxffs_read.c
@@ -0,0 +1,174 @@
+/****************************************************************************
+ * fs/nxffs/nxffs_read.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * References: Linux/Documentation/filesystems/romfs.txt
+ *
+ * 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 <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs.h>
+#include <nuttx/mtd.h>
+
+#include "nxffs.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxffs_rdseek
+ *
+ * Description:
+ * Seek to the file position before read or write access. Note that the
+ * simplier nxffs_ioseek() cannot be used for this purpose. File offsets
+ * are not easily mapped to FLASH offsets due to intervening block and
+ * data headers.
+ *
+ * Input Parameters:
+ * volume - Describes the current volume
+ * entry - Describes the open inode
+ * fpos - The desired file position
+ *
+ ****************************************************************************/
+
+static ssize_t nxffs_rdseek(FAR struct nxffs_volume_s *volume,
+ FAR struct nxffs_entry_s *entry,
+ off_t fpos)
+{
+#warning "Missing Logic"
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+/****************************************************************************
+ * Name: nxffs_read
+ *
+ * Description:
+ * This is an implementation of the NuttX standard file system read
+ * method.
+ *
+ ****************************************************************************/
+
+ssize_t nxffs_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
+{
+ FAR struct nxffs_volume_s *volume;
+ FAR struct nxffs_ofile_s *ofile;
+ ssize_t ret;
+
+ fvdbg("Read %d bytes from offset %d\n", buflen, filep->f_pos);
+
+ /* Sanity checks */
+
+ DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
+
+ /* Recover the open file state from the struct file instance */
+
+ ofile = (FAR struct nxffs_ofile_s *)filep->f_priv;
+
+ /* Recover the volume state from the open file */
+
+ volume = (FAR struct nxffs_volume_s *)filep->f_inode->i_private;
+ DEBUGASSERT(volume != NULL);
+
+ /* Get exclusive access to the volume. Note that the volume exclsem
+ * protects the open file list.
+ */
+
+ ret = sem_wait(&volume->exclsem);
+ if (ret != OK)
+ {
+ ret = -errno;
+ fdbg("sem_wait failed: %d\n", ret);
+ goto errout;
+ }
+
+ /* Check if the file was opened with read access */
+
+ if ((ofile->mode & O_RDOK) == 0)
+ {
+ fdbg("File not open for read access\n");
+ ret = -EACCES;
+ goto errout_with_semaphore;
+ }
+
+ /* Seek to the current file offset */
+
+ ret = nxffs_rdseek(volume, &ofile->entry, filep->f_pos);
+ if (ret < 0)
+ {
+ fdbg("nxffs_fwseek failed: %d\n", -ret);
+ ret = -EACCES;
+ goto errout_with_semaphore;
+ }
+
+ /* Read data from that file offset */
+
+ ret = nxffs_rddata(volume, (FAR uint8_t *)buffer, buflen);
+ if (ret > 0)
+ {
+ /* Update the file offset */
+
+ filep->f_pos += ret;
+ }
+
+errout_with_semaphore:
+ sem_post(&volume->exclsem);
+errout:
+ return ret;
+}
+
diff --git a/nuttx/fs/nxffs/nxffs_reformat.c b/nuttx/fs/nxffs/nxffs_reformat.c
index 8f34a93734..672d578667 100644
--- a/nuttx/fs/nxffs/nxffs_reformat.c
+++ b/nuttx/fs/nxffs/nxffs_reformat.c
@@ -95,7 +95,7 @@ static int nxffs_format(FAR struct nxffs_volume_s *volume)
memset(volume->cache, CONFIG_NXFFS_ERASEDSTATE, volume->geo.erasesize);
for (blkptr = volume->cache, i = 0;
i < volume->blkper;
- blkptr += SIZEOF_NXFFS_BLOCK_HDR, i++)
+ blkptr += volume->geo.blocksize, i++)
{
FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s*)blkptr;
memcpy(blkhdr->magic, g_blockmagic, NXFFS_MAGICSIZE);
@@ -121,7 +121,7 @@ static int nxffs_format(FAR struct nxffs_volume_s *volume)
nxfrd = MTD_BWRITE(volume->mtd, lblock, volume->blkper, volume->cache);
if (nxfrd != volume->blkper)
{
- fdbg("Write erase block %d failed: %d\n", alignedblock, nxfrd);
+ fdbg("Write erase block %d failed: %d\n", lblock, nxfrd);
return -EIO;
}
}
@@ -176,7 +176,7 @@ static int nxffs_badblocks(FAR struct nxffs_volume_s *volume)
modified = false;
for (blkptr = volume->cache, i = 0;
i < volume->blkper;
- blkptr += SIZEOF_NXFFS_BLOCK_HDR, i++)
+ blkptr += volume->geo.blocksize, i++)
{
FAR struct nxffs_block_s *blkhdr = (FAR struct nxffs_block_s*)blkptr;
@@ -184,7 +184,7 @@ static int nxffs_badblocks(FAR struct nxffs_volume_s *volume)
bad = false;
if (memcmp(blkhdr->magic, g_blockmagic, NXFFS_MAGICSIZE) != 0 ||
- blkhdr->state == BLOCK_STATE_GOOD)
+ blkhdr->state != BLOCK_STATE_GOOD)
{
bad = true;;
}
@@ -228,7 +228,7 @@ static int nxffs_badblocks(FAR struct nxffs_volume_s *volume)
nxfrd = MTD_BWRITE(volume->mtd, lblock, volume->blkper, volume->cache);
if (nxfrd != volume->blkper)
{
- fdbg("Write erase block %d failed: %d\n", alignedblock, nxfrd);
+ fdbg("Write erase block %d failed: %d\n", lblock, nxfrd);
return -EIO;
}
}
diff --git a/nuttx/fs/nxffs/nxffs_write.c b/nuttx/fs/nxffs/nxffs_write.c
new file mode 100644
index 0000000000..363a1d60fd
--- /dev/null
+++ b/nuttx/fs/nxffs/nxffs_write.c
@@ -0,0 +1,147 @@
+/****************************************************************************
+ * fs/nxffs/nxffs_write.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * References: Linux/Documentation/filesystems/romfs.txt
+ *
+ * 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 <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs.h>
+#include <nuttx/mtd.h>
+
+#include "nxffs.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxffs_write
+ *
+ * Description:
+ * This is an implementation of the NuttX standard file system write
+ * method.
+ *
+ ****************************************************************************/
+
+ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer, size_t buflen)
+{
+ FAR struct nxffs_volume_s *volume;
+ FAR struct nxffs_wrfile_s *wrfile;
+ ssize_t ret;
+
+ fvdbg("Write %d bytes to offset %d\n", buflen, filep->f_pos);
+
+ /* Sanity checks */
+
+ DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
+
+ /* Recover the open file state from the struct file instance */
+
+ wrfile = (FAR struct nxffs_wrfile_s *)filep->f_priv;
+
+ /* Recover the volume state from the open file */
+
+ volume = (FAR struct nxffs_volume_s *)filep->f_inode->i_private;
+ DEBUGASSERT(volume != NULL);
+
+ /* Get exclusive access to the volume. Note that the volume exclsem
+ * protects the open file list.
+ */
+
+ ret = sem_wait(&volume->exclsem);
+ if (ret != OK)
+ {
+ ret = -errno;
+ fdbg("sem_wait failed: %d\n", ret);
+ goto errout;
+ }
+
+ /* Check if the file was opened with write access */
+
+#ifdef CONFIG_DEBUG
+ if ((wrfile->ofile.mode & O_WROK) == 0)
+ {
+ fdbg("File not open for write access\n");
+ ret = -EACCES;
+ goto errout_with_semaphore;
+ }
+#endif
+
+ /* Seek to the current file offset */
+
+ nxffs_ioseek(volume, wrfile->dathdr + wrfile->wrlen);
+
+ /* Write data to that file offset */
+
+ ret = nxffs_wrdata(volume, (FAR const uint8_t*)buffer, buflen);
+ if (ret > 0)
+ {
+ /* Update the file offset */
+
+ filep->f_pos += ret;
+ }
+#warning "Add check for block full"
+
+errout_with_semaphore:
+ sem_post(&volume->exclsem);
+errout:
+ return ret;
+}
diff --git a/nuttx/include/nuttx/mtd.h b/nuttx/include/nuttx/mtd.h
index 2cf56a2b48..1acf0f530a 100644
--- a/nuttx/include/nuttx/mtd.h
+++ b/nuttx/include/nuttx/mtd.h
@@ -2,7 +2,7 @@
* include/nuttx/mtd.h
* Memory Technology Device (MTD) interface
*
- * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
diff --git a/nuttx/include/nuttx/nxffs.h b/nuttx/include/nuttx/nxffs.h
new file mode 100644
index 0000000000..e4625a0576
--- /dev/null
+++ b/nuttx/include/nuttx/nxffs.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+ * include/nuttx/nxffs.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NXFFS_H
+#define __INCLUDE_NUTTX_NXFFS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+/* If the erased state of FLASH memory is anything other than 0xff, then this
+ * configuration should be provided.
+ */
+
+#ifndef CONFIG_NXFFS_ERASEDSTATE
+# define CONFIG_NXFFS_ERASEDSTATE 0xff
+#endif
+
+#if CONFIG_NXFFS_ERASEDSTATE != 0xff && CONFIG_NXFFS_ERASEDSTATE != 0x00
+# error "CONFIG_NXFFS_ERASEDSTATE must be either 0x00 or 0xff"
+#endif
+
+/* At present, only a single pre-allocated NXFFS volume is supported. This
+ * is because here can be only a single NXFFS volume mounted at any time.
+ * This has to do with the fact that we bind to an MTD driver (instead of a
+ * block driver) and bypass all of the normal mount operations.
+ */
+
+#undef CONFIG_NXFSS_PREALLOCATED
+#define CONFIG_NXFSS_PREALLOCATED 1
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: nxffs_initialize
+ *
+ * Description:
+ * Initialize to provide NXFFS on an MTD interface
+ *
+ * Input Parameters:
+ * mtd - The MTD device that supports the FLASH interface.
+ *
+ * Returned Value:
+ * Zero is returned on success. Otherwise, a negated errno value is
+ * returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+EXTERN int nxffs_initialize(FAR struct mtd_dev_s *mtd);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INCLUDE_NUTTX_NXFFS_H */