Introduction to Linux device driver 潘仁義
The role of device driver Flexible Mechanism? Policy? 只提供存取硬體的能力,而不加諸任何限制 介於『應用程式』與『硬體裝置』的軟體層 功能性? 簡潔性?
Splitting the Kernel
Classes of devices and modules Character device Can be accessed as a stream of bytes open, close, read, write /dev/console Block device Can host a filesystem and transfer any number of bytes at a time mount a filesystem Network interface Can exchange data with other hosts packet transmission
Kernel compile and installation Version 2.4.10 above Kernel source http://www.kernel.org/ Make kernel cd /usr/src/linux make clean make menuconfig make dep; make bzImage make modules; make modules_install cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.24 cp .config /boot/config-2.4.24 cp System.map /boot/System.map.2.4.24 lilo; reboot; dmesg
/usr/src/linux directory kernel/ 除了fs, mm, networking外的核心碼 fs/ File system mm/ Memory management net/ Socket library, Protocol stack ipc/ and lib/ Include/ and arch/ driver/ driver/char, driver/block, driver/net
Linux booting process A Guided Tour of a Linux Boot http://ourworld.compuserve.com/homepages/KanjiFlash/BPTour.htm The Linux Boot Process http://oldfield.wattle.id.au/luv/boot.html The Linux Kernel HOWTO http://24.221.230.253/HOWTO/kernel-howto/linux_boot_process.html
Demo example Source Make Run http://www.oreilly.com.tw/chinese/linux/ldd2.html http://www.oreilly.com.tw/bookcode/ldd2-samples-1.0.2.tar.gz Make cd ~/ldd2/misc-modules/ make clean; make Oops? cd /usr/include/ mv linux linux.orig ln –s /usr/src/linux/include/linux/ linux mv asm asm.orig ln –s /usr/src/linux/include/linux/acm/ asm Oops? Again make export.ver #include<slab.h> Run tail –f /var/log/messages insmod ./hello.o MODULE_LICENSE(“GPL”)
作業 裝一台linux, compile kernel, boot 裝上demo code, 執行 eCos eCos home http://www.ecos.sourceware.org/ eCosCentric http://www.ecoscentric.com/ WebCast: A License-Free Alternative RTOS for the G4 PowerPC http://seminar2.techonline.com/~pentek22/sep2303/index.shtml