Arm-Linux kernel porting (2) -- Linux kernel 2.6.22
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
Platform: mini2440 cross tool chain: arm-linux-gcc-4.3.2
I. Basic kernel porting knowledge
Porting a kernel is also called building a BSP (boardsupprot packet ). BSP provides two functions: one is to provide underlying support for Kernel running, and the other is to shield board-related details.
BSP construction is divided into three layers
1. Level of Architecture
Provide Linux Kernel support for some systems, such as ARM and X86 chips. This type of work is generally completed in the following directories of arc/xxx/Except for palt-xxx and mach-xxx.
2. SOC levels
We provide Linux Kernel support for SOC microprocessors provided by some companies, such as Samsung's S3C2440. This type of work is generally completed in the arch/xxx/plat-xxxxarch/xxx/mach-xxxx directory. We can see that there are both plat-s3c24xx and mach-s3c2440 directories under the arch/arm/directory, this is because the plat-s3c24xx directory stores all the same codes of the series, the mach-s3c2440 only stores the Code related to S3C2440.
2. Board level
This is what we usually do for cainiao. The above two layers are generally completed by the chip company Daniel, but the board levels of different circuit boards need to be completed by our cainiao. This type of work is mainly completed in the mach-xxxx/directory below the Board file, such as mach-s3c2440/smdk-s3c2440.c this S3C2440 standard board file. Many documents and many books are directly modified in this file. This is wrong. Different board files should be created for different circuit boards. For example, my file is mini2440, you should create a smdk-mini2440.c file or a mach-mini2440.c file under the mach-s3c2440. It is very nonstandard to modify it directly. This is not to transplant the kernel, but to destroy the kernel! (This is what song Baohua said ).
Next, start porting.
Ii. BSP Construction
1. Support for creating board files
This step I will rebuild a board file mach-mini2440.c instead of modifying it directly in the smdk-s3c2440.c, which may be a bit of a hassle, but in order to maintain a respectful attitude and normative approach to the kernel, I think this should be done.
If we recreate an empty board file, it will lead to a lot of work, and fortunately the smdk-s3c2440.c file has helped us do a lot of work, we copy it directly and name it a mach-mini2440.c.
Cp arch/ARM/mach-s3c2440/smdks3c2440. c ARCH/ARM/mach-s3c2440/mach-mini2440.c
Modify the ARCH/ARM/mach-s3c2440/mach-mini2440.c file to replace the name in the machine_start macro bracket with ID with mini2440, the name is random, we take "mini2440", this ID will eventually be extended to mach_type_mini2440, find the corresponding ID in arch/ARM/tools/mach_types, and add the ID of our machine in mach_types.
Machine_start (mini2440, "mini2440 ")
/* Maintainer: Ben dooks <ben@fluff.org> */
. Phys_io = s3c2410_pa_uart,
. Io_pg_offst = (u32) s3c24xx_va_uart)> 18) & 0 xfffc,
. Boot_params = s3c2410_sdram_pa + 0x100,
. Init_irq = s3c24xx_init_irq,
. Map_io = smdk2440_map_io,
. Init_machine = smdk2440_machine_init,
. Timer = & s3c24xx_timer,
Machine_end
Add the machine ID in mach_types, and then add the last line.
Mini2440 mach_mini2440 mini2440 1999
The first one indicates the machine name, which is also random. The second one is the macro name defined in the kconfig configuration item. We will define the name mach_mini2440 in the following step, the third parameter indicates the name of the first parameter of mach_start, and the fourth parameter is the ID number. ID number. We can set it to 1999.
Modify the kconfig and makefile under the arch/ARM/mach-s3c2440/directory to build Kernel support for board files so that they can be configured and compiled into the kernel.
First, modify kconfig and add the following content before endmenu:
87 config mach_mini2440 // macro definition of the Development Board name
88 bool "mini2440" // NAME OF THE DEVELOPMENT BOARD
89 select cpu_s3c2440 // type of the processor used by the Development Board
90 help
91 Say Y here if you are using the mini2440. // help information
Modify the Makefile.
Obj-$ (CONFIG_MACH_MINI2440) + = mach-mini2440.o
Note that this line should be added after obj-$ (CONFIG_ARCH_S3C2440) + = smdk-s3c2440.o, otherwise the compilation error will occur.
In this way, you can use makemenuconfig to configure whether the mini2440 board file is compiled into the kernel.
Go to the linux-2.6.22 directory and run makemenuconfig.
After loading the default configuration file, you can start to configure the new menu. Enter the System Types menu item, open the S3C24XX Implementations menu, and a list of target development boards is displayed:
[] Simtec ElectronicsBAST (EB2410ITX)
[] IPAQ H1940
[] Acer N30
[] Smdk2410/a9m2410
[] Smdk2440
[] Aesop2440
[] Thorcom vr1000
[] HP ipaq rx3715
[] Nexvision otom Board
[] Nexvision nexcoder2440 light board
[] Mini2440
Select the mini2440 Option
Then execute makezimage. If it can be compiled properly, you can compile the mini2440 board file into the kernel. If not, check the preceding steps.
2. Modify the machine code
Compile the zimage generated under ARCH/ARM/boot to the kernel partition of the NAND, and then start it.
Copylinux kernel from 0x00060000 to 0x30008000, size = 0x00500000... Done
Zimage magic = 0x016f2818
Setup Linux parameters at 0x30000100
Linux command line is: "console = ttySAC0 root =/dev/nfsnfsroot = 192.168.1.101:/home/work/shiyan/rootfsip = 192.168.1.102: 192.168.1.101: 192.168.1.1: 255.255.255.0: mini2440: eth0: off"
Machine Type = 362
NOW, Booting Linux ......
UncompressingLinux ....................................... ........................................ .................. done, booting the kernel.
Error: unrecognized/unsupported machine ID (r1 = 0x0000016a ).
The kernel prompts an unrecognized machine ID, so modify the bootloader parameter to set the machine ID to 1999. I use supervivi to run the set parammach_type 1999 command.
3. Modify the clock source frequency
Start the kernel, there is a series of garbled characters, this is because the clock source settings are not correct, my Development Board is using 12 m crystal oscillator, so in arch/arm/mach-s3c2440.c of s3c24xx_init_clocks (16934400 ); change 16924400 to 12000000. That is, change to s3c24xx_init_clocks (12000000 );
4. Add NAND partition information
Start again and find that it still cannot be started because the NAND partition information entered in the kernel is incorrect. So modify the NAND partition information, a lot of people's approach is to directly modify the ARCH/ARM/plat-s3c24xx/Common-smdk.c file in the smdk_default_nand_part data structure, this is not to advocate the practice, because or that sentence, destroys the kernel. We should create the NAND information for our own board file in the arch/ARM/mach-s3c2440/mach-mini2440.c file. We have staticstruct platform_device in the mach-mini2440.c
* Before smdk2440_devices [], add
Static struct mtd_partition smdk_default_nand_part [] = {
/* Fill in the mini2440 partition information I use */
[0] = {
. Name = "patition1 supervivi ",
. Size = 0x00040000,
. Offset = 0,
},
[1] = {
. Name = "patition2 Param ",
. Offset = 0x00040000,
. Size = 0x00020000,
},
[2] = {
. Name = "patition3 kernel ",
. Offset = 0x00060000,
. Size = 0x00500000,
},
[3] = {
. Name = "patition4 root ",
. Offset = 0x00560000,
. Size = 64*1024*1024,
},
[4] = {
. Name = "patition5 NAND ",
. Offset = 0,
. Size = 64*1024*1024,
},
};
Static struct s3c2410_nand_set smdk_nand_sets [] = {
[0] = {
. Name = "NAND ",
. Nr_chips = 1,
. Nr_partitions = array_size (smdk_default_nand_part ),
. Partitions = smdk_default_nand_part,
},
};
Then modify the smdk2440_machine_init function of the mach-mini2440.c and pass our NAND to the NAND device.
Static void _ init smdk2440_machine_init (void)
{
S3c24xx_fb_set_platdata (& smdk2440_ LCD _cfg );
/* Pass our nand information to the nand device */
Initi_device_nand.dev.platform_data = & smdk_nand_info; // set nand infoto nand
Platform_add_devices (smdk2440_devices, ARRAY_SIZE (smdk2440_devices ));
// Smdk_machine_init ();
// Smdk_machine_init () function shielding, because he will pass the partition information in the arch/arm/plat-s3c24xx/Common-smdk.c to the nand, so that our own nand information is overwritten
S3c2410_pm_init (); // Add this function because it is called in smdk_machine_init.
}
Modify the smdk2440_devices of the mach-mini2440.c.
Static struct platform_device * smdk2440_devices [] _ initdata = {
& Initi_device_usb,
& Amp; cloud_device_ LCD,
& Initi_device_nand, // Add a nand device to the kernel
& Amp; cloud_device_wdt,
& Amp; initi_device_i2c,
& Amp; cloud_device_iis,
};
6. Added support for the yaffs file system.
After completing the preceding steps, you still cannot mount the root file system, because the kernel does not support the yaffs file system.
Download the cvs-root-yaffs.tar.gz patch package file, decompress, run the script file patch-ker.sh in the yaffs2 folder to patch the kernel, the usage is as follows:
Usage:./patch-ker.sh c/l kernelpath
If c/l is c, then copy, if l then link
If it is l, the source code of yaffs2 is linked to the kernel. If it is c, copy
We run./patch-ker.sh c work/kernel_make/linux2.6.22
Install the yaffs2 patch on the kernel, and then use makemenuconfig to configure the kernel to support the yaffs2 file system.
File systems --->
Miscellaneous filesystems --->
<*> Yaffs2 File System Support
7. Configure the kernel to support the Eabi Interface
After the above steps are completed, the kernel will output
VFS: mounted root (yaffs filesystem) on device 31: 2.
Freeing init memory: 132 k
Then it gets stuck. This print shows that the kernel has actually mounted to the root file system. The reason is that the INIT process on the root file system cannot be started. It is because the interfaces of the kernel and the root file system applications are inconsistent. Therefore, use make menuconfig in the kernel to configure Eabi support.
Kernel features --->
Memory split... --->
[] Preemptible kernel...
[*] Use the arm Eabi to compile Thekernel
[*] Allow old Abi binaries to run ......
Memory Model (flatmemory) --->
[] Add LRU list to tarcknon-evictable pages