/**************************************************** ****************************************/
How to view the kernel source code:
1. Delete linux-3.5 -for-look/arch/arm/ Code for everything about Samsung. Because this kernel supports a lot of chips, we learned arm. When querying, it prevents the code of other platforms from being queried, so simplify the code.
2.ctags -R .
3.vim -t memcpy
4.vim command line mode: cstag memcpy
5.ctrl + ] : enter
6.ctrl + o : exit
/************* **************************************************** ************************/
Add your own code in the kernel:
1. The driver can be directly compiled into the kernel.
2. Or compile it into a module, and then install it when needed.
3.mkdir linux-3.5/Driver/mydriver
4.Create a few files: my.c Makefile
code in my.c:
1 #include <linux/init.h>
2 #include <linux/module.h>
3 # include <linux/sched.h>
4 //Executed during the kernel startup process, and the function type executed during the kernel startup process is fixed: int test_init(void): The return value and line >>
parameters are fixed.
5 //init segment: This function is placed in the init segment. The advantage is that after the code is executed, the function body is released, saving some memory. >> can only be called
once. Don't call it later.
6 static __init int test_init(void)
7 {
8 int i;
9 //If the resource application fails, will the beggar make a corresponding error
10 //
11 //return -ENOMEM; memory application failed
12 for(i=0;i< 20;i++)
13 {
14 printk("hello kernel\n");
15 }
16 //printf("") //>> 1
17 return 0;
18
19 }
20 //Put the test_init function into the kernel startup process and execute
21 module_init(test_init);
22 MODULE_LICENSE("GPL"); //This is the code that follows the GPL open source rules, and whoever uses the code we wrote in the future must also Follow the GPL rules.
23 //The following three lines are optional
24 MODULE_AUTHOR("LIUYE");
25 MODULE_VERSION("V1.0");
26 MODULE_DESCRIPTION("test for class");
Makefile:
obj-y += my.o
vim . ./Makefile The information of the lower Makefile is added to the upper layer of the makefile. The makefile is a hierarchical compilation structure. The upper layer malefile records the lower layer makefile information in order to compile correctly.
obj-y += mydriver/ There must be "/" here, because this is a directory
and you can exit to linux-3.5/ make -j4
[liuye@LiuYe linux-3.5]$>make -j4
CHK include/linux/ version.h
CHK include/generated/utsrelease.h
make[1]: 'include/generated/mach-types.h' is up to date.
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
CC drivers/mydriver/my.o
LD drivers/mydriver/built-in.o
LD drivers/built-in.o
LINK vmlinux
LD vmlinux.o
MODPOST vmlinux.o
WARNING: modpost: Found 9 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
GEN .version
CHK include/generated/compile.h
UPD include/generated/compile.h
CC init/version.o
LD init/built-in.o
KSYM .tmp_kallsyms1.o
KSYM .tmp_kallsyms2.o
LD vmlinux
SYSMAP System.map
OBJCOPY arch/arm/boot/Image
Kernel: arch/arm/boot/Image is ready
GZIP arch/arm/boot/ compressed/piggy.gzip
AS arch/arm/boot/compressed/piggy.gzip.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
Building modules , stage 2.
MODPOST 3 modules
can see that our code is compiled and linked. Then replace the zImage to the SD card, flash the machine, just flash the zImage.
[ 3.225000] usbhid: USB HID core driver
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] hello kernel
[ 3.225000] Samsung Audio Subsystem Driver, (c) 2011 Samsung Electronics
[ 3.225000] audss_init: RCLK SRC[busclk]
[ 3.225000] Samsung SRP driver, (c)2011 Samsung Electronics
[ 3.310000] mmcblk0boot1: mmc0:0001 M4G1YC partition 2 2.00 MiB
You can see that our code is already running during the kernel boot process.
/**************************************************** ************************************/
Add your own code to the kernel:
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324838142&siteId=291194637
Recommended
Ranking