9
0
Fork 0

Add a flash_eraseall() function

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3918 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2011-08-27 16:31:41 +00:00
parent e1a8bc740d
commit 13674294d4
5 changed files with 164 additions and 10 deletions

View File

@ -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).

View File

@ -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

View File

@ -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;
}

View File

@ -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");
/* Only one ioctl command is supported (and that is just passed on to MTD */
DEBUGASSERT(inode && inode->i_private);
if (cmd == BIOC_XIPBASE && arg != 0)
/* 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).
*/
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;

View File

@ -147,6 +147,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
*