E System is the first embedded file System designed specifically for NAND Flash memory, suitable for high-volume storage devices. YAFFS is a log-based file system that provides robustness for wear balancing and power failure recovery. It is also well tuned for high-capacity Flash chips, optimized for boot time and RAM usage. Suitable for high-volume storage devices, the Yaffs code has been successfully used on many different 32-bit and 64-bit cpus, including MIPS, 68000, ARM, ColdFire, PowerPC and x86, and has even been used on various DSP architecture chips.

At present, there are two versions of YAFFS and YAFFS2. The main difference between YAFFS1 and YAFFS2 lies in the size of PAGE read and write. YAFFS2 can support up to 2K Bytes PAGE, which is much higher than YAFFS ‘512 Bytes, so it has more advantages over large-capacity NAND Flash. YAFFS2 is currently the preferred file system for NAND Flash.

YAFFS2 has the following characteristics: written in C code, it supports large and small end processors and is easy to transplant. Provides nAND Flash bad block processing mechanism and ECC verification algorithm to detect and correct certain bit flips. Using the log file system design, the abnormal power failure does not damage the file system, and the recovery speed after the power failure is fast. Has a highly optimized and predictable garbage collection strategy with excellent performance and a high degree of certainty. Has a lower memory footprint than most journaled file systems. Supports POSIX interfaces and is easy to use.

YAFFS2 transplantation

1. YAFFS2 source code official website: yaffs.net/get-yaffs

The code is divided into the following parts:

A, core file system code, located in the yaffs2 directory



B. Direct interface file, located in yaffs2/direct directory

C, the flash driver sample, as well as the simulator and configuration for testing, are located in the yaffs2/direct/ test-framework directory

D. Relevant test cases in other directories

See the official documentation: yaffs.net/documents/y…

2. Add files

To copy the following files to AliOS – Things/kernel/modules/fs/yaffs2 directory, and write the corresponding makefile or added to the corresponding project.

A) These files are located in the yaffs2 and yaffs2/direct directories of the source code. B) There are multiple yportenv.h and yaffs_attribs.c files. The former uses the version in the direct directory, and the latter uses the version in the yaffs2 directory. C) Yaffs_alios. c, yaffs_install_drv.c, and yaffs_install_drv.h are used to adapt alios-things and drivers. See kernel/modules/fs/yaffs2.

3.1 Add corresponding data and function definition a) Yportenv.h add the following code:

#define CONFIG_YAFFS_DIRECT
#define CONFIG_YAFFS_PROVIDE_DEFS
#define CONFIG_YAFFSFS_PROVIDE_VALUES
#define CONFIG_YAFFS_DEFINES_TYPES

#define inline RHINO_INLINE

typedef long off_t;
typedef unsigned long loff_t;
typedef long dev_t;
typedef int mode_t;Copy the code

B) Yaffsfs.c add the following code:

unsigned int yaffs_trace_mask = 0;

unsigned int strnlen(const char *s, unsigned int max) {
        register const char *p;
        for(p = s; *p && max--; ++p);
        return(p - s);
    }Copy the code

C) yaffs_list.h add the following code:

#define inline RHINO_INLINECopy the code

3.2 Interconnecting with the OPERATING System The operating system interface for alios-Things has been implemented. You can directly include yaffs_alios.c.

In this file, functions such as yaffsfs_Lock, yaffsfs_Unlock, yaffsfs_CurrentTime, Yaffsfs_malloc, and yaffsfs_free are interlinked. In addition, a background task for Yaffs is created.

The yaffsfs_CheckMemRegion function is used to check whether the memory address is valid.

The operating system interface functions are listed as follows:

Void yaffsfs_Lock (void); Void yaffsfs_Unlock (void); U32 yaffsfs_CurrentTime (void); Int yaffsfs_GetLastError (void); Void yaffsfs_SetError (int err); Void * yaffsfs_malloc (size_t size); Void yaffsfs_free (void * PTR); Void yaffsfs_OSInitialisation (void); Void yaffs_bug_fn(const char *file_name, int line_no); Int yaffsfs_CheckMemRegion(const void *addr, size_t size, int write_request);Copy the code

3.3 Interconnecting with the Nand Flash Driver YAFFs_install_drv. c YAFFS interconnect with the Nand Flash driver. You need to configure parameters in PARAM based on the hardware and implement the following driver functions:

static int nand_WriteChunk(struct yaffs_dev *dev, int nand_chunk,
                   const u8 *data, int data_len,
                   const u8 *oob, int oob_len);
static int nand_ReadChunk(struct yaffs_dev *dev, int nand_chunk,
                   u8 *data, int data_len,
                   u8 *oob, int oob_len,
                   enum yaffs_ecc_result *ecc_result);
static int nand_EraseBlock(struct yaffs_dev *dev, int block_no);
static int nand_MarkBad(struct yaffs_dev *dev, int block_no);
static int nand_CheckBad(struct yaffs_dev *dev, int block_no);
static int nand_Initialise(struct yaffs_dev *dev);Copy the code

After completing the above steps, the transplantation of YAFFS2 is completed.

Scan for more information: