You are on page 1of 71

Linux Kernel Basic

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

Hardware Basic Knowledge


CPU Architecture MMU

CPU Architecture
Control Unit Arithmetic Logic Unit Registers Program Counter Instruction Register Cache Translation Lookaside Buffer


Protected Mode pmode. pmode 80286 x86 CPU x86 LinuxFreeBSD Windows 2.0

MMU
MMUMemory Management Unit CPU MMU
- -

X86 MMU4K/2M/4MPAGE


CPU CPU


0 1 2 3 COM2

4
5 6 7 8

COM1
LPT2 LPT1

9
10 11 12 13

PC
Available Available PS/2

14
15 NM1

Available

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

OS Basic Knowledge

- -

RTOS POSIX

IPC
GUI

RTOS
Real Time Operating SystemRTOS .
- -


- =+CPU+ISR - =MAX() + ISR

RTOSVxWorks, uC/OS.

POSIX
POSIX Portable Operating System Interface of Unix POSIX UNIX Institute of Electrical and Electronics EngineersIEEE POSIX UNIX POSIX UNIX DEC OpenVMS Windows NT POSIX IEEE Std. 1003.1-19901995 POSIX.1POSIX.1 C API POSIX.1 International Standards OrganizationISO ISO/IEC 99451:1990

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

Linux Kernel Intro


Kernel Kernel Linux Kernel


2.0.35 2.1.88

Kernel
patch linux kernel - linux-2.2.16 linux-2.2.17

linux-2.2.17
patch - patch patch-xx.xx.xx.bz2, bzip2

gzip .gz

patch
- patch /usr/src : bzip2 -cd patch-xx.xx.xx.bz2 | patch -p0

- patch p -p0-p1 patch


linux/xxxx/file.c p0 /xxxx-p1 xxxx/file.c

Where is Linux kernel?


Official website: http://www.kernel.org Bug report:

http://bugzilla.kernel.o
rg Mail archive site:


UCLinux RTLinux

Linux Kernel
Linux Distribution 300Linux Linux

Linux Distribution
1. 2. MBRLILO, GRUB 3. CDE/KDE/GNOME 4. X WindowXfree86 5. DNS/HTTP/SMTP/FTP/NNTP/PPP

6. NFSSamba
7. mysqlPostgreSQLDB2Oracle 8 Sybase

8. Netscape/StarOffice/xIRC/LICQ/Gimp/x11amp
9. //DPM / RPM

300Linux
Debian fedora Suse dubuntu Ubuntu Mandriva archlinux Slackware turbolinux gentoo lfs magiclinux LINUX linux centos caos 2x 64 Studio Abuldu Adamantix ADIOS Admelix Alinex aLinux ALT amaroK Live Amber Annvix AnNyung ANTEMIUM APODIO Arabian ArcheOS Archie Ark Arudius AsianLinux Asianux ASLinux ASPLinux Astaro Asterisk Athene ATmission Atomix Aurora Aurox AUSTRUMI Hubworx B2D BackTrack Bayanihan BeatrIX Berry BIG LINUX BioBrew Bioknoppix blackPanther BLAG Blin Bluewall Buffalo Caixa Mgica Ctix CCux CDlinux Censornet ClarkConnect Clusterix clusterKNOPPIX Condorux Cosix Coyote CRUX Damn Small Danix DARKSTAR DeadCD Deep-Water DeLi AGNULA Devil Dizinha DNALinux Dreamlinux P!tux dyne:bolic Eadem Edubuntu eduKnoppix EduLinux Ehad eLearnix Elive ELX EnGarde ERPOSS ESware Euronode Evinux EzPlanet One FAMELIX Feather Featherweight Fermi Finnix Flash Flonix Foresight FoRK FoX Desktop Freedows Freeduc Freeduc-Sup GNIX Gnoppix GNUstep GobLinX GoboLinux Grafpup grml Guadalinex h3knix Haansoft Hakin9 Hancom Hedinux Helix Hikarunix Hiweed HKLPG Holon Honeywall How-Tux iBox IDMS Ignalum Impi ndLinux INSERT IPCop Slack JoLinux Julex K12LTSP Kaella Kalango KANOTIX Karamad Kate OS K-DEMar Kinneret Klax kmLinux knopILS Knoppel Knopperdisk KNOPPIX Knoppix 64 KnoppiXMAME Knoppix STD KnoppMyth KnoSciences Komodo Kororaa Kubuntu Kurumin L.A.S LG3D LIIS Linare Lineox LinEspa gnuLinEx LinnexOS Linpus Linspire LinuxConsole Linux-EduCD LINUXO LinuxLive LinuxTLE Linux XP Litrix LiveCD Router LiVux LLGP LliureX LNX-BBC Loco Lormalinux Luit Lunar MAX Mayix MCNLive Media Lab Mediainlinux MEPIS Miracle Mockup MoLinux Momonga Monoppix Morphix MoviX Muriqui Murix Musix Mutagenix Myah OS myLinux Nasgaa Natures Navyn OS NepaLinux Netwosix Niigata Nitix Nonux NST NuxOne Omoikane Onebase O-Net OpenLab OpenLX OpenNA Openwall Oralux Overclockix PaiPix ParallelKnoppix Pardus Parsix PCLinuxOS Peachtree Penguin Sleuth Pentoo Pequelin Phaeronix Phayoune PHLAK Pie Box Pilot Pingo Pingwinek Plamo PLD pocketlinux Poseidon pQui Progeny Project dEv PUD Puppy QiLinux Quantian redWall Resala RIP ROCK Rocks Cluster ROOT ROSLIMS rPath Linux4all RR4/RR64 Rubix Heretix RUNT Salvare SAM Santa Fe Scientific Securepoint Sentry Firewall Shabdix Skolelinux Slackintosh Slamd64 SLAMPP SLAX Slix Slo-Tech SLYNUX SME Server SmoothWall SNAPPIX Snfrix SoL Sorcerer Source Mage StartCom StressLinux STUX STX SuliX Symphony OS SystemRescue T2 TA-Linux Tablix Tao Taprobane Thinstation Tilix tinysofa Topologilinux Trinity Trustix Truva TumiX TupiServer Turkix Ufficio Zero UHU-Linux Ultima Underground Ututo Vector VLOS Vine VNLinux Voltalinux Wazobia White Box WIENUX Wolvix WOMP! Xandros Xarnoppix Xenoppix X-evian Xfld X/OS Xteam Yellow Dog Yoper YES Zenwalk ZerahStar ZoneCD Frugalware FTOSX GeeXboX Gelecek GenieOS GentooTH Gentoox GEOLivre Gibraltar Ging Caixa

Linux
Ubuntu openSUSE Fedora Debian GNU/Linux Mandriva Linux PCLinuxOS MEPIS Linux KNOPPIX Slackware Linux Gentoo Linux

Linxu

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

Kernel Design Goals


performance: efficiency, speed
- utilize resources to capacity, low overhead, code size

stability: robustness, resilience


- uptime, graceful degradation

capability: features, flexibility, compatibility security, protection


- protect users from each other, secure system from bad guys

portability

clarity
extensibility

Linux Features
UNIX-like operating system all the features you would expect in a modern UNIX - preemptive multitasking - virtual memory (protected memory, paging) - shared libraries - demand loading, dynamic kernel modules - shared copy-on-write executables - TCP/IP networking other features: - SMP support, large memory, large files - advanced networking, advanced filesystems - efficient, stable, highly portable, supports most device hardware - active development community, support, documentation, open source - GUIs, applications

Linux

OS

System Call Interface(POSIX.1),shell, GUI, Compiler, Library, etc.

Module Interface

Modules

Linux Kernel
Device Driver Interface

Linux

Device Drivers

CPU Disk

Other Devices

Linux
1. S C H E DC P U C P U 2. M M

3. V F S V F S V F S
4. N E T

5. I P C
linuxmonolithic windows(microkernel)

Vahalias Diagram
From Unix Internals: The New Frontiers Uresh Vahalia / Prentice-Hall 1996

a.out file device virtual memory framework

elf

coff
NFS exec switch FFS

anonymous

vnode/vfs interface core utilities

s5fs

disk

block device switch STREAMS

scheduler framework

time-sharing

real-time tape system

network

tty

Stephen Tweedies Diagram


User Processes Scheduler Syscalls VM Traps

Process Manager

Socket Manager

VFS

Memory Allocator

Math Support

Network Protocols

File Systems

Char Devices
Block Devices

Packet Requestor
Net Devices

IO Requestor

Waterloo Diagrams
mm fs ipc

sched vfs sched ipc mm net net

Conceptual

Concrete

Another Diagrams
Applications

System Libraries (libc)


System Call Interface

I/O Related
Modules File Systems Networking Device Drivers

Process Related Scheduler Memory Management IPC

Architecture-Dependent Code Hardware

Linux Kernel Source Tree 1/2


An Overview of the source tree Linux/arch Linux/drivers Linux/fs Linux/include

Linux/Init
Linux/ipc Linux/kernel Linux/lib

Linux Kernel Source Tree 2/2


Linux/mm Linux/net Linux/script Tree Summary

Source Tree Layout


Documentation init arch drivers fs include lib mm /usr/src/linux scripts ipc kernel net

alpha arm i386 ia64 m68k mips mips64 ppc s390 sh sparc sparc64

acorn atm block cdrom char dio fc4 i2c i2o ide ieee1394 isdn macintosh misc net

adfs affs autofs autofs4 bfs code cramfs devfs devpts efs ext2 fat hfs hpfs

asm-alpha asm-arm asm-generic asm-i386 asm-ia64 asm-m68k asm-mips asm-mips64 linux math-emu net pcmcia scsi video

adfs affs autofs autofs4 bfs code cramfs devfs devpts efs ext2 fat hfs hpfs

802 appletalk atm ax25 bridge core decnet econet ethernet ipv4 ipv6 ipx irda khttpd lapb

linux/Documentation
spotty but important collection of developer-generated documentation; you need to read whats in here! recent effort to produce javadoc-style documentation from source header comments using OpenDoc an ambitious open-source kernel book effort has begun; see kernelbook.sourceforge.net for details some especially interesting entries:
kernel-docs.txt (a bit out of date but good) filesystems/ (very extensive) networking/ (very extensive) kmod.txt oops-tracing.txt spinlocks.txt (the official story from Linus)

linux/arch
subdirectories for each current port each contains kernel, lib, mm, boot and other directories whose contents override code stubs in architecture independent code lib contains highly-optimized common utility routines such as memcpy, checksums, etc.

arch as of 2.4:
- alpha, arm, i386, ia64, m68k, mips, mips64 - ppc, s390, sh, sparc, sparc64

linux/drivers
largest amount of code in the kernel tree (~1.5M) device, bus, platform and general directories drivers/char n_tty.c is the default line discipline

drivers/block elevator.c, genhd.c, linear.c, ll_rw_blk.c, raidN.c


drivers/net specific drivers and general routines Space.c and net_init.c drivers/scsi scsi_*.c files are generic; sd.c (disk), sr.c (CD-ROM), st.c (tape), sg.c (generic) general: - cdrom, ide, isdn, parport, pcmcia, - pnp, sound, telephony, video buses fc4, i2c, nubus, pci, sbus, tc, usb platforms acorn, macintosh, s390, sgi

linux/fs
contains:
- virtual filesystem (VFS) framework - subdirectories for actual filesystems

vfs-related files:
- exec.c, binfmt_*.c - files for mapping new process images - devices.c, blk_dev.c device registration, block device support - super.c, filesystems.c - inode.c, dcache.c, namei.c, buffer.c, file_table.c - open.c, read_write.c, select.c, pipe.c, fifo.c - fcntl.c, ioctl.c, locks.c, dquot.c, stat.c

linux/include
include/asm-* - architecture-dependent include subdirectories include/linux - header info needed both by the kernel and user apps - usually linked to /usr/include/linux - kernel-only portions guarded by #ifdefs - #ifdef __KERNEL__ /* kernel stuff */ - #endif other directories: - math-emu - net - pcmcia - scsi - video

linux/init
just two files: version.c, main.c version.c contains the version banner that prints at boot main.c architecture-independent boot code start_kernel is the primary entry point

linux/ipc
System V IPC facilities if disabled at compile-time, util.c exports stubs that simply return ENOSYS one file for each facility:
- sem.c semaphores - shm.c shared memory - msg.c message queues

linux/kernel
the core kernel code sched.c the main kernel file
- scheduler, wait queues, timers, alarms, task queues

process control
- fork.c, exec.c, signal.c, exit.c - acct.c, capability.c, exec_domain.c

kernel module support


- kmod.c, ksyms.c, module.c

other operations
- time.c, resource.c, dma.c, softirq.c, itimer.c - printk.c, info.c, panic.c, sysctl.c, sys.c

linux/lib
kernel code cannot call standard C library routines files:
brlock.c Big Reader spinlocks cmdline.c kernel command line parsing routines errno.c global definition of errno inflate.c gunzip part of gzip.c used during boot string.c portable string code
- usually replaced by optimized, architecture-dependent routines

- vsprintf.c libc replacement

linux/mm
paging and swapping - swap.c, swapfile.c (paging devices), swap_state.c (cache) - vmscan.c paging policies, kwapd - page_io.c low-level page transfer allocation and deallocation - slab.c slab allocator - page_alloc.c page-based allocator zone allocator - vmalloc.c kernel virtual-memory allocator memory mapping - memory.c paging, fault-handling, page table code - filemap.c file mapping - mmap.c, mremap.c, mlock.c, mprotect.c

linux/net
changing too fast!

linux/scripts
scripts for:
- menu-based kernel configuration - kernel patching - generating kernel documentation

Sizes (linux-2.4.0)
size 90M 4.5M 16.5M 54M directory /usr/src/linux/ Documentation arch drivers entries 19 97 12 31 files 7645 380 1685 2256 loc 2.6M na 466K 1.5M

5.6M
14.2M 28K 120K 332K 80K 356K 5.8M 400K

fs
include init ipc kernel lib mm net scripts

70
19 2 6 25 8 19 33 26

489
2262 2 6 25 8 19 453 42

150K
285K 1K 4.5K 12K 2K 12K 162K 12K

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

Diffent of Each Linux Kernel


2.4 2.6

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Source Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

Development Tools Intro


Vi/Vim GNU
- GCC - GDB - GNU Debuger

CVS/SVN

VI / VIM
Basic and powerful editor on Linux.

GNU
GCC
- LinuxgccGNU C CompilerGNU GNU gcc 20%~30%

GDB
- Linux gdb GNU . gdb C C++ . .

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

Build Linux Kernel


Configuring Compiling Build Root File Sytem Configure BootLoader


Linux
- Makefile Linux Makefile Linux - config.in - Ncurses Xwindows Make configMake menuconfig make xconfig

Tcl/TKPerl C


Makefile Linux config.in Linux , :

Make config, make oldconfig Make menuconfig Make xconfig

scripts/Configure scripts/Menuconfig scripts/tkparse

Makefile
Makefile Linux Linux Makefile Linux Makefile Makefile - Makefile Makefile - .config make config - arch/*/Makefile CPU Makefile arch/arm/Makefile Makefile - Makefile drivers/Makefile - Rules.make Makefile make config .config Makefile .config Makefile vmlinux module Makefile Makefile Makefile include arch/$(ARCH)/Makefile CPU Makefile Makefile Makefile .config include $(TOPDIR)/Rules.make Rules.make Makefile c Makefile

Configure Options 1/2


1. Code maturity level options () 2. Loadable module support () 3. Block layer ()

4. Processor type and features ()


5. Power management options () 6. Bus options (PCI, PCMCIA, EISA, MCA, ISA) () 7. Executable file formats () 8. Networking () 9. Device Drivers ()

Configure Options 2/2


10. File systems () 11. Instrumentation Support () 12. Kernel hacking (hack)

13. Security options ()


14. Cryptographic options () 15. Library routines ( )

Configure Option list


Linux2.6.19 Basic/kernel options.html

Standard Process of Build Linux Kernel


cd /usr/src/linux-2.6.x make menuconfig (or make xconfig) make dep

make clean
make bzImage make modules make modules_install make install Use the command ls -l /boot to make sure the initrd-2.6.x.img file was created. Confirm that the file /boot/grub/grub.conf contains a title section with the same version as the kernel package just installed Reboot

Build
Build

Agenda
Hardware Basic Knowledge OS Basic Knowledge Linux Kernel Intro Linux Kernel Source Architecture Difference of Each Linux Kernel

Development Tools Intro


Build Linux Kernel Linux Kernel and Embedded System

Linux Kernel an Embedded Sytem


Embedded system overview Build Linux cross-compile environment Real time optimize Customize Porting

End

Any Questions?

You might also like