aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/kbuild
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/kbuild')
-rw-r--r--Documentation/kbuild/modules.txt119
1 files changed, 60 insertions, 59 deletions
diff --git a/Documentation/kbuild/modules.txt b/Documentation/kbuild/modules.txt
index 61fc079eb966..a2a178da02ff 100644
--- a/Documentation/kbuild/modules.txt
+++ b/Documentation/kbuild/modules.txt
@@ -1,7 +1,7 @@
1 1
2In this document you will find information about: 2In this document you will find information about:
3- how to build external modules 3- how to build external modules
4- how to make your module use kbuild infrastructure 4- how to make your module use the kbuild infrastructure
5- how kbuild will install a kernel 5- how kbuild will install a kernel
6- how to install modules in a non-standard location 6- how to install modules in a non-standard location
7 7
@@ -36,13 +36,13 @@ In this document you will find information about:
36 36
37kbuild includes functionality for building modules both 37kbuild includes functionality for building modules both
38within the kernel source tree and outside the kernel source tree. 38within the kernel source tree and outside the kernel source tree.
39The latter is usually referred to as external modules and is used 39The latter is usually referred to as external or "out-of-tree"
40both during development and for modules that are not planned to be 40modules and is used both during development and for modules that
41included in the kernel tree. 41are not planned to be included in the kernel tree.
42 42
43What is covered within this file is mainly information to authors 43What is covered within this file is mainly information to authors
44of modules. The author of an external modules should supply 44of modules. The author of an external module should supply
45a makefile that hides most of the complexity so one only has to type 45a makefile that hides most of the complexity, so one only has to type
46'make' to build the module. A complete example will be present in 46'make' to build the module. A complete example will be present in
47chapter 4, "Creating a kbuild file for an external module". 47chapter 4, "Creating a kbuild file for an external module".
48 48
@@ -137,7 +137,7 @@ when building an external module.
137 module versioning work. 137 module versioning work.
138 138
139--- 2.5 Building separate files for a module 139--- 2.5 Building separate files for a module
140 It is possible to build single files which is part of a module. 140 It is possible to build single files which are part of a module.
141 This works equal for the kernel, a module and even for external 141 This works equal for the kernel, a module and even for external
142 modules. 142 modules.
143 Examples (module foo.ko, consist of bar.o, baz.o): 143 Examples (module foo.ko, consist of bar.o, baz.o):
@@ -151,7 +151,7 @@ when building an external module.
151 151
152This example shows the actual commands to be executed when building 152This example shows the actual commands to be executed when building
153an external module for the currently running kernel. 153an external module for the currently running kernel.
154In the example below the distribution is supposed to use the 154In the example below, the distribution is supposed to use the
155facility to locate output files for a kernel compile in a different 155facility to locate output files for a kernel compile in a different
156directory than the kernel source - but the examples will also work 156directory than the kernel source - but the examples will also work
157when the source and the output files are mixed in the same directory. 157when the source and the output files are mixed in the same directory.
@@ -170,7 +170,7 @@ the following commands to build the module:
170 O=/lib/modules/`uname-r`/build \ 170 O=/lib/modules/`uname-r`/build \
171 M=`pwd` 171 M=`pwd`
172 172
173Then to install the module use the following command: 173Then, to install the module use the following command:
174 174
175 make -C /usr/src/`uname -r`/source \ 175 make -C /usr/src/`uname -r`/source \
176 O=/lib/modules/`uname-r`/build \ 176 O=/lib/modules/`uname-r`/build \
@@ -230,7 +230,7 @@ following files:
230 230
231 endif 231 endif
232 232
233 In example 1 the check for KERNELRELEASE is used to separate 233 In example 1, the check for KERNELRELEASE is used to separate
234 the two parts of the Makefile. kbuild will only see the two 234 the two parts of the Makefile. kbuild will only see the two
235 assignments whereas make will see everything except the two 235 assignments whereas make will see everything except the two
236 kbuild assignments. 236 kbuild assignments.
@@ -255,7 +255,7 @@ following files:
255 echo "X" > 8123_bin_shipped 255 echo "X" > 8123_bin_shipped
256 256
257 257
258 In example 2 we are down to two fairly simple files and for simple 258 In example 2, we are down to two fairly simple files and for simple
259 files as used in this example the split is questionable. But some 259 files as used in this example the split is questionable. But some
260 external modules use Makefiles of several hundred lines and here it 260 external modules use Makefiles of several hundred lines and here it
261 really pays off to separate the kbuild part from the rest. 261 really pays off to separate the kbuild part from the rest.
@@ -282,9 +282,9 @@ following files:
282 282
283 endif 283 endif
284 284
285 The trick here is to include the Kbuild file from Makefile so 285 The trick here is to include the Kbuild file from Makefile, so
286 if an older version of kbuild picks up the Makefile the Kbuild 286 if an older version of kbuild picks up the Makefile, the Kbuild
287 file will be included. 287 file will be included.
288 288
289--- 4.2 Binary blobs included in a module 289--- 4.2 Binary blobs included in a module
290 290
@@ -301,18 +301,19 @@ following files:
301 obj-m := 8123.o 301 obj-m := 8123.o
302 8123-y := 8123_if.o 8123_pci.o 8123_bin.o 302 8123-y := 8123_if.o 8123_pci.o 8123_bin.o
303 303
304 In example 4 there is no distinction between the ordinary .c/.h files 304 In example 4, there is no distinction between the ordinary .c/.h files
305 and the binary file. But kbuild will pick up different rules to create 305 and the binary file. But kbuild will pick up different rules to create
306 the .o file. 306 the .o file.
307 307
308 308
309=== 5. Include files 309=== 5. Include files
310 310
311Include files are a necessity when a .c file uses something from another .c 311Include files are a necessity when a .c file uses something from other .c
312files (not strictly in the sense of .c but if good programming practice is 312files (not strictly in the sense of C, but if good programming practice is
313used). Any module that consist of more than one .c file will have a .h file 313used). Any module that consists of more than one .c file will have a .h file
314for one of the .c files. 314for one of the .c files.
315- If the .h file only describes a module internal interface then the .h file 315
316- If the .h file only describes a module internal interface, then the .h file
316 shall be placed in the same directory as the .c files. 317 shall be placed in the same directory as the .c files.
317- If the .h files describe an interface used by other parts of the kernel 318- If the .h files describe an interface used by other parts of the kernel
318 located in different directories, the .h files shall be located in 319 located in different directories, the .h files shall be located in
@@ -323,11 +324,11 @@ under include/ such as include/scsi. Another exception is arch-specific
323.h files which are located under include/asm-$(ARCH)/*. 324.h files which are located under include/asm-$(ARCH)/*.
324 325
325External modules have a tendency to locate include files in a separate include/ 326External modules have a tendency to locate include files in a separate include/
326directory and therefore needs to deal with this in their kbuild file. 327directory and therefore need to deal with this in their kbuild file.
327 328
328--- 5.1 How to include files from the kernel include dir 329--- 5.1 How to include files from the kernel include dir
329 330
330 When a module needs to include a file from include/linux/ then one 331 When a module needs to include a file from include/linux/, then one
331 just uses: 332 just uses:
332 333
333 #include <linux/modules.h> 334 #include <linux/modules.h>
@@ -348,7 +349,7 @@ directory and therefore needs to deal with this in their kbuild file.
348 The trick here is to use either EXTRA_CFLAGS (take effect for all .c 349 The trick here is to use either EXTRA_CFLAGS (take effect for all .c
349 files) or CFLAGS_$F.o (take effect only for a single file). 350 files) or CFLAGS_$F.o (take effect only for a single file).
350 351
351 In our example if we move 8123_if.h to a subdirectory named include/ 352 In our example, if we move 8123_if.h to a subdirectory named include/
352 the resulting Kbuild file would look like: 353 the resulting Kbuild file would look like:
353 354
354 --> filename: Kbuild 355 --> filename: Kbuild
@@ -362,9 +363,9 @@ directory and therefore needs to deal with this in their kbuild file.
362 363
363--- 5.3 External modules using several directories 364--- 5.3 External modules using several directories
364 365
365 If an external module does not follow the usual kernel style but 366 If an external module does not follow the usual kernel style, but
366 decide to spread files over several directories then kbuild can 367 decides to spread files over several directories, then kbuild can
367 support this too. 368 handle this too.
368 369
369 Consider the following example: 370 Consider the following example:
370 371
@@ -374,7 +375,7 @@ directory and therefore needs to deal with this in their kbuild file.
374 | +- hal/include/hardwareif.h 375 | +- hal/include/hardwareif.h
375 +- include/complex.h 376 +- include/complex.h
376 377
377 To build a single module named complex.ko we then need the following 378 To build a single module named complex.ko, we then need the following
378 kbuild file: 379 kbuild file:
379 380
380 Kbuild: 381 Kbuild:
@@ -387,12 +388,12 @@ directory and therefore needs to deal with this in their kbuild file.
387 388
388 389
389 kbuild knows how to handle .o files located in another directory - 390 kbuild knows how to handle .o files located in another directory -
390 although this is NOT reccommended practice. The syntax is to specify 391 although this is NOT recommended practice. The syntax is to specify
391 the directory relative to the directory where the Kbuild file is 392 the directory relative to the directory where the Kbuild file is
392 located. 393 located.
393 394
394 To find the .h files we have to explicitly tell kbuild where to look 395 To find the .h files, we have to explicitly tell kbuild where to look
395 for the .h files. When kbuild executes current directory is always 396 for the .h files. When kbuild executes, the current directory is always
396 the root of the kernel tree (argument to -C) and therefore we have to 397 the root of the kernel tree (argument to -C) and therefore we have to
397 tell kbuild how to find the .h files using absolute paths. 398 tell kbuild how to find the .h files using absolute paths.
398 $(src) will specify the absolute path to the directory where the 399 $(src) will specify the absolute path to the directory where the
@@ -412,7 +413,7 @@ External modules are installed in the directory:
412 413
413--- 6.1 INSTALL_MOD_PATH 414--- 6.1 INSTALL_MOD_PATH
414 415
415 Above are the default directories, but as always some level of 416 Above are the default directories, but as always, some level of
416 customization is possible. One can prefix the path using the variable 417 customization is possible. One can prefix the path using the variable
417 INSTALL_MOD_PATH: 418 INSTALL_MOD_PATH:
418 419
@@ -420,17 +421,17 @@ External modules are installed in the directory:
420 => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel 421 => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel
421 422
422 INSTALL_MOD_PATH may be set as an ordinary shell variable or as in the 423 INSTALL_MOD_PATH may be set as an ordinary shell variable or as in the
423 example above be specified on the command line when calling make. 424 example above, can be specified on the command line when calling make.
424 INSTALL_MOD_PATH has effect both when installing modules included in 425 INSTALL_MOD_PATH has effect both when installing modules included in
425 the kernel as well as when installing external modules. 426 the kernel as well as when installing external modules.
426 427
427--- 6.2 INSTALL_MOD_DIR 428--- 6.2 INSTALL_MOD_DIR
428 429
429 When installing external modules they are default installed in a 430 When installing external modules they are by default installed to a
430 directory under /lib/modules/$(KERNELRELEASE)/extra, but one may wish 431 directory under /lib/modules/$(KERNELRELEASE)/extra, but one may wish
431 to locate modules for a specific functionality in a separate 432 to locate modules for a specific functionality in a separate
432 directory. For this purpose one can use INSTALL_MOD_DIR to specify an 433 directory. For this purpose, one can use INSTALL_MOD_DIR to specify an
433 alternative name than 'extra'. 434 alternative name to 'extra'.
434 435
435 $ make INSTALL_MOD_DIR=gandalf -C KERNELDIR \ 436 $ make INSTALL_MOD_DIR=gandalf -C KERNELDIR \
436 M=`pwd` modules_install 437 M=`pwd` modules_install
@@ -444,16 +445,16 @@ Module versioning is enabled by the CONFIG_MODVERSIONS tag.
444Module versioning is used as a simple ABI consistency check. The Module 445Module versioning is used as a simple ABI consistency check. The Module
445versioning creates a CRC value of the full prototype for an exported symbol and 446versioning creates a CRC value of the full prototype for an exported symbol and
446when a module is loaded/used then the CRC values contained in the kernel are 447when a module is loaded/used then the CRC values contained in the kernel are
447compared with similar values in the module. If they are not equal then the 448compared with similar values in the module. If they are not equal, then the
448kernel refuses to load the module. 449kernel refuses to load the module.
449 450
450Module.symvers contains a list of all exported symbols from a kernel build. 451Module.symvers contains a list of all exported symbols from a kernel build.
451 452
452--- 7.1 Symbols fron the kernel (vmlinux + modules) 453--- 7.1 Symbols fron the kernel (vmlinux + modules)
453 454
454 During a kernel build a file named Module.symvers will be generated. 455 During a kernel build, a file named Module.symvers will be generated.
455 Module.symvers contains all exported symbols from the kernel and 456 Module.symvers contains all exported symbols from the kernel and
456 compiled modules. For each symbols the corresponding CRC value 457 compiled modules. For each symbols, the corresponding CRC value
457 is stored too. 458 is stored too.
458 459
459 The syntax of the Module.symvers file is: 460 The syntax of the Module.symvers file is:
@@ -461,27 +462,27 @@ Module.symvers contains a list of all exported symbols from a kernel build.
461 Sample: 462 Sample:
462 0x2d036834 scsi_remove_host drivers/scsi/scsi_mod 463 0x2d036834 scsi_remove_host drivers/scsi/scsi_mod
463 464
464 For a kernel build without CONFIG_MODVERSIONING enabled the crc 465 For a kernel build without CONFIG_MODVERSIONING enabled, the crc
465 would read: 0x00000000 466 would read: 0x00000000
466 467
467 Module.symvers serve two purposes. 468 Module.symvers serves two purposes:
468 1) It list all exported symbols both from vmlinux and all modules 469 1) It lists all exported symbols both from vmlinux and all modules
469 2) It list CRC if CONFIG_MODVERSION is enabled 470 2) It lists the CRC if CONFIG_MODVERSION is enabled
470 471
471--- 7.2 Symbols and external modules 472--- 7.2 Symbols and external modules
472 473
473 When building an external module the build system needs access to 474 When building an external module, the build system needs access to
474 the symbols from the kernel to check if all external symbols are 475 the symbols from the kernel to check if all external symbols are
475 defined. This is done in the MODPOST step and to obtain all 476 defined. This is done in the MODPOST step and to obtain all
476 symbols modpost reads Module.symvers from the kernel. 477 symbols, modpost reads Module.symvers from the kernel.
477 If a Module.symvers file is present in the directory where 478 If a Module.symvers file is present in the directory where
478 the external module is being build this file will be read too. 479 the external module is being built, this file will be read too.
479 During the MODPOST step a new Module.symvers file will be written 480 During the MODPOST step, a new Module.symvers file will be written
480 containing all exported symbols that was not defined in the kernel. 481 containing all exported symbols that were not defined in the kernel.
481 482
482--- 7.3 Symbols from another external module 483--- 7.3 Symbols from another external module
483 484
484 Sometimes one external module uses exported symbols from another 485 Sometimes, an external module uses exported symbols from another
485 external module. Kbuild needs to have full knowledge on all symbols 486 external module. Kbuild needs to have full knowledge on all symbols
486 to avoid spitting out warnings about undefined symbols. 487 to avoid spitting out warnings about undefined symbols.
487 Two solutions exist to let kbuild know all symbols of more than 488 Two solutions exist to let kbuild know all symbols of more than
@@ -490,9 +491,9 @@ Module.symvers contains a list of all exported symbols from a kernel build.
490 impractical in certain situations. 491 impractical in certain situations.
491 492
492 Use a top-level Kbuild file 493 Use a top-level Kbuild file
493 If you have two modules: 'foo', 'bar' and 'foo' needs symbols 494 If you have two modules: 'foo' and 'bar', and 'foo' needs
494 from 'bar' then one can use a common top-level kbuild file so 495 symbols from 'bar', then one can use a common top-level kbuild
495 both modules are compiled in same build. 496 file so both modules are compiled in same build.
496 497
497 Consider following directory layout: 498 Consider following directory layout:
498 ./foo/ <= contains the foo module 499 ./foo/ <= contains the foo module
@@ -509,15 +510,15 @@ Module.symvers contains a list of all exported symbols from a kernel build.
509 knowledge on symbols from both modules. 510 knowledge on symbols from both modules.
510 511
511 Use an extra Module.symvers file 512 Use an extra Module.symvers file
512 When an external module is build a Module.symvers file is 513 When an external module is built, a Module.symvers file is
513 generated containing all exported symbols which are not 514 generated containing all exported symbols which are not
514 defined in the kernel. 515 defined in the kernel.
515 To get access to symbols from module 'bar' one can copy the 516 To get access to symbols from module 'bar', one can copy the
516 Module.symvers file from the compilation of the 'bar' module 517 Module.symvers file from the compilation of the 'bar' module
517 to the directory where the 'foo' module is build. 518 to the directory where the 'foo' module is built.
518 During the module build kbuild will read the Module.symvers 519 During the module build, kbuild will read the Module.symvers
519 file in the directory of the external module and when the 520 file in the directory of the external module and when the
520 build is finished a new Module.symvers file is created 521 build is finished, a new Module.symvers file is created
521 containing the sum of all symbols defined and not part of the 522 containing the sum of all symbols defined and not part of the
522 kernel. 523 kernel.
523 524
@@ -525,7 +526,7 @@ Module.symvers contains a list of all exported symbols from a kernel build.
525 526
526--- 8.1 Testing for CONFIG_FOO_BAR 527--- 8.1 Testing for CONFIG_FOO_BAR
527 528
528 Modules often needs to check for certain CONFIG_ options to decide if 529 Modules often need to check for certain CONFIG_ options to decide if
529 a specific feature shall be included in the module. When kbuild is used 530 a specific feature shall be included in the module. When kbuild is used
530 this is done by referencing the CONFIG_ variable directly. 531 this is done by referencing the CONFIG_ variable directly.
531 532
@@ -537,7 +538,7 @@ Module.symvers contains a list of all exported symbols from a kernel build.
537 538
538 External modules have traditionally used grep to check for specific 539 External modules have traditionally used grep to check for specific
539 CONFIG_ settings directly in .config. This usage is broken. 540 CONFIG_ settings directly in .config. This usage is broken.
540 As introduced before external modules shall use kbuild when building 541 As introduced before, external modules shall use kbuild when building
541 and therefore can use the same methods as in-kernel modules when testing 542 and therefore can use the same methods as in-kernel modules when
542 for CONFIG_ definitions. 543 testing for CONFIG_ definitions.
543 544