Development of trueffs file system driver for VxWorks Embedded Operating System

Source: Internet
Author: User

The embedded system's requirements for execution speed and system reliability determine that an embedded system requires a safe and fast storage device, this kind of equipment also requires features such as small size, large capacity, and no loss of power-down data. Flash memory can meet the above requirements. This also makes flash memory the main storage device in the embedded system.
Now Flash technology is mature and has become an industrial standard, but the question is how to manage flash devices more effectively. improve flash efficiency. accelerate the operation speed and manage the use frequency of each flash unit to improve the flash service life. Therefore, people gradually focus on flash management software. M-System's true flash File System (trueffs) is the flash management software launched in this context. Its basic function is to complete the flash disk simulation function, this allows you to operate flash like a disk, while trueffs provides a standard block setting interface to perform read/write operations on the sector. This function is enough for the file system and the operating system to manage flash.
Therefore, true flash is also used by many embedded operating systems, including the VxWorks of Fenhe Corporation. For this reason, the development of trueffs driver for Flash has become a must for embedded system developers. However, the development of the trueffs driver is closely related to the hardware, and the development process is also very difficult. However, there are a lot of related information about the level and principle of the trueffs file system. the specific development process of the driver is rarely introduced. Therefore, this article aims to analyze the trueffs principle and take Samsung's NAND Flash k9f2808uob as an example, this section describes how to develop the trueffs driver on the VxWorks operating system.

About trueffs
Trueffs can provide complete block device functions for the operating system. This enables flash to be managed by the operating system and file system like a standard disk device. At the same time, it also provides transparent Flash Media Management, well with improved flash service life (loss balancing algorithm), to ensure data integrity (security algorithm. bad Data ing), optimized flash performance (fragment recovery) and other advantages. Its structure 1 is shown.
 
Figure 1 Basic Structure of trueffs
As shown in the figure, trueffs consists of three modules: block device API (driver layer), block Device Simulation + flash management layer, and MTD layer.
At the top is the driver layer, which provides block device services for the file system of the operating system. The code at this layer is determined by different operating systems.
The module in the middle is the core part of the entire trueffs, which includes the block Device Simulation Algorithm and flash management algorithm (usually called the Translation Layer, Translation Layer or TL ). This module is responsible for translating the file system sectors into flash physical blocks. During address translation, it can also balance the loss, map bad data blocks, and other related operations (such as fragment recovery ).
The module at the bottom is the MTD (memory technology driver) layer. It provides basic interfaces for reading, writing, and erasing flash. Operations at this layer are controlled by the flash management layer.

Trueffs in tornado
Trueffs in tornado is an integrated FLASH file management system in the WinDriver tornado development environment. It can manage Flash files through the DOS file system in VxWorks. You can create and control a file system through the standard file system interface. This allows users to read and write files in flash, which is as simple as Directly Reading and Writing files on DOS file system devices.
Location 2 of trueffs in VxWorks is shown.
 
Figure 2 Location of trueffs in VxWorks
Tornado provides a driver layer interface for tureffs, so DOS file system or NFS (Network File System) can be used in VxWorks ). For embedded applications, they only need to simply call the relevant file system interface functions.
The trueffs hierarchy and functions in Tornado are consistent with the preceding basic hierarchy and functions of trueffs. For driver layer (or core layer) and Translation Layer Code, Fenghe provides the code in binary format. That is to say, the completion of the driver layer and Translation Layer functions does not need to be concerned by the driver developers. Therefore, the development of trueffs drivers for flash devices focuses on the development of MTD layer. The following uses Samsung's NAND Flash k9f2808uob as an example, to introduce the development process of the trueffs driver for flash in the VxWorks operating system.

Driver development of trueffs under VxWorks
The trueffs driver development in VxWorks is mainly for the MTD layer. As shown in figure 1, the MTD layer is mainly used to recognize, read, write, and erase flash devices. This part of work is related to the specific flash memory and storage and system connection. That is to say, when different flash devices are selected, the connection method of the flash chip will be different, and the code files for implementing the MTD layer will also be different. Tornado provides several flash trueffs MTD-layer driver solutions: they are in installdir \ target \ SRC \ DRV \ tffs (installdir is the tornado installation directory ). these include trueffs of several flash companies such as Intel and AMD.
MTD layer driver. In this way, if developers use these flash chips, they only need to copy the relevant code files to the directory where the BSP is located, add the corresponding target code to the mach_extra file of makefile. However, in many cases, the flash chip used by developers is not provided in tornado. Therefore, developers need to write the MTD-layer driver code by themselves, which is also the main work of trueffs driver development.

Introduction to nand flash memory k9f2808uob
The capacity of k9f2808uob is 132 mb. The storage space is organized by 32768 (rows) and 528 bytes (columns) per page. The remaining 16 pages are located at 512 ~ of the column address ~ 527, k9f2808uob also divides the storage space into blocks, each of which consists of 32 pages. Therefore, k9f2808uob contains a total of 1024 blocks, and its internal structure is shown in 3.
 
The read and write operations of k9f2808uob are block-based operations. The address is transmitted through an 8-bit port. The CLE and ale signal lines can be used to reuse commands and addresses on the I/O port. Commands, addresses, and data are written to the device from the I/O port by lowering the WE AND Ce, as shown in table 1.
 

MTD layer driver programming
The MTD layer is driven by the software to implement the recognition, read, write and erase functions of Flash devices. Therefore, the first step of development is to create an MTD-layer driver code file under the BSP directory. You can name the file k9f2808. C during design. The following work is to implement flash operations in its files. This operation can be completed through the nandmtdidentify (), nandmtdread (), nandmtdwrite (), and nandmtderase () functions. In addition, a flash memory ing function nandmtdmap () is required (). The compilation of these functions is related to the Organization, commands, and functions of k9f2808uob and the connection of their chip pins.
Figure 4 shows the hardware connection between the flash chip k9f2808 and the embedded ARM chip. As shown in the figure, ngcs1 and nwe and Noe of b0x read and write k9f2808uob together with the gate, while the address lock signal ale and the control lock signal CLE are controlled by the addr2 and addr1 of b0x respectively, the status of k9f2808uob is read through gpc8, and gpc9 is used to control the chip selection signal. The eight data input and output pins are respectively connected to the eight data lines of b0x.
 
The hardware connection diagram shows that the base address of Flash is 0x02000000, the control lock address is 0x02000002, and the address lock address is 0x02000004, you can define them as nfbaseaddr, nfcleaddr, and nfaleaddr. For flash writing commands, address operations can be completed by the following functions:
/* Write_command-write command */
Local void write_command (uchar cmd)
{
* (Volatile uchar *) nfcleadd) = cmd;
}
/* Write_address-write address */
Local void write_address (uchar ADDR)
{
* (Volatile uchar *) nfaleadd) = ADDR;
}
The Flash status can be read through the I/O port control register of b0x, which is defined as follows:
# Define nfrbstatus () (* (volatile uint32 *) jx44b0x_pdatc) & (1 <8 ))
Due to the length, the read, write, and erase functions cannot be listed one by one here. developers can refer to the chip information, according to the operating sequence of k9f2808uob, write the functions for reading, writing, and erasing flash.
Among the five functions mentioned above, note nandmtdidentify (), because this function not only completes device identification, it will also be called when the trueffs file system is initialized, as shown in call process 5. Therefore, nandmtdidentify needs to set flash parameters and register the read, write, and erase functions at the upper layer for upper-layer function calls. However, the following code must be added to the function during design:
 
Figure 5 call process of the identify function in tureffs in VxWorks
Pvol-> write = nandmtdwrite;
Pvol-> erase = nandmtderase;
Pvol-> map = nandmtdmap,
After the k9f2808. c file is complete, add k9f2808. O to the mach_extra file of makefile to add the tureffs file driver to the system.

Socket driver identification and system configuration
After the MTD layer driver is complete, the next step is the socket driver identification and trueffs file system configuration. This part of work is relatively simple. The code for the socket layer is in ipvffs. c, developers can directly copy any installdir \ target \ SRC \ DRV \ tffs \ sockets under the xxx-sysTffs.c to the BSP directory, and renamed it into javasffs. c. Modify the macro definitions of flash_base_adrs and flash_size, and add the macro definition:
# Define include_mtd_nand
Copy the tffsconfig. c file to the BSP directory and register your nandmtdidentify in mtdtable [] of tffsconfig. C:
# Ifdefinclude_mtd_nand
Nandmtdidentify,
# Endif
Next, modify the stdcomp. h file in installdir \ target \ H \ tffs. Add MTD Identification Function
Flstatus nandmtdiden1 (flflash vo1 );
At this point, the socket driver recognition is complete. Finally, you can add the macro definition of the required function in config. h:
# Define include_tffs
# Define include_tffs_dosfs
# Define include_tffs_show

Implementation result
After all the above work is completed, VxWorks will call the tffsdrv () function at startup and initialize the trueffs file system. You can use the tffsdevformat function to format
Flash device, and use the usrtffsconfig function to create a trueffs device. Because the macro definition of the DOS file system is included, you can access the flash device in DOS mode. The result is as follows:
-> Usrtffsconfig0, 0, "/tffs0"
-> Devs
DRV name
0/null
1/Tyco/0
1/Tyco/L
5 Host:
6/Vio
3/tffs0
-> Copy "VxWorks", "/tffs0/VxWorks"
Copy OK: 966996 bytes copied
-> 11 "/tffs0"
Listing directory/tffs0:
-Rwxrwxrwx 1 0 966668
Jan 1 1980 VxWorks

Conclusion
The simulation function of trueffs on disks allows you to perform a series of operations such as reading, writing, partitioning, and formatting on flash devices in the embedded VxWorks operating system. By calling the I/O Control of the operating system, VxWorks can also easily Access Flash devices. On the other hand, the use of tureffs technology to manage data read and write operations in flash can greatly increase the number of write operations on flash, thus improving the life of flash. Taking NAND Flash k9f2808uob as an example, this paper introduces how to implement the trueffs driver on the VxWorks operating system with the embedded chip b0x. It can be seen that the implementation of the trueffs driver can be widely used in various industrial control systems and has great practical value.

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.