mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Add Ken Pettit's SMART FS
This commit is contained in:
@@ -134,6 +134,20 @@ struct nfsdir_s
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FS_SMARTFS
|
||||
/* SMARTFS is the Sector Mapped Allocation for Really Tiny FLASH filesystem.
|
||||
* it is designed to use small sectors on small serial FLASH devices, using
|
||||
* minimal RAM footprint.
|
||||
*/
|
||||
|
||||
struct fs_smartfsdir_s
|
||||
{
|
||||
uint16_t fs_firstsector; /* First sector of directory list */
|
||||
uint16_t fs_currsector; /* Current sector of directory list */
|
||||
uint16_t fs_curroffset; /* Current offset withing current sector */
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_DISABLE_MOUNTPOINT */
|
||||
|
||||
struct fs_dirent_s
|
||||
@@ -174,19 +188,22 @@ struct fs_dirent_s
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
#ifdef CONFIG_FS_FAT
|
||||
struct fs_fatdir_s fat;
|
||||
struct fs_fatdir_s fat;
|
||||
#endif
|
||||
#ifdef CONFIG_FS_ROMFS
|
||||
struct fs_romfsdir_s romfs;
|
||||
struct fs_romfsdir_s romfs;
|
||||
#endif
|
||||
#ifdef CONFIG_FS_BINFS
|
||||
struct fs_binfsdir_s binfs;
|
||||
struct fs_binfsdir_s binfs;
|
||||
#endif
|
||||
#ifdef CONFIG_FS_NXFFS
|
||||
struct fs_nxffsdir_s nxffs;
|
||||
struct fs_nxffsdir_s nxffs;
|
||||
#endif
|
||||
#ifdef CONFIG_NFS
|
||||
struct nfsdir_s nfs;
|
||||
struct nfsdir_s nfs;
|
||||
#endif
|
||||
#ifdef CONFIG_FS_SMARTFS
|
||||
struct fs_smartfsdir_s smartfs;
|
||||
#endif
|
||||
#endif /* !CONFIG_DISABLE_MOUNTPOINT */
|
||||
} u;
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
#define FIOC_OPTIMIZE _FIOC(0x0003) /* IN: None
|
||||
* OUT: None
|
||||
*/
|
||||
#define FIOC_FILENAME _FIOC(0x0004) /* IN: FAR const char ** pointer
|
||||
#define FIOC_FILENAME _FIOC(0x0004) /* IN: FAR const char ** pointer
|
||||
* OUT: Pointer to a persistent file name
|
||||
* (Guaranteed to persist while the file
|
||||
* is open).
|
||||
@@ -146,6 +146,35 @@
|
||||
* IN: None
|
||||
* OUT: None (ioctl return value provides
|
||||
* success/failure indication). */
|
||||
#define BIOC_LLFORMAT _BIOC(0x0004) /* Low-Level Format on SMART flash devices
|
||||
* IN: None
|
||||
* OUT: None (ioctl return value provides
|
||||
* success/failure indication). */
|
||||
#define BIOC_GETFORMAT _BIOC(0x0005) /* Returns SMART flash format information
|
||||
* such as format status, logical sector
|
||||
* size, total sectors, free sectors, etc.
|
||||
* IN: None
|
||||
* OUT: Pointer to the format information. */
|
||||
#define BIOC_ALLOCSECT _BIOC(0x0006) /* Allocate a logical sector from the block
|
||||
* device.
|
||||
* IN: None
|
||||
* OUT: Logical sector number allocated. */
|
||||
#define BIOC_FREESECT _BIOC(0x0007) /* Allocate a logical sector from the block
|
||||
* device.
|
||||
* IN: None
|
||||
* OUT: Logical sector number allocated. */
|
||||
#define BIOC_READSECT _BIOC(0x0008) /* Read a logical sector from the block
|
||||
* device.
|
||||
* IN: Pointer to sector read data (the
|
||||
* logical sector number, count and
|
||||
* read buffer address
|
||||
* OUT: Number of bytes read or error */
|
||||
#define BIOC_WRITESECT _BIOC(0x0009) /* Write to data to a logical sector
|
||||
* IN: Pointer to sector write data (the
|
||||
* logical secor number and write
|
||||
* buffer address
|
||||
* OUT: None (ioctl return value provides
|
||||
* success/failure indication). */
|
||||
|
||||
/* NuttX MTD driver ioctl definitions ***************************************/
|
||||
|
||||
@@ -164,6 +193,15 @@
|
||||
* of device memory */
|
||||
#define MTDIOC_BULKERASE _MTDIOC(0x0003) /* IN: None
|
||||
* OUT: None */
|
||||
#define MTDIOC_GETCAPS _MTDIOC(0x0004) /* IN: None
|
||||
* OUT: Capabilities flags */
|
||||
#define MTDIOC_SECTERASE _MTDIOC(0x0005) /* IN: Sector number to erase
|
||||
* OUT: None */
|
||||
#define MTDIOC_BYTEWRITE _MTDIOC(0x0006) /* IN: Pointer to bytewrite structure
|
||||
* OUT: None */
|
||||
|
||||
#define MTDIOC_CAPS_SECTERASE 0x01
|
||||
#define MTDIOC_CAPS_BYTEWRITE 0x02
|
||||
|
||||
/* NuttX ARP driver ioctl definitions (see netinet/arp.h) *******************/
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/fs/mksmartfs.h
|
||||
*
|
||||
* Copyright (C) 2013 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* 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_SMART_MKSMARTFS_H
|
||||
#define __INCLUDE_NUTTX_SMART_MKSMARTFS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mksmartfs
|
||||
*
|
||||
* Description:
|
||||
* Make a SMART (Sector Mapped Allocation for Really Tiny) Flash file
|
||||
* system image on the specified block device (must be a SMART device).
|
||||
*
|
||||
* Inputs:
|
||||
* pathname - the full path to a registered block driver
|
||||
* nrootdirs - the number of Root Directory entries to support
|
||||
* on this device (supports multiple mount points).
|
||||
*
|
||||
* Return:
|
||||
* Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately:
|
||||
*
|
||||
* EINVAL - NULL block driver string
|
||||
* ENOENT - 'pathname' does not refer to anything in the filesystem.
|
||||
* ENOTBLK - 'pathname' does not refer to a block driver
|
||||
* EACCESS - block driver does not support write or geometry methods or
|
||||
* is not a SMART device
|
||||
*
|
||||
* Assumptions:
|
||||
* - The caller must assure that the block driver is not mounted and not in
|
||||
* use when this function is called. The result of formatting a mounted
|
||||
* device is indeterminate (but likely not good).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||
EXTERN int mksmartfs(FAR const char *pathname, uint8_t nrootdirs);
|
||||
#else
|
||||
EXTERN int mksmartfs(FAR const char *pathname);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_SMART_MKSMARTFS_H */
|
||||
+43
-4
@@ -58,6 +58,14 @@
|
||||
#define MTD_BWRITE(d,s,n,b)((d)->bwrite ? (d)->bwrite(d,s,n,b) : (-ENOSYS))
|
||||
#define MTD_IOCTL(d,c,a) ((d)->ioctl ? (d)->ioctl(d,c,a) : (-ENOSYS))
|
||||
|
||||
/* If any of the low-level device drivers declare they want sub-sector erase
|
||||
* support, then define MTD_SUBSECTOR_ERASE.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_MP25P_SUBSECTOR_ERASE)
|
||||
# define CONFIG_MTD_SUBSECTOR_ERASE 1
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -70,10 +78,25 @@
|
||||
|
||||
struct mtd_geometry_s
|
||||
{
|
||||
uint16_t blocksize; /* Size of one read/write block */
|
||||
uint16_t erasesize; /* Size of one erase blocks -- must be a multiple
|
||||
* of blocksize. */
|
||||
size_t neraseblocks; /* Number of erase blocks */
|
||||
uint16_t blocksize; /* Size of one read/write block */
|
||||
uint16_t erasesize; /* Size of one erase blocks -- must be a multiple
|
||||
* of blocksize. */
|
||||
size_t neraseblocks; /* Number of erase blocks */
|
||||
#ifdef CONFIG_MTD_SUBSECTOR_ERASE
|
||||
uint16_t subsectorsize; /* Size of the sub-sector erase block */
|
||||
uint16_t nsubsectors; /* Number of sub-sector erase blocks */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* The following defines the information for writing bytes to a sector
|
||||
* that are not a full page write (bytewrite).
|
||||
*/
|
||||
|
||||
struct mtd_byte_write_s
|
||||
{
|
||||
uint32_t offset; /* Offset within the device to write to */
|
||||
uint16_t count; /* Number of bytes to write */
|
||||
const uint8_t *buffer; /* Pointer to the data to write */
|
||||
};
|
||||
|
||||
/* This structure defines the interface to a simple memory technology device.
|
||||
@@ -169,6 +192,22 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd,
|
||||
|
||||
int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: smart_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize to provide a Sector Mapped Allocation for Really Tiny (SMART)
|
||||
* Flash block driver wrapper around an MTD interface
|
||||
*
|
||||
* Input Parameters:
|
||||
* minor - The minor device number. The MTD block device will be
|
||||
* registered as as /dev/mtdsmartN where N is the minor number.
|
||||
* mtd - The MTD device that supports the FLASH interface.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int smart_initialize(int minor, FAR struct mtd_dev_s *mtd);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: flash_eraseall
|
||||
*
|
||||
|
||||
+2
-1
@@ -357,7 +357,8 @@ enum spi_dev_e
|
||||
SPIDEV_WIRELESS, /* Select SPI Wireless device */
|
||||
SPIDEV_TOUCHSCREEN, /* Select SPI touchscreen device */
|
||||
SPIDEV_EXPANDER, /* Select SPI I/O expander device */
|
||||
SPIDEV_MUX /* Select SPI multiplexer device */
|
||||
SPIDEV_MUX, /* Select SPI multiplexer device */
|
||||
SPIDEV_AUDIO /* Select SPI audio codec device */
|
||||
};
|
||||
|
||||
/* Certain SPI devices may required differnt clocking modes */
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
|
||||
#define BINFS_MAGIC 0x4242
|
||||
#define NXFFS_MAGIC 0x4747
|
||||
#define SMARTFS_MAGIC 0x54524D53
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
|
||||
Reference in New Issue
Block a user