摘要
在嵌入式系统中,由于闪存具有容量大、速度快、功耗低等优点,越来越广泛地用作系统的外部存储设备。闪存是EEPROM的一种,主要分为NOR或非和NAND与非两种。大部分闪存文件存储应用都需要把闪存设备模拟成每扇区512字节的块设备,再在模拟的设备上使用标准的文件系统。这种实现无法避免在向扇区擦除和之后的写入过程中掉电对文件系统造成的损害。JFFS/JFFS2是新出现的专门针对闪存设计的文件系统,直接在闪存之上实现损耗平衡和防掉电。但是JFFS/JFFS2支持的闪存设备类型有限。
在我们课题所涉及的无线路由器上,硬件只支持Disk On Chip与Compact Flash两种设备。DOC是一种与非闪存,在Linux中通过NFTL对系统表现为普通的块设备,在其上可使用普通的文件系统。实验表明,在DOC上使用普通的文件系统,系统几乎不具备防掉电性。CF是一种或非闪存,芯片内部使用了FTL的技术,无法直接被JFFS/JFFS2支持,只能在其上使用普通的文件系统或通过一种技术将其模拟成JFFS/JFFS2支持的MTD设备。实验表明,这种模拟技术虽然可以提高系统的防掉电能力,但会对CF的使用寿命造成一定的影响。
考虑到大多数嵌入式Linux系统的特点,即系统运行时虽然会向文件系统写入很多文件、但大多数情况下不用对这些数据进行持久保存,本文从实验系统的实际情况出发,设计了一种新的文件系统技术。该技术将Linux系统正常运行时的文件写操作均放在内存中,只有在需要对文件进行持久保存的时候才会在很短的时间内将修改过的文件保存到闪存中。该文件系统中还设计了一些容错技术,即使在向闪存写入的过程中意外掉电,系统在下次启动时也能够检测并自动修复。另外根据Linux根文件系统自身的一些特点,该技术将只读的文件以支持压缩的文件系统格式存放在闪存中,以提高闪存的利用率;而对于可写文件在保存时则采用普通的文件系统格式,由闪存内部的FTL/NFTL来实现损耗平衡。该技术充分利用了Linux内核支持的各种文件系统格式,对其进行优化组合,特别适合于一般嵌入式Linux系统。
Flash memory is evolving in the embedded systems due to its attractive features such as large capacity, fast access speed and low power consumption. Flash is a form of EEPROM, available mainly in two types, the traditional NOR flash and the newer NAND flash. The majority applications of flash for file storage have involved using the flash to emulate a block device with 512 bytes sectors, on top of which using standard file systems. This approach provides no wear leveling, and is extremely unsafe with the potential power loss between the erase and subsequent rewrite of the data. JFFS/JFFS2 are the newly emerging file systems specifically designed for flash memory, which provide wear leveling directly on the chip and are crash-proof because they are log-structured. However, JFFS/JFFS2 only supports limited number of types of flashes.
The mainboard of the Wireless Router in our project only supports the Disk On Chip and the Compact Flash as the on-board external storage device. DOC is a type of NAND flash device and emulated by the NFTL as a normal block device, on top of which you may put the normal file systems. Experiments on the WR show that using the normal file systems on DOC is not crash-proof. CF is a type of NOR flash and it cannot be directly supported by JFFS/JFFS2. It supports the normal file systems by introducing the FTL, or with MTD emulation using block device, it is feasible to put the JFFS/JFFS2 file systems on CF. Experiments show that such emulation improves the crash-proof performance of the system, but it also greatly reduces the life cycle of flash chip.
Considering the characteristics of most embedded Linux systems, that though the system writes miscellaneous files at runtime, most of them need not be persistent across reboots, this paper proposed a new file system technology, which moves all the write operations on the files into RAM at runtime and only saves the modified files back to the flash within a short time when the persistent storage is needed. It also has adopted some fault-tolerance mechanisms to detect and recovery from accidental power losses even when the seldom saving process is right in progress. To make the most efficient use of the flash chip, the read-only files are crammed into a compressed file system; as for the rewritable files, it uses the normal file systems with the chip builtin FTL/NFTL to provide wear leveling. The technology presented in the paper makes the best combination of the file system formats that the Linux kernel supports and it is especially suitable for embedded Linux systems.
引文
Rusty Russell, Daniel Quinlan and Christopher Yeoh, Filesystem Hierarchy Standard, http://www.pathname.com/fhs/pub/fhs-2.3.html, Filesystem Hierarchy Standard Group, 2004
Cliff Brake and Jeff Sutherland,Flash Filesystems for Embedded Linux Systems,http://www.linuxdevices.com/articles/AT7478621147.html,Embedded Linux Journal,July 2001
Anand K Santhanam and Vishal Kulkarni, Linux system development on an embedded device --- Tinkering with PDAs for fun and profit, http://www-106.ibm.com/developerworks/library/l-embdev.html, March 2002
Vipin Malik, The Linux MTD, JFFS HOWTO, http://ftp.linux.org.uk/pub/people/dwmw2/mtd/cvs/mtd/mtd-jffs-HOWTO.txt, August 2001
David Woodhouse, JFFS : The Journalling Flash File System, Red Hat, Inc.
David Woodhouse and Rick Lehrbaum, About the built-in Flash memory support in kernel 2.4.x, http://www.linuxdevices.com/articles/AT8473001566.html, Febr 2001
Mark Meade, Booting GRUB on the DiskOnChip 2000 and Millennium, http://lakeshoremicro.com/diskonchip-grub-howto.html, Revision 0.4, Febr 2003
Gerard Beekmans, Linux From Scratch, Version 5.0, http://www.linuxfromscratch.org, 2003
Paul Gortmaker, Werner Almesberger and Hans Lermen, Initrd and Ramdisk documations, Linux kernel source files, Documentation/initrd.txt and Documentation/ramdisk.txt
Christoph Rohland et al., Linux filesystems documentations, Linux kernel source files, Documentation/filesystems/*.txt
Matt Kraai and Mark Whitley, How to Add a New Applet to BusyBox, Busybox-0.65 source file, docs/new-applet-HOWTO.txt
Mendel Cooper, Advanced Bash-Scripting Guide --- An in-depth exploration of the gentle art of shell scripting, Brindle-Phlogiston Associates, http://108.scie-uestc.net/Guide/abs-guide/, March 2002
Arnold D. Robbins, Effective AWK Programming --- A User's Guide for GNU Awk, ed. 1.0.3, http://108.scie-uestc.net/Guide/gawk/gawk_toc.html, February 1997