Ramdisk file system creation and debugging

Source: Internet
Author: User

Development Environment: fedora 9
Tool chain for cross-Compilation: Arm-Linux-GCC 4.3.2 with Eabi
Embedded Linux kernel version: 2.6.29.4-friendlyarm. I cannot remember the details when I wrote the post yesterday. I started the development board today and checked it with uname-R, which is 2.6.29.4-friendlyarm. The post has been changed. This article is based on the kernel version of 2.6.29.4-friendlyarm. Other versions should be similar for reference only.
Development Board: mini2440-128M NAND Flash
Bootloader: u-boot-2009.11

The procedure is as follows:
1. Extract the kernel source code tree
Unzip the linux-2.6.29-mini2440-20090708.tgz to your own working directory, will generate a friendly arm modified and there are several mini2440 default configuration file of the kernel source code directory linux-2.6.29. For detailed steps, refer to the user manual of the friendly mini2440 Development Board.

2. Modify Kernel configuration options
Go to the kernel source code directory linux-2.6.29 directory
# Cp config_mini2440_t35. config
# Make menuconfig arch = arm
Open the configuration menu and modify the following two configuration items:
A): General setup --> select initial Ram filesystem and RAM disk...
B): device drivers --> Block devices --> select the ram block device support item.

Check whether optimize for size is selected. If not, optimize the kernel size and configure it as needed.
Modify (8192) the default RAM disk size Kbytes option(4096) default RAM disk size KbytesThe reason for the modification is that the ramdisk I created later is of the size of 4096kb. Of course, if you want to create an 8192kb ramdisk, it will be 8192 here, and so on. But the smallest system does not need such a large ramdisk. The default configuration for this item is (4096). I have changed this configuration before, so it is (8192. If the size does not match the ramdisk size, the kernel still appears at startup.
Panic Kernel panic, prompting that the ramdisk format is incorrect and cannot be mounted to ramdisk.
Next, pay special attention to the fact 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 make menuconfig arch = arm and select <*> second extended FS Support. To provide Kernel support for the ext2 file system.I have previously added the ext2 file system, so I didn't explain it at the beginning. Here, I want to explain why some people have followed my method, but still Kernel panic, add this step in particular.
Save the configuration and exit.
In this way, the ramdisk startup function and ramdisk driver support are added to the kernel.

3. 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 = 0x32.1600,0x200000 root =/dev/Ram RW init =/linuxrc console = ttysac0 mem = 64 m"
Save.
Starting from ramdisk, the starting address of the ramdisk compressed file is at the memory address 0x3000000, and the file size is 0x200000.
This parameter can also be set to the boot Options menu when make menuconfig arch = arm, and then modified 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 = 0x32.1600,0x200000 root =/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.

4. Compile the kernel
# Make zimage arch = arm cross_compile = arm-Linux-
Then wait for about 20 minutes.
After compilation, the zimage kernel image is displayed in the current directory.
It seems that the friendly arm has commented on the uimage target in the kernel source code directory. Some people have said in the forum that directly making uimage seems to prompt that there is no uimage target. So I will first create a zimage and then convert it to a uimage using the mkimage tool of U-boot. In fact, uimage adds a 64-byte kernel image description at the beginning of zimage.

5. Create a uimage kernel Image
Since the bootloader I use is u-boot, the method to convert zimage to uimage is as follows:
# Mkimage-A arm-O Linux-T kernel-C none-A 0x30008000-E 0x30008000-n "Linux kernel image"-D zimage uimage-ramdisk
Note: The mkimage tool is a uimage kernel image production tool in U-boot format. After the U-boot is compiled, it will be under the tools directory under the U-boot source code tree. We recommend that you copy it to the/sbin/directory of the host for ease of use. The specific parameters used by mkimage are not described in detail. For details, refer to them.

6. Create the ramdisk 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 etc lib proc sbin sys usr mnt tmp VaR
# Mkdir usr/bin usr/lib usr/sbin lib/modules

B) create the most basic device file:
# Cd Dev
# Mknod-M 666 console C 5 1
# Mknod-M 666 null C 1 3
# CD ..

C) install the/etc configuration file:
Here, you can directly copy the basic configuration files in root_qtopia of the friendly arm, just copy the necessary files and delete the content, because the ramdisk I made does not contain qtopia and so on, it is useless to copy it all.
I directly decompress the ETC configuration file of the smallest system found on the Internet to the root file system I created, and added some content to the root_qtopia with reference to the friendly arm, see the final description.
The procedure is as follows:
# Tar etc.tar.gz-C/XXX/rootfs
Xxx indicates the directory where the rootfs you want to create is located.

D) Compile the kernel module:
The method is as follows:
Linux kernel source code directory (linux-2.6.29)
# Make modules arch = arm cross_compile = arm-Linux-

E) install the kernel module:
# Make modules_install arch = arm install_mod_path =/XXX/rootfs
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 busybox settings-> build options-> select "build busybox as a static binary", that is, static links, avoiding copying a large number of library files.
Installation Options-> 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.
Busybox installation prefix (/XXX/rootfs). 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 busybox installation prefix (/XXX/rootfs. The root file system directory (/XXX/rootfs) that I want to create ).

H) Create a ramdisk root file system image
The method is as follows:
Upper Limit
, Download specific address: http://sourceforge.net/projects/genext2fs? Source = DLP
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 4096-D rootfs ramdisk
-B indicates that the size of the created ramdisk is kb.
-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
Start U-boot and pause the Automatic startup of U-boot. In the U-boot command line, type the following command to download the kernel and ramdisk image:
[U-boot @ mini2440] # TFTP 0x32000000 uimage-ramdisk
Dm9000 I/O: 0x20000300, ID: 0x90000a46
Dm9000: Running in 16 Bit mode
Mac: 08: 08: 11: 18: 12: 27
Operating at 100 m full duplex mode
Using dm9000 Device
TFTP from server 192.168.31.117; our IP address is 192.168.31.230
Filename 'uimage-ramdisk '.
Load address: 0x32000000
Loading: t ###################################### ###########################
######################################## #########################
#
Done
Bytes transferred = 1917752 (1d4338 HEX)
[U-boot @ mini2440] # TFTP 0x31000000 ramdisk.gz
Dm9000 I/O: 0x20000300, ID: 0x90000a46
Dm9000: Running in 16 Bit mode
Mac: 08: 08: 11: 18: 12: 27
Operating at 100 m full duplex mode
Using dm9000 Device
TFTP from server 192.168.31.117; our IP address is 192.168.31.230
Filename 'ramdisk.gz '.
Load address: 0x31000000
Loading: t ###################################### ###########################
####
Done
Bytes transferred = 1002594 (f4c62 HEX)

8) use the ramdisk root file system to start the kernel.
Run the following command on the U-boot command line to start the system:
Bootm 0x32000000
# Booting kernel from legacy image at 32000000...
Image name: Linux-2.6.29.4-FriendlyARM
Created: 2010-04-09 15:13:52 UTC
Image Type: ARM Linux kernel image (uncompressed)
Data size: 1917688 bytes = 1.8 MB
Load address: 30008000
Entry Point: 30008000
Verifying checksum... OK
Loading kernel image... OK
OK

Starting kernel...

Uncompressing Linux ...................................... .......................
........................................ ........................ Done, booting t
He kernel.
Linux version 2.6.29.4-friendlyarm (root@localhost.localdomain) (GCC version 4.3
. 2 (sourcery g ++ lite 2008q3-72) #3 Fri APR 9 23:13:36 CST 2010
CPU: ARM920T [41129200] Revision 0 (armv4t), Cr = c0007177
CPU: vivt data cache, vivt Instruction Cache
MACHINE: friendlyarm mini2440 Development Board
Memory Policy: ECC disabled, data cache writeback
...... Too long content is omitted here ......
Ramdisk: compressed image found at Block 0
VFS: mounted root (ext2 filesystem) on device 1:0.
Freeing init memory: 136 K
Eth0: link down

Processing/etc/profile... Done

# Eth0: link up, 100 Mbps, full-duplex, LPA 0x45e1

Now the system is started successfully.

----------------------------------------------------------------------------------
Postscript:Because the default configuration file mini2440 of the friendly arm is to directly compile the driver and so on into the kernel, the kernel module is not used. 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 lo 127.0.0.1
/Sbin/ifconfig eth0 192.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. Additional: In addition, you can use the following method to burn both the kernel and ramdisk to the NAND Flash and modify bootcmd so that U-boot can automatically start the system. The method is described below. You can do it yourself.
The method is as follows:

U-boot # TFTP 0x32000000 zimage
U-boot # NAND erase 0x00200000 0x200000
U-boot # NAND write 0x32000000 0x00200000 0x00200000
U-boot # setenv bootcmd NAND read 0x32000000 0x00200000 0x00200000 \; go 0x30008000
U-boot # boot
Note that 0x200000 is a kernel within 2 M. If your kernel is larger than 2 m, replace 0x200000 with 0x300000 (for example, the kernel size is within 3 m)
It is actually the method for starting the zimage kernel using the go command in uboot.
######################################## ############################
U-boot # TFTP 0x32000000 uimage
U-boot # NAND erase 0x00200000 0x200000
U-boot # NAND write 0x32000000 0x00200000 0x00200000
U-boot # setenv bootcmd NAND read 0x32000000 0x00200000 0x00200000 \; bootm 0x30008000
U-boot # boot
Note that 0x200000 is a kernel within 2 M. If your kernel is larger than 2 m, replace 0x200000 with 0x300000 (for example, the kernel size is within 3 m)
Actually, it is the uimage kernel startup method using the bootm command in uboot.
========================================================== ======================================
Note: number of bytes to be erased from the start address of the NAND erase.
Number of bytes to write to the start address of NAND write
In addition, both the start address and the number of bytes to be erased/written must be an integer multiple of your U-boot erasure and the minimum block size to be written. For example, the minimum block size of the u-boot-2009.11_tekkaman erase and write of tekkaman is kb, so the above four numbers (the starting address to erase/write, the number of bytes to erase/write) all must be an integer multiple of kb.(This blog reposted from the http://www.arm9home.net/read.php? Tid-5610.html Technology Forum, I feel the blogger, the article is very good, has a strong practical significance, recently reading ramdisk, found this article, to share with you.

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.