Transplantation of Linux-2.6.32.2 Kernel on mini2440 (4)-root file system creation (3)

Source: Internet
Author: User
Tags gz file

Port Environment (Bold font in redIs the modified content,Blue bold ChineseFor special attention)

1. host environment: centos 5.5 and 1 GB memory in vmare.

2. Integrated Development Environment: Elipse ide

3. compiling environment: Arm-Linux-GCC v4.4.3 and arm-None-Linux-gnueabi-GCC v4.5.1.

4. Development Board: mini2440, 2 m nor flash, 128 m nand Flash.

5, U-boot version: u-boot-2009.08

6, Linux: linux-2.6.32.2

7. References:

Complete embedded Linux application development manual, edited by Wei Dongshan.

Mini2440 Linux porting Development Practice Guide

Create a linux root file system

Kernel panic when the system starts mounting the root file system

Next, return to the issue of mounting the NAND Flash partition.

[6] copy the MTD-uitls tool created in the previous article to the created root file system in the/root/Linux-test/mtdtools/MTD-utils/usrdir/sbin directory. usr/sbin directory

[Root @ localhost mtdtools] # cp-a mtd-utils/usrdir/usr/sbin/*/nfsboot/rootfs/usr/sbin/
[Root @ localhost mtdtools] #

[7] Test MTD tool correctness. For MTD tool usage, refer to the use of MTD-utils tool.

Run the command on the terminal after min2440 is started.

[Root @ mini2440/] # flash_info
Illegal instruction
[Root @ mini2440/] #

Online Search finds that illegal instruction is an invalid command. The reason for the illegal instruction is that the program receives the sigill signal, which indicates that the CPU sends an exception after detecting the illegal command, then, the ISR responsible for handling the exception sends the issue to the process containing the illegal command. When the program receives this signal, it generally reports the illegal instruction error message.

The cause of an executable program containing invalid commands is generally that the CPU architecture is incorrect. The march specified during compilation is different from the march of the actually executed machine. In this case, because the tool chain is the same and the connection script is the same, the executable program can be executed without the exec format error. However, it contains some incompatible commands. Another possibility is that the execution permission of the program is insufficient. For example, a program running in the object state can only execute non-privileged commands. Once the CPU encounters a privileged command, an illegal instruction error will occur.

The processor status changes dynamically during system operation. Switching from the object state to the tube state can only be achieved through interruption. The conversion from the canonicalized state to the object state can be achieved by modifying the program State word psw. It is likely that the CPU architecture or kernel you compile and run is different.

In addition, Linux is a sysv UNIX System and FreeBSD is a bsd unix system.

The compiler supports the new binary API standard Eabi for embedded applications. By default, the kernel does not support Eabi. the compiler uses a non-Eabi compiler. In this case

Kernel features --->

[*] Use the arm Eabi to compile the kernel (config_aeabi = y)
[*] Allow old Abi binaries to run with this kernel (Experimenta) (config_oabi_compat = y)

Method 1

Configure the Eabi and old Eabi support options in the kernel, and copy the Lib library file under the compiler to the Lib library of the target board (ARM-Linux-GCC v4.4.3)

[Root @ localhost ~] # Cp-A/usr/local/ARM/4.4.3/lib // nfsboot/rootfs/lib
[Root @ localhost ~] #

The tool generated by re-compilation in arm-Linux is located in mtdtools/MTD-utils/mtd_install/usr/sbin and copied to the root directory usr/sbin.

[Root @ localhost ~] # Cp-A./Linux-test/mtd-utils-1.4.4/mtd_install/usr/sbin // nfsboot/rootfs/usr/sbin

Start min2440 again and run it on the terminal

[Root @ mini2440/] # flash_info
Illegal instruction
[Root @ mini2440/] #

After careful check, the above operation has a problem, that is, the result of CP is that another lib directory is created under Lib, and another sbin directory is created under sbin, now, move the files in the Lib sub-directory under lib and sbin sub-directories under sbin to the directory at the upper level, replace the files that already exist, and perform the correct operations.

[Root @ localhost ~] # Cp-Av/usr/local/ARM/4.4.3/lib/*/nfsboot/rootfs/lib

[Root @ localhost ~] # Cp-Av./Linux-test/mtd-utils-1.4.4/mtd_install/usr/sbin/*/nfsboot/rootfs/usr/sbin

[Root @ mini2440/] # flash_info
Usage: flash_info Device

OK. Finally, the MTD operation tool that can be executed on the target board is obtained!

Method 2

Refer to this article on how to solve illegal instruction, put the/usr/local/ARM/Compiler/ARM-None-Linux-gnueabi/libc/armv4t/lib directory (that is, the library directory of your compiler) copy all files under to the lib directory of the root directory, and then modify the kernel makefile to make cross = arm-None-Linux-gnueabi-
(V4.5.1 and arm-Linux-are official versions 4.4.3 ).

(1) modify the cross_compile of makefile under the linux-2.6.32.2 root directory

[Root @ localhost linux-2.6.32.2] # Vim makefile
Open the editor and run it in command mode.

/Cross

Then go

Export kbuild_buildhost: =$ (subarch)
Arch? = Arm
Cross_compile? =Arm-None-Linux-gnueabi-

# Architecture as present in compile. h
Save and exit. Execute

[Root @ localhost linux-2.6.32.2] # Make clean
[Root @ localhost linux-2.6.32.2] # Make uimage
Regenerate uimage Image

(2) copy the compiled kernel compiler to the lib directory of the target root file system using the Lib library.

[Root @ localhost linux-2.6.32.2] # cp-A/usr/local/ARM/Compiler/ARM-None-Linux-gnueabi/libc/armv4t/lib/*/nfsboot/rootfs/lib

Here we put method 2 as a backup processing method here.

[8] First, understand the differences between/dev/MTD and/dev/mtdblock.

(1)/dev/mtdn is the character device corresponding to the MTD partition implemented by the system in the MTD architecture of Linux. It contains some IOCTL and supports many commands, such as memgetinfo, memerase. Tools such as flash_eraseall in MTD-util are implemented based on these IOCTL to perform flash operations, such as flash_erase in MTD.

If (IOCTL (FD, memgetinfo, & meminfo )! = 0)
{
Perror ("memgetinfo ");
Close (FD );
Exit (1 );
}

Here, memgetinfo is in \ drivers \ MTD \ NAND \ mtdchar. C of Linux MTD:

Case memgetinfo:
Info. type = MTD-> type;
Info. Flags = MTD-> flags;
Info. size = MTD-> size;
Info. erasesize = MTD-> erasesize;
Info. writesize = MTD-> writesize;
Info. oobsize = MTD-> oobsize;
/* The below fields are obsolete */
Info. ecctype =-1;
Info. eccsize = 0;
If (copy_to_user (argp, & info, sizeof (struct mtd_info_user )))
Return-efault;
Break;

The/dev/mtdblockn is a block device generated when the driver uses add_mtd_partitions () to add MTD device partitions. According to the above content, I understand why nandwrite, flash_eraseall, flash_erase, and other tools cannot be used to operate on/dev/mtdblockn, because/dev/mtdblock does not contain the corresponding IOCTL, this operation is not supported.

(2) The master device number of the mtd char device is 90, while that of the mtdblock device is 31;

This device number is defined in \ include \ Linux \ MTD. h.

(3) The size of MTD Block devices can be obtained by viewing the partition information:

[Root @ mini2440/] # Cat proc/Partitions
Major minor # Blocks name

31 0 256 mtdblock0
31 1 128 mtdblock1
31 2 5120 mtdblock2
31 3 125568 mtdblock3
31 4 131072 mtdblock4
[Root @ mini2440/] #

The size of the block device shown above is the number of blocks, and each block is 1 kb. Each character device corresponds to each of the above ELE. Me devices, that is,/dev/mtd0 corresponds to/dev/mtdblock0, and so on. In other words, some attributes of mtdblockn are the attributes of mtdn, such as the size.

(4) For each MTD character device, for example, using nandwrite to write data to/dev/mtd0, the actual operation is/dev/mtdblock0. In these operations, offset refers to the offset in the MTD partition. For example, to write data to the position where the offset of/dev/mtd1 is 0, the physical offset of the actual operation is offset =/dev/mtd0 size = 128kb.

[9] Write the root file system to the mtdblock3 Partition

(1) view partition information

[Root @ mini2440/] # mtd_debug info/dev/mtd3
MTD. type = mtd_nandflash
MTD. Flags = mtd_cap_nandflash
MTD. size = 128581632 (122 m)
MTD. erasesize = 131072 (128 K)
MTD. writesize = 2048 (2 k)
MTD. oobsize = 64
Regions = 0

(2) erase the mtd3 partition of NAND
[Root @ mini2440/] # flash_erase DEV/mtd3 0x560000 0x1e0
Erasing 128 kibyte @ 4140000 -- 100% complete
[Root @ mini2440/] # Mount-T yaffs DEV/mtd3 MNT/yaffs
Mount: mounting DEV/mtd3 on MNT/yaffs failed: block device required
[Root @ mini2440/] # Mount-T yaffs DEV/mtdblock3 MNT/yaffs
Yaffs: Dev is 32505859 name is "mtdblock3" RW

(3) Mount/dev/mtdblock3 to/mnt/yaffs

[Root @ mini2440/mnt] # ls yaffs
[Root @ mini2440/mnt] # Mount-T yaffs/dev/mtdblock3 yaffs
Yaffs: Dev is 32505859 name is "mtdblock3" RW
Yaffs: passed flags ""

(4gz decompress the packaged rootfs.tar.gz File System to the mounted yaffs directory. Note that you need to remove the pair path. After decompression, the content of the root file system is displayed.

[Root @ mini2440/mnt] # ls yaffs
Bin etc lib MNT sbin USR
Boot home linuxrc proc sys VaR
Dev init lost + found Root TMP WWW

[10] modify the U-boot startup parameters and boot from mtdblock3

[U-boot @ mini2440] #Setenv bootargs'Noinitrd console = ttysac0, 115200 init =/linuxr
C mem = 64 m Root =/dev/mtdblock3 RW rootfstype = yaffs IP = 10.1.0.129: 10.1.0.128: 10.1.
0.1: 255.255.255.0: eth0: Off'
[U-boot @ mini2440] # saveenv
Saving environment to Nand...
Erasing Nand...
Erasing at 0x4000000000002 -- 0% complete.
Writing to Nand... Done
[U-boot @ mini2440] #

[11] After restarting the Development Board, check the startup information.

......

IP-config: complete:
Device = eth0, ADDR = 10.1.0.129, mask = 255.255.255.0, GW = 10.1.0.1,
Host = 10.1.0.129, domain =, Nis-domain = (none ),
Bootserver = 10.1.0.128, rootserver = 10.1.0.128,Rootpath =
Yaffs: Dev is 32505859 name is "mtdblock3" rwyaffs: passed flags ""
VFS: mounted root (yaffs filesystem) on device 31: 3.
Freeing init memory: 112 K
---------- Munt all ----------------
**************************************** *******
* ********** Booting to mini2440 *****************
Kernel version: linux-2.6.32.2
The fans: singleboy
Date: 2011.5.30
**************************************** *******

Please press enter to activate this console.

The root system is successfully guided.

This also indicates that the previous tool used to create the yaffs image has problems.

[12] Summary

In order to guide the root file system from NAND Flash, the whole process is twists and turns, but through study and research, there are other ways to solve this problem.

(1) mount the NFS file system to ensure that the entire system can be correctly guided from NFS.

(2) ensure that you can see the relevant yaffs information in the startup information; otherwise, it indicates that the yaffs file system is faulty.

(3) try to mount the mtdblockx partition from the system started by NFS. Because the system does not contain the MTD tool, pay attention to the preparation of the MTD tool.

(4) After mtdblockx is mounted successfully, the NFS server can directly package the root file system to the root or home directory of the NFS root file system, then extract the root file system to the mtdblock partition on the control terminal of the Development Board. Be sure to remove the absolute path.

(5) modify the U-boot parameters to boot from mtdblockx.

Legacy problems: migration of ubi File System on U-boot and Linux systems

Next, we will port the kernel RTC driver.

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.