2015-11-25 21:46:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/mtd/filemtd.c
|
|
|
|
*
|
2021-04-10 08:50:57 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
2021-04-10 08:50:57 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
2021-04-10 08:50:57 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2023-02-01 14:41:12 +01:00
|
|
|
#include <sys/param.h>
|
2015-11-25 21:46:28 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2023-02-06 16:05:12 +01:00
|
|
|
#include <sys/mount.h>
|
2015-11-25 21:46:28 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
2017-10-11 18:18:30 +02:00
|
|
|
#include <nuttx/fs/fs.h>
|
2015-11-25 21:46:28 +01:00
|
|
|
#include <nuttx/fs/ioctl.h>
|
2023-02-06 16:05:12 +01:00
|
|
|
#include <nuttx/fs/loopmtd.h>
|
2015-11-25 21:46:28 +01:00
|
|
|
#include <nuttx/mtd/mtd.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2020-03-21 20:54:03 +01:00
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_FILEMTD_BLOCKSIZE
|
|
|
|
# define CONFIG_FILEMTD_BLOCKSIZE 512
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FILEMTD_ERASESIZE
|
|
|
|
# define CONFIG_FILEMTD_ERASESIZE 4096
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FILEMTD_ERASESTATE
|
|
|
|
# define CONFIG_FILEMTD_ERASESTATE 0xff
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_FILEMTD_ERASESTATE != 0xff && CONFIG_FILEMTD_ERASESTATE != 0x00
|
|
|
|
# error "Unsupported value for CONFIG_FILEMTD_ERASESTATE"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_FILEMTD_BLOCKSIZE > CONFIG_FILEMTD_ERASESIZE
|
|
|
|
# error "Must have CONFIG_FILEMTD_BLOCKSIZE <= CONFIG_FILEMTD_ERASESIZE"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef FILEMTD_BLKPER
|
|
|
|
#define FILEMTD_BLKPER (CONFIG_FILEMTD_ERASESIZE/CONFIG_FILEMTD_BLOCKSIZE)
|
|
|
|
|
|
|
|
#if FILEMTD_BLKPER*CONFIG_FILEMTD_BLOCKSIZE != CONFIG_FILEMTD_ERASESIZE
|
|
|
|
# error "CONFIG_FILEMTD_ERASESIZE must be an even multiple of CONFIG_FILEMTD_BLOCKSIZE"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This type represents the state of the MTD device. The struct mtd_dev_s
|
|
|
|
* must appear at the beginning of the definition so that you can freely
|
|
|
|
* cast between pointers to struct mtd_dev_s and struct file_dev_s.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct file_dev_s
|
|
|
|
{
|
2015-11-28 16:00:26 +01:00
|
|
|
struct mtd_dev_s mtd; /* MTD device */
|
2017-11-03 00:07:08 +01:00
|
|
|
struct file mtdfile;
|
2015-11-28 16:00:26 +01:00
|
|
|
size_t nblocks; /* Number of erase blocks */
|
|
|
|
size_t offset; /* Offset from start of file */
|
|
|
|
size_t erasesize; /* Offset from start of file */
|
|
|
|
size_t blocksize; /* Offset from start of file */
|
2015-11-25 21:46:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-25 21:57:25 +01:00
|
|
|
static ssize_t filemtd_read(FAR struct file_dev_s *priv,
|
2023-03-09 09:01:58 +01:00
|
|
|
FAR unsigned char *buffer, size_t offsetbytes,
|
|
|
|
unsigned int nbytes);
|
2015-11-25 21:57:25 +01:00
|
|
|
static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset,
|
2023-03-09 09:01:58 +01:00
|
|
|
FAR const void *src, size_t len);
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
/* MTD driver methods */
|
|
|
|
|
2023-03-09 09:01:58 +01:00
|
|
|
static int filemtd_erase(FAR struct mtd_dev_s *dev, off_t startblock,
|
|
|
|
size_t nblocks);
|
2016-07-18 04:19:44 +02:00
|
|
|
static ssize_t filemtd_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
2023-03-09 09:01:58 +01:00
|
|
|
size_t nblocks, FAR uint8_t *buf);
|
2016-07-18 04:19:44 +02:00
|
|
|
static ssize_t filemtd_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
2023-03-09 09:01:58 +01:00
|
|
|
size_t nblocks, FAR const uint8_t *buf);
|
2016-07-18 04:19:44 +02:00
|
|
|
static ssize_t filemtd_byteread(FAR struct mtd_dev_s *dev, off_t offset,
|
2023-03-09 09:01:58 +01:00
|
|
|
size_t nbytes, FAR uint8_t *buf);
|
2015-11-25 21:46:28 +01:00
|
|
|
#ifdef CONFIG_MTD_BYTE_WRITE
|
|
|
|
static ssize_t file_bytewrite(FAR struct mtd_dev_s *dev, off_t offset,
|
2023-03-09 09:01:58 +01:00
|
|
|
size_t nbytes, FAR const uint8_t *buf);
|
2015-11-25 21:46:28 +01:00
|
|
|
#endif
|
2023-03-09 09:01:58 +01:00
|
|
|
static int filemtd_ioctl(FAR struct mtd_dev_s *dev, int cmd,
|
|
|
|
unsigned long arg);
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2023-02-06 16:05:12 +01:00
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
static ssize_t mtd_loop_read(FAR struct file *filep, FAR char *buffer,
|
2023-03-09 09:01:58 +01:00
|
|
|
size_t buflen);
|
2023-02-06 16:05:12 +01:00
|
|
|
static ssize_t mtd_loop_write(FAR struct file *filep,
|
2023-03-09 09:01:58 +01:00
|
|
|
FAR const char *buffer, size_t buflen);
|
2023-02-06 16:05:12 +01:00
|
|
|
static int mtd_loop_ioctl(FAR struct file *filep, int cmd,
|
2023-03-09 09:01:58 +01:00
|
|
|
unsigned long arg);
|
2023-02-06 16:05:12 +01:00
|
|
|
#endif /* CONFIG_MTD_LOOP */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
static const struct file_operations g_fops =
|
|
|
|
{
|
|
|
|
NULL, /* open */
|
|
|
|
NULL, /* close */
|
|
|
|
mtd_loop_read, /* read */
|
|
|
|
mtd_loop_write, /* write */
|
|
|
|
NULL, /* seek */
|
|
|
|
mtd_loop_ioctl, /* ioctl */
|
|
|
|
};
|
|
|
|
#endif /* CONFIG_MTD_LOOP */
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: filemtd_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-28 21:17:17 +02:00
|
|
|
static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset,
|
2015-11-25 21:57:25 +01:00
|
|
|
FAR const void *src, size_t len)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR const uint8_t *pin = (FAR const uint8_t *)src;
|
2022-03-16 12:27:31 +01:00
|
|
|
FAR uint8_t *pout = NULL;
|
2015-11-25 21:46:28 +01:00
|
|
|
char buf[128];
|
2021-12-13 22:48:24 +01:00
|
|
|
int buflen;
|
2022-03-16 12:27:31 +01:00
|
|
|
int remain = 0;
|
2015-11-25 21:46:28 +01:00
|
|
|
uint8_t oldvalue;
|
|
|
|
uint8_t srcvalue;
|
|
|
|
uint8_t newvalue;
|
|
|
|
size_t seekpos;
|
|
|
|
|
|
|
|
/* Set the starting location in the file */
|
|
|
|
|
|
|
|
seekpos = priv->offset + offset;
|
|
|
|
|
2021-12-13 22:48:24 +01:00
|
|
|
for (buflen = 0; len > 0; len--)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
if (buflen == 0)
|
|
|
|
{
|
|
|
|
/* Read more data from the file */
|
|
|
|
|
2017-11-03 00:07:08 +01:00
|
|
|
file_seek(&priv->mtdfile, seekpos, SEEK_SET);
|
2021-12-13 22:48:24 +01:00
|
|
|
buflen = file_read(&priv->mtdfile, buf, MIN(len, sizeof(buf)));
|
2022-03-16 12:27:31 +01:00
|
|
|
pout = (FAR uint8_t *)buf;
|
2021-12-13 22:48:24 +01:00
|
|
|
remain = buflen;
|
2015-11-25 21:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the source and destination values */
|
|
|
|
|
|
|
|
oldvalue = *pout;
|
|
|
|
srcvalue = *pin++;
|
|
|
|
|
|
|
|
/* Get the new destination value, accounting for bits that cannot be
|
|
|
|
* changes because they are not in the erased state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if CONFIG_FILEMTD_ERASESTATE == 0xff
|
|
|
|
newvalue = oldvalue & srcvalue; /* We can only clear bits */
|
|
|
|
#else /* CONFIG_FILEMTD_ERASESTATE == 0x00 */
|
|
|
|
newvalue = oldvalue | srcvalue; /* We can only set bits */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Report any attempt to change the value of bits that are not in the
|
|
|
|
* erased state.
|
|
|
|
*/
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2015-11-25 21:46:28 +01:00
|
|
|
if (newvalue != srcvalue)
|
|
|
|
{
|
2017-10-19 17:53:41 +02:00
|
|
|
ferr("ERROR: Bad write: source=%02x dest=%02x result=%02x\n",
|
2015-11-25 21:46:28 +01:00
|
|
|
srcvalue, oldvalue, newvalue);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Write the modified value to simulated FLASH */
|
|
|
|
|
|
|
|
*pout++ = newvalue;
|
2021-12-13 22:48:24 +01:00
|
|
|
remain--;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2017-06-28 21:17:17 +02:00
|
|
|
/* If our buffer is full, then seek back to beginning of
|
|
|
|
* the file and write the buffer contents
|
2015-11-25 21:46:28 +01:00
|
|
|
*/
|
|
|
|
|
2021-12-13 22:48:24 +01:00
|
|
|
if (remain == 0)
|
2017-06-28 21:17:17 +02:00
|
|
|
{
|
2017-11-03 00:07:08 +01:00
|
|
|
file_seek(&priv->mtdfile, seekpos, SEEK_SET);
|
2021-12-13 22:48:24 +01:00
|
|
|
file_write(&priv->mtdfile, buf, buflen);
|
|
|
|
seekpos += buflen;
|
|
|
|
buflen = 0;
|
2017-06-28 21:17:17 +02:00
|
|
|
}
|
2015-11-25 21:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write remaining bytes */
|
|
|
|
|
|
|
|
if (buflen != 0)
|
|
|
|
{
|
2017-11-03 00:07:08 +01:00
|
|
|
file_seek(&priv->mtdfile, seekpos, SEEK_SET);
|
2021-12-13 22:48:24 +01:00
|
|
|
file_write(&priv->mtdfile, buf, buflen);
|
2015-11-25 21:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: filemtd_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-25 21:57:25 +01:00
|
|
|
static ssize_t filemtd_read(FAR struct file_dev_s *priv,
|
|
|
|
FAR unsigned char *buffer, size_t offsetbytes,
|
2017-10-19 17:53:41 +02:00
|
|
|
unsigned int nbytes)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
/* Set the starting location in the file */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
file_seek(&priv->mtdfile, priv->offset + offsetbytes, SEEK_SET);
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2017-11-03 00:07:08 +01:00
|
|
|
return file_read(&priv->mtdfile, buffer, nbytes);
|
2015-11-25 21:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-07-18 04:19:44 +02:00
|
|
|
* Name: filemtd_erase
|
2015-11-25 21:46:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-18 04:19:44 +02:00
|
|
|
static int filemtd_erase(FAR struct mtd_dev_s *dev, off_t startblock,
|
2017-10-19 17:53:41 +02:00
|
|
|
size_t nblocks)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
|
|
|
size_t nbytes;
|
|
|
|
size_t offset;
|
|
|
|
char buffer[128];
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
|
|
|
/* Don't let the erase exceed the original size of the file */
|
|
|
|
|
|
|
|
if (startblock >= priv->nblocks)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startblock + nblocks > priv->nblocks)
|
|
|
|
{
|
|
|
|
nblocks = priv->nblocks - startblock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the erase block to a logical block and the number of blocks
|
|
|
|
* in logical block numbers
|
|
|
|
*/
|
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
startblock *= (priv->erasesize / priv->blocksize);
|
|
|
|
nblocks *= (priv->erasesize / priv->blocksize);
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
/* Get the offset corresponding to the first block and the size
|
|
|
|
* corresponding to the number of blocks.
|
|
|
|
*/
|
|
|
|
|
2015-11-28 16:00:26 +01:00
|
|
|
offset = startblock * priv->blocksize;
|
|
|
|
nbytes = nblocks * priv->blocksize;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
/* Then erase the data in the file */
|
|
|
|
|
2017-11-03 00:07:08 +01:00
|
|
|
file_seek(&priv->mtdfile, priv->offset + offset, SEEK_SET);
|
2015-11-25 21:46:28 +01:00
|
|
|
memset(buffer, CONFIG_FILEMTD_ERASESTATE, sizeof(buffer));
|
2021-12-13 22:48:24 +01:00
|
|
|
while (nbytes > 0)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
2021-12-13 22:48:24 +01:00
|
|
|
file_write(&priv->mtdfile, buffer, MIN(nbytes, sizeof(buffer)));
|
|
|
|
nbytes -= MIN(nbytes, sizeof(buffer));
|
2015-11-25 21:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-07-18 04:19:44 +02:00
|
|
|
* Name: filemtd_bread
|
2015-11-25 21:46:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-18 04:19:44 +02:00
|
|
|
static ssize_t filemtd_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
2017-10-19 17:53:41 +02:00
|
|
|
size_t nblocks, FAR uint8_t *buf)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
|
|
|
off_t offset;
|
|
|
|
off_t maxblock;
|
|
|
|
size_t nbytes;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev && buf);
|
|
|
|
|
|
|
|
/* Don't let the read exceed the original size of the file */
|
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
maxblock = priv->nblocks * (priv->erasesize / priv->blocksize);
|
2015-11-25 21:46:28 +01:00
|
|
|
if (startblock >= maxblock)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startblock + nblocks > maxblock)
|
|
|
|
{
|
|
|
|
nblocks = maxblock - startblock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the offset corresponding to the first block and the size
|
|
|
|
* corresponding to the number of blocks.
|
|
|
|
*/
|
|
|
|
|
2015-11-28 16:00:26 +01:00
|
|
|
offset = startblock * priv->blocksize;
|
|
|
|
nbytes = nblocks * priv->blocksize;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
/* Then read the data from the file */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
filemtd_read(priv, buf, offset, nbytes);
|
2015-11-25 21:46:28 +01:00
|
|
|
return nblocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-07-18 04:19:44 +02:00
|
|
|
* Name: filemtd_bwrite
|
2015-11-25 21:46:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-18 04:19:44 +02:00
|
|
|
static ssize_t filemtd_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
2017-10-11 18:18:30 +02:00
|
|
|
size_t nblocks, FAR const uint8_t *buf)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
|
|
|
off_t offset;
|
|
|
|
off_t maxblock;
|
|
|
|
size_t nbytes;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev && buf);
|
|
|
|
|
|
|
|
/* Don't let the write exceed the original size of the file */
|
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
maxblock = priv->nblocks * (priv->erasesize / priv->blocksize);
|
2015-11-25 21:46:28 +01:00
|
|
|
if (startblock >= maxblock)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startblock + nblocks > maxblock)
|
|
|
|
{
|
|
|
|
nblocks = maxblock - startblock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the offset corresponding to the first block and the size
|
|
|
|
* corresponding to the number of blocks.
|
|
|
|
*/
|
|
|
|
|
2015-11-28 16:00:26 +01:00
|
|
|
offset = startblock * priv->blocksize;
|
|
|
|
nbytes = nblocks * priv->blocksize;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
/* Then write the data to the file */
|
|
|
|
|
|
|
|
filemtd_write(priv, offset, buf, nbytes);
|
|
|
|
return nblocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-07-18 04:19:44 +02:00
|
|
|
* Name: filemtd_byteread
|
2015-11-25 21:46:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-18 04:19:44 +02:00
|
|
|
static ssize_t filemtd_byteread(FAR struct mtd_dev_s *dev, off_t offset,
|
2017-10-19 17:53:41 +02:00
|
|
|
size_t nbytes, FAR uint8_t *buf)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
2021-12-04 13:48:15 +01:00
|
|
|
off_t maxoffset;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(dev && buf);
|
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
/* Don't let the read exceed the original size of the file */
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
maxoffset = priv->nblocks * priv->erasesize;
|
|
|
|
if (offset >= maxoffset)
|
2020-03-21 20:54:03 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
if (offset + nbytes > maxoffset)
|
|
|
|
{
|
|
|
|
nbytes = maxoffset - offset;
|
|
|
|
}
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
filemtd_read(priv, buf, offset, nbytes);
|
2015-11-25 21:46:28 +01:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: file_bytewrite
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_BYTE_WRITE
|
|
|
|
static ssize_t file_bytewrite(FAR struct mtd_dev_s *dev, off_t offset,
|
2017-10-11 18:18:30 +02:00
|
|
|
size_t nbytes, FAR const uint8_t *buf)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
|
|
|
off_t maxoffset;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev && buf);
|
|
|
|
|
|
|
|
/* Don't let the write exceed the original size of the file */
|
|
|
|
|
2015-11-28 16:00:26 +01:00
|
|
|
maxoffset = priv->nblocks * priv->erasesize;
|
2015-11-25 21:46:28 +01:00
|
|
|
if (offset + nbytes > maxoffset)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
if (offset + nbytes > maxoffset)
|
|
|
|
{
|
|
|
|
nbytes = maxoffset - offset;
|
|
|
|
}
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
/* Then write the data to the file */
|
|
|
|
|
|
|
|
filemtd_write(priv, offset, buf, nbytes);
|
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-07-18 04:19:44 +02:00
|
|
|
* Name: filemtd_ioctl
|
2015-11-25 21:46:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-19 17:53:41 +02:00
|
|
|
static int filemtd_ioctl(FAR struct mtd_dev_s *dev, int cmd,
|
|
|
|
unsigned long arg)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
|
|
|
int ret = -EINVAL; /* Assume good command with bad parameters */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case MTDIOC_GEOMETRY:
|
|
|
|
{
|
2015-11-25 21:57:25 +01:00
|
|
|
FAR struct mtd_geometry_s *geo =
|
|
|
|
(FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
if (geo)
|
|
|
|
{
|
2021-08-11 06:21:39 +02:00
|
|
|
memset(geo, 0, sizeof(*geo));
|
|
|
|
|
2020-03-21 20:54:03 +01:00
|
|
|
/* Populate the geometry structure with information need to
|
|
|
|
* know the capacity and how to access the device.
|
2015-11-25 21:46:28 +01:00
|
|
|
*/
|
|
|
|
|
2015-11-28 16:00:26 +01:00
|
|
|
geo->blocksize = priv->blocksize;
|
|
|
|
geo->erasesize = priv->erasesize;
|
2015-11-25 21:46:28 +01:00
|
|
|
geo->neraseblocks = priv->nblocks;
|
|
|
|
ret = OK;
|
2015-11-25 21:57:25 +01:00
|
|
|
}
|
2015-11-25 21:46:28 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-08-15 20:10:23 +02:00
|
|
|
case BIOC_PARTINFO:
|
|
|
|
{
|
|
|
|
FAR struct partition_info_s *info =
|
|
|
|
(FAR struct partition_info_s *)arg;
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
info->numsectors = priv->nblocks *
|
|
|
|
priv->erasesize / priv->blocksize;
|
|
|
|
info->sectorsize = priv->blocksize;
|
|
|
|
info->startsector = 0;
|
|
|
|
info->parent[0] = '\0';
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
case MTDIOC_BULKERASE:
|
|
|
|
{
|
2015-11-25 21:57:25 +01:00
|
|
|
/* Erase the entire device */
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
ret = filemtd_erase(dev, 0, priv->nblocks);
|
2015-11-25 21:46:28 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-07-16 19:16:41 +02:00
|
|
|
case MTDIOC_ERASESTATE:
|
|
|
|
{
|
|
|
|
FAR uint8_t *result = (FAR uint8_t *)arg;
|
|
|
|
*result = CONFIG_FILEMTD_ERASESTATE;
|
|
|
|
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
default:
|
|
|
|
ret = -ENOTTY; /* Bad command */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-02-06 16:05:12 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mtd_loop_setup
|
|
|
|
*
|
|
|
|
* Description: Dynamically setups up a FILEMTD enabled loop device that
|
|
|
|
* is backed by a file. The resulting loop device is a
|
|
|
|
* MTD type block device vs. a generic block device.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
static int mtd_loop_setup(FAR const char *devname, FAR const char *filename,
|
|
|
|
int sectsize, int erasesize, off_t offset)
|
|
|
|
{
|
|
|
|
FAR struct mtd_dev_s *mtd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mtd = filemtd_initialize(filename, offset, sectsize, erasesize);
|
|
|
|
if (mtd == NULL)
|
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = register_mtddriver(devname, mtd, 0755, NULL);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
filemtd_teardown(mtd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MTD_LOOP */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mtd_loop_teardown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Undo the setup performed by loopmtd_setup
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
static int mtd_loop_teardown(FAR const char *devname)
|
|
|
|
{
|
|
|
|
FAR struct file_dev_s *dev;
|
|
|
|
FAR struct inode *inode;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Open the block driver associated with devname so that we can get the
|
|
|
|
* inode reference.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = open_blockdriver(devname, MS_RDONLY, &inode);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ferr("ERROR: Failed to open %s: %d\n", devname, -ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inode private data is a reference to the loop device structure */
|
|
|
|
|
|
|
|
dev = (FAR struct file_dev_s *)inode->u.i_mtd;
|
|
|
|
|
|
|
|
/* Validate this is a filemtd backended device */
|
|
|
|
|
|
|
|
if (!filemtd_isfilemtd(&dev->mtd))
|
|
|
|
{
|
|
|
|
ferr("ERROR: Device is not a FILEMTD loop: %s\n", devname);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
close_blockdriver(inode);
|
|
|
|
|
|
|
|
/* Now teardown the filemtd */
|
|
|
|
|
|
|
|
filemtd_teardown(&dev->mtd);
|
|
|
|
unregister_blockdriver(devname);
|
|
|
|
kmm_free(dev);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MTD_LOOP */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mtd_loop_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
static ssize_t mtd_loop_read(FAR struct file *filep, FAR char *buffer,
|
2023-03-09 09:01:58 +01:00
|
|
|
size_t len)
|
2023-02-06 16:05:12 +01:00
|
|
|
{
|
|
|
|
return 0; /* Return EOF */
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MTD_LOOP */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mtd_loop_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
static ssize_t mtd_loop_write(FAR struct file *filep,
|
2023-03-09 09:01:58 +01:00
|
|
|
FAR const char *buffer, size_t len)
|
2023-02-06 16:05:12 +01:00
|
|
|
{
|
|
|
|
return len; /* Say that everything was written */
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MTD_LOOP */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mtd_loop_ioctl
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
static int mtd_loop_ioctl(FAR struct file *filep, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
/* Command: LOOPIOC_SETUP
|
|
|
|
* Description: Setup the loop device
|
|
|
|
* Argument: A pointer to a read-only instance of struct losetup_s.
|
|
|
|
* Dependencies: The loop device must be enabled (CONFIG_MTD_LOOP=y)
|
|
|
|
*/
|
|
|
|
|
|
|
|
case MTD_LOOPIOC_SETUP:
|
|
|
|
{
|
|
|
|
FAR struct mtd_losetup_s *setup =
|
|
|
|
(FAR struct mtd_losetup_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
if (setup == NULL)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = mtd_loop_setup(setup->devname, setup->filename,
|
2023-03-09 09:01:58 +01:00
|
|
|
setup->sectsize, setup->erasesize,
|
|
|
|
setup->offset);
|
2023-02-06 16:05:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Command: LOOPIOC_TEARDOWN
|
|
|
|
* Description: Teardown a loop device previously setup via
|
|
|
|
* LOOPIOC_SETUP
|
|
|
|
* Argument: A read-able pointer to the path of the device to be
|
|
|
|
* torn down
|
|
|
|
* Dependencies: The loop device must be enabled (CONFIG_MTD_LOOP=y)
|
|
|
|
*/
|
|
|
|
|
|
|
|
case MTD_LOOPIOC_TEARDOWN:
|
|
|
|
{
|
|
|
|
FAR const char *devname = (FAR const char *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
if (devname == NULL)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = mtd_loop_teardown(devname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MTD_LOOP */
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-02-18 00:48:46 +01:00
|
|
|
* Name: filemtd_initialize
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2023-02-18 00:48:46 +01:00
|
|
|
* Create and initialize a FILE MTD device instance.
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2023-02-18 00:48:46 +01:00
|
|
|
* path - Path name of the file backing the MTD device
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-02-18 00:48:46 +01:00
|
|
|
FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset,
|
|
|
|
int16_t sectsize, int32_t erasesize)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
|
|
|
FAR struct file_dev_s *priv;
|
2023-02-18 00:48:46 +01:00
|
|
|
struct stat sb;
|
2015-11-25 21:46:28 +01:00
|
|
|
size_t nblocks;
|
2023-02-18 00:48:46 +01:00
|
|
|
size_t filelen;
|
2017-11-03 00:07:08 +01:00
|
|
|
int mode;
|
|
|
|
int ret;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2023-02-18 00:48:46 +01:00
|
|
|
/* Stat the file */
|
|
|
|
|
|
|
|
ret = nx_stat(path, &sb, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ferr("ERROR: Failed to stat %s: %d\n", path, ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
filelen = sb.st_size;
|
|
|
|
if (offset > filelen)
|
|
|
|
{
|
|
|
|
ferr("ERROR: Offset beyond end of file\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
filelen = filelen - offset;
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
/* Create an instance of the FILE MTD device state structure */
|
|
|
|
|
|
|
|
priv = (FAR struct file_dev_s *)kmm_zalloc(sizeof(struct file_dev_s));
|
|
|
|
if (!priv)
|
|
|
|
{
|
2016-06-12 16:31:22 +02:00
|
|
|
ferr("ERROR: Failed to allocate the FILE MTD state structure\n");
|
2015-11-25 21:46:28 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-11 13:23:22 +02:00
|
|
|
/* Set the file open mode. */
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2020-05-11 13:23:22 +02:00
|
|
|
mode = O_RDOK | O_WROK;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2017-10-19 17:53:41 +02:00
|
|
|
/* Try to open the file. NOTE that block devices will use a character
|
|
|
|
* driver proxy.
|
|
|
|
*/
|
2015-11-25 21:46:28 +01:00
|
|
|
|
2018-09-15 18:49:41 +02:00
|
|
|
ret = file_open(&priv->mtdfile, path, mode);
|
2017-11-03 00:07:08 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-09-15 18:49:41 +02:00
|
|
|
ferr("ERROR: Failed to open the FILE MTD file %s: %d\n", path, ret);
|
2017-11-03 00:07:08 +01:00
|
|
|
kmm_free(priv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-28 16:00:26 +01:00
|
|
|
/* Set the block size based on the provided sectsize parameter */
|
|
|
|
|
|
|
|
if (sectsize <= 0)
|
|
|
|
{
|
|
|
|
priv->blocksize = CONFIG_FILEMTD_BLOCKSIZE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->blocksize = sectsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the erase size based on the provided erasesize parameter */
|
|
|
|
|
|
|
|
if (erasesize <= 0)
|
|
|
|
{
|
|
|
|
priv->erasesize = CONFIG_FILEMTD_ERASESIZE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->erasesize = erasesize;
|
|
|
|
}
|
|
|
|
|
2021-12-04 13:48:15 +01:00
|
|
|
if ((priv->erasesize / priv->blocksize) * priv->blocksize
|
|
|
|
!= priv->erasesize)
|
|
|
|
{
|
|
|
|
ferr("ERROR: erasesize must be an even multiple of sectsize\n");
|
|
|
|
file_close(&priv->mtdfile);
|
|
|
|
kmm_free(priv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
/* Force the size to be an even number of the erase block size */
|
|
|
|
|
2023-02-18 00:48:46 +01:00
|
|
|
nblocks = filelen / priv->erasesize;
|
2015-11-25 21:46:28 +01:00
|
|
|
if (nblocks < 3)
|
|
|
|
{
|
2016-06-12 16:31:22 +02:00
|
|
|
ferr("ERROR: Need to provide at least three full erase block\n");
|
2018-09-15 21:04:56 +02:00
|
|
|
file_close(&priv->mtdfile);
|
2015-11-25 21:46:28 +01:00
|
|
|
kmm_free(priv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform initialization as necessary. (unsupported methods were
|
|
|
|
* nullified by kmm_zalloc).
|
|
|
|
*/
|
|
|
|
|
2016-07-18 04:19:44 +02:00
|
|
|
priv->mtd.erase = filemtd_erase;
|
|
|
|
priv->mtd.bread = filemtd_bread;
|
|
|
|
priv->mtd.bwrite = filemtd_bwrite;
|
|
|
|
priv->mtd.read = filemtd_byteread;
|
2015-11-25 21:46:28 +01:00
|
|
|
#ifdef CONFIG_MTD_BYTE_WRITE
|
|
|
|
priv->mtd.write = file_bytewrite;
|
|
|
|
#endif
|
2016-07-18 04:19:44 +02:00
|
|
|
priv->mtd.ioctl = filemtd_ioctl;
|
2018-11-08 16:46:11 +01:00
|
|
|
priv->mtd.name = "filemtd";
|
2015-11-25 21:46:28 +01:00
|
|
|
priv->offset = offset;
|
|
|
|
priv->nblocks = nblocks;
|
|
|
|
|
|
|
|
return &priv->mtd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-02-18 00:48:46 +01:00
|
|
|
* Name: filemtd_teardown
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2023-02-18 00:48:46 +01:00
|
|
|
* Teardown a previously created filemtd device.
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2017-10-19 19:09:23 +02:00
|
|
|
* dev - Pointer to the mtd driver instance.
|
2015-11-25 21:46:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-02-18 00:48:46 +01:00
|
|
|
void filemtd_teardown(FAR struct mtd_dev_s *dev)
|
2015-11-25 21:46:28 +01:00
|
|
|
{
|
2022-03-16 12:27:31 +01:00
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
/* Close the enclosed file */
|
|
|
|
|
2018-09-15 21:04:56 +02:00
|
|
|
file_close(&priv->mtdfile);
|
2015-11-25 21:46:28 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_REGISTRATION
|
2017-10-19 17:53:41 +02:00
|
|
|
/* Un-register the MTD with the procfs system if enabled */
|
|
|
|
|
2015-11-25 21:46:28 +01:00
|
|
|
mtd_unregister(&priv->mtd);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Free the memory */
|
|
|
|
|
|
|
|
kmm_free(priv);
|
|
|
|
}
|
2015-11-28 16:00:26 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: filemtd_isfilemtd
|
|
|
|
*
|
|
|
|
* Description:
|
2023-02-18 00:48:46 +01:00
|
|
|
* Tests if the provided mtd is a filemtd device.
|
2015-11-28 16:00:26 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* mtd - Pointer to the mtd.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool filemtd_isfilemtd(FAR struct mtd_dev_s *dev)
|
|
|
|
{
|
2022-03-16 12:27:31 +01:00
|
|
|
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
|
2015-11-28 16:00:26 +01:00
|
|
|
|
2017-10-19 17:53:41 +02:00
|
|
|
return (priv->mtd.erase == filemtd_erase);
|
2015-11-28 16:00:26 +01:00
|
|
|
}
|
2023-02-06 16:05:12 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mtd_loop_register_driver
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Registers MTD Loop Driver
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_LOOP
|
|
|
|
int mtd_loop_register(void)
|
|
|
|
{
|
|
|
|
return register_driver("/dev/loopmtd", &g_fops, 0666, NULL);
|
|
|
|
}
|
|
|
|
#endif
|