Linux started successfully from ramdisk root file system

Source: Internet
Author: User

The U-boot customization, kernel customization, and ramdisk root file system have been completed by referring to the China-embedded lab manual and online materials. Let's sum up. I have referenced many articles on the Internet, so I will not mention them one by one. Thank you for your help.

Development Environment: Red Hat Enterprise 5

Cross-compilation tool chain: arm-linux-gcc4.3.2

Embedded Linux kernel version: friendly arm of the mini2440 Development Board with the kernel linux-2.6.32.2 CD

Development Board: mini2440-64MNand flash

Bootloader: u-boot-1.20

The procedure is as follows:

1. U-BOOT Customization

Because there are a lot of content, I 'd like to sum up another article in the next day.

2. decompress the kernel source code tree.

For detailed steps, refer to the user manual of the friendly mini2440 Development Board.

3. Modify Kernel configuration options

Make menuconfig, open the configuration menu, and modify the following two configuration items:

A): General setup --> select initial Ram filesystem and RAM disk...

B): devicedrivers --> Block devices --> select the ram block devicesupport item.

Modify (4920) default RAM disk size Kbytes option to (8192) default RAM disk size Kbytes

Note that ramdisk is a memory virtual disk technology, which is essentially not a file system. It uses the ext2 file system when using the file system. Therefore, you must go to the file systems menu when making menuconfig and select <*> second extended FS Support. To provide Kernel support for the ext2 file system.

Save the configuration and exit.

In this way, the ramdisk startup function and ramdisk driver support are added to the kernel.
4. Modify kernel startup parameters

There are two methods:

A): Modify row 310th of. config and modify the definition of "config_cmdline ".

Change to config_cmdline = "initrd = 0x32000000, 0x200000root =/dev/Ram RW console = ttysac0 mem = 64 m" and save.

Starting from ramdisk, the starting address of the ramdisk compressed file is at the memory address 0x32000000, and the file size is 0x200000.

You can also enter the boot Options menu when makemenuconfig arch = arm, and then modify this parameter in the default kernel command string. The results are the same.

B): You can use the bootargs environment variable of U-boot to pass the startup parameters without modifying the 310th-line definition of. config.

Also, change the environment variable to bootargs = initrd = 0x31000000, 0x200000root =/dev/Ram RW init =/linuxrc console = ttysac0 mem = 64 m

And saveenv to save the U-boot environment variable

A) and B) have the same effect. (Note: I only tried a and B)
5. Compile the kernel

Note: It seems that the friendly arm has commented out the uimage target in the kernel source code directory, and the direct makeuimage will prompt that there is no uimage target. Zimage is a commonly used compressed image file in armlinux. uimage is a dedicated image file for U-boot. It adds a "Header" with a length of 0x40 before zimage ", this section describes the type, loading location, generation time, and size of the image file. In other words, there is no difference between zimage and uimage if it is executed directly from the position 0x40 of uimage. In addition, the linux2.4 kernel does not support uimage. The linux2.6 kernel supports many embedded systems, but uimage generation also needs to be configured.

Here, I directly copy the mkimage tool in/tools under the root directory of U-boot to the/usr/bin directory of the host, and then execute it directly under the root directory of the kernel.

# Make uimagearch = arm cross_compile = arm-Linux-

Wait for a while and the kernel compilation is complete.

6. Create a ramdisk root file system (actually, create a root file system)

This process is the core step for creating the ramdisk root file system. The method is as follows:

A) Create the root file system directory:

# Transfer CD to your working directory.

# Mkdir rootfs

# Cd rootfs

# Mkdir bin Dev etclib proc sbin sys usr mnt tmp VaR

# Mkdir usr/binusr/lib usr/sbin lib/modules
B) create the most basic device file:

# Cd Dev

# Mknod-M 666 console C 5 1

# Mknodded-M 666 nullc 1 3

# CD ..
C) install the/etc configuration file:

I am using the ETC configuration file provided by the country embed. without modification, I directly decompress it to the root file system.

The procedure is as follows:

# Tar etc.tar.gz-C/XXX/rootwhj

Xxx indicates the path of the root directory you want to create.
D) Compile the kernel module:

Go to the Linux kernel source code root directory

# Make modulesarch = arm cross_compile = arm-Linux-
E) install the kernel module:

# Makemodules_install arch = arm install_mod_path =/XXX/rootwhj // kernel modules in the embedded system must be in the file system

Xxx indicates the directory where the rootfs you want to create is located.
F) Configure busybox

Go to the busybox directory and execute # Make menuconfig

Go to busyboxsettings-> build options-> select "build busyboxas a static binary", that is, static links, avoiding copying a large number of library files.

Installationoptions-> select "Don't use/usr" to prevent the busybox from being accidentally installed in the corresponding directory of the host system and damaging the host system.

Busyboxinstallation prefix (/XXX/rootwhj). modifying this option indicates that the compiled busybox will be installed to this location.
G) Compile and install busybox

# Make arch = arm cross_compile = arm-Linux-

After several minutes of compilation

# Make install

Install it in the directory set by busyboxinstallation prefix (/XXX/rootwhj. The root file system directory (/XXX/rootwhj) that I want to create ).

// Create the root file system

H) Create a ramdisk root file system image

The method is as follows:

Upload.

Compile and generate the tool genext2fs and put it in the/sbin/directory of the host for ease of use.

Jump to the top-level directory of the rootfs to be created

# Genext2fs-B 8192-d rootfs ramdisk

-B indicates that the ramdisk size is 8 Mb.

-D refers to the root file system directory to be created as ramdisk

The last ramdisk is the name of the created ramdisk, which can be changed.

# Gzip-9-F ramdisk

Compress the ramdiskin the simplified format as ramdisk.gz.
7. Download the kernel image and ramdisk Image

DRAM: 64 MB
Flash: 512 KB
In: Serial
Out: Serial
Err: Serial
Whj2440 # printenv
Bootargs = root = ramfs devfs = Mount console = ttysa0, 9600
Bootdelay = 3
Baudrate = 115200
Ethenv = 00: 01: 02: 03: 04: 05
Filesize = 1da248
Fileaddr = 32000000
Netmask = 255.255.255.0
Ipaddr = 202.205.85.164
Serverip = 202.205.85.165
Stdin = serial
Stdout = serial
Stderr = serial

Environment size: 248/65532 bytes
Whj2440 # TFTP 31000000 uimage
Dm9000 I/O: 0x20000300, ID: 0x90000a46
Mac: 00: 80: 00: 80: 00: 80
TFTP from server 202.205.85.165; our IP address is 202.205.85.164
Filename 'uimage '.
Load address: 0x31000000
Loading: t ####################################### ##########################
######################################## #########################
######################################## #########################
######################################## #########################
######################################## #########################
######################################## #########################
#
Done
Bytes transferred = 2329916 (238d3c HEX)
Whj2440 # TFTP 32000000 ramdisk.gz
Dm9000 I/O: 0x20000300, ID: 0x90000a46
Mac: 00: 80: 00: 80: 00: 80
TFTP from server 202.205.85.165; our IP address is 202.205.85.164
Filename 'ramdisk.gz '.
Load address: 0x32000000
Loading: t ####################################### ##########################
######################################## #########################
######################################## #####
Done
Bytes transferred= 891755 (d9b6b HEX)

8. Use the ramdisk root file system to start the kernel

Whj2440 # bootm3000000
# Booting image at 31000000...
Image name: Linux-2.6.32.2-ARMofWHJ
Created: 2011-09-06 22: 48: 18utc
Image Type: ARM Linux kernel image (uncompressed)
Data size: 2329852 bytes = 2.2 MB
Load address: 30008000
Entry Point: 30008000
Verifying checksum... OK
OK

Starting kernel...

Uncompressinglinux ....................................... ......................
........................................ ........................................
...... Done, booting the kernel.
Linux version 2.6.32.2-armofwhj (root@localhost.localdomain) (GCC version 4.3.2
(Sourcery g ++ lite 2008q3-72) #17 wed Sep 7 06:41:21 CST 2011
CPU: ARM920T [41129200] Revision 0 (armv4t), Cr = c0007177
CPU: vivt data cache, vivt Instruction Cache
MACHINE: friendlyarm mini2440 Development Board
Warning: Bad configuration page, trying to continue
Memory Policy: ECC disabled, data cache writeback
CPU s3c2440a (ID 0x32440001)

Too long in the middle, omitted

Ramdisk: gzip image found at Block 0
VFS: mounted root (ext2 filesystem) on device 1:0.
Freeing init memory: 176 K

Processing/etc/profile... Done

#

 

Now the system is started successfully.

----------------------- The following is a reference ------------------------------------------

Postscript:The default configuration file mini2440 from the friendly arm is to directly compile the driver and so on into the kernel, and does not use the kernel module. Therefore, do not perform the following steps to compile and install the kernel module in step 3 of the above process. I have not compiled the kernel module. According to the root_qtopia root file system of the friendly arm, nothing exists in/lib/modules/'uname-R. In addition, in the past, the config_mini2440_t35 with the friendly arm was used to compile the kernel module by default. We found that only the hello_modules kernel module examples were available. Here we do not need to use this hello_modules, so these two steps are skipped.

Note:Since the ETC configuration file in the minimum system does not write a script to automatically start the NIC, the NIC cannot be automatically started when ramdisk is started. Later, the script is automatically started by referring to the script in the root_qtopia root file system of the friendly arm.

Modify as follows:

Modify the/etc/init. d/RCS file under the rootfs of the ramdisk root file system to be created.

Add the following two lines at the bottom to automatically start the NIC:

/Sbin/ifconfig lo127.0.0.1

/Sbin/ifconfig eth0192.168.31.230 netmask 255.255.255.0 up

This method is found by analyzing the Startup Process of the root_qtopia root file system.

By analyzing the root_qtopia root file system, we can find more information. This is not detailed here.

Exercise your ability to analyze and solve problems. Haha.

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.