ARM-Linux porting (4)-root file system construction

Source: Internet
Author: User

Arm-Linux porting (4)-root file system construction

K-style

 

Reprinted please indicate from Hengyang Normal College 08 electric 2 k-style http://blog.csdn.net/ayangke,QQ:843308498 mailbox: yangkeemail@qq.com

 

Related tool versions:

Busybox-1.7.0 arm-linux-4.3.2 linux-2.6.22

 

1. Configure and install busybox.

There are various command applications under the/bin and/sbin directories in our root file system, and these programs are built through busybox in the embedded system, every command is actually a link pointing to busybox. busybox determines the command operation through the input parameters.

1) Configure busybox

Unzip the busybox-1.7.0, then enter the directory, and configure with makemenuconfig. Here we configure two items

First, you can select Dynamic library compilation in the compilation option. Of course, you can also choose static files. However, the root file system built in this way will be larger than the dynamic compilation.

-> Busybox settings

-> Buildoptions

-> Buildshared libbusybox

Second, select the tab key completion function in the performance fine-tuning option.

-> Busybox settings

-> Busyboxlibrary Tuning

-> Commandline editing

-> Tabcompletion

Others are some command configurations. If you want to make your root file system have any command, select that command. I chose the default configuration. Generally, basic commands are selected for you.

2) Compile busybox

Modify Makefile and "ARCH? = Arm "and" CROSS_COMPILE? = Arm-linux-", and then use the make command to compile. The following error occurs during compilation:

../Arm-none-linux-gnueabi/libc/usr/include/linux/netfilter. h: 44:

Error: field 'in' has incomplete type

Solution:

Modify the arm-linux cross-compilation tool chain

In usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include/linux/netfilter. add the missing header file at the beginning of the header file: # include <netinet/in. h>

3) install busybox

Here we first create a new root_fs to build the root file system,

Then run the makeconfig_prefix =/home/Y-kee/work/root_make/root_fs command to install busybox. The following directory and file appear under root_fs. We can see that linuxrc is a link to busybox.

[Root @ localhost root_fs] # ls-l

Total 12

Drwxr-XR-x 2 root Root 4096 Oct 19 05: 41bin

Lrwxrwxrwx 1 Root 11 Oct 22 11: 17 linuxrc-> bin/busybox

Drwxr-XR-x 2 root Root 4096 Oct 22 18: 43 sbin

Drwxr-XR-x 4 Root 4096 Oct 22 16: 52usr

Go to the bin directory and you can see that all these files are links to busybox (except busybox itself ).

[Root @ localhostroot_fs] # ls bin-l

Total 0

Lrwxrwxrwx 1 Root 7 Oct 22 11: 17 addgroup-> busybox

Lrwxrwxrwx 1 Root 7 Oct 22 11: 17 adduser-> busybox

Lrwxrwxrwx 1 Root 7 Oct 22 11: 17ash-> busybox

-Rwxr-XR-x 1 Root 0 Oct 23 13: 20 busybox

Lrwxrwxrwx 1 Root 7 Oct 22 11: 17cat-> busybox

Lrwxrwxrwx 1 root 7 Oct 22 11: 17 catv-> busybox

 

2. Install the glibc library.

Create the lib directory under root_fs, and copy the lib file under the arm-linux-Cross-compilation chain to the lib directory under root_fs. I use

Cp/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/* root_fs/lib/*-df
The-d option indicates that the linked file is copied as the original link; otherwise, the copied link file is a copy.

 

3. Construct the/etc,/dev, and proc directories.

/Etc and/dev are required by a root file system. The/etc file must contain the configuration file inittab. dev required for the init process to start. The directory must contain the two Device Files console and null required for the init process to start. The proc directory is the virtual proc file system that mounts the kernel. In this way, some commands of the process, such as ps, will be valid.

1) Run mkdiretc dev proc in the dev directory

2) create an inittab file under etc

The format of configuration information in inittab has been explained in my previous article linux porting (3. We will write two lines of configuration information in it.

: Sysinit:/etc/init. d/rcS

: Askfirst:/bin/sh

The first line is used to start the script file rcS, this is because we can use this file to boot the system to do a job for us, such as mounting the file system or starting some other applications.

The second is to start the shell interpreter sh.

3) configure the script file RFM

Create the init. d directory in the etc directory, and then create an rcS file in the init. d directory, and add executable permissions to the RFM file.

Write Data in the rcS directory

#! Bin/sh

Mount-

Execute the mount-a command in the rcS, so the command will mount the corresponding directory according to the fstab file in the etc.

4) configure the fstab file

Create a new fstab file in the etc directory, and then write

# Device mount-point type options dump fsck order

Proc/proc defaults 0 0

The first parameter is the device, the second parameter is the mount point, and the third parameter is the setting. The remaining values are written as two zeros.

5) build the device files under the dev directory.

Because the console and null devices are required to start the init process, you need to create these two device files, enter the dev directory, and then execute

Mknod console c 5 1

Mknod null c 1 3

If the two device files are not manually created by mknod, an error occurs during kernel startup:

Warning: unable to open an initialconsole.

Note that the two device files must be created under dev. I created these two files in the etc directory for a while, and it took most of my time to find the reason. In addition, when using cdetc or cddev, do not place a slash in front of etc and dev. I am a mean user, and have followed the slash, as a result, some files are deleted in the etc directory of the LINUX system on the PC, resulting in system crash.

After completing the above steps, make the root file system into a yaffs2 image and install it in flash.

 

5. Configure mdev to support hot swapping

Busybox uses an mdev in the sbin directory to support hot swapping. What is hot swapping? If a device is inserted during linux Startup, mdev will automatically create a device file for you in the dev directory.

Mdev.txt in the/busyboxsource code is described. The screenshot is as follows:

Mdev has two primary uses: initialpopulation and dynamic updates. Both

Require sysfs support in the kernel andhave it mounted at/sys. For dynamic

Updates, you also need to havehotplugging enabled in your kernel.

 

Here's a typical code snippet from theinit script:

[1] mount-t sysfs/sys

[2] echo/bin/mdev>/proc/sys/kernel/hotplug

[3] mdev-s

 

Of course, a more "full" setupwowould entail executing this before the previous

Code snippet:

[4] Mount-T tmpfs mdev/dev

[5] mkdir/dev/PTS

[6] Mount-T devpts/dev/PTS

 

The simple explanation here is that [1] You need to have/sys mounted before

Executing mdev. Then you [2] instruct the kernel to execute/bin/mdev whenever

A device is added or removed so that thedevice node can be created or

Destroyed. Then you [3] seed/dev with all the devicenodes that were created

While the system was booting.

 

For the "full" setup, you wantto [4] Make sure/Dev is a tmpfs filesystem

(Assumingyou're running out of Flash). Then you want to [5] Create

/Dev/PTS mount point and finally [6] mount the devpts filesystem on it.

When we use this function in flash, we only need to go through step [1] [2] [3. That is

[1] Mount-T sysfs/sys

[2] echo/bin/mdev>/proc/sys/kernel/hotplug

[3] mdev-S

So in the etc/init. d/RCS file, change

Mount-

Echo/bin/mdev>/proc/sys/kernel/hotplug

Mdev-S

Change the ECT/fstab file

# Device Mount-point type options dump fsck order

Proc/proc defaults 0 0

Sysfs/sys sysfs defaults 0 0

Create a sys directory under root_fs.

Then we can create a new yaffs2 image to automatically create device files. Note that the created console and null device files cannot be deleted, because they were used before mdev worked.

 

6. Improve the root file system.

1) Add inittab under the etc directory

: Ctrlaltdel:/sbin/reboot

: Shutdown:/bin/umount-a-r

: Restart:/sbin/init

To specify the additional work that the system performs when executing special operation commands (shultdown, restart, ctrlaltdel.

 

2) create MNT, TMP, and root directories under root_fs

 

Note:

Do not move the binsbin usr and linuxrc created by busybox in the root_fs directory when creating the root file system, because many of these directories and files are linked files. Moving the kernel may cause the following errors during kernel startup:

Request_module: runaway loop modprobe binfmt-0000

I have been suffering from this problem for a long time! Later, I copied these files and directories from a good root file system. Remember!

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.