Monday, April 10, 2017

Kernel Development

1.Kernel Source Code

The Linux kernel code is designed to be portable. All code outside arch/ should be portable.
Never use floating point numbers in kernel code.
Internal kernel API to implement kernel code can undergo changes between two 2.6.x releases.
External API must not change (system calls, /proc, /sys), as it could break existing programs.
New features can be added, but kernel developers try to keep backward compatibility with earlier versions, at least for 1 or several years.
Architecture specific code
Machine / board specific code
Block layer core
drivers/   
All device drivers except sound ones (usb, pci...)
fs/   
Filesystems (fs/ext3/, etc.)
Kernel headers
Architecture and machine dependent headers
Linux kernel core headers
init/ 
Linux initialization (including main.c)
ipc/ 
Code used for process communication
Linux kernel core (very small!)
mm/
Memory management code (small too!)
Network support code (not drivers)
Sound support code and drivers
lib/  
Misc library routines (zlib, crc32...)
Security model implementations (SELinux...)
Part of the kernel build system
Top Linux makefile (sets arch and version)
Scripts for internal or external use
Maintainers of each kernel part. Very useful!
Overview and building instructions
Kernel development sources are now managed with git: http://kernel.org/pub/software/scm/git/
Proxy: export http_proxy="proxy.server.com:8080"; export ftp_proxy="proxy.server.com:8080";

git-clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git


2.Kernel Configuration

The configuration is stored in the .config file at the root of kernel sources. As options have dependencies, typically never edited by hand, but through graphical interfaces:
make [xconfig|gconfig|menuconfig|oldconfig]
To modify a kernel in a GNU/Linux distribution: the configuration files are usually released in /boot/, together with kernel images: /boot/config-2.6.17-11-generic.

3.Kernel Compilation

1 make -j 4
Vmlinux: the raw uncompressed kernel image, at the ELF format, useful for debugging purposes, but cannot be booted.
arch/<arch>/boot/*Image: the final, usually compressed, kernel image that can be booted (bzImage for x86, zImage for ARM, vmImage.gz for Blackfin, etc.).
*.ko: All kernel modules, spread over the kernel source tree, as .ko files.
2 make install
Do the installation for the host system by default, so needs to be run as root.
/boot/vmlinuz-<version>: Compressed kernel image. Same as the one in arch/<arch>/boot.
/boot/System.map-<version>: Stores kernel symbol addresses.
/boot/config-<version>: Kernel configuration for this version.
3 make modules_install
Do the installation for the host system by default, so needs to be run as root.
Installs all modules in /lib/modules/<version>/
kernel/: Module .ko (Kernel Object) files, in the same directory structure as in the sources.
modules.alias: Module aliases for module loading utilities. Example line: alias sound-service-?-0 snd_mixer_oss.
modules.dep: Module dependencies.
modules.symbols: Tells which module a given symbol belongs to.
Kernel cleanup targets
make clean: clean-up generated files(to force recompiling drivers)
make mrproper: remove all generated files, include .config file
make distclean: also remove editor backup and patch reject files
Device file creation
Device files are not created when a driver is loaded. They have to be created in advance:
sudo mknod /dev/<device> [c|b] <major> <minor>
Specifying cross-compilation
ARCH ?= arm CROSS_COMPILE ?= arm-linux-
The Makefile defines CC = $(CROSS_COMPILE)gcc
Pass ARCH and CROSS_COMPILE on the make command line.
Define ARCH and CROSS_COMPILE as environment variables.
Default configuration in boards/machines! Check if one exists in arch/<arch>/configs/ for your target.
1.1 make <machine>_defconfig                                 #in toplevel source directory
1.2 make
1.3 copy arch/<arch>/boot/zImage to target.       #autocopy with arch/<arch>/boot/install.sh
1.4 make INSTALL_MOD_PATH=<dir>/ modules_install
1.5 copy <dir>/lib/modules/ to /lib/modules/ on the target storage




No comments:

Post a Comment