Linux Modules Character drivers IO & Memory Linux Kernel Process Management Process Address space Linux Scheduler Memory Management Interrupts Signals System Calls Kernel Synchronization Linux Inter Process Communications Serial Ports Parallel Ports Introduction to Hardware Linux Timers DMA in Linux Linux Threads Linux Thread Synchronization Linux Multi Threading Debugging in Linux GDB GNU Debugger KDB Kernel Debugger KGDB Kernel GNU Debugger Example Ethernet Driver |
Linux History ü
1991: Linux kernel written from scratch
in 6 months by LinusTorvaldsin his Helsinki
University room, to overcome limitations of his 80386 PC. ü
1991: Linus shares
his kernel on the net. Programmers fromthe whole
world join in and contribute to coding and testing ü
1992: Linux released under the GNU
General Public License ü
1994: Linux 1.0 released ü
1994: Red Hat founded by Bob Young and
Marc Ewing, creating anew business model. ü
1995: GNU/Linux and free software
developing in Internet servers. ü
2001: IBM invests $1 billion in Linux ü
2002: GNU/Linux wide adoption starts in
many industry sectors. ü
2005: Linux Kernel 2.6 Linux Kernel 2.6 Features ü
Performance and Determinism ü
A Pre-emptible
Kernel ü
An Efficient Scheduler ü
New Synchronization Primitives ü
Sharing Memory with Less Contention ü
POSIX Threads, Signals, and Timers ü
Support for Custom Designs ü
Devices, Busses, and I/O ü
No Keyboard, No Monitor, No Wires ü
Linux on 64-bit
Machines ü
Linux on
Microcontrollers Linux Distribution ü
Consists of boot diskette and other
diskettes or CD-ROM ü
Popular distribution: RedHat,
Debian, Slackware, Caldera
and SuSe. Linux Versioning Scheme Releases are versioned as x.y.z Stable versions x.y:
main release number y:
even number z:
identifies the exact release version number Examples: 2.0.40, 2.2.26, 2.4.27, 2.6.7
... Development versions y:
odd number Examples: 2.3.42, 2.5.74
... LINUX Architecture ü
Microkernel: Minimum functionality
–IPC, MM and scheduler Remaining functions as autonomous
processes Communicating to kernel via a well
defined interface ü
Advantage Individual components work independently Less
trouble to maintain ü
Drawbacks Slow, prevents optimizations ü
Trend: Microkernel architecture. E.g.,
Mach Kernel or kernel of Windows NTMINIX and Hurd
System, examples of microkernel ü
Linux –Classical monolithic
architecture, most components accessed via accurately defined interfaces. Architecture of generic linux Supported hardware architectures ü
See the arch/ directory ü
Minimum: 32 bit processors, with or
without MMU ü
32 bit architectures:alpha,
arm, cris, h8300, i386, m68k, m68knommu, mips,parisc, ppc, s390, sh, sparc, um, v850 ü
64 bit architectures:ia64, mips64,
ppc64 sh64, sparc64, x86_64 ü
See arch/README or
Documentation/arch/README for details Linux Key Features ü
Portability and hardware support ü
Scalability Can run on super computers as well as
on tiny devices ü
Compliance to standards and
interoperability ü
Networking ü
Security ü
Stability and reliability ü
Modularity The Kernel Source arch - This
subdirectory contains all of the architecture specific code for each supported
architecture (MIPS, ARM, 386 and so on), there is subdirectory under
"arch". Each supported architecture subdirectory has four major
subdirectories: kernel: which contains the architecture specific
kernel code mm: which contains the architecture
specific memory mgmt code. lib: which contains architecture
specific library code (vsprintf...)target platform
directory -which contains platform specific code Note: Linux ports to processors without memory management units(MMU) are also available. documentation: This subdirectory contains the
documentation for the kernel. Drivers: This subdirectory contains
the code for the device drivers. Each type of device has subdirectories, such as char, block,
net... fs: This directory contains the
file system code. This has further subdirectories for each supported file
system (ext2, proc, ...) include: The include
subdirectory contains the include files for the kernel. It has further
subdirectories for common include files for all architectures), one for every
architecture supported. init-This
directory contains the initialization code for the kernel. kernel-This
directory contains the main kernel code. lib-This
directory contains the library code of the kernel. mm-This
directory contains the memory management code.The
directory structure of the LINUX sources/usr/src/linux Kernel Development on x86 platform The Linux kernel development requires following steps: ü
Selecting kernel ü
Configuring kernel ü
Compiling kernel ü
Installing the kernel Access to the kernel sources Download sources from http://kernel.org/pub/linux/kernel/v2.6/linux2.6.7.tar.bz2 http://kernel.org/pub/linux/kernel/v2.6/linux2.6.7.tar.bz2.sign Or get a patch vsthe x.y.<z1> version: ftp://ftp.kernel.org/pub/linux/kernel/v2.6/patch2.6.7.bz2 ftp://ftp.kernel.org/pub/linux/kernel/v2.6/patch2.6.7.bz2.sign Check the integrity of sources: gpg–verify linux2.6.7.tar.bz2.sign linux2.6.7.tar.bz2 GnuPG details:
http://www.gnupg.org/gph/en/manual.html Kernel source signature details: http://www.kernel.org/signature.html Using the Patch command ü
patch
command: uses the output of the diff command to apply a set of changes to a
source tree. ü
patch basic usage:patch
-pn< diff_file n:
number of directory levels to skip ü
Linux patches: Always to apply to the x.y.<z1> version Always produced for n=1 patch -p1 < linux_patch Kernel Configuration The Linux kernel configuration is usually found in the
kernel source in the file: /usr/src/linux/.config. The
kernel can be configured using text mode or graphical configurator. ü
make config-starts
a character based questions and answer session ü
make menuconfig-starts
a terminal-oriented configuration tool (using ncurses) ü
make xconfig-starts
a X based configuration tool Kernel Configuration… Makefile edition
Setting the version and target architecture if needed Kernel configuration: defining what features to include in
the kernel: make xconfig or make menuconfig or make oldconfig Kernel configuration file (Makefile
syntax) stored in the .config file
at the root of the kernel sources Distribution kernel config files
usually released in /boot/ MakefileChanges To identify your kernel image with others build from the
same sources, use the EXTRAVERSION variable: VERSION = 2 PATCHLEVEL = 6 SUBLEVEL = 7 EXTRAVERSION = -acme1 uname–r will return: 2.6.7-acme1 Kernel Configuration… When the kernel configuration runs, it reads the main kernel
configuration file, located in arch/i386/Kconfig. This configuration file also includes other configuration
files as needed. For example arch/i386/Kconfigfile
includes source
"sound/core/Kconfig" Which includes source
"sound/core/Kconfig" source "sound/drivers/Kconfig" Compiling and installing Kernel make make
install make modules_install Building Kernel The "make" command (with
no arguments) now automatically (and silently) generates dependency information,
compiles the kernel, and compiles any drivers that you have selected for
installation as modules. Once you have configured your kernel, simply issuing the
make command, followed by the make install and
make
modules_install commands, is the most
common build and install procedure for 2.6-based kernels. Makes changes in the grub.conf
file Copies modules to /lib/modules/<kernel version>/ Linux Initialization for Intel Platforms –Boot Process 1.
A boot loader finds the kernel image on
the disk, loads it into memory, and starts it. 2.
The kernel initializes the devices and
its drivers. 3.
The kernel mounts the root filesystem. 4.
The kernel starts a program called
init. 5.
init
sets the rest of the processes in motion. 6.
The last processes that init starts as
part of the boot sequence allow you to log in. Boot Loaders Before the kernel runs init, a boot loader starts the
kernel. Sometimes, you need to tell the boot loader to load different kernels
or operating systems, and to start in different modes. The boot loader loads a
kernel image into memory and hands control of the CPU to the new image,
possibly supplying it with some parameters. LILO LILO can load the kernel from a variety of media, including
floppy disks, hard disks and some flash devices (configured to operate as hard
disks). LILO can be configured to pass startup parameters to the
Linux kernel during the bootstrap process. Depending on the configuration, you
can customize the startup screens for embedded device, and control other
aspects of the initialization and runtime configuration that LILO boots. LILO can also be configured to load a special filesystem,
referred to as an initial RAM disk, or initrd, that
can augment the bootstrap sequence in certain ways GRUB GRUB stands for Grand Unified Bootloader,
a system that is slowly replacing LILO. The most important feature is its ability to navigate filesystems, so you can read files without loading a
kernel. GRUB has a menu interface that’s easy enough to navigate,
but ifyou need to boot from a different kernel,
change the root partition,or
supply extra kernel parameters, you should get into the mini-shell. Initialization Overview When the operating system starts, the kernel runs /sbin/init. This can be either a script or a program, but
typically it is a program that processes the statements in /etc/initab. The default inittab file tells
init to run the commands in the file/etc/rc.d/rcS. In
addition, init spawns programs to present login prompts on two virtual
terminals. Init Runlevels: The idea behind operating different services at different runlevelsessentially revolves around the fact that
different systems can be used in a different ways.Thefollowing
runlevelsare defined in Red Hat Linux
: ü
0 -Halt ü
1 -Single-user mode ü
2 -Multi-user mode, without networking ü
3 -Full multi-user mode ü
4 -Not used ü
5 -Full multi-user mode (with an
X-based login screen) ü
6 -Reboot; The
default runlevelfor a system to boot to and stop is
configured in /etc/inittab. Adding a new module (hello) to the Build process 1. Make a directory -drivers/hello Create or Copy file -Kconfig, Makefile, hello.c hello.c-A simple kernel module Kconfig-Add following statements # #
hello module configuration # menu
"Hello Module support" config HELLO tristate "Include Hello module?" ---help--- Linux Kernel Module
demonstration –Hello endmenu Makefile-Add following statement obj-$(CONFIG_HELLO) +=
hello/ Adding a new module (hello) to the Build process… 2. Add the following statement before endmenu statement: source "drivers/hello/Kconfig" And add the following statement at the end of file in Makefile: obj-$(CONFIG_HELLO) += hello.o 3. Config, Build and Deploy the kernel. make
xconfig Look at the menu item displayed under drivers. Select and save the configuration and exit. Look for CONFIG_HELLO in .configfile |