The transplantation of cramfs root file system is successful (tested under fs2410)

Publisher:清新心情Latest update time:2016-08-02 Source: eefocusKeywords:cramfs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1 Introduction

According to Unix conventions, any object (including devices) in a Linux system is usually considered a file. The root file system is the starting point of all files and device nodes, and it is the key to whether the system can start normally. This article will introduce in detail how to use the Busybox tool set to create a simple root file system, namely the Cramfs root file system.

 

2 Development Platform Introduction

The development system adopts the host + target board development mode, and the target board and the host communicate through serial lines and Ethernet cables. The host uses: PC + Red Hat 9 under VMware6.0 virtual machine Target board: FS2410 experimental development board developed by Shenzhen Youlong Company: Its main parameters: CPU: Samsung S3C2410, main frequency 203MHz; memory: 64M bytes; NOR Flash: 2M bytes (SST39VF1601); NAND Flash: 64M bytes (K9F1208); embedded Linux version: Linux2.4.18

After the root file system is generated, use the Boot Loader to burn it into partition 2 of the NAND Flash of the development board and run it (its address is: offset 0x200000, size 0x1e00000).

 

3 Basic structure of the root file system

The top-level directories of the embedded Linux root file system have their own special usage and purpose. Generally speaking, the root file system of an embedded Linux system should contain the following:

(1) The minimum directories that can ensure that most applications in the embedded Linux system can run normally include /bin /dev /etc /lib /proc /sbin /usr /tmp /var. If the user needs to provide an expandable environment for multiple users, the following directories must also be created: /home /mnt /opt /root.

(2) Basic link libraries required for the root file system: Glibc and uClibc.

(3) Basic system configuration files: rcS, inittab, fstab, linuxrc and other script files

   (4) Basic device files: /dev/tty0 /dev/ttyS0 /dev/console

(5) Basic applications: such as cd, ls, mv, cp, etc.

 

4 Use Busybox to create a Cramfs root file system

4.1 Introduction to Cramfs

Cramfs (Compressed Rom File System) is a file system with only the most basic features that Linux Torvalds participated in developing when he was working at Transmeta. It is a new read-only file system designed for Linux kernel versions after 2.4. It uses zlib compression, and the compression ratio can generally reach 1:2, but it can still achieve efficient random reading. In Linux systems, directories that do not need to be modified frequently are usually compressed and stored, and the compressed files are decompressed when the system boots. Because Cramfs does not affect the system's file reading speed and is a highly compressed file system. Therefore, it is widely used in embedded systems.

In an embedded environment, both memory and external storage resources need to be used sparingly. If you use the RAMDISK method to use the file system, then after the system is running, you must first decompress the image file on the Flash into the memory and build the RAMDISK environment before you can start running the program. But it also has a fatal weakness. Under normal circumstances, the same code not only occupies space in the Flash (in a compressed form), but also occupies a larger space in the memory (in a decompressed form), which violates the requirement of saving resources as much as possible in an embedded environment.

The use of Cramfs file system can solve this problem well. Cramfs is a compressed file system. It does not need to decompress all the contents of the file system into the memory at once. Instead, when the system needs to access data at a certain location, it immediately calculates the location of the data in Cramfs, decompresses it into the memory in real time, and then obtains the data that needs to be read in the file system by accessing the memory. The decompression in Cramfs and the storage location of the data in the memory after decompression are maintained by the Cramfs file system itself. Users do not need to understand the specific implementation process. Therefore, this method enhances transparency, which is convenient for developers and saves storage space. Therefore, we chose to use this simple Cramfs file system to transplant the root file system during development.

4.2 Introduction to Busybox

Busybox is a single executable implementation of standard Linux tools. Busybox includes some simple tools, such as cat and echo, as well as some larger and more complex tools, such as grep, find, mount, and telnet. Some people call Busybox the Swiss Army Knife of Linux tools. Simply put, Busybox is like a large toolbox that integrates and compresses many Linux tools and commands. Although these tools in Busybox are simplified compared to GNU tools, they are very practical. Busybox is designed with full consideration of special working environments with limited hardware resources. It adopts a modular design, and it uses a configuration menu similar to the Linux kernel configuration menu, making configuration and tailoring quite simple. This feature of Busybox makes it very suitable for embedded system applications. Almost all embedded Linux uses Busybox as a tool. At the same time, the installation script of Busybox makes it easy to build a Linux root file system based on Busybox. This article uses the powerful tool set Busybox to create a Cramfs root file system.

4.3 Configure Busybox

The source code of Busybox can be downloaded from the official website http://www.busybox.net/. We use the source code package busybox-1.00-pre10.tar.bz2 provided by Shenzhen Youlong Company. Note that the newer the version, the better. If the new version cannot be started normally in the target board after compilation, you can try to return to the older version. We used busybox-1.1.3 at the beginning of the development process, and the resulting root file system could not be started normally on fs2410. Switching back to busybox-1.00-pre10 can easily solve this problem.

First, copy busybox-1.00-pre10.tar.bz2 to the user's home directory: home/jixiang (you can set the directory where busybox is copied to).

[root@mynet jixiang]# cd /home/jixiang

[root@mynet jixiang]# tar vxjf busybox-1.00-pre10.tar.bz2

[root@mynet jixiang]# cd busybox-1.00-pre10

[root@mynet busybox-1.00-pre10]# make menuconfig

Enter the configuration menu interface, and make the following configuration:

(1) In General Configuration, be sure to select the "Support for devfs" option. The new version of Busybox has removed this option, but it should be possible to add it by modifying the configuration file.Transplantation of cramfs root file system under Youlong FS2410 - jixiang1119 - jixiang

                                      Figure 1 Configuration support device file system interface

 

(2) In the Build Options option, select "Static Library" and set the PREFIX of the cross-compilation tool. The path of the cross-compilation tool I use is: /usr/local/arm/3.3.2/bin. (The specific situation depends on the different cross-compilation environment paths of the host machine.Transplantation of cramfs root file system under Youlong FS2410 - jixiang1119 - jixiang

                                                Figure 2 Configuration static library interface

(3) In the Init Utilities option, "Support reading an inittab file" should be selected so that you can initialize according to your own inittab file; "Support running init from within an initrd" should be selected, otherwise you will be prompted with a very confusing prompt "/bin/sh: can't access tty; job control turned off", although you can enter the console command line.Transplantation of cramfs root file system under Youlong FS2410 - jixiang1119 - jixiang

                       Figure 3 Script file configuration interface

(4) Another Bourne-like Shell →Choose your default shell (ash) →, here you should select the default shell: ash, otherwise sh will not be generated and the script file cannot be interpreted.

Transplantation of cramfs root file system under Youlong FS2410 - jixiang1119 - jixiang

                        Figure 4 Shell configuration

(5) Other configurations can be configured according to your own development needs.

4.3 Compile and install Busybox

      After the configuration is complete, exit and save (it is best to back up the .config file for later use), then start generating and execute make TARGET_ARCH=arm; TARGET_ARCH here is required.

[root@mynet busybox-1.00-pre10]# make TARGET_ARCH=arm

[root@mynet busybox-1.00-pre10]# make install

Busybox will create three subdirectories, bin, sbin, and usr, and a link file, linuxrc, under the default PREFIX directory - install.

4.4 Prepare to generate cramfs file system

(1) Create a folder rootfs, copy the bin, sbin, and usr directories generated in the _install directory to rootfs, and create other subdirectories in the rootfs directory. Execute the command mkdir dev etc home lib mnt proc sys tmp var to create the corresponding folders, and then create the init.d folder under etc.

(2) Prepare the startup files inittab, fstab, linuxrc, and rcS. Inittab and fstab are placed in the etc directory, rcS is placed in the etc/init.d/ directory, and linuxrc is placed in the rootfs directory.

(3) Writing a simple configuration file

linuxrc file:

#!/bin/sh

echo "mount /etc as ramfs"

/bin/mount -f -t cramfs -o remount,ro /dev/bon/2 /

/bin/mount -t ramfs ramfs /var

/bin/mkdir -p /var/tmp

/bin/mkdir -p /var/run

/bin/mkdir -p /var/log

/bin/mkdir -p /var/lock

/bin/mkdir -p /var/emptymk

#/bin/mount -t usbdevfs none /proc/bus/usb

exec /sbin/init

 

rcS file:

#!/bin/sh

/bin/mount –a

 

fstab file:

none        /proc        proc    defaults    0 0

none        /dev/pts    devpts    mode=0622    0 0

tmpfs        /dev/shm    tmpfs    defaults    0 0

Note that the above files should have execution permissions. You can use chmod 755 to modify their permissions.

4.5 Generate Cramfs root file system image

We use the cramfs-1.1.tar.gz source package provided by Youlong to generate the root file system image.

After decompression, put mkcramfs in the /bin directory of the host Red Hat9.

Go to the parent directory of the rootfs directory and execute: mkcramfs rootfs test.cramfs

5 Download and run test.cramfs

Download test.cramfs to the file partition in the nand flash of the Youlong FS2410 development board through dnw (its address is: offset 0x200000, size 0x1e00000), and the file system starts normally. The startup interface is as follows:

NET: Registered protocol family 1

NET: Registered protocol family 17

VFS: Mounted root (cramfs filesystem) readonly.

Mounted devfs on /dev

Freeing init memory: 124K

mount /etc as ramfs

mount: /etc/mtab: No such file or directory

mount: /etc/mtab: Read-only file system

mount: /etc/mtab: No such file or directory

mount: /etc/mtab: Read-only file system

mount: /etc/mtab: Read-only file system

mount: /etc/mtab: Read-only file system

mount: /etc/mtab: Read-only file system

Please press Enter to activate this console.

 

BusyBox v1.00-pre10 (2009.09.01-12:23+0000) Built-in shell (ash)

Enter 'help' for a list of built-in commands.

 

/ # ls

bin etc lib mint bin temp var

dev      home     linuxrc  proc     sys      usr

/ #

Keywords:cramfs Reference address:The transplantation of cramfs root file system is successful (tested under fs2410)

Previous article:ARM assembly and C mixed programming marquee program
Next article:Marquee experiment implemented by arm assembly

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号