Embedded flash file system and file system selection on the linux (rpm)

Common file system embedded linux

• romfs: read-only file system, ROM space can be placed, also
be in the RAM of the system, used to make the embedded linux
root file system
• RamFS: using its own structure formed VFS memory file-based
system, using the system's RAM space
• JFFS / JFFS2: Flash design for the log file system
• Yaffs: designed specifically for Nand Flash

• proc: send information to process the kernel and kernel module provides
for a mechanism to Check system information module loaded
• devFS: device file system
Ext2fs on the Linux
• 4 TB storage support, up to 1012 characters in the file name
• select logic blocks
• fast symbolic links
• Ext2 flash device is not suitable for
• IDE device that is as block device design, logical block size must
be a 512 byte, 1 KB, 2KB, etc.
• provides no sector-based erase / write operation is well managed
• If a sector erase single byte, must copies the entire sector to the
RAM, then erased, and then rewritten
• in the event of a power failure, the Ext2fs not prevent collapse
• file system Support wear leveling, shortens the life of the flash
jffs / jffs2 file system strengths and weaknesses
• system log files
• provides better crash, power failure security
• jffs2 support for flash uniform wear
• Perform flash erase sector level on / write / read operations to be
better than the Ext2 file system
• File system close to full time, JFFS2 will greatly slow down the running
speed - garbage collection
on Nand yaffs advantages of the file system
• specifically for Nand flash design journaled file system
• jffs / jffs2 not suitable for large-capacity Nand flash
• JFFS log by jffs_node established in RAM, taking up
RAM space: for 128MB of Nand takes about 4MB of space
to maintenance node
when needed • start the scan log node, not suitable for large capacity
of Flash Nand
• the FAT system does not log
compiled yaffs file system
• mtd latest patch upgrade?
• Interface update for the yaffs
is not compatible with the original • mtd driver, needs to be rewritten
• If you use the old drive mtd need to define the Makefile
MTD_OLD = -DCONFIG_YAFFS_USE_OLD_MTD
• Reference document: yaffs-rootfs-HOWTO
• The latest version of the website yaffs :
http://www.aleph1.co.uk/armlinux/projects/yaffs
use yaffs file system
• system can be seen by yaffs cat / proc / yaffs command
information systems of
Mount -t yaffs • / dev / mtdblock / 0 / mnt / Ya
FFS



on Linux file system

JFFS full name: The Journalling Flash File System (Log Flash File System) was originally developed by Axis Communications of Sweden, Red Hat's David Woodhouse it improved. As the actual file system of the original flash chips for embedded devices and micro-emergence. JFFS log structured file system, which means that it is basically a long list of nodes. Each node contains some of the information about the file - name of the file might be, maybe some data. Relative to Ext2 fs, JFFS because there are several advantages and is gaining popularity in diskless embedded devices:
  
   1 JFFS executed on the sector level flash erase / write / read operations than good Ext2 file system.
   2 JFFS provides better than Ext2 crash / power-down security. When a small amount of data needs to be changed, Ext2 file system will copy the entire sector into memory (DRAM), the merging of new data in memory, and write the whole sector. This means that in order to change a single word, you must perform the entire sector (64 KB) read / erase / write routines - do so efficiency is very low. If bad luck, when the DRAM is in the combined data, a power failure or other accidents, the entire data set is lost, because after the data is read into DRAM erased flash sector. JFFS attach a file instead of rewriting the entire sector, and has a crash / power-down security this feature.
   3 This is probably the most important point: JFFS is created specifically for embedded devices such as flash memory chips like that, so it's the whole design provides better flash management.
   To build JFFS file system, first of all have hardware support FLASH and JFFS file system operating system.



Abstract: This paper analyzes the jffs file system mechanism uclinux 2.4 kernel. Hoping to help the majority of product development engineers based uclinux.

Keywords: uclinux vfs jffs

stated: This document is issued in accordance with the spirit of free software, open source, anyone can get free, use and re-released, but you do not limit the rights of others to republish your published content. The purpose of this paper is published hope it will be useful to the reader, but WITHOUT ANY WARRANTY, without even the implied warranty for a particular purpose. More detailed information, please refer to the GNU General Public License (GPL), and GNU Free Documentation License (GFDL).

You should have received a copy of the document and the copy of the GNU General Public License (GPL) together. If not, write to:
at The as Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA02139, USA

welcome you to point out errors in the documentation and question


a, flash read and write particularity
for embedded systems, flash is very a common device, and most embedded systems are built on the flash file system, due to the special nature of the flash operation, making the file system on the file system on the flash disk and ordinary have great difference particularity flash operation include:
(1) a single byte can be erased, the smallest unit of erase is a Block, sometimes referred to as a sector. A typical size of a block is 64k. Different flash will be different, with particular reference to the specification flash chips.
(2) write operations to a location only turned out to be empty (that is, the contents of the address is the whole f), if the position is not empty, the write operation does not work, that is to say if you want to overwrite the original has a content the space can only be read out of the sector to the ram, the ram rewrite, then write the entire sector.
Because of these special write, so based on this device flash file also has its own unique characteristics, here we are with jffs example for analysis.

Two, jffs architecture introduced
a storage structure
in jffs, all files and directories are treated the same, with a jffs_raw_inode is to represent


the entire flash from the raw inode is a permutation of a composition, a directory is only a raw inode for file is composed of one or more raw inode composition.

2, files
in the file system to mount the flash device when the flash will be scanned, thereby establishing a jffs_file structure and a node list according to all the files belonging to the raw inode flash.
The following chart shows the composition of a file of


a file is composed of several jffs_node, each of which jffs_node is based on flash jffs_raw_inode get established, jffs_file two lists major maintenance
release lists: mainly describes the node to create sooner or later, that is, He said version_head point is one of the oldest of the node, which means most of the garbage collection when the recovery is the oldest node.
Zone list: This list is created mainly for reading and writing files, the file data area pointed to node version_head represented sequentially after 0 ~~~ n-1 nodes are n ~~~ m-1 m ~~~~ o ...... -1 where n-<M <= "" P = "" />

. 3, the operation
The file read operation should be relatively simple, but write operations, including operations such as file name change is caused by a new jffs_node birth, while the raw inode write a matched to the flash, such an operation could lead to front jffs_node a complete failure of the above data, resulting in a space on a corresponding raw inode flash becomes dirty.
Here is an example may be more clearly.

Range list is a file from the above three jffs_node composition, when we do the following write operation when
lseek (fd, 10, SEEK_SET);
the Write (fd, buf, 40);
the first and last node is truncated the second node is completely replaced with the new data, the node will be picked from the list, flash space becomes dirty. If the write operation is as follows when
lseek (FD, 23 is, SEEK_SET);
Write (FD, buf,. 5);
In this case, the second node is split into two node, while generating a new node, the list element Range become five.





Based on the Linux2.6 YAFFS file system migration
v1.0,2005-6-6
a, YAFFS File System Introduction
YAFFS, Yet Another Flash File System, is an embedded Flash file system designed specifically for JFFS / JFFS2 similar . Compared with JFFS, it reduces the number of functions, therefore faster and uses less memory.
YAFFS and provides the underlying operating JFFS write leveling, garbage collection and so on. They differ in that:
(1), JFFS is a log file system to ensure the stability of the file system by logging mechanism. YAFFS only borrowed ideas logging system and does not provide a log function, so the less stable than JAFFS, but less resource consumption.
(2), JFFS list management in a multi-stage dirty blocks need to be recovered, and using the system to generate a pseudorandom variable determining block recovered by this method can provide better write leveling, from start to finish in the pair YAFFS block search, so the garbage collection JFFS slow, but can extend the life of NAND.
(3), JFFS supports file compression for smaller storage capacity of the system; YAFFS does not support compression, storage capacity is more suitable for large systems.
YAFFS also drive with NAND chips, and provides direct access to the file system API for embedded systems, Linux users can not use the MTD and VFS, directly manipulate files. NAND Flash mostly used MTD + YAFFS model. MTD (Memory Technology Devices, memory technology devices) is the interface of the Flash operation, provides a series of standard functions, the drive hardware design and system programming separately.
Second, the migration file system YAFFS
yaffs code from
http://www.aleph1.co.uk/armlinux/projects/ download (yaffs code comprises yaffs_ecc
.c, yaffs_fileem.c, yaffs_fs.c, yaffs_guts.c, yaffs_mtdif. c, yaffs_ramem.c.)
table Yaffs file system source code files and related functions described in
the file name function
yaffs_ecc.c ECC check algorithm
yaffs_fileem.c test Flash
yaffs_fs.c file system interface functions
yaffs_guts.c Yaffs file system algorithm
yaffs_mtdif.c NAND function
yaffs_ramem.c Ramdisk achieve
1. YAFFS no kernel, so it is necessary to establish their own YAFFS directory and copy the downloaded YAFFS code to the directory.
FS #mkdir / yaffs
#cp * .c (yaffs Source code) FS / yaffs
2. Modify fs / Kconfig, may be configured such that yaffs:
Source "FS / yaffs / the Kconfig"
. 3. Modify fs / makefile, add the following:
obj - $ (CONFIG_YAFFS_FS) + = yaffs /
4. yaffs directory generated at fs directory, and generates a makefile in which Kconfig and
Makefile content:
yaffs OBJS-: = yaffs_fs.o yaffs_guts yaffs_mtdif.o yaffs_ecc.o .o
EXTRA_CFLAGS + = $ (YAFFS_CONFIGS) -DCONFIG_KERNEL_2_6
Kconfig content:
#
# YAFFS the Configurations File System
#
config YAFFS_FS
Tristate "Yet Another Flash Filing System (YAFFS) File System Support"
Help
  YAFFS, for Yet Another Flash Filing System, is a filing system
  optimised for NAND Flash chips.

  To compile the YAFFS file system support as a module, choose M here:
  the module will be called yaffs.

  If unsure, say N.

  Further information on YAFFS is available at
  <
http://www.aleph1.co.uk/yaffs/>.

config YAFFS_MTD_ENABLED
bool "NAND mtd support"
depends on YAFFS_FS
help
  This adds the yaffs file system support for working with a NAND mtd.

  If unsure, say Y.

config YAFFS_RAM_ENABLED
bool "yaffsram file system support"
depends on YAFFS_FS
help
  This adds the yaffsram file system support. Nice for testing on x86,
  but uses 2MB of RAM. Don't enable for NAND-based targets.

  If unsure, say N.

comment "WARNING: mtd and/or yaffsram support should be selected"
depends on YAFFS_FS && !YAFFS_MTD_ENABLED && !YAFFS_RAM_ENABLED

config YAFFS_USE_OLD_MTD
bool "Old mtd support"
depends on YAFFS_FS && 0
help
  Enable this to use the old MTD stuff that did not have yaffs support.
  You can use this to get around compilation problems, but the best
  thing to do is to upgrade your MTD support. You will get better speed.

  If unsure, say N.

config YAFFS_USE_NANDECC
bool "Use ECC functions of the generic MTD-NAND driver"
depends on YAFFS_FS
default y
help
  This enables the ECC functions of the generic MTD-NAND driver.
  This will not work if you are using the old mtd.

  NB Use NAND ECC does not work at present with yaffsram.

  If unsure, say Y.

config YAFFS_ECC_WRONG_ORDER
bool "Use the same ecc byte order as Steven Hill's nand_ecc.c"
depends on YAFFS_FS
help
  This makes yaffs_ecc.c use the same ecc byte order as
  Steven Hill's nand_ecc.c. If not set, then you get the
  same ecc byte order as SmartMedia.

  If unsure, say N.

config YAFFS_USE_GENERIC_RW
bool "Use Linux file caching layer"
default y
depends on YAFFS_FS
help
  Use generic_read/generic_write for reading/writing files. This
  enables the use of the Linux file caching layer.

  If you disable this, then caching is disabled and file read/write
  is direct.

  If unsure, say Y.

config YAFFS_USE_HEADER_FILE_SIZE
bool "Use object header size"
depends on YAFFS_FS
help
  When the flash is scanned, two file sizes are constructed:
  * The size taken from the object header for the file.
  * The size figured out by scanning the data chunks.
  If this option is enabled, then the object header size is used,
  otherwise the scanned size is used.

  If unsure, say N.

config YAFFS_DISABLE_CHUNK_ERASED_CHECK
bool "Turn off debug chunk erase check"
depends on YAFFS_FS
default y
help
  Enabling this turns off the test that chunks are erased in flash
  before writing to them. This is safe, since the write verification
  will fail. Suggest enabling the test (ie. say N)
  during development to help debug things.

  If unsure, say Y.

#config YAFFS_DISABLE_WRITE_VERIFY
# bool "Disable write verify (DANGEROUS)"
# depends on YAFFS_FS && EXPERIMENTAL
# help
#   I am severely reluctant to provide this config. Disabling the
#   verification is not a good thing to do since NAND writes can
#   fail silently. Disabling the write verification will cause your
#   teeth to rot, rats to eat your corn and give you split ends.
#   You have been warned. ie. Don't uncomment the following line.
#
#   If unsure, say N.
#

config YAFFS_SHORT_NAMES_IN_RAM
bool "Cache short names in RAM"
depends on YAFFS_FS
default y
help
  If this config is set, then short names are stored with the
  yaffs_Object. This costs an extra 16 bytes of RAM per object,
  but makes look-ups faster.

  If unsure, say Y.
5.在/arch/arm/mach-s3c2410/mach-smdk2410.c找到smdk_default_nand_part结构,修改nand分区,如下:
struct mtd_partition smdk_default_nand_part[] = {
    [0] = {
          .name   = "vivi",
          = 0x00020000 .size,
          .offset = 0x00000000,
    },
    [. 1] = {
          .name = "param",
          .size = 0x00010000,
          .offset = 0x00020000,
    },
    [2] = {
          .name = "Kernel",
          .size 0x00100000 =,
          .offset = 0x00030000,
    },
    [. 3] = {
          .name = "the root",
          .size = 0x01900000,
          .offset = 0x00130000,
    },
    [. 4] = {
          .name = "User",
          .size = 0x025d0000 ,
          .offset = 0x01a30000,
    }
};
NOTE: this section partition to be bonded to the inside vivi set.
6.配置内核时选中MTD支持:
Memory Technology Devices (MTD) --->
<*> Memory Technology Device (MTD) support
  MTD partitioning support
  ……
--- User Modules And Translation Layers
<*> Direct char device access to MTD devices
<*> Caching block device access to MTD devices
……
NAND Flash Device Drivers --->
<*> NAND Device Support
<*> NAND Flash support for S3C2410 SoC
  S3C2410 NAND driver debug
7.配置内核时选中YAFFS支持:
File systems --->
Miscellaneous filesystems --->
<*> Yet Another Flash Filing System(YAFFS) file system support
  NAND mtd support
  Use ECC functions of the generic MTD-NAND driver
  Use Linux file caching layer
  Check the chunk Debug ERASE OFF Turn
  the Cache Short names in the RAM
8. The compiled kernel development and kernel downloaded to flash plate.
Three, test Yaffs file system:
1. After starting the kernel boot information which can be seen in the following:
the NAND Device: Manufacturer ID: 0xEC, Chip ID: 0x76 (Samsung the NAND 64MiB 'bit-3,3V. 8)
Scanning Device for Bad Blocks
Creating the MTD. 5 Partitions ON "the NAND 64MiB 'bit-3,3V. 8":
0x00000000-0x00020000: "Vivi"
0x00020000-0x00030000: "param"
0x00030000-0x00130000: "Kernel"
0x00130000-0x01a30000: "the root"
0x01a30000-0x04100000: " the User "
2.






pipefs nodev
nodev futexfs
nodev tmpfs
nodev eventpollfs
nodev the devpts
nodev ramfs
    vfat
nodev devfs
nodev NFS
    yaffs
nodev rpc_pipefs
under the relevant directory 3. Check dev directory see:
~ # LS dev / MTD -Al
drwxr XR-X-0. 1 the root Jan the root 00:00. 1.
drwxr XR-X-0. 1 the root the root. 1 Jan 00:00 ..
CRW-RW. 1 the root-rw- the root 90, Jan. 1 00:00 0 0
Cr - R & lt - r-- the root. 1 90 the root,. 1. 1 Jan 00:00 0ro
CRW-RW-90 rw- the root the root. 1, 2 Jan 00:00. 1. 1
Cr - R & lt - r-- the root the root 90. 1,. 3. 1 Jan 00:00 1ro
CRW -rw-rw- 1 root root 90, 4 Jan 1 00:00 2
cr--r--r--   1 root   root     90,   5 Jan 1 00:00 2ro
crw-rw-rw-   1 root   root     90,   6 Jan 1 00:00 3
cr--r--r--   1 root   root     90,   7 Jan 1 00:00 3ro
crw-rw-rw-   1 root   root     90,   8 Jan 1 00:00 4
cr--r--r--   1 root   root     90,   9 Jan 1 00:00 4ro

~ # ls dev/mtdblock/ -al
drwxr-xr-x   1 root   root         0 Jan 1 00:00 .
drwxr-xr-x   1 root   root         0 Jan 1 00:00 ..
brw-------   1 root   root     31,   0 Jan 1 00:00 0
brw-------   1 root   root     31,   1 Jan 1 00:00 1
brw-------   1 root   root     31,   2 Jan 1 00:00 2
brw-------   1 root   root     31,   3 Jan 1 00:00 3
brw-------   1 root   root     31,   4 Jan 1 00:00 4
4.mount、umount
Establishing mount directory
~ #mkdir / mnt / flash0
~ #mkdir / mnt / FLASH1
Mountblockdevice device
~ #mount yaffs -t / dev / mtdblock /. 3 / mnt / flash0
~ #mount yaffs -t / dev / mtdblock /. 4 / mnt / FLASH1
~ 1.txt #cp / mnt / flash0
~ #cp 2.txt / mnt / FLASH1
directory on the mount view, you can see just copy the files in the directory, after its umount, mount up again copy can be found the file still exists, then delete the file and umount, the mount again, you can find a copy of the file has been deleted, whereby the partition can read and write properly.
The root file system on the establishment of Flash
~ # yaffs Mount -t / dev / mtdblock /. 3 / mnt / flash0
~ #cp (your the rootfs) / mnt / flash0
~ #umount / mnt / flash0
restart, start to change the parameters:
param set linux_cmd_line "noinitrd root = / dev / mtdblock3 init = / linuxrc console = ttySAC0"
reboot, the development board can start from the root file system flash.
Note: Here you have to add devfs file system support in the kernel, otherwise the kernel can not find / dev / mtdblock / 3 directory



Currently more flash file system, using more is JFFS2 file system. JFFS2 file system based on NOR flash can be said to be more mature, the JFFS2 supports NAND flash have also been released. Source code to http://www.linux-mtd.infradead.org above download. But in my tests, on the nand flash mounted JFFS2 file system is very unstable, often CRC error occurred. Especially when a write operation, each reset will have a CRC error, it can be said of JFFS2 supports NAND flash file system is not yet mature. The YAFFS file system is designed specifically for NAND flash, the source code to
http://www.aleph1.co.uk/yaffs/index.html the download. During the test, stable performance much more stable than JFFS2 file system, and mount the partition of time less than JFFS2 file system. JFFS2 mount a file system with a 2m takes about 1s. The following describes the use JFFS2 file system and YAFFS uclinux below.
1, JFFS2
to
http://www.linux-mtd.infradead.org above to download the latest MTD and JFFS2 archive. There is also archive tools related kernel patches and some of the MTD. The main patch is ilookup-2.4.23.patch, because the latest MTD driver to use a ilookup () function. After playing patches, updates the MTD driver JFFS2 file system and began to write their own nand flash drives. If you do not want to JFFS2 as the root file system, then also you need to modify MTD_BLOCK_MAJOR. Reference may be driven inside the example, the simplest is the reference spia.c.
The main write driver flash partition structure is defined, the definition of flash read address, the flash write control ** _ hwcontrol () function. Nand flash specific operations depends on used chip data. Relatively speaking NOR flash drive to be simpler. :)
After he rearrangement
Memory Devices under Technology (the MTD)
  CONFIG_MTD the Y =
  CONFIG_MTD_DEBUG the Y =
  CONFIG_MTD_DEBUG_VERBOSE =. 3
  CONFIG_MTD_PARTITIONS the Y =
  CONFIG_MTD_CHAR the Y =
  CONFIG_MTD_BLOCK the Y =
the NAND under the Drivers the Flash Device
  CONFIG_MTD_NAND = Y
  define your own drivers
File systems under
CONFIG_JFFS2_FS = the Y
  CONFIG_JFFS2_FS_DEBUG = 2
CONFIG_JFFS2_FS_NAND = Y / * * this is the newly added /
in the Configuration v1.3.4 the uClinux
the Flash Tools under
CONFIG_USER_MTDUTILS the Y =
  CONFIG_USER_MTDUTILS_ERASE the Y =
  CONFIG_USER_MTDUTILS_ERASEALL the Y =
  CONFIG_USER_MTDUTILS_MKFSJFFS2 = Y
final commissioning is hard work. : (MTD After completion of commissioning drive, the file system can be mounted in the top JFFS2 Referring flash partitioning:. Cat / proc / mtd, erase partition: eraseall / dev / mtd * for example to mount the first partition /. mnt directory:
first: eraseall / dev / mtd0
then: Mount JFFS2 -t / dev / mtdblock0 / mnt
2, YAFFS
YAFFS meaning as 'yet another flash file system', is an open source file system is by far the only one .YAFFS designed specifically for NAND flash file system has good portability, can in linux, uclinux, wince and
run the following.
in
http://www.aleph1.co.uk/yaffs/index.html download the source code .YAFFS source documentation file system. archive which also contains YAFFS on devextras.h, yaffs_ecc.c, yaffs_ecc.h, yaffs_guts.c, yaffs_guts.h, yaffs_mtdif.h, yaffs_mtdif.c yportenv.h and
further you need to configure macros: CONFIG_YAFFS_FS and CONFIG_YAFFS_MTD_ENABLED, is configured in the above mtd articulated yAFFS, when there are other configurations require assistance can also be configured.
to build a yaffs directory below fs directory, in the above said document examination To create a new Makefile:
O_TARGET: = yaffs.o
Y-obj: = yaffs_fs.o yaffs_guts.o yaffs_mtdif.o yaffs_ecc.o
obj-m: = $ (O_TARGET)
the include $ (TOPDIR) /Rules.make
next step is to change the directory config.in fs and makefile, configure YAFFS when the YAFFS connection inside.
If, as before, has driven the NAND MTD good tune, plus YAFFS very simple. Because YAFFS do their own ECC check, it should MTD driver inside ECC removed. Into which the driving this-> eccmode = NAND_ECC_NONE it.
Further YAFFS mkyaffs is to erase flash, so that the plus mkyaffs.c mtd-utils, the compiled together into.
The final step is to compile, huh, huh. The middle there will be some warning does not matter, it is to write variables and functions of no use, but then again write the code YAFFS does not standardized. Of course, its performance does impress. Interested can try.

Reproduced in: https: //www.cnblogs.com/leaway/archive/2006/12/08/586698.html

Guess you like

Origin blog.csdn.net/weixin_34148508/article/details/93840421