Computer System Laboratory

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
52 Advanced Operating Systems Writing Device Drivers.
Embedded Systems Programming Writing Device Drivers.
Embedded System Programming Introduction to Device Drivers.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
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.
Device Management. Serial Port Serial Device Serial Device Memory CPU Printer Terminal Modem Mouse etc.
Operating System Program 5 I/O System DMA Device Driver.
Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux.
COMPUTER SYSTEM LABORATORY Lab10 - Sensor II. Lab 10 Experimental Goal Learn how to write programs on the PTK development board (STM32F207). 2013/11/19/
Computer System Laboratory
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.
Lab 10 Department of Computer Science and Information Engineering National Taiwan University Lab10 – Debugging II 2014/12/2 1 /16.
UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform.
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.
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.
Implementation of Embedded OS Lab4 Cortex-M3 Programming.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Implementation of Embedded OS Lab3 Porting μC/OS-II.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
ICOM Noack Linux I/O structure Device special files Device switch tables and fops How the kernel finds a device Parts of a device driver or module.
Lab 8 Department of Computer Science and Information Engineering National Taiwan University Lab8 - Root Filesystem 2015/11/10/ 22 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.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
Input/Output (I/O) Important OS function – control I/O
Computer System Laboratory
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Computer System Laboratory
Linux Kernel Module Programming
Computer System Laboratory
Implementation of Embedded OS
Implementation of Embedded OS
Computer System Laboratory
Computer System Laboratory
Linux Kernel Driver.
Want to play a game? – Linux Kernel Modules
Introduction to the Kernel and Device Drivers
An Introduction to Device Drivers
The slides must be understood in Lecture 5
Computer System Laboratory
CS703 - Advanced Operating Systems
Operation System Program 1
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Implementation of Embedded OS
Computer System Laboratory
Outline Device Management Device Manager Design Buffering
Computer System Laboratory
Computer System Laboratory
Loadable Kernel Modules
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

Computer System Laboratory Lab10 Linux Drivers

Experimental Goal Understand the architecture of Linux drivers and learn how to control LCD LCD Lab8 2019/4/14

Environment Host System Build System Target System Software Windows XP/Ubuntu 8.04 Build System Ubuntu 8.04 Target System XScale PXA270 Software Linux kernel, please refer to Lab5 BusyBox, please refer to Lab6 Creator PXA270 LCD driver, please refer to Lab9 Also include 8-bit LED lamps, 4-digit 7 segment LED and keypad drivers You can download all the source codes from RSWiki CSL Course Software Lab10 2019/4/14

Device Drivers What are the 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 the device driver Lab10 2019/4/14

Linux Device Drivers Why learning Linux driver model? Why Linux? The rate at which new hardware becomes available (and obsolete!) pguarantees that driver writers will be busy for the foreseeable future Why Linux? Linux shares the biggest market for embedded systems Lab10 2019/4/14

Linux Device Drivers (Cont.) Three fundamental types: Character device driver Block device driver Network device driver Other types: USB driver PCI driver …… Lab10 2019/4/14

Writing Linux Drivers A Linux device driver can be divided into two drivers Virtual device driver Physical device driver filename description type major number minor number /dev/ttyS0 First UART serial port char 4 64 User Device File Kernel Device Driver define file_operations register driver (VFS) Virtual Device Driver Hardware implement system calls define chipset header define I/O wrapper functions Physical Device Driver implement chipset control functions Lab10 2019/4/14

Linking Modules to Linux Lab10 2019/4/14

How to Write a Module? A “hello world” example Note that the messages in printk will be showed in the kernel, you can use dmesg command to check the messages Lab10 2019/4/14

Related Commands in Linux insmod module.ko This command is used to insert a module into the kernel The command is like ld, in that it links any unresolved symbol in the module to the symbol table of the running kernel Unlike the linker, however, it doesn’t modify the module’s disk file, but rather than in-memory copy rmmod module_name This command is used to remove a module from the kernel The 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 Lab10 2019/4/14

Writing Driver - Virtual Device Driver Define file_operations and implement system calls Register driver (character device) struct file_operations dev_fops = { open: dev_open, read: dev_read write: dev_write, release: dev_release, ioctl: dev_ioctl, }; int register_chrdev(unsigned int major, const char *name, struct file_operations *fops) Lab10 2019/4/14

Writing Driver - Physical Device Driver Hardware dependent Two common approaches to access hardware, i.e. memory mapped I/O and port I/O Memory mapped I/O: Access I/O (port) in the same way as memory is accessed For example, suppose there is a device that has a 8 bit I/O port connected to the system, and its address is mapped at 0x10000. 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; } Lab10 2019/4/14

Writing Driver - Physical Device Driver (Cont.) 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) Use the I/O commands Release I/O port if (check_region(0x378, 1)) { printk("<1>parallelport: cannot reserve 0x378\n"); } else { request_region(0x378, 1, "demo"); } char data=inb(0x378);//Read(in) data form the port 0x378 outb(data, 0x378); //Write(out) data to the port 0x378 release_region(0x378, 1); Lab10 2019/4/14

Creating Device File In UNIX and Linux, devices are accessed in the same way as files are accessed These device files are normally in the /dev directory We can create device file by the following command: % mknod /dev/demo c 60 0 More details about mknod can be found at: http://linux.vbird.org/linux_basic/0230filesystem.php#mknod http://rswiki.csie.org/dokuwiki/_media/courses:100_2:lab10_doc.pdf Lab10 2019/4/14

Using Your Driver in Applications Open the file /dev/demo and test its read and write functions just like a normal file #include <stdio.h> int main() { char buf[512]; FILE *fp = fopen("/dev/demo", "w+"); if(fp == NULL) { printf("can't open device!\n"); return 0; } fread(buf, sizeof(buf), 1, fp); fwrite(buf, sizeof(buf), 1, fp); fclose(fp); Lab10 2019/4/14

Lab Steps Please download the driver of Lab9 and modify the LCD driver Change the major number to 119 e.g. #define MAJOR_NUM 119 Change creator-pxa270 driver to module mode in menuconfig <M> Creator-pxa270 LCD Implement a new ioctl command to show “hello world” on LCD Please add lsmod, insmod, rmmod commands in busybox The commands are under Linux Module Utilities You need to check the support of 2.6.x Linux Kernels Do not forget to create the new LCD device file % mknod /dev/lcd c 119 0 Please write an application to display string on the LCD Panel, where the string is a command-line argument of the application Lab10 2019/4/14

Lab Steps (Cont.) Please print messages in driver modules when you insert and remove them Please print messages in driver commands when you access the device e.g. “open command is issued.” Lab10 2019/4/14

Lab Requirement Show more than one messages on LCD from applications Show the messages of using the new ioctl command on LCD Show the messages of accessing the device Including open, close, write, ioctl, etc. Lab10 2019/4/14

Bonus On PXA270, there is a 4x4 keypad device In Lab8, we port a tetris to PXA270. Now, we would like to use the keypad to play the tetris Please modify the driver and tetris to support the keypad The keypad driver is included in the LCD driver Please show the number of the key pressed on LCD For more information about hardware registers, please refer to Create Creator PreSOCes Development Kit User’s Guide, 3.7.4 keypad LCD 有 15*15 的大小 Lab10 2019/4/14

Hints We can use ioctl() to read data from the keypad in applications In the LCD driver, you can add poll file operation to support the select function used in the tetris, e.g. For more information about poll, please refer to Linux Device Drivers 3rd, chapter 6, section “poll and select”, http://lwn.net/images/pdf/LDD3/ In the tetris, there are three functions related to input from keyboard tetris/src/input/inp_unixterm.c readchr(), waitinput_stdin(), init_keybd() We can replace the keyboard with keypad by modifying the 3 functions above struct file_operations creator_pxa270_lcdtxt_fops = { ... write: creator_pxa270_lcdtxt_write, poll: creator_pxa270_lcdtxt_poll, Lab10 2019/4/14