summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-08-27 16:31:41 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-08-27 16:31:41 +0000
commit021fe70054d93cf21e99cd7ffeaa10054f2bdac6 (patch)
treef21b4561ad36b31d352525cc405aa54af4d9063f
parent1b571c64512a21d7aabc7122ead9bac785c8ff56 (diff)
downloadpx4-nuttx-021fe70054d93cf21e99cd7ffeaa10054f2bdac6.tar.gz
px4-nuttx-021fe70054d93cf21e99cd7ffeaa10054f2bdac6.tar.bz2
px4-nuttx-021fe70054d93cf21e99cd7ffeaa10054f2bdac6.zip
Add a flash_eraseall() function
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3918 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/ChangeLog5
-rw-r--r--nuttx/drivers/mtd/Make.defs2
-rwxr-xr-xnuttx/drivers/mtd/flash_eraseall.c113
-rwxr-xr-xnuttx/drivers/mtd/ftl.c41
-rw-r--r--nuttx/include/nuttx/mtd.h11
5 files changed, 163 insertions, 9 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 3468a5b62..3f5fa7e6d 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -2036,3 +2036,8 @@
* Scripts/makefiles/documents. Several adjustments, corrections and
typo fixes so that NuttX will build correctly on FreeBSD using the
ASH shell (submitted by Kurt Lidl).
+ * drivers/mtd/flash_eraseall.c: Add a callable function that accepts
+ the path to a block driver and then erases the underlying FLASH memory
+ (assuming that the block driver is an MTD driver wrapped in the FTL
+ layer).
+
diff --git a/nuttx/drivers/mtd/Make.defs b/nuttx/drivers/mtd/Make.defs
index 58870521b..2a1143158 100644
--- a/nuttx/drivers/mtd/Make.defs
+++ b/nuttx/drivers/mtd/Make.defs
@@ -36,7 +36,7 @@
# Include MTD drivers
-CSRCS += ftl.c m25px.c at45db.c ramtron.c rammtd.c
+CSRCS += at45db.c flash_eraseall.c ftl.c m25px.c rammtd.c ramtron.c
# Include MTD driver support
diff --git a/nuttx/drivers/mtd/flash_eraseall.c b/nuttx/drivers/mtd/flash_eraseall.c
new file mode 100755
index 000000000..7d42fe9d4
--- /dev/null
+++ b/nuttx/drivers/mtd/flash_eraseall.c
@@ -0,0 +1,113 @@
+/****************************************************************************
+ * drivers/mtd/flash_eraseall.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 <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs.h>
+#include <nuttx/ioctl.h>
+#include <nuttx/mtd.h>
+
+/****************************************************************************
+ * Private Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: flash_eraseall
+ *
+ * Description:
+ * Call a block driver with the MDIOC_BULKERASE ioctl command. This will
+ * cause the MTD driver to erase all of the flash.
+ *
+ ****************************************************************************/
+
+int flash_eraseall(FAR const char *driver)
+{
+ FAR struct inode *inode;
+ FAR const struct block_operations *ops;
+ int ret;
+
+ /* Open the block driver */
+
+ ret = open_blockdriver(driver ,0, &inode);
+ if (ret < 0)
+ {
+ fdbg("ERROR: Failed to open '%s': %d\n", driver, ret);
+ return ret;
+ }
+
+ /* Get the block operations */
+
+ ops = inode->u.i_bops;
+
+ /* Invoke the block driver ioctl method */
+
+ ret = -EPERM;
+ if (ops->ioctl)
+ {
+ ret = ops->ioctl(inode, MTDIOC_BULKERASE, 0);
+ }
+
+ /* Close the block driver */
+
+ close_blockdriver(inode);
+ return ret;
+}
diff --git a/nuttx/drivers/mtd/ftl.c b/nuttx/drivers/mtd/ftl.c
index ff3c19345..f01a19470 100755
--- a/nuttx/drivers/mtd/ftl.c
+++ b/nuttx/drivers/mtd/ftl.c
@@ -420,21 +420,46 @@ static int ftl_geometry(FAR struct inode *inode, struct geometry *geometry)
static int ftl_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
{
struct ftl_struct_s *dev ;
- int ret = -ENOTTY;
+ int ret;
fvdbg("Entry\n");
+ DEBUGASSERT(inode && inode->i_private);
- /* Only one ioctl command is supported (and that is just passed on to MTD */
+ /* Only one block driver ioctl command is supported by this driver (and
+ * that command is just passed on to the MTD driver in a slightly
+ * different form).
+ */
- DEBUGASSERT(inode && inode->i_private);
- if (cmd == BIOC_XIPBASE && arg != 0)
+ if (cmd == BIOC_XIPBASE)
{
- dev = (struct ftl_struct_s *)inode->i_private;
- ret = MTD_IOCTL(dev->mtd, MTDIOC_XIPBASE, arg);
- if (ret < 0)
+ /* The argument accompanying the BIOC_XIPBASE should be non-NULL. If
+ * DEBUG is enabled, we will catch it here instead of in the MTD
+ * driver.
+ */
+
+#ifdef CONFIG_DEBUG
+ if (arg == 0)
{
- fdbg("MTD ioctl(MTDIOC_XIPBASE) failed: %d\n", ret);
+ fdbg("ERROR: BIOC_XIPBASE argument is NULL\n");
+ return -EINVAL;
}
+#endif
+
+ /* Just change the BIOC_XIPBASE command to the MTDIOC_XIPBASE command. */
+
+ cmd = MTDIOC_XIPBASE;
+ }
+
+ /* No other block driver ioctl commmands are not recognized by this
+ * driver. Other possible MTD driver ioctl commands are passed through
+ * to the MTD driver (unchanged).
+ */
+
+ dev = (struct ftl_struct_s *)inode->i_private;
+ ret = MTD_IOCTL(dev->mtd, cmd, arg);
+ if (ret < 0)
+ {
+ fdbg("ERROR: MTD ioctl(%04x) failed: %d\n", cmd, ret);
}
return ret;
diff --git a/nuttx/include/nuttx/mtd.h b/nuttx/include/nuttx/mtd.h
index 1acf0f530..95286dee5 100644
--- a/nuttx/include/nuttx/mtd.h
+++ b/nuttx/include/nuttx/mtd.h
@@ -148,6 +148,17 @@ extern "C" {
EXTERN int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd);
/****************************************************************************
+ * Name: flash_eraseall
+ *
+ * Description:
+ * Call a block driver with the MDIOC_BULKERASE ioctl command. This will
+ * cause the MTD driver to erase all of the flash.
+ *
+ ****************************************************************************/
+
+EXTERN int flash_eraseall(FAR const char *driver);
+
+/****************************************************************************
* Name: rammtd_initialize
*
* Description: