Porting the Linux kernel is to allow the Linux system to run on its own hardware platform and work properly. One of the most important is the driver's migration, only the driver can drive the hardware device, the upper layer of the application to run properly.
Currently, the Linux support kernel series mainly has the following, unzip the linux-3.5-20131028.tgz file, into the folder,
In addition to the Arch folder, it is the same file for most platforms:
In the kernel folder, contains some kernel files;
In the arch file is supported by a variety of platform files, which are some chip companies supported by some of the drivers;
In general, the Linux system tailoring is divided into the following steps:
The first step: Unzip the linux-3.5-20131028.tgz Linux source package, enter the linux-3.5 folder,
Step Two: Configure the. config file, here, directly using the Tiny4412_linux_defconfig
CP tiny4412_linux_defconfig. config
The third step: Select the Build module, this step, you can choose to need those modules compiled into the image file, because, considering the various power issues, some of the functions of the Linux module is not necessary to compile into the kernel
Make Menuconfig Enter Selection module compilation
Fourth step: Make generates the zimage image, which is similar to the. iso file for the WinDOS system. Previously, the file image was used when configuring the cross-compilation environment.
Fifth step: DNW to the Board, the Board of the Linux system run up, here, the Linux system is successfully running on the board:
Next, it is the authoring part of the kernel module:
Paste the code First:
1#include <linux/init.h>2#include <linux/module.h>3 4Module_license ("GPL"); 5Module_author ("Bunfly"); 6 7 intTest_init ()8 { 9Printk"hahahhahahahah\n"); Ten One return 0; A } - - voidtest_exit () the { -Printk"exit\n"); - } - +Module_init (test_init); -Module_exit (test_exit); +
Because it is in the kernel layer, there is no previous include<stdio.h> such as header files, here replaced by two linux/init. and Linux/module header file
7 int Test_init ()
8 {
9 PRINTK ("hahahhahahahah\n");
10
return 0;
12}
Write a function here, print a word,
In Module_init (Test_init), a callback function is used to invoke the Test.init function, which is the function that executes when loaded into the kernel;
So, Module_exit (); Is the function that executes when the kernel is unloaded;
4 module_license ("GPL");///Declaration of Open Source agreement followed by the development module
5 module_author ("Bunfly"); Declare the developer of the module
These two lines will appear warning if not stated:
1 2 ha: 3 make-c/home/bunfly/source_code/linux-3.5
m=/home/kernel/arm/ram/520 /1st Span style= "color: #800080;" >4 clean: 6 make-c/home/bunfly/source_code/linux-3.5 m=/home/kernel/arm/ram/< Span style= "color: #800080;" >520 /1st cle an 7 8 TEST.O 10
The above are makefile files
Make generates a. ko file, load the kernel module on the board:
Next program, print out the name of the task:
2#include <linux/thread_info.h>3#include <linux/module.h>4#include <linux/sched.h>5 6Module_license ("GPL"); 7Module_author ("Bunfly"); 8 9 intTest_init ()Ten { One inti =0; A structTask_struct *T; - structThread_info *info;//Thread Information - theUnsignedLongAddr = (unsignedLong) &i; -UnsignedLong Base= addr & ~0x1fff;//align in 8K bytes -info = (structThread_info *)Base;//find the address of the thread -t = info->task;//Get task Information +Printk"%s\n", T->comm);//print out the name of the task - + return 0; A } at - voidtest_exit () - { -Printk"exit\n"); - } - inModule_init (test_init); -Module_exit (test_exit); to
Makefile
1 2 ha: 3 Make-c/home/bunfly/source_code/linux-3.5 m=' pwd ' 4 5 Clean: 6 make-c/home/bunfly/source_code/linux-3.5 m=' pwd ' clean 7 8 obj-m + = test.o9 ~ ~
Make
Run on the ARM board:
Summary: This time through their own appropriate tailoring, generate a zimage image file, and, I wrote a simple kernel module, on the ARM board, insert kernel module, run.
Here, there are some fixed ways: for example, the kernel code of the makefile file, later need to compile kernel modules are fixed methods:
In the second file, by using an alignment to find the address, the method of obtaining the name parameter in the fixed structure task comm should be thoroughly understood and applied flexibly:
Add a little knowledge of indexing to search for files, which is useful for finding file keywords Ctags
First to the directory that needs to be searched: Build index file: Ctags-r. ..
Open any file freely: Vim Hong
Find keywords: ta xxxx
If you want to continue looking for a keyword, just move the cursor to the top and press: CTRL +]
Returns the result of the search you just found CTRL + O
Here is the workflow for Linux kernel development
Linux kernel Configuration and compilation