Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Documentation/applications/testing/nand_sim/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,23 @@ is still the wrapper, not the actual upper half, as the upper half methods
may call the other methods as well internally and we might want to log
them as well*.

Registering Device & Daemon
===========================
Registering Device & Background Task
====================================

This wrapper is then registered using ``register_mtddriver``, and this
whole thing is converted to be a daemon, so that the device can keep running
in the background.
whole thing is launched as a background task, so that the device can keep
running after the ``nand`` command returns to the shell.

Making it a daemon is achieved by using ``fork()``, killing the parent, and
using ``daemon()`` in child.
The ``nand`` command starts a dedicated NuttX task with ``task_create()``,
waits until the device registration finishes, and then returns control to
the shell. This keeps the simulator alive in the background without relying
on ``fork()``, whose post-fork execution model is not appropriate for this
kind of long-running initialization in the flat build used by the simulator.

Known Issues
============

* ECC is not implemented yet.
* MLC NAND Flash is not implemented yet.
* Due to the fixed name of the device, there can't be more than one instance
of this virtual device.
of this virtual device.
16 changes: 2 additions & 14 deletions drivers/mtd/mtd_nandram.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,10 @@ int nand_ram_eraseblock(FAR struct nand_raw_s *raw, off_t block)
int nand_ram_rawread(FAR struct nand_raw_s *raw, off_t block,
unsigned int page, FAR void *data, FAR void *spare)
{
int ret;
uint32_t read_page;
struct nand_ram_data_s *read_page_data;
struct nand_ram_spare_s *read_page_spare;

ret = OK;
read_page = (block << NAND_RAM_LOG_PAGES_PER_BLOCK) + page;
read_page_data = nand_ram_flash_data + read_page;
read_page_spare = nand_ram_flash_spare + read_page;
Expand All @@ -349,14 +347,6 @@ int nand_ram_rawread(FAR struct nand_raw_s *raw, off_t block,
nand_ram_ins_i, "rawread", read_page);
nand_ram_status();

if (nand_ram_flash_spare[read_page].bad != NAND_RAM_BLOCK_GOOD)
{
ret = -EFAULT;
NAND_RAM_LOG("[LOWER %" PRIu64 " | %s] Failed: %s\n",
nand_ram_ins_i, "rawread", EFAULT_STR);
goto errout;
}

nand_ram_flash_spare[read_page].n_read++;

if (data != NULL)
Expand All @@ -378,11 +368,9 @@ int nand_ram_rawread(FAR struct nand_raw_s *raw, off_t block,
}

NAND_RAM_LOG("[LOWER %" PRIu64 " | %s] Done\n", nand_ram_ins_i, "rawread");

errout:
nxmutex_unlock(&nand_ram_dev_mut);

return ret;
return OK;
}

/****************************************************************************
Expand Down Expand Up @@ -444,7 +432,7 @@ int nand_ram_rawwrite(FAR struct nand_raw_s *raw, off_t block,

if (spare != NULL)
{
memcpy((FAR void *)write_page_spare, data, NAND_RAM_SPARE_SIZE);
memcpy((FAR void *)write_page_spare, spare, NAND_RAM_SPARE_SIZE);
}

NAND_RAM_LOG("[LOWER %" PRIu64 " | %s] Done\n", nand_ram_ins_i,
Expand Down
24 changes: 23 additions & 1 deletion drivers/mtd/mtd_nandwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ int nand_wrapper_ioctl(FAR struct mtd_dev_s *dev, int cmd,
unsigned long arg)
{
int ret;
FAR uint8_t *erasestate;
FAR struct nand_wrapper_dev_s *nand_dev;

nand_dev = (struct nand_wrapper_dev_s *)dev;
Expand All @@ -282,7 +283,28 @@ int nand_wrapper_ioctl(FAR struct mtd_dev_s *dev, int cmd,
", Arg : %zu\n", nand_wrapper_ins_i, "ioctl", cmd, arg);
DEBUGASSERT(nand_dev && nand_dev->under.mtd.ioctl);

ret = nand_dev->under.mtd.ioctl(dev, cmd, arg);
if (cmd == MTDIOC_ERASESTATE)
{
erasestate = (FAR uint8_t *)arg;
if (erasestate == NULL)
{
ret = -EINVAL;
}
else
{
/* The wrapped bread path exposes blank NAND pages as zero-filled
* buffers after ECC handling, so report the same visible erase
* state to higher layers.
*/

*erasestate = 0x00;
ret = OK;
}
}
else
{
ret = nand_dev->under.mtd.ioctl(dev, cmd, arg);
}

if (ret >= 0)
{
Expand Down
13 changes: 2 additions & 11 deletions fs/mnemofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@
# ##############################################################################

if(CONFIG_FS_MNEMOFS)
target_sources(
fs
PRIVATE mnemofs_blkalloc.c
mnemofs_ctz.c
mnemofs_fsobj.c
mnemofs_journal.c
mnemofs_lru.c
mnemofs_master.c
mnemofs_rw.c
mnemofs_util.c
mnemofs.c)
target_sources(fs PRIVATE mnemofs.c mnemofs_alloc.c mnemofs_ctz.c
mnemofs_dirent.c mnemofs_file.c mnemofs_rw.c)
endif()
41 changes: 0 additions & 41 deletions fs/mnemofs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,3 @@ config FS_MNEMOFS
depends on !DISABLE_MOUNTPOINT && MTD_NAND
---help---
Build the mnemofs NAND flash file system.

if FS_MNEMOFS
config MNEMOFS_EXTRA_DEBUG
bool "MNEMOFS Extra Debug Logs"
default n
depends on FS_MNEMOFS
---help---
Prints extra log information related to mnemofs.

config MNEMOFS_JOURNAL_NBLKS
int "MNEMOFS Journal Block Count"
default 20
range 4 65536
depends on FS_MNEMOFS
---help---
Number of blocks that mnemofs will use for the journal. Specifying
this will only work on formatting a NAND flash using mnemofs. If the
device is already formatted, the on-flash journal block count will
be considered instead. Two additional blocks will be allocated for
the master blocks.

config MNEMOFS_NLRU
int "MNEMOFS LRU Node Count"
default 20
range 1 255
depends on FS_MNEMOFS
---help---
Number of nodes used by mnemofs for LRU. The higher the value is,
the lesser would be the wear on device with higher RAM
consumption.

config MNEMOFS_NLRUDELTA
int "MNEMOFS LRU Delta Count"
default 20
range 1 255
depends on FS_MNEMOFS
---help---
Number of deltas used by mnemofs for LRU for every node. The higher
the value is, the lesser would be the wear on device with higher RAM
consumption.
endif # FS_MNEMOFS
11 changes: 4 additions & 7 deletions fs/mnemofs/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ ifeq ($(CONFIG_FS_MNEMOFS),y)

# Add the mnemofs C files to the build

CSRCS += mnemofs_blkalloc.c
CSRCS += mnemofs.c
CSRCS += mnemofs_alloc.c
CSRCS += mnemofs_ctz.c
CSRCS += mnemofs_fsobj.c
CSRCS += mnemofs_journal.c
CSRCS += mnemofs_lru.c
CSRCS += mnemofs_master.c
CSRCS += mnemofs_dirent.c
CSRCS += mnemofs_file.c
CSRCS += mnemofs_rw.c
CSRCS += mnemofs_util.c
CSRCS += mnemofs.c

# Add the mnemofs directory to the build

Expand Down
Loading
Loading