Transplantation of Linux-2.6.32.2 Kernel on mini2440 (1)-build autonomous development environment

Source: Internet
Author: User

Transplantation of Linux-2.6.32.2 Kernel on mini2440 (1) --- build independent development environment

Export the environment (the bold font in red is the modified content,Blue bold ChineseFor special attention)

1. host environment: fedora10 and 1 GB memory in vmare.

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

3. Development Board: mini2440, 4 m nor flash, 64 m NAND Flash.

4, Linux: linux-2.6.32.2

5. References:

[1] complete embedded Linux application development manual, edited by Wei Dongshan.

[2] http://blogold.chinaunix.net/u3/101649/showart_2276906.html

[3] mini2440 Linux porting Development Practice Guide

1.1To build an independent development environment

During the U-Boot porting, porting to the mini2440 on the u-boot-2009.08 (6) --- adding the boot kernel feature mentioned machine code (mach_type), in the pilot test, in order to facilitate testing, the Linux kernel is friendly and officially transplanted. Now we will start from here and start Linux kernel transplantation step by step.

[1] download and decompress the kernel source code

On the command line terminal, you can download the SDK by using the following methods:

[Root @ localhost ~] # Wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.2.tar.gz

Decompress the package:

[Root @ localhost ~] # Cd./Linux-test/
[Root @ localhost Linux-test] # tar-zxf ../linux-2.6.32.2.tar.gz
[Root @ localhost Linux-test] # ls
Linux-2.6.32.2Linux-2.6.39: yaffs2 yaffs2.tar.gz
[Root @ localhost Linux-test] # linux-2.6.32.2 CD
[Root @ localhost linux-2.6.32.2] #

[2] specifying cross-compilation Variables

The purpose of our porting is to allow the Linux-2.6.32.2 to run on the mini2440. First, we want to make the default target platform of the Linux-2.6.32.2 become the ARM platform, modify the makefile under the directory.

Open/makefile with gedit, locate row 183, and modify as follows:

# Alternatively cross_compile can be set in the environment.
# Default value for cross_compile is not to prefix executables
# Note: Some ubuntures assign cross_compile in their arch/*/makefile
Export kbuild_buildhost: =$ (subarch)
Arch? = Arm
Cross_compile? = Arm-Linux-

# Architecture as present in compile. h

Among them, arch specifies the target platform as arm, and cross_compile specifies the cross compiler. Here the default cross compiler is specified. If you want to use other, write the full path of the compiler here. Note thatDo not leave spaces behind arm and arm-LinuxOtherwise, an error occurs during compilation.

Next, we need to test whether the Linux compilation is successful. Run:
[Root @ localhost linux-2.6.32.2] # Make s3c2410_defconfig

Use the default Kernel configuration file. The s3c2410_defconfig is the default configuration file of smdk2440.
[Root @ localhost linux-2.6.32.2] # Make

Long Compilation Time ....... After compilation, you do not need to write it to the Development Board to verify its correctness.

[3] Build your own Target Platform

(1) machine code

The above compilation is the target platform configuration supported by the Linux kernel, which corresponds to smdk2440. Now we want to refer to smdk2440 to join our own development board platform. We use mini2440, So we name it mini2440. It should be noted that the Linux-2.6.32.2 itself has included support for mini2440, so there is a duplicate name. What should we do? Here we still use the mini2440 name, but in the subsequent porting steps, we can directly Delete the mini2440 code that comes with the original kernel to avoid confusion with our own porting.

First, it is critical that the kernel determines the target platform to be started through the machine code (mach_type) passed in by bootloader at startup, the friendly arm has applied for its own machine code 1999 for mini2440, which is located in the linux-2.6.32.2/ARCH/ARM/tools/mach_types file, as shown below:

Open/ARCH/ARM/tools/Mach-types and locate Row 3. The definition of the machine code in the file is as follows (in the black box ):
Exeda mach_exeda exeda 1994
Mx31sf005 mach_mx31sf005 mx31sf005 1995
F5d8231_4_v2 mach_f5d8231_4_v2 f5d8231_4_v2 1996
Q2440 mach_q2440 q2440 1997
Qq2440 mach_qq2440 qq2440 1998
Mini2440 mach_mini2440 mini2440 1999
Colibri300 mach_colibri300 colibri3002000
Jades machine _jades jades 2001
Spark mach_spark 2002
Benzina mach_benzina benzina 2003

Near line 1985 (mach-types.h) of the U-boot/include/ASM-arm/u-boot-2009.08 file, the machine code definition for mini2440 is shown below:

# Define mach_type_q2440 1997
# Define mach_type_qq2440 1998
# Define mach_type_mini2440 1999 // machine code of mini2440
# Define mach_type_colibri300 2000
# Define mach_type_jades 2001

This requires matching. If the kernel machine code does not match the bootloader input, the following errors will often occur:
Uncompressing Linux ...................................... ........................................ ........................................ ........... done, booting
The kernel.
When it runs, it stops.

Next, we noticed that there is a linux-2.6.32.2 file under the mach-s3c2440/ARCH/ARM/mach-mini2440.c directory, it is actually the main content added by foreign fans for mini2440 transplantation, but we don't need it, delete it directly. Copy the linux-2.6.32.2 under mach-s3c2440/ARCH/ARM/mach-smdk2440.c/directory. Name it a mach-mini2440.c, open the file, navigate to the end, find

Machine_start (S3C2440, "smdk2440"), change it
MacHine_start (mini2440, "mini2440 Development Board ")
Tip: After the Development Board is running, enter CAT/proc/cpuinfo on the command line terminal to view the information about the development board we added. Of course, this information can be customized to what we need.

(2) modify the clock source frequency

In the mach-mini2440.c file we just copied and modified above, locate to the vicinity of Line 163, put the 16934400 (representing the original smdk2440 target board crystal oscillator is 16.9344 MHz) changed to the 12000000 actually used on the mini2440 Development Board (representing the 12 MHz crystal oscillator on the mini2440 Development Board and the component number is x2), as shown below:

Static void _ init smdk2440_map_io (void)
{
S3c24xx_init_io (smdk2440_iodesc, array_size (smdk2440_iodesc ));
 2011-0xx_init_clocks (12000000 );
S3c24xx_init_uarts (smdk2440_uartcfgs, array_size (smdk2440_uartcfgs ));
}

(3) from smdk2440 to mini2440

Because we want to make our own mini2440 platform system, so the mach-mini2440.c all smdk2440 words changed to mini2440, you can use the batch processing command to modify, in VIM command mode input:

% S/smdk2440/mini2440/g
In the above sentence, replace all the strings that match "smdk2440" with "mini2440", and the preceding "% s" indicates string matching, the final "G" represents global, which means global. However, here we use another method to replace it with search in gedit, which is more convenient. The operation is as follows:

Gedit-> Search-> replace. In the displayed dialog box, enter "smdk2440" in the search box, enter "mini2440" in the replacement box, and click "replace all.

In addition, there is another need to be changed. In the mini2440_machine_init (void) function, comment out the call of the smdk_machine_init () function, because we will write our own initialization function later, you do not need to call the original smdk2440. Locate row 173 and modify it as follows:

Static void _ init mini2440_machine_init (void)
{
S3c24xx_fb_set_platdata (& mini2440_fb_info );
Initi_i2c0_set_platdata (null );

Platform_add_devices (mini2440_devices, array_size (mini2440_devices ));
 // Smdk_machine_init ();
}

(4) Compile and Test

Run the following command in the Linux source code root directory:

[Root @ localhost linux-2.6.32.2] # Make mini2440_defconfig
#
# Configuration written to. config
#
[Root @ localhost linux-2.6.32.2] # Make mini2440_defconfig

Use the built-in Linux mini2440 configuration.
[Root @ localhost linux-2.6.32.2] # Make zimage

Compile the kernel for a long time. zimage will be generated at last. Download the generated Kernel File zimage (in the arch/ARM/boot directory) to the memory of the board and run it. You can see that the kernel can be started properly, as shown below, however, at this time, most of the hardware drivers have not been added, and there is no file system, so you cannot log on.

......

[4] How the mini2440 option in the Kernel configuration menu is associated with the actual code

Before we start porting other drivers, let's take a look at some of the "mysterious" knowledge, that is, how the mini2440 option appears in the Kernel configuration menu when running make menuconfig. Make sure that make mini2440_defconfig has been executed to load the default configuration. Because this operation is executed on the X86 platform, the default system is X86 platform, and the following modifications must be made in the top-layer makefile:

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

Now go into the linux-2.6.32.2 root directory in the terminal and execute:

[Root @ localhost linux-2.6.32.2] #Make menuconfig

The Kernel configuration Root menu is displayed.

Press the up and down arrow keys to move to system type and press enter to enter the sub-menu,

Find the S3C2440 machines and press enter to enter the sub-menu,

Here we can see the Linux kernel's support options for the mini2440 Development Board. Where do they come from?
Open the Linux-2.6.32.2/ARCH/ARM/mach-s3c2440/kconfig file and locate near line 99, you can find the following information (simhei part ):

Config mach_at2440evb
Bool "avantech at2440evb Development Board"
Select cpu_s3c2440
Select initi_dev_usb_host
Select initi_dev_nand
Help
Say y here if you are using the at2440evb Development Board

Config mach_mini2440
Bool "mini2440 Development Board"
Select cpu_s3c2440
Select eeprom_at24
Select leds_trigger_backlight
Select snd_s3c24xx_soc_s3c24xx_uda134x
Select initi_dev_nand
Select initi_dev_usb_host
Help
Say y here to select support for the mini2440. is a 10 cm x 10 cm Board
Available via various sources. It can come with a 3.5 "or 7" Touch LCD.

Endmenu

Now you understand, "mini2440 Development Board" is defined in this kconfig file. Of course, you can change it to other display information based on your preferences. The information displayed here only appears in the Kernel configuration menu. To make the selected configuration take effect, you also need to add the corresponding code file in makefile according to this configuration, see makefile in this directory and locate 25 rows, as shown below:

# Machine support

OBJ-$ (config_mach_anubis) + = mach-anubis.o
OBJ-$ (config_mach_osiris) + = mach-osiris.o
OBJ-$ (config_mach_rx3715) + = mach-rx3715.o
OBJ-$ (config_arch_s3c2440) + = mach-smdk2440.o
OBJ-$ (config_mach_nexcoder_2440) + = mach-nexcoder.o
OBJ-$ (config_mach_at2440evb) + = mach-at2440evb.o
OBJ-$ (config_mach_mini2440) + = mach-mini2440.o

In this way, the configuration file is associated with the actual code file through the configuration definition. The configuration definition here is "config_mach_mini2440", and there are many similar configuration definitions in the kernel, some configuration definitions still have dependencies, so we will not detail them here. As we get familiar with the kernel code structure, you will gradually learn to analyze and find the various configurations and definitions you need.

[5] porting the NAND driver and changing the partition information

(1) modify the NAND Flash Partition Table

The default partition of the system is not necessarily what we need, so we need to modify it by ourselves. In addition, the structure information of NAND Flash needs to be added to make it suitable for the built-in NAND Flash Driver Interface, for more information about the registration of NAND Flash devices, see smdk2440.
Open/ARCH/ARM/plat-s3c24xx/common-smdk.c, locate near 110 lines, you can see such a struct:

Static struct mtd_partition smdk_default_nand_part [] = {
[0] = {
. Name = "Boot Agent ",
. Size = sz_16k,
. Offset = 0,
},
[1] = {
. Name = "S3C2410 flash partition 1 ",
. Offset = 0,
. Size = sz_2m,
},
[2] = {
. Name = "S3C2410 flash partition 2 ",
. Offset = sz_4m,
. Size = sz_4m,
},
[3] = {
. Name = "S3C2410 flash partition 3 ",
. Offset = sz_8m,
. Size = sz_2m,
},
[4] = {
. Name = "S3C2410 flash partition 4 ",
. Offset = sz_1m * 10,
. Size = sz_4m,
},
[5] = {
. Name = "S3C2410 flash partition 5 ",
. Offset = sz_1m * 14,
. Size = sz_1m * 10,
},
[6] = {
. Name = "S3C2410 flash partition 6 ",
. Offset = sz_1m * 24,
. Size = sz_1m * 24,
},
[7] = {
. Name = "S3C2410 flash partition 7 ",
. Offset = sz_1m * 48,
. Size = sz_16m,
}
};

This is actually the NAND Flash partition table, in the Linux-2.6.32.2, the NAND driver is registered as a platform device, which can also see the following information in the 166 line of this file:

Static struct s3c2410_platform_nand smdk_nand_info = {
. Tacls = 20,
. Twrph0 = 60,
. Twrph1 = 20,
. Nr_sets = array_size (smdk_nand_sets ),
. Sets = smdk_nand_sets,
};

Refer to the above structure information, we also add implementation in our own mach-mini2440.c according to this, at the same time need to refer to the friendly arm of the original kernel in the NAND Partition Table, operations such:

Open/ARCH/ARM/mach-s3c2440/mach-mini2440.c, locate row 151, and add the partition table definition structure after the change below to it:

. Lpcsel = (0xce6 )&~ 7) | 1 <4,
};

/* NAND parititon from 2.4.18-swl5 */

Static struct mtd_partition mini2440_default_nand_part [] = {
[0] = {
. Name = "Boot ",
//; Here is the partition where the bootloader is located. You can place U-boot, supervivi, and other content, corresponding to/dev/mtdblock0.
. Offset = 0,
. Size = 0x00040000, // 256 K
},
[1] = {
. Name = "Param ",
// This is the parameter area of supervivi, which is also part of bootloader. If U-boot is large, you can overwrite this area without affecting system startup, corresponding to/dev/mtdblock1
. Offset = 0x00040000,
. Size = 0x00020000,
},
[2] = {
. Name = "kernel ",
// The partition where the kernel is located. The size is 5 MB, which is enough to put down most of the customized giant kernels. For example, the kernel uses a larger Linux logo image, which corresponds to/dev/mtdblock2.
. Offset = 0x00060000,
. Size = 0x00500000,
},
[3] = {
. Name = "rootfs ",
// File system partition. The friendly arm is mainly used to store the content of the yaffs2 file system, corresponding to/dev/mtdblock3
. Offset = 0x00560000,
. Size = 1024*1024*1024,
},
[4] = {
. Name = "NAND ",
//; This area represents the entire NAND flash disk, which is reserved for use. For example, you can access and read it through an application later.You can use/dev/mtdblock4 to back up the entire NAND flash disk.
. Offset = 0x00000000,
. Size = 1024*1024*1024,
}
};

// Here is the NAND Flash settings table of the development board, because there is only one sheet on the board, so there is only one table
Static struct s3c2410_nand_set mini2440_nand_sets [] = {
[0] = {
. Name = "NAND ",
. Nr_chips = 1,
. Nr_partitions = array_size (mini2440_default_nand_part ),
. Partitions = mini2440_default_nand_part,
},
};

/* Choose a set of timings which shocould suit most 512 Mbit
* Chips and beyond.
*/
//; Here are some features of NAND Flash, which must be filled in against datasheet. In most cases, follow the following parameters:
Static struct s3c2410_platform_nand mini2440_nand_info = {
. Tacls = 20,
. Twrph0 = 60,
. Twrph1 = 20,
. Nr_sets = array_size (mini2440_nand_sets ),
. Sets = mini2440_nand_sets,
. Ignore_unset_ecc = 1,
};
In addition, you also need to register the NAND flash device to the system.

Static struct platform_device * mini2440_devices [] _ initdata = {
& Initi_device_usb,
& Amp; cloud_device_ LCD,
& Amp; cloud_device_wdt,
& Amp; cloud_device_i2c0,
& Amp; cloud_device_iis,
 & Amp; cloud_device_nand,// Add the NAND flash device to the device list STRUCTURE OF THE DEVELOPMENT BOARD
};
(3) Add the compilation header file

Locate 50 lines in the above file and add the header file:

# Include <Linux/MTD. h>
# Include <Linux/MTD/NAND. h>
# Include <Linux/MTD/nand_ecc.h>
# Include <Linux/MTD/Partitions. h>
# Include <plat/NAND. h>

(4) input the mini2440_nand_info struct initialization parameter.

Go to the vicinity of row 223 and modify as follows:

Static void _ init mini2440_machine_init (void)
{
Initi_i2c0_set_platdata (null );
 Initi_device_nand.dev.platform_data = & mini2440_nand_info;
Platform_add_devices (mini2440_devices, array_size (mini2440_devices ));
// Smdk_machine_init ();
}

Save the settings.

1.2,Compilation Test

So far, the transplantation of the NAND Flash Driver has been completed. After the modification is complete, it is best to execute the make menuconfig command every time.

[Root @ localhost linux-2.6.32.2] # Make clean

Because the kernel may have increased or decreased the module to be compiled, you must clear the compiled target module before compilation. Otherwise, compilation errors may occur and then compile the module:

[Root @ localhost linux-2.6.32.2] # Make zimage

After compilation, generate the zimage file, power on the Development Board, and then burn zimage to the Development Board. The following information is displayed:

S3c24xx NAND driver, (c) 2004 simtec Electronics
S3c24xx-nand s3c2440-nand: tacls = 3, 29ns twrph0 = 7 69ns, twrph1 = 3 29ns
S3c24xx-nand s3c2440-nand: NAND soft ECC
Nand device: Manufacturer ID: 0xec, chip ID: 0xf1 (Samsung NAND 128mib, 3 V 8-bit)
Scanning Device for Bad blocks
Creating 5 MTD partitions on "NAND 128mib, 3 V 8-bit ":
0x0000000000000000-0x000000040000: "Boot"
Uncorrectable error:
0x000000040000-0x000000060000: "Param"
Ftl_cs: FTL header not found.
0x000000060000-0x000000560000: "kernel"
Ftl_cs: FTL header not found.
0x000000560000-0x000040560000: "root"
MTD: partition "root" extends beyond the end of device "NAND 128mib, 3 V 8-bit"
-- Size truncated to 0x7aa0000
Ftl_cs: FTL header not found.
0x0000000000000000-0x000040000000: "NAND"
MTD: partition "NAND" extends beyond the end of device "NAND 128mib, 3 V 8-bit"
-- Size truncated to 0x8000000
Uncorrectable error:
Dm9000 Ethernet driver, v1.31
Ohci_hcd: USB 1.1 'open' host controller (OHCI) Driver
S3c2410-ohci s3c2410-ohci: s3c24xx OHCI
S3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
S3c2410-ohci s3c2410-ohci: IRQ 42, Io mem 0x49000000
USB usb1: configuration #1 chosen from 1 choice
Hub 1-. 0: USB hub found
Hub 1-0: 1. 0: 2 ports Detected

We can see the blue information at startup. They are the information of the newly added NAND Flash partition and some information about the nand flash of the development board. Here we can see the 128 m nand Flash.

......

Rpcbind: Server 10.1.0.128 not responding, timed out
Root-NFS: Unable to get nfsd port number from server, using default
Looking up port of RPC 100005/1 on 10.1.0.128
Rpcbind: Server 10.1.0.128 not responding, timed out
Root-NFS: Unable to get mountd port number from server, using default
Root-NFS: server returned error-5 while mounting/nfsboot
VFS: Unable to mount root FS via NFS, trying floppy.
VFS: cannot open root device "NFS" or unknown-block (2, 0)
Please append a correct "root =" Boot option; here are the available partitions:
1f00 256 mtdblock0 (driver ?)
1f01 128 mtdblock1 (driver ?)
1f02 5120 mtdblock2 (driver ?)
1f03 125568 mtdblock3 (driver ?)
1f04 131072 mtdblock4 (driver ?)
Kernel panic-not syncing: VFS: Unable to mount root FS on unknown-block (2, 0)
[<C002e9c0>] (unwind_backtrace + 0x0/0xd8) from [<c02d4798>] (panic + 0x40/0x118)
[<C02d4798>] (panic + 0x40/0x118) from [<c0008e68>] (mount_block_root + 0x1c8/0x208)

[<C0008e68>] (mount_block_root + 0x1c8/0x208) from [<c00090fc>] (prepare_namespace
+ 0x160/0 x1b8)
[<C00090fc>] (prepare_namespace + 0x160/0 x1b8) from [<c0008434>] (kernel_init + 0xd8
/0x10c)
[<C0008434>] (kernel_init + 0xd8/0x10c) from [<c002a868>] (kernel_thread_exit + 0x0/
0x8)

An error occurred while hanging in the partition.
Solution:
In the partition, you can remove the following code:
[1] = {
. Name = "Param ",
// This is the parameter area of supervivi, which is also part of bootloader. If U-boot is large, you can overwrite this area without affecting system startup, corresponding to/dev/mtdblock1
. Offset = 0x00040000,
. Size = 0x00020000,
},
Depending on the situation, the reason for the above may also be that the yaffs file system is not added to the linux-2.6.32.2.
From: http://www.cnblogs.com/hnrainll/archive/2011/06/09/2076138.html

Next, add the yaffs File System to the linux-2.6.32.2.

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.