Changes between Version 12 and Version 13 of linux/kernel
- Timestamp:
- 04/08/2019 05:12:23 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
linux/kernel
v12 v13 101 101 102 102 [=#building] 103 == Building the Linux kernel ( out-of-tree) ==104 Building the Linux kernel 'out-of-tree' refers to building it outside of the Board Support Package development environment. Each BSP that Gateworks provides builds the kernel for you, but doing constant kernel development within those BSP's may not be very time efficient.103 == Building the Linux kernel (cross-compiling) 104 Building the Linux kernel for a target board that differs from your development host outside various Board Support Package development environments is easily accomplished. 105 105 106 106 Gateworks developers typically do kernel development out-of-tree and boot the kernel over the network to speed up development. … … 180 180 export ARCH=arm 181 181 export CROSS_COMPILE=arm-openwrt-linux- 182 export INSTALL_MOD_PATH=install183 182 export LOADADDR=0x10008000 184 183 }}} … … 227 226 * uImage - compressed kernel wrapped in a U-Boot image header (use this for Ventana/IMX6) which requires the $LOADADDR env variable to tell U-Boot where to uncompress the kernel to 228 227 * modules - for building loadable kernel modules (*.ko) 229 * modules_install - for installing the loadable kernel modules to $INSTALL_MOD_PATH (env)230 * headers_install - for installing kernel header files to INSTALL_HDR_PATH (which must be passed in to make)228 * modules_install - for installing the loadable kernel modules (set the INSTALL_MOD_PATH parameter to the location you wish to install to) 229 * headers_install - for installing kernel header files for development of userspace applications that use the kernel APIs (set the INSTALL_HDR_PATH parameter to the location you wish to install to) 231 230 * dtbs - for building device-tree blobs (*.dtb) from kernel source tree (Ventana/IMX6; for Newport we use out-of-kernel tree device-tree) 232 231 * Examples: 233 232 - Newport/CN80XX: 234 233 {{{#!bash 235 make Image modules modules_install INSTALL_HDR_PATH=install/usr headers_install 234 mkdir install 235 make INSTALL_MOD_PATH=install INSTALL_HDR_PATH=install/usr Image modules modules_install headers_install 236 236 }}} 237 237 - Ventana/IMX6: 238 238 {{{#!bash 239 make uImage dtbs modules modules_install INSTALL_HDR_PATH=install/usr headers_install 239 mkdir install 240 make INSTALL_MOD_PATH=install INSTALL_HDR_PATH=install/usr uImage dtbs modules modules_install headers_install 240 241 }}} 241 242 … … 243 244 * kernel images (Image/uImage) will be in arch/$ARCH/boot 244 245 * dtbs will be in arch/$ARCH/boot/dts 245 * modules will be in $INSTALL_MOD_PATH. You can create a tarball via: 246 {{{#!bash 247 tar -C $INSTALL_MOD_PATH --owner=0 --group=0 -cvJf modules.tar.xz . 248 }}} 249 246 * modules will be in the directory specified by the INSTALL_MOD_PATH parameter. You can create a tarball via: 247 {{{#!bash 248 tar -C <INSTALL_MOD_PATH dir> --owner=0 --group=0 -cvJf modules.tar.xz . 249 }}} 250 251 252 [=#headers] 253 == Installing Kernel Headers 254 The 'make headers_install' command exports the kernel's header files in a form suitable for use by userspace programs. These headers describe the API for user space programs attempting to use kernel services and are used by the system's C library (ie glibc or uClibc) to define available system calls as well as constants and structures to be used with these system calls. The C library's header files are usually installed in /usr/include and the kernel's headers are usually in /usr/include/linux and /usr/include/asm. Kernel headers are backwards compatible but not forwards compatible meaning a program built against a C library using older kernel headers should run on a newr kernel (although possibly missing access to new features) but a program built against newer kernel headers may not work on an older kernel. 255 256 The 'make headers_install' command uses two optional arguments to define the architecture (ARCH) and the location to install the files (INSTALL_HDR_PATH) 257 258 Reference: 259 - https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt 260 261 262 [=#modules] 263 == Building external (out of tree) kernel modules 264 The Linux 'kbuild' system is used by the Linux kernel for kernel configuration. Linux kernel modules must use kbuild to stay compatible with the changes in the build infrastructure. A kernel module can be built stand-alone either 'in tree' (within the directory structure of the linux kernel) or 'out of tree' (aka 'external') meaning it exists in a directory of its own outside of the linux source tree. 265 266 An external module must always include a wrapper makefile that supports building the module using 'make' with no arguments. See [https://www.kernel.org/doc/Documentation/kbuild/modules.txt modules.txt] for details. 267 268 To build external modules you must have a prebuilt kernel available that contains the configuration and header files used in the build. Also the kernel must have been built with modules enabled. 269 270 To build an external kernel module you typically would use: 271 {{{#!bash 272 cd <external-module-directory> 273 make -C <path-to-prebuilt-kernel> M=$PWD 274 }}} 275 * this will build the modules located in the current directory pointed to by the M param 276 * you can then manually copy or load your kernel modules or use the modules_install make target to install them to a specific path 277 * if cross-compiling make sure to define ARCH and CROSS_COMPILE env variables and have the $(CROSS_COMPILE)-gcc in your path 278 279 As an example consider the following files in a directory called 'hello-driver': 280 * hello.c: 281 {{{#!bash 282 #include <linux/init.h> 283 #include <linux/module.h> 284 MODULE_LICENSE("Dual BSD/GPL"); 285 286 static int hello_init(void) 287 { 288 printk(KERN_ALERT "Hello, world\n"); 289 return 0; 290 } 291 292 static void hello_exit(void) 293 { 294 printk(KERN_ALERT "Goodbye, cruel world\n"); 295 } 296 297 module_init(hello_init); 298 module_exit(hello_exit); 299 }}} 300 * Makefile: 301 {{{#!bash 302 obj-m := hello.o 303 }}} 304 * building: 305 {{{#!bash 306 make -C <path-to-prebuilt-kernel> M=$PWD 307 ls hello.ko 308 }}} 309 310 311 References: 312 - https://www.kernel.org/doc/Documentation/kbuild/modules.txt 313 - https://www.oreilly.com/library/view/linux-device-drivers/0596005903/ch02.html 250 314 251 315 252 316 [=#backports] 253 == Building the Latest Kernel Modules - Wireless Backports ==254 Because we don't use mainline linux, but require the latest drivers in wireless, we use the {{{backports}}} project. For more detail on this project, please visit their [https://backports.wiki.kernel.org/index.php/Main_Page documentation] site.317 == Building the Latest Kernel Modules for an older kernel - Linux Backports 318 Sometimes you may be using a kernel is not as new as the mainline kernel at kernel.org and you desire a driver or newer driver from the latest kernel. The [https://backports.wiki.kernel.org/index.php/Main_Page Linux Backports] project aims at providing this capability. 255 319 256 320 In order to build this, you will need a kernel tree already built. In this example, I will assume the {{{gateworks_fslc_3.14_1.0.x_ga}}} kernel is being used. … … 370 434 371 435 372 373 [=#modules] 374 = Kernel Modules 436 [=#insmod] 437 = Loading Kernel Modules 375 438 Kernel modules are dynamically loadable portions of the kernel that can be loaded or unloaded at runtime. It is generally not feasible to build every kernel driver statically into a modern Linux kernel so instead only options required to load further modules are build static. 376 439