1*4882a593Smuzhiyun// -*- mode:doc; -*- 2*4882a593Smuzhiyun// vim: set syntax=asciidoc: 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun[[linux-kernel-specific-infra]] 5*4882a593Smuzhiyun=== Infrastructure specific to the Linux kernel package 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunThe Linux kernel package can use some specific infrastructures based on package 8*4882a593Smuzhiyunhooks for building Linux kernel tools or/and building Linux kernel extensions. 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun[[linux-kernel-tools]] 11*4882a593Smuzhiyun==== linux-kernel-tools 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunBuildroot offers a helper infrastructure to build some userspace tools 14*4882a593Smuzhiyunfor the target available within the Linux kernel sources. Since their 15*4882a593Smuzhiyunsource code is part of the kernel source code, a special package, 16*4882a593Smuzhiyun+linux-tools+, exists and re-uses the sources of the Linux kernel that 17*4882a593Smuzhiyunruns on the target. 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunLet's look at an example of a Linux tool. For a new Linux tool named 20*4882a593Smuzhiyun+foo+, create a new menu entry in the existing 21*4882a593Smuzhiyun+package/linux-tools/Config.in+. This file will contain the option 22*4882a593Smuzhiyundescriptions related to each kernel tool that will be used and 23*4882a593Smuzhiyundisplayed in the configuration tool. It would basically look like: 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun------------------------------ 26*4882a593Smuzhiyun01: config BR2_PACKAGE_LINUX_TOOLS_FOO 27*4882a593Smuzhiyun02: bool "foo" 28*4882a593Smuzhiyun03: select BR2_PACKAGE_LINUX_TOOLS 29*4882a593Smuzhiyun04: help 30*4882a593Smuzhiyun05: This is a comment that explains what foo kernel tool is. 31*4882a593Smuzhiyun06: 32*4882a593Smuzhiyun07: http://foosoftware.org/foo/ 33*4882a593Smuzhiyun------------------------------ 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunThe name of the option starts with the prefix +BR2_PACKAGE_LINUX_TOOLS_+, 36*4882a593Smuzhiyunfollowed by the uppercase name of the tool (like is done for packages). 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun.Note 39*4882a593SmuzhiyunUnlike other packages, the +linux-tools+ package options appear in the 40*4882a593Smuzhiyun+linux+ kernel menu, under the `Linux Kernel Tools` sub-menu, not under 41*4882a593Smuzhiyunthe `Target packages` main menu. 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunThen for each linux tool, add a new +.mk.in+ file named 44*4882a593Smuzhiyun+package/linux-tools/linux-tool-foo.mk.in+. It would basically look like: 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun------------------------------ 47*4882a593Smuzhiyun01: ################################################################################ 48*4882a593Smuzhiyun02: # 49*4882a593Smuzhiyun03: # foo 50*4882a593Smuzhiyun04: # 51*4882a593Smuzhiyun05: ################################################################################ 52*4882a593Smuzhiyun06: 53*4882a593Smuzhiyun07: LINUX_TOOLS += foo 54*4882a593Smuzhiyun08: 55*4882a593Smuzhiyun09: FOO_DEPENDENCIES = libbbb 56*4882a593Smuzhiyun10: 57*4882a593Smuzhiyun11: define FOO_BUILD_CMDS 58*4882a593Smuzhiyun12: $(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools foo 59*4882a593Smuzhiyun13: endef 60*4882a593Smuzhiyun14: 61*4882a593Smuzhiyun15: define FOO_INSTALL_STAGING_CMDS 62*4882a593Smuzhiyun16: $(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \ 63*4882a593Smuzhiyun17: DESTDIR=$(STAGING_DIR) \ 64*4882a593Smuzhiyun18: foo_install 65*4882a593Smuzhiyun19: endef 66*4882a593Smuzhiyun20: 67*4882a593Smuzhiyun21: define FOO_INSTALL_TARGET_CMDS 68*4882a593Smuzhiyun22: $(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \ 69*4882a593Smuzhiyun23: DESTDIR=$(TARGET_DIR) \ 70*4882a593Smuzhiyun24: foo_install 71*4882a593Smuzhiyun25: endef 72*4882a593Smuzhiyun-------------------------------- 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunOn line 7, we register the Linux tool +foo+ to the list of available 75*4882a593SmuzhiyunLinux tools. 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunOn line 9, we specify the list of dependencies this tool relies on. These 78*4882a593Smuzhiyundependencies are added to the Linux package dependencies list only when the 79*4882a593Smuzhiyun+foo+ tool is selected. 80*4882a593Smuzhiyun 81*4882a593SmuzhiyunThe rest of the Makefile, lines 11-25 defines what should be done at the 82*4882a593Smuzhiyundifferent steps of the Linux tool build process like for a 83*4882a593Smuzhiyunxref:generic-package-tutorial[+generic package+]. They will actually be 84*4882a593Smuzhiyunused only when the +foo+ tool is selected. The only supported commands are 85*4882a593Smuzhiyun+_BUILD_CMDS+, +_INSTALL_STAGING_CMDS+ and +_INSTALL_TARGET_CMDS+. 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun.Note 88*4882a593SmuzhiyunOne *must not* call +$(eval $(generic-package))+ or any other 89*4882a593Smuzhiyunpackage infrastructure! Linux tools are not packages by themselves, 90*4882a593Smuzhiyunthey are part of the +linux-tools+ package. 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun[[linux-kernel-ext]] 93*4882a593Smuzhiyun==== linux-kernel-extensions 94*4882a593Smuzhiyun 95*4882a593SmuzhiyunSome packages provide new features that require the Linux kernel tree 96*4882a593Smuzhiyunto be modified. This can be in the form of patches to be applied on 97*4882a593Smuzhiyunthe kernel tree, or in the form of new files to be added to the 98*4882a593Smuzhiyuntree. The Buildroot's Linux kernel extensions infrastructure provides 99*4882a593Smuzhiyuna simple solution to automatically do this, just after the kernel 100*4882a593Smuzhiyunsources are extracted and before the kernel patches are 101*4882a593Smuzhiyunapplied. Examples of extensions packaged using this mechanism are the 102*4882a593Smuzhiyunreal-time extensions Xenomai and RTAI, as well as the set of 103*4882a593Smuzhiyunout-of-tree LCD screens drivers +fbtft+. 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunLet's look at an example on how to add a new Linux extension +foo+. 106*4882a593Smuzhiyun 107*4882a593SmuzhiyunFirst, create the package +foo+ that provides the extension: this 108*4882a593Smuzhiyunpackage is a standard package; see the previous chapters on how to 109*4882a593Smuzhiyuncreate such a package. This package is in charge of downloading the 110*4882a593Smuzhiyunsources archive, checking the hash, defining the licence informations 111*4882a593Smuzhiyunand building user space tools if any. 112*4882a593Smuzhiyun 113*4882a593SmuzhiyunThen create the 'Linux extension' proper: create a new menu entry in 114*4882a593Smuzhiyunthe existing +linux/Config.ext.in+. This file contains the option 115*4882a593Smuzhiyundescriptions related to each kernel extension that will be used and 116*4882a593Smuzhiyundisplayed in the configuration tool. It would basically look like: 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun------------------------------ 119*4882a593Smuzhiyun01: config BR2_LINUX_KERNEL_EXT_FOO 120*4882a593Smuzhiyun02: bool "foo" 121*4882a593Smuzhiyun03: help 122*4882a593Smuzhiyun04: This is a comment that explains what foo kernel extension is. 123*4882a593Smuzhiyun05: 124*4882a593Smuzhiyun06: http://foosoftware.org/foo/ 125*4882a593Smuzhiyun------------------------------ 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunThen for each linux extension, add a new +.mk+ file named 128*4882a593Smuzhiyun+linux/linux-ext-foo.mk+. It should basically contain: 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun------------------------------ 131*4882a593Smuzhiyun01: ################################################################################ 132*4882a593Smuzhiyun02: # 133*4882a593Smuzhiyun03: # foo 134*4882a593Smuzhiyun04: # 135*4882a593Smuzhiyun05: ################################################################################ 136*4882a593Smuzhiyun06: 137*4882a593Smuzhiyun07: LINUX_EXTENSIONS += foo 138*4882a593Smuzhiyun08: 139*4882a593Smuzhiyun09: define FOO_PREPARE_KERNEL 140*4882a593Smuzhiyun10: $(FOO_DIR)/prepare-kernel-tree.sh --linux-dir=$(@D) 141*4882a593Smuzhiyun11: endef 142*4882a593Smuzhiyun-------------------------------- 143*4882a593Smuzhiyun 144*4882a593SmuzhiyunOn line 7, we add the Linux extension +foo+ to the list of available 145*4882a593SmuzhiyunLinux extensions. 146*4882a593Smuzhiyun 147*4882a593SmuzhiyunOn line 9-11, we define what should be done by the extension to modify 148*4882a593Smuzhiyunthe Linux kernel tree; this is specific to the linux extension and can 149*4882a593Smuzhiyunuse the variables defined by the +foo+ package, like: +$(FOO_DIR)+ or 150*4882a593Smuzhiyun+$(FOO_VERSION)+... as well as all the Linux variables, like: 151*4882a593Smuzhiyun+$(LINUX_VERSION)+ or +$(LINUX_VERSION_PROBED)+, +$(KERNEL_ARCH)+... 152*4882a593SmuzhiyunSee the xref:kernel-variables[definition of those kernel variables]. 153