Support for Yaffs images in U-Boot

Source: Internet
Author: User

 

Introduction
U-Boot is a common Boot program for Embedded operating systems. It has a wide range of functions, supports a variety of operating systems and CPU Systems, is easy to expand and transplant functions, open source code and other advantages. U-Boot supports both startup and download modes. In the download mode, you can use the nand read/write commands that come with U-Boot to work with them. jffs 2 and other parameters are used to read and write cramfs, Jffs 2, and other file system images, facilitating debugging during the development process. The Yaffs file system is a read-write file system designed specifically for nand flash. It has stable and excellent performance on nand flash. U-Boot itself does not directly support reading and writing images in the Yaffs file system. Due to the special structure of the Yaffs file system, you need to modify the nand command to read and write the Yaffs image on NANDFLASH.

1. Related Work Introduction
1.1 brief introduction to the structure of the Yaffs File System
Currently, commonly used FLASH file systems in embedded systems include Cramfs, Jffs 2, Yaffs, and exfat. Cramfs is a compressed read-only file system. It is decompressed to the memory during system startup. Jffs 2, Yaffs, and Exfat are read-write file systems. Jffs 2 is generally used in nor flash. Exfat is not an open-source file system implementation and is generally used in Windows CE operating systems. Yaffs is a read-write file system designed specifically for nand flash. It can provide loss balancing and power loss Protection for Embedded Memory functional requirements. The source code of the Yaffs file system is open, which is very convenient to transplant in a variety of embedded operating systems.
Generally, a nand flash storage device consists of several blocks, and one block consists of several pages. Generally, the size of a nand flash chip smaller than 128 MB is 528 B on one page, which is divided into two primary data zones of 256 B and 16 B in sequence; the size of a 128 MB or more nand flash chip is usually 2 KB on one page. Due to the high probability of bitwise inversion in nand flash, ECC is usually used for error detection and recovery during reading and writing.
The design of the Yaffs file system fully takes into account the features of nand flash, such as page-based access units, and organizes files into Chunk segments ). Take page 528 B as an example. The Yaffs file system uses the first 512 B of data storage and 16 B of additional space, organization information of ECC and file systems used to store data (known as OOB data ). Through OOB data, not only can error detection and Bad Block Processing be realized, but also can avoid scanning the entire storage medium during loading and speed up file system loading. The specific structure of a page is shown in table 1.

We can see that, compared with other file systems, the generated Yaffs image contains OOB data. Therefore, ECC is not required when you burn a Yaffs image, only data of 512 B and OOB of 16 B can be written in sequence. At the same time, the Yaffs image uses the first block on the partition to store a struct named Yaffs_ObjectHeader. This struct records the files, paths, and related links in the partition. Therefore, you must skip the first available block when writing. Currently, the commonly used version of The Yaffs file system is Yaffs 2, which greatly improves the performance in many aspects.
1.2 U-Boot support for common file systems
In the actual development process, Boot programs, such as U-Boot, are generally used to complete file-to-FLASH burning and Boot. U-Boot supports Cramfs and Jffs 2 file systems. These file systems are designed for nor flash, and all file data is a simple form of linear table organization. Due to the OOB zone with functions for data verification and so on, the data organization form of the Yaffs file system is no longer a linear table.
U-Boot does not provide read/write support for the Yaffs file system. However, because the read/write process of the file system is similar to that of other file systems, you can modify the FLASH read/write command of U-Boot to increase the function of processing data in Area 00B, that is, you can read and write the Yaffs file system.

2. Specific implementation
Here, we use U-Boot 1.1.6, and nand flash uses Samsung's K9F1208UOM. Each page of the nand flash is 512 B, plus 16 B Additional space. The entire chip capacity is 64 MB. Previously, the related macro definition has been correctly configured, and the relevant nand flash Driver has been transplanted so that U-Boot can operate on the chip correctly.
2.1 Add a new command for U-Boot.
In fact, U-Boot has implemented the required nand command. You only need to write the proper nand flash Driver and define the corresponding macro, you can perform basic read/write operations on nand flash. To add support for the Yaffs image, you only need to implement a new parameter. In order to give the following steps a clear explanation, we will briefly describe how to add a new command to U-Boot. The paths described below are all in the U-Boot source code directory.
(1) define the macro of the corresponding command in the include/define _confdefs.h file. It cannot be the same as the existing macro value.
(2) The specific code that implements command operations in common/cmd_name.c. the name in the file name is the name of the corresponding command. In this file, you must first compile the command implementation function. In addition, you must use a U_BOOT_CMD () Macro function to fill in the cmd_tbl_t struct of the command. The prototype of this struct is defined in include \ command. h and contains the name, number of parameters, implementation functions, usage instructions, help, and other information of the corresponding command. Finally, modify the common/Makefile file to add the file as the compilation target.
(3) Add the macro defined by (1) to the CONFIG_COMMANDS macro in the corresponding development board header file (under include/con-figs.
When performing the preceding steps, modify the code of an existing command as needed.
2.2 add new parameters for the nand command
Based on the above analysis, add the write. yaffs parameter to the nand command to support the Yaffs image. Follow the steps in section 2.1. Since the nand command has been implemented, you only need to modify the com-mon/mongo_nand.c file.
(1) Add the following parameters to the U_BOOT_CMD () Macro function in the common/cmd_nand.c file:

Some parameters in the struct prototype defining read/write operations are not used. These parameters are related to the method of selecting ECC. Because the Yaffs file system already contains OOB data, these parameters are not used. In addition, opts. skipfirstblk is a new variable added to the nand_write_options_t struct. Therefore, you need to modify this struct. In include/nand. h, add the following variable definitions to the struct nand_write_options struct:
Int skipfirstblk;
In addition, you need to modify the nand_write_opts function to add support for this variable.
2.3 modify the nand_write_opts Function
In drivers/nand/nand_util.c, according to its code, in the while (blockstart! = (Mtdoffset &(~ Erasesize_blockalign + 1) Add the following code after the loop body:

After performing the preceding steps, U-Boot supports reading and writing the Yaffs file system image. Generally, you can first download data to the memory through a serial port or network interface during the nand flash write operation, and then burn the data to the nand flash according to the command format. For example:


Run the preceding three commands in U-Boot: test. download the yaffs file system image of Yaffs to the memory, erase a FLASH space, and use Nand Write. the yaffs command writes it to nand flash. After writing, a message is displayed:
Writing data at 0xd67200-100% complete.
3663264 bytes written: OK
In addition, because ECC is not used, there will be a large number of prompts during the write process:
Writing data without ECC to NAND_FLASH is not recom-mended
In fact, the ECC data is included in the image when the Yaffs image is generated, so the prompt here does not matter. In the drivers/nand/nand_basec.c file, comment out the printk function in case NAND_ECC_NONE: Statement branch in the nand_write_page function to eliminate this prompt.

3. Performance of the Yaffs File System
In actual use, the general CPU speed is much higher than the FLASH read/write speed, so the read/write speed of the yaffs file system is mainly determined by the read/write time delay of the specific FLASH chip.
For Commonly Used Yaffs 2, the write speed is 1.5 ~ 4.5 MB/S, the read speed is 7.6 ~ 16.7 MB/S. The delete operation is 7.8 ~ 62.5 MB/s, 2.1 ~ garbage collection ~ 7.7 MB/s. Generally, the data exchange volume of embedded systems is small, so the file system can fully meet the requirements of general real-time operations.
In addition, as a log file system, the Yaffs file system can effectively protect data integrity and avoid damages to data due to power loss. At the same time, compared with other FLASH file systems, the implementation of the Yaffs file system has brought a lot of optimization to the nand flash, and has better performance in terms of speed, memory usage and energy consumption.

4 knots
On the basis of analyzing the basic structure of the Yaffs file system, you can add new parameters to the existing U-Boot command to support U-Boot reading and writing the Yaffs file system image. Finally, a simple test is conducted to verify the performance. The results show that the file system image written to FLASH can be mounted by the kernel of the embedded Linux and other operating systems. This facilitates the creation and debugging of the Yaffs root file system image of the embedded system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.