chapter 2 - Hello World Model

Slides:



Advertisements
Similar presentations
DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Advertisements

Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Computer System Laboratory
Building and Running Modules Sarah Diesburg COP 5641.
Building and Running Modules Linux Kernel Programming CIS 4930/COP 5641.
CIS238/DL1 Chapter 15 Rebuilding the Linux Kernel Preparing the Source Code Locating the Source Code Installing the Source Code Read the Documentation.
Building and Running Modules Ted Baker  Andy Wang CIS 4930 / COP 5641.
52 Advanced Operating Systems Writing Device Drivers.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
Embedded System Programming Introduction to Device Drivers.
CS 635 Advanced Systems Programming Spring 2005 Professor Allan B. Cruse University of San Francisco.
CS 635 Advanced Systems Programming Fall 2007 Professor Allan B. Cruse University of San Francisco.
Add a New System Call to Linux. Hw1 Add a New System Call to Linux and Compile Kernel Add a New System Call to Linux by Kernel Module.
Tutorial and Demos on Linux Virtual Machine
1 Netfilter in Linux Bing Qi Department of Computer Science and Engineering Auburn university.
CSCI S-1 Section 3. Deadlines for Homework 2 Problems 1-8 in Parts C and D – Friday, July 3, 17:00 EST Parts E and F – Tuesday, July 7, 17:00 EST.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
1 Week 6 Intro to Kernel Modules, Project 2 Sarah Diesburg Florida State University.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
NCHU System & Network Lab Lab 3 System Call Operating System Lab.
For OS Experiments. What Do We Need? A Computer &
JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl,
Sogang University Advanced Operating Systems (Linux Module Programming) Sang Gue Oh, Ph.D.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
Linux Kernel Management. Module 9 – Kernel Administration ♦ Overview The innermost layer of Linux operating system is the kernel, which is a thin layer.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
Interfacing Device Drivers with the Kernel
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
Kernel Modules – Introduction CSC/ECE 573, Sections 001 Fall, 2012.
1 Intro to Kernel Modules and /proc Sarah Diesburg CS 3430 Operating Systems.
1 Setup and Compile Linux Kernel Speaker: Yi-Ji Jheng Date:
Virtual Memory Mohammad H. Mofrad February 23, 2016
Rebuilding Linux Kernel Dedicated to penguin lovers everywhere 26 September 20161Rebuilding kernel by Visakh M R.
Multiple file project management & Makefile
Add a New System Call to Linux
OS – Ex 1 Nezer J. Zaidenberg.
Device Driver_Skeleton
Python’s Modules Noah Black.
Formatting Output & Enumerated Types & Wrapper Classes
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Chapter 1: A Tour of Computer Systems
Linux Kernel Module Programming
Kernel module & Syscall Hijacking
Computer System Laboratory
Linking & Loading.
Drivers and the kernel UNIX system has three layers: Kernel
Linux Kernel Module Programming
COSC 350 System Programming
CS-3013 Operating Systems C-term 2008
Want to play a game? – Linux Kernel Modules
Intro to Kernel Modules and /proc
IS3440 Linux Security Unit 7 Securing the Linux Kernel
CS 6560 Operating System Design
Operation System Program 1
Kernel – Device Drivers (part 2)
Lab 4 Kernel Module Operating System Lab.
Linking & Loading CS-502 Operating Systems
Tutorial: The Programming Interface
CS 6560 Operating System Design Kernel Loadable Modules
Implementation of Embedded OS
Computer System Laboratory
Introduction to Linux device driver
Linking & Loading CS-502 Operating Systems
A very basic introduction
Presentation transcript:

chapter 2 - Hello World Model chenbo2008@ustc.edu.cn 中国科学技术大学软件学院

《Linux Device Driver 3rd》 Definition: Device drivers take on a special role in the Linux kernel. They are distinct “black boxes” that make a particular piece of hardware respond to a well-defined internal programming interface; they hide completely the details of how the device works. 《Linux Device Driver 3rd》

MODULE_LICENSE(); module_init(); module_exit(); Unless your module is explicitly marked as being under a free license recognized by the kernel, it is assumed to be proprietary, and the kernel is “tainted” when the module is loaded. In include/linux/module.h, line 126 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)

MODULE_LICENSE(); module_init(); module_exit(); In include/linux/init.h, line 213 212 /* Each module must use one module_init(), or one no_module_init*/ 213 #define module_init(initfn) \ 214 static inline initcall_t__inittest(void) \ 215 { return initfn; } \ 216 intinit_module(void) __attribute__((alias(#initfn))); 217 218 /* This is only required if you want to be unloadable. */ 219 #define module_exit(exitfn) \ 220 static inline exitcall_t__exittest(void) \ 221 { return exitfn; } \ 222 void cleanup_module(void) __attribute__((alias(#exitfn)));

This module contains kernel function printk(),It behaves similarly to the standard C library function printf. In kernel/printk.c, line 502 502 asmlinkage int printk(constchar *fmt, ...) 503 { 504 va_listargs; 505 intr; 506 507 va_start(args, fmt); 508 r = vprintk(fmt, args); 509 va_end(args); 510 511 return r; 512 }

Why using printk()? The kernel needs its own printing function because it runs by itself, without the help of the C library. In kernel/printk.c, line 502 502 asmlinkage int printk(constchar *fmt, ...) 503 { 504 va_listargs; 505 intr; 506 507 va_start(args, fmt); 508 r = vprintk(fmt, args); 509 va_end(args); 510 511 return r; 512 }

Now, can you explain why kernel source tree is required in building device driver? In kernel/printk.c, line 502 502 asmlinkage int printk(constchar *fmt, ...) 503 { 504 va_listargs; 505 intr; 506 507 va_start(args, fmt); 508 r = vprintk(fmt, args); 509 va_end(args); 510 511 return r; 512 }

KERNELDIR = /usr/src/linux PWD := $(shell pwd) #INSTALLDIR = /home/tekkaman/working/rootfs/lib/modules CC = $(CROSS_COMPILE)gcc obj-m := hello.o moudles: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: cp hello.ko $(INSTALLDIR) clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

#make #insmod ./hello.ko #rmmod hello % make make[1]: Entering directory `/usr/src/linux-2.6.18' CC [M] /root/test/hello.o Building modules, stage 2. MODPOST CC /root/test/hello.mod.o LD [M] /root/test/hello.ko make[1]: Leaving directory `/usr/src/linux-2.6.18' % su root#

[root@bc root]#insmod hello.ko [root@bc root]#hello world enter[root@bc root]#rmmod hello [root@bc root]#hello world exit [root@bc root]#dmesg -c

Compiling kernel modules(An Example) The make file accompany the example KERNELDIR = /usr/src/linux PWD := $(shell pwd) #INSTALLDIR = /home/rootfs/lib/modules #CROSS_COMPILE = /usr/local/arm/2.95.3/bin/arm-linux- CC = $(CROSS_COMPILE)gcc obj-m := hello.o moudles: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: cp hello.ko $(INSTALLDIR) clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

Compiling kernel modules(An Example)

Compiling kernel modules(An Example)

thank you !