Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.

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

Linux device-driver issues
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
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
Lab 4 Department of Computer Science and Information Engineering National Taiwan University Lab4 - Bootloader 2014/10/14/ 13 1.
52 Advanced Operating Systems Writing Device Drivers.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
Embedded Systems Programming Writing Device Drivers.
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.
Tutorial and Demos on Linux Virtual Machine
Computer System Laboratory
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
COMPUTER SYSTEM LABORATORY Lab8 - Debugging II. Lab 8 Experimental Goal Learn how to debug Linux in source-level by Domingo and diagnose target boards.
An Introduction to Device Drivers Sarah Diesburg COP 5641 / CIS 4930.
COMPUTER SYSTEM LABORATORY Lab4 - Bootloader. Lab 4 Experimental Goal Learn how to build U-Boot bootloader for PXA /10/8/ 142.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
Operating System Program 5 I/O System DMA Device Driver.
Lab 3 Department of Computer Science and Information Engineering National Taiwan University Lab3 - Cross Tools 2014/10/7/ 20 1.
Computer System Laboratory
COMPUTER SYSTEM LABORATORY Lab10 - Sensor II. Lab 10 Experimental Goal Learn how to write programs on the PTK development board (STM32F207). 2013/11/19/
For OS Experiments. What Do We Need? A Computer &
Computer System Laboratory
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Input Systems (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
Lab 11 Department of Computer Science and Information Engineering National Taiwan University Lab11 - Porting 2014/12/9/ 26 1.
COMP 3438 – Part I - Lecture 4 Introduction to Device Drivers Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Lab 1 Department of Computer Science and Information Engineering National Taiwan University Lab1 - Sensor 2014/9/23/ 13 1.
Sogang University Advanced Operating Systems (Linux Module Programming) Sang Gue Oh, Ph.D.
Lab 10 Department of Computer Science and Information Engineering National Taiwan University Lab10 – Debugging II 2014/12/2 1 /16.
COMPUTER SYSTEM LABORATORY Lab6 - Root Filesystem.
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.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
Lab 14 Department of Computer Science and Information Engineering National Taiwan University Lab14 – Camera 2014/12/30 1 /14.
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13 – Interrupt + Timer 2014/12/23 1 /16.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
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.
An Introduction to Device Drivers Ted Baker  Andy Wang COP 5641 / CIS 4930.
Interfacing Device Drivers with the Kernel
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
OS Project 0 February 25, Outline  Linux Installation  Linux Kernel Compilation  System Call Development  Kernel Modules / 452.
Implementation of Embedded OS Lab4 Cortex-M3 Programming.
Implementation of Embedded OS Lab3 Porting μC/OS-II.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Lab 5 Department of Computer Science and Information Engineering National Taiwan University Lab5 – Bootloader + OS Kernel 2015/10/27/ 25 1.
Lab 8 Department of Computer Science and Information Engineering National Taiwan University Lab8 - Root Filesystem 2015/11/10/ 22 1.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
Implementation of Embedded OS
Lab 5 Department of Computer Science and Information Engineering National Taiwan University Lab5 - OS Kernel 2014/10/21/ 16 1.
Kernel Modules – Introduction CSC/ECE 573, Sections 001 Fall, 2012.
1 Intro to Kernel Modules and /proc Sarah Diesburg CS 3430 Operating Systems.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
Virtual Memory Mohammad H. Mofrad February 23, 2016
Lecture 3 Module Programming and Device Driver (Homework#1 included)
Linux Kernel Module Programming
Computer System Laboratory
Implementation of Embedded OS
Computer System Laboratory
Linux Kernel Driver.
Introduction to the Kernel and Device Drivers
An Introduction to Device Drivers
Intro to Kernel Modules and /proc
Operation System Program 1
Lab 4 Kernel Module Operating System Lab.
Implementation of Embedded OS
Computer System Laboratory
Computer System Laboratory
Loadable Kernel Modules
Presentation transcript:

Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Understand the architecture of Linux device drivers and learn how to control the LCD of PXA /12/16 2 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Host System  Windows XP  Build System  VirtualBox + Ubuntu 8.04  Target System  Creator XScale PXA270  Software  Linux kernel, please refer to Lab5  BusyBox, please refer to Lab6  Creator PXA270 LCD driver  You can download all software from RSWiki CSL Course SoftwareRSWiki CSL Course Software 2014/12/16 3 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  What are device drivers?  Make a particular piece of hardware respond to a well-defined internal programming interface.  Hide completely the details of how the device works.  User activities are performed by means of a set of standardized calls that are independent of the specific driver.  Mapping those calls to device-specific operations that act on real hardware is then the role of a device driver. 2014/12/16 4 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  There are three fundamental types of Linux device drivers.  Character device driver  Block device driver  Network device driver  We will only learn how to write character device drivers in this Lab. 2014/12/16 5 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  A Linux device driver can be divided into two parts.  Virtual device driver  Physical device driver 2014/12/16 6 /21 filenamedescription typ e major numb er minor numb er /dev/ttyS 0 First UART serial port ch ar 464 User Kernel Device Driver Hardware Device File implement chipset control functions define I/O wrapper functions define chipset header implement system calls register driver (VFS) define file_operations Virtual Device Driver Physical Device Driver

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Define file_operations and implement system calls. #include struct file_operations dev_fops = { open: dev_open, read: dev_read, write: dev_write, release: dev_release, ioctl: dev_ioctl, }; 2014/12/16 7 /21 Implement these functions

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Register a character device driver in the initial function. int register_chrdev(unsigned int major, const char *name, struct file_operations *fops);  Unregister a character device driver in the exit function. int unregister_chrdev(unsigned int major, const char *name); 2014/12/16 8 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Two common approaches to access hardware.  Memory mapped I/O  Port I/O  Memory mapped I/O:  Access I/O (port) in the same way as that memory is accessed.  For example, there is a device that has a 8 bit I/O port connected to the system, and its address is mapped at 0x We can read and write the I/O port like this: #define DATA_PORT (*(volatile char*)(0x10000)) char read_b() {return DATA_PORT;} void write_b(char data) {DATA_PORT = data;} 2014/12/16 9 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Port I/O:  If the I/O system has its own address independent of memory, then it is port I/O.  Register the I/O port. E.g., 0x378. if (check_region(0x378, 1)) { printk(" parallelport: cannot reserve 0x378\n"); } else { request_region(0x378, 1, "demo"); }  Use the I/O commands. char data = inb(0x378);//Read data form the port 0x378 outb(data, 0x378); //Write data to the port 0x378  Release I/O port. release_region(0x378, 1); 2014/12/16 10 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  In Linux, devices are accessed in the same way as that files are accessed.  These device files are normally in the /dev directory.  We can create a device file by the following command.  % mknod /dev/demo c  More details about mknod can be found at  鳥哥的 Linux 私房菜. 鳥哥的 Linux 私房菜  So, we can manipulate the device via reading/writing its device file.  Most Linux drivers are implemented as kernel modules. 2014/12/16 11 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  A kernel module is an object file that contains code to extend the running kernel of an operating system.  Typically used to add support for new hardware and/or filesystems, or for adding system calls.  When the functionality provided by an kernel module is no longer required, it can be unloaded in order to free memory and other resources. 2014/12/16 12 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  % insmod module.ko  This command is used to insert a module into the kernel.  It doesn’t modify the module’s disk file, but rather than in-memory copy.  % rmmod module.ko  This command is used to remove a module from the kernel.  This command invokes the delete_module() system call, which calls cleanup_module() in the module itself if the usage count is zero or returns an error otherwise.  % lsmod  List the module currently linked to Linux. 2014/12/16 13 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University #include #include #include static int init_demo(void) { printk("Hello World!\n"); return 0; } static void cleanup_demo(void) { printk("Goodbye World!\n"); } module_init(init_demo); module_exit(cleanup_demo); MODULE_LICENSE("Dual BSD/GPL"); 2014/12/16 14 /21 initial function cleanup function declaration of initial/cleanup functions

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Note that the messages in printk will be showed in the kernel, you can use dmesg command to check the messages.  We need to compile this module with kernel, and the result will be demo.ko. Here is the example of Makefile. CC = arm-unknown-linux-gnu-gcc obj-m := demo.o all: make -C M=$(PWD) modules clean: make -C M=$(PWD) clean 2014/12/16 15 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Open the file /dev/demo and test its read and write functions just like a normal file. #include #include #include int main() { int fd, data; if((fd = open("/dev/demo", O_RDWR)) < 0) { printf("couldn't open /dev/demo\n"); return 1; } write(fd, "Hello World!", 13); read(fd, &data, 4); close(fd); return 0; } 2014/12/16 16 /21

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Now we add the PXA270 LCD driver to Linux kernel as a kernel module.PXA270 LCD driver  Step 1: extract the driver, and copy to your Linux kernel source in Lab5.  Step 2: compile modules.  We build the driver as a module.  % make menuconfig  “Device Drivers”  “Character devices”  “Creator-pxa270 LCD”  % make modules  The result creator-pxa270-lcd.ko is in drivers/char/.  Step 3: check these commands lsmod, insmod, rmmod in your root filesystem.  If you don’t have any of these, please refer to Lab6 and copy a new root filesystem 2014/12/16/21 17

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Step 4: transfer creator-pxa270-lcd.ko to PXA270.  Step 5: insert the module to Linux.  % insmod creator-pxa270-lcd.ko  You will see “good” on the 4-Digit 7 segment LED.  Tips  If you want to reload the module, do not forget to remove the running module first.  % rmmod creator-pxa270-lcd.ko 2014/12/16/21 18

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Please refer to previous slides to implement a simple driver for a virtual device demo.  Create the device with major number 60 and minor number 0.  When you initialize module, delete module, open device, close device, read device and write device, please print messages.  E.g., printk(“Open command is issued.”);  You don’t need to implement the “real work” of functions.  Write an application to control the LCD.  Trace the driver code and know how it works.  Do not forget to create the LCD device file.  % mknod /dev/lcd c /12/16/21 19

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  You can refer to the PXA270 LCD driver to implement your demo driver.  See the struct file_operations and know how to implement these system calls.  Also see how to control LCD by ioctl commands.  You may want to define some ioctl commands in your application.  You can refer to Writing device drivers in Linux: A brief tutorial for more information.Writing device drivers in Linux: A brief tutorial 2014/12/16/21 20

Lab 12 Department of Computer Science and Information Engineering National Taiwan University  Show the messages of accessing the demo device.  Including open, close, read, write, initial, remove.  Show more than one message on LCD from applications.  Show your group number, and your student IDs. 2014/12/16/21 21