adding-packages-linux-kernel-spec-infra.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. [[linux-kernel-specific-infra]]
  4. === Infrastructure specific to the Linux kernel package
  5. The Linux kernel package can use some specific infrastructures based on package
  6. hooks for building Linux kernel tools or/and building Linux kernel extensions.
  7. [[linux-kernel-tools]]
  8. ==== linux-kernel-tools
  9. Buildroot offers a helper infrastructure to build some userspace tools
  10. for the target available within the Linux kernel sources. Since their
  11. source code is part of the kernel source code, it is not very
  12. practical to use separate packages for them as they often need to be
  13. built with the same kernel version as the kernel being used on the
  14. target. The small Linux kernel tools infrastructure is a simplified
  15. packaging mechanism based on the generic package infrastructure to
  16. help building those tools.
  17. Let's look at an example of a Linux tool. For a new Linux tool named
  18. +foo+, create a new menu entry in the existing
  19. +linux/Config.tools.in+. This file will contain the option
  20. descriptions related to each kernel tool that will be used and
  21. displayed in the configuration tool. It would basically look like:
  22. ------------------------------
  23. 01: config BR2_LINUX_KERNEL_TOOL_FOO
  24. 02: bool "foo"
  25. 03: help
  26. 04: This is a comment that explains what foo kernel tool is.
  27. 05:
  28. 06: http://foosoftware.org/foo/
  29. ------------------------------
  30. The name of the option starts with the prefix +BR2_LINUX_KERNEL_TOOL_+,
  31. followed by the uppercase name of the tool (like is done for packages).
  32. Then for each linux tool, add a new +.mk+ file named +linux/linux-tool-foo.mk+.
  33. It would basically look like:
  34. ------------------------------
  35. 01: ################################################################################
  36. 02: #
  37. 03: # foo
  38. 04: #
  39. 05: ################################################################################
  40. 06:
  41. 07: LINUX_TOOLS += foo
  42. 08:
  43. 09: FOO_DEPENDENCIES = libbbb
  44. 10:
  45. 11: define FOO_BUILD_CMDS
  46. 12: $(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/tools foo
  47. 13: endef
  48. 14:
  49. 15: define FOO_INSTALL_STAGING_CMDS
  50. 16: $(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/tools \
  51. 17: DESTDIR=$(STAGING_DIR) \
  52. 18: foo_install
  53. 19: endef
  54. 20:
  55. 21: define FOO_INSTALL_TARGET_CMDS
  56. 22: $(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/tools \
  57. 23: DESTDIR=$(@D) \
  58. 24: foo_install
  59. 25: endef
  60. --------------------------------
  61. On line 7, we register the Linux tool +foo+ to the list of available
  62. Linux tools.
  63. On line 9, we specify the list of dependencies this tool relies on. These
  64. dependencies are added to the Linux package dependencies list only when the
  65. +foo+ tool is selected.
  66. The rest of the Makefile, lines 11-25 defines what should be done at the
  67. different steps of the Linux tool build process like for a
  68. xref:generic-package-tutorial[+generic package+]. They will actually be
  69. used only when the +foo+ tool is selected. The only supported commands are
  70. +_BUILD_CMDS+, +_INSTALL_STAGING_CMDS+ and +_INSTALL_TARGET_CMDS+.
  71. .Note
  72. One *must not* call +$(eval $(generic-package))+ or any other
  73. package infrastructure! Linux tools are not packages by themselves,
  74. they are part of the +linux+ package.
  75. [[linux-kernel-ext]]
  76. ==== linux-kernel-extensions
  77. Some packages provide new features that require the Linux kernel tree
  78. to be modified. This can be in the form of patches to be applied on
  79. the kernel tree, or in the form of new files to be added to the
  80. tree. The Buildroot's Linux kernel extensions infrastructure provides
  81. a simple solution to automatically do this, just after the kernel
  82. sources are extracted and before the kernel patches are
  83. applied. Examples of extensions packaged using this mechanism are the
  84. real-time extensions Xenomai and RTAI, as well as the set of
  85. out-of-tree LCD screens drivers +fbtft+.
  86. Let's look at an example on how to add a new Linux extension +foo+.
  87. First, create the package +foo+ that provides the extension: this
  88. package is a standard package; see the previous chapters on how to
  89. create such a package. This package is in charge of downloading the
  90. sources archive, checking the hash, defining the licence informations
  91. and building user space tools if any.
  92. Then create the 'Linux extension' proper: create a new menu entry in
  93. the existing +linux/Config.ext.in+. This file contains the option
  94. descriptions related to each kernel extension that will be used and
  95. displayed in the configuration tool. It would basically look like:
  96. ------------------------------
  97. 01: config BR2_LINUX_KERNEL_EXT_FOO
  98. 02: bool "foo"
  99. 03: help
  100. 04: This is a comment that explains what foo kernel extension is.
  101. 05:
  102. 06: http://foosoftware.org/foo/
  103. ------------------------------
  104. Then for each linux extension, add a new +.mk+ file named
  105. +linux/linux-ext-foo.mk+. It should basically contain:
  106. ------------------------------
  107. 01: ################################################################################
  108. 02: #
  109. 03: # foo
  110. 04: #
  111. 05: ################################################################################
  112. 06:
  113. 07: LINUX_EXTENSIONS += foo
  114. 08:
  115. 09: define FOO_PREPARE_KERNEL
  116. 10: $(FOO_DIR)/prepare-kernel-tree.sh --linux-dir=$(@D)
  117. 11: endef
  118. --------------------------------
  119. On line 7, we add the Linux extension +foo+ to the list of available
  120. Linux extensions.
  121. On line 9-11, we define what should be done by the extension to modify
  122. the Linux kernel tree; this is specific to the linux extension and can
  123. use the variables defined by the +foo+ package, like: +$(FOO_DIR)+ or
  124. +$(FOO_VERSION)+... as well as all the Linux variables, like:
  125. +$(LINUX_VERSION)+ or +$(LINUX_VERSION_PROBED)+, +$(KERNEL_ARCH)+...
  126. See the xref:kernel-variables[definition of those kernel variables].