嵌入式系统中的几种文件系统的比较和优缺点(CRAMFS JFFS2 YAFFS2 Initrd SquashFS EXT4)【转】

转自:https://blog.csdn.net/u010299133/article/details/97116168

Introduction to file system:

In the embedded system,the common file systems include the compressed RAM file system(CRAMFS),journaling flash file system v2(jiffs2),NFS,initrd,YAFFS2,ext4,squashfs,and unsorted block image file system(UBIFS),these file system have the following features:

CRAMFS and jffs2 have good spatial features;therefore,they are applicable for embedded applications.

CRAMFS and squashFS are read-only file system,which are supported only by the serial peripheral interface(spi)NOR flash currently.

SquashFS provides the highest compression rate.

JFFS2 is a readable/writable file system.

NFS is suitable for the commissioning phase at the initial stage of development.

YAFFS2 is applicable only to the nand flash.

initrd uses the read-only CRAMFS.

EXT4 applies to the emmc and the ufs.

 


The following are their main differences:

CRAMFS:

CRAMFS is a  new file system that was developed based on linux kernel v2.4 and later.CRAMFS is easy to use,easy to load,and has a running speed.

the advantages and the disadvantages of CRAMFS are as follows:

advantages:

CRAMFS stores file data in compression mode.When the CRAMFS runs,the data is decompressed.This mode can save storage space in flash memory.

disadvantages:

CRAMFS cannnot directly run on flash memory,bacuse it stores compressed files.When CRAMFS runs,the data need to be decompressed and then copied to the memory,which reduces read efficiency.Also,CRAMFS is read-only.

For linux running on the board to support CRAMFS,you must add the cramfs optaion when compiling the kernel.The process is as follows:after running make menuconfig----file system---Miscellaneous filssystems---Compressed ROM file system support(cramfs)(OBSOLETE). the option is selected in the sdk kernel by default.

The mkfs.cramfs tool is used to create the CRAMFS image,To be specific,the CRAMFS image is generated after you process a created file system by using mkfs.cramfs.This procedure is similar to the procedure for creating an ISO file image using a CD_ROM.The related command is as follows:

mkfs.cramfs ./rootbox ./cramfs-root.img

where,rootbox is a created root file system,and cramfs-root.img is generated CRAMFS image.

JFFS2:

jffs2 is the actual file system used in original flash chips of embedded mini-devices. As a readable/writable file system with structured logs,JFFS2 has  the following advantages and the disadvantages:

advantages:

The stored files are compressed. The most important is that the system is readable and writable.

disadvantages:

When being mounted, the entire JFFS2 needs to be scanned.Therefore,when the jffs2 partition is expanded,the mounting time also increase.Flash memory space may be wasted if jffs2 format is used.The main causes of this are excessive use of log files and reclamation of useless storage unites of the system.The size of wasted space is equal to the size of several data segments.Another disadvantages is that the running speed of iffs2 decreases rapidly when the memory is full or nearly full due to trash collection.

To load jffs2,perform the following steps:

step1 scan the entire chip,check log nodes,and load all the log nodes to the buffer.

step2 Collate all the log nodes to collect effective nodes and generate a file directory.

step3 Search the file system for invalid nodes and then delete them.

step4 Collate the information int he memory and release the invalid nodes that loaded to the buffer.

The preceding features show that system reliability is improved at the expense of system speed. Additionally,flash chip with large capacity,the loading process is slower.

To enable the kernel support for jffs2,After running the menuconfig command, File system---Misceaneous filesystem---journalling Flash System v2(JFFS2)support。

To create a jffs2 file system,run the following command:

mkfs.jffs2 -d ./rootbox -l -e 0x20000 -o jffs2-root.img

you can download the mkfs.jffs2 tool from the internet or obtain it from the sdk.rootbox is a created root file system.The jffs2 parameters are as follows:

jffs2 parameters
parameter description
d specifies the root file system
l indicates the little-endian mode
e specifies the buffer size of the flash memory
o exports images

 YAFFS2:

yaffs2 is an embedded file system designed for the nand flash.As a file system with structured logs,yaffs2 provides the loss balance and power failure protection,which ensure the consistency and integrity of the file system in case of power failure.

The advantages and disadvantages of yaffs2 are as follows:

advantages

1.designed for nand flash and provides optimized software structure and fast running speed.

2.stores the file organization by using the space area of the hardware.only the organization information is scanned in the case of system startup.in this way,the system starts fast.

3.adopts the multi-policy trash recycle algorithm.therfor,yaffs2 improves the efficiency and fairness of trash recycle for the loss balance. 

disadvantages 1.the stores files are not conprocessed,even when the contents are same , a yaffs2 image is greater than a jffs2 images. 

in the sdk ,yaffs2 is provided as a module.To generated the yaffs2 module,you need to add the path of the related kernel code to the makefile in the yaffs2 code package,and then perform compilation.

both the yaffs2 image and the cramfs image can be generated by using tools.To generete a yaffs3 image,run the following command:

mkyaffs2image ./rootbox yaffs2-root.img [pagesize] [exxtype]

rootbox :root file system

ysffs2-root.img:generate yaffs2 image

pagesize:is the page size of the nand flash welded on the board

ecctype:is the error checking and correcting(ECC)type of the nand flash.

initrd:

The initrd is equivalent to the store media and supports the formats such as ext2 and cramfs.therefor, the kernel must support both initrd and cramfs.the following configurations must be complete to enable the initrd to work normaly.The following configurations are complete int he sdk by default.if you change the configurations by mistake,do as follows:

 device driver>Block devices, and select RAM block device support
general setup>inital RAM filssystem and RAM disk(initramfs/initrd)support
File system>MIscellaneous filesystem and Compressed Rom file system support(cramfs)(OBSOLETE)

To create an iitrd image,perform the following steps:

step1 Create a CRAMFS image.

step2 create an inird image based on the created CRAMFS image by runnning follow command:

mklmage -A arm64 -T ramdisk -C none -a 0 -e 0 -n cramfs-initrd -d ./cramfs-image cramfs-initrd

 SquashFS:

squashfs is a read-only file system based on the linux kernel and features high compression rate.

and it has following features:

compresses data,inode,and directories
retains 32-bit uid/gids and file creation time
detects and deletes duplicate files
support s a maximum of 4 GB file system

To use squashFS,perform the following steps:

step1

create a kernel image supporting squashfs by going to the linux-4.9-x dirrctory and running the following commands:

cp arch/arm64/configs/hi3559av100_arm64_big_little_defconfig .config

make ARCH=arm64 CROSS_COMPILE=aarch64-himix100-linux- menuconfig(save the configurations and exit)

make ARCH=arm64 CROSS_COMPILE=aarch64-himix100-linux- uImage

cd ../../arm-trusted-firmware/arm-trusted-firware

./mk.sh

step2

create the image of the squashfs file system by using mkSquashFS stored in SDK/pachage/osdrv/tools/pc_tools.To use squashFS,run the following command:

./mkSquashFS rootfs ./rootfs.squashfs.img -b 64k -comp xz

rootfs is the created root filesystem

rootfs.squashfs.img is the generated image of the squashfs fiel system

-b 64k indicates that the block size of the squashfs file system is 64kb(which determnes the actual block size of the spi flash)

-comp xz indicates that the algorithm for compressing the file system is xz.you need to modify the parameters as requird.

EXT4:

ext4 is an efficient,excellent,reliable,and unique file system. compared withe ext3,ext4 is optimazed in the data structure of the file system.

 To use ext4,perform the following steps:

step1

 go to the linux kernel linux-4.9.y directory and run the following commands to create a kernel image supporting ext4:


 cp arch/arm64/configs/hi3559av100_arm64_xxx_defconfig .config 

step2  create the image of the ext4 file system by running the following command to use make_ext4fs stored in osdrv/tools/pc_tools:
 ./make_ext4fs -l 96M -s rootfs.ext4.img rootfs
 -l 96M indicates that the block size og the ext4 file system used to configure the  emmc in u-boot is 96Mb
 -s indicates that the algorithm for compressing file system is gzip
 rootfs.ext4.img is the generated image of the file system
 rootfs is the created root file system 
 you need to modify the parameters as required.

The above information comes from the document:Development Environment User Guide

posted @ 2021-01-14 14:48  Sky&Zhang  阅读(1816)  评论(0编辑  收藏  举报