Category:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
0
1
2
3
4
5
6
7
8
9
Position:IcFull.com » IC Electronic information » Category: k

IC Electronic information

kbuild system - compiled kernel module

In Electronic Infomation Category: k | on December 13,2010

Linux kernel is a single core, but by way of dynamically loaded modules, making it very flexible and HEF4046BT datasheet and convenient development. So, it is how to compile the kernel it? We can start by analyzing its Makefile. The following is a simple hello kernel module Makefile.

ifneq ($ (KERNELRELEASE ),)

obj-m: = hello.o

else < / P>

KERNELDIR: = / lib / modules / $ (shell uname-r) / build

PWD: = $ (shell pwd)

default:

$ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules

clean:

rm-rf *. o *. mod.c *. mod.o *. ko

endif

hello when we finish a module, just use the above makefile. And then make click on the line.

hello module, we assume that the source code in / home / study / prog / mod / hello / under.

When we make in this directory when you run, make is how to implement it?

LDD3 Chapter IV "compilation and HEF4046BT price and loading" is only briefly mentioned in the Makefile is executed twice, but the specific process is about?

First of all, make the back because no goal, it will make the first Makefile not to. At the beginning of the target as the default implementation of the goals. So make default as the target. make executes $ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules

.

shell is a function of the internal make, assuming that the current kernel version is 2.6.13-study, so the $ (shell uname-r) The result is 2.6.13-study

here actual operation is

make-C / lib/modules/2.6.13-study/build M = / home / study / prog / mod / hello / modules

/ lib / modules/2.6.13-study/build is a pointer to the kernel source / usr / src / linux symbolic link.

visible, make the implementation of the two. The first module executed is read the source code of hello directory / home / study / prog / mod / hello / under the Makefile. The second execution is the implementation / usr / src / linux / Makefile under the time.

but there are many perplexing questions:

1. This KERNELRELEASE also confusing, What is it? In / home / study / prog / mod / hello / Makefile is not defined in this variable, so the work is else ... endif this paragraph. However, if the hello module to the kernel source code. For example into / usr / src / linux / driver / in, KERNELRELEASE have defined.

in / usr / src / linux / Makefile in

162 KERNELRELE ASE = $ (VERSION). $ (PATCHLEVEL). $ (SUBLEVEL) $ (EXTRAVERSION ) $ (LOCALVERSION)

this time, hello module is no longer a separate compile with make, but in the kernel using make modules to compile.

this way, the Makefile to compile and HEF4046BT suppliers and as a separate part of the compile-time kernel can work properly.

2. The obj-m: = hello.o when it will perform to it?

in the implementation:

make-C / lib/modules/2.6.13-study/build M = / home / study / prog / mod / hello / modules

time, make to / usr / src / linux / Makefile find the target modules:

862. PHONY: modules

863 modules: $ (vmlinux-dirs) $ ( if $ (KBUILD_BUILTIN), vmlinux)

864 @ echo Building modules, stage 2 .;

865 $ (Q) $ (MAKE)-rR-f $ (srctree) / scripts / Makefile.modpost

can be seen, two-stage:

1. compile hello.o file.

2. Generate hello.mod.o hello.ko

in this process will be called

make-f scripts / Makefile.build bj = / home / study / prog / mod / hello

in scripts / Makefile.build contains many documents:

011-include. config

012

013 include $ (if $ (wildcard $ (obj) / Kbuild), $ (obj) / Kbuild, $ (obj) / Makefile)

among them / home / study / prog / mod / hello / Makefile

then KERNELRELEASE already exists.

so the execution is:

obj-m: = hello.o

make modules more details on the process can be scripts / Makefile.modpost file found in the Notes. If you want to see make the entire implementation process, you can run make-n.

Thus, the kernel Kbuild large and complex systems.

HEF4046BT datasheetHEF4046BT suppliersHEF4046BT Price

Related technical information

All right reserved:icfull.com © 2010-2016 Certificate