ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

Similar documents
ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work

Administrivia. Course Objectives. Overview. Lecture Notes Week markem/cs333/ 2. Staff. 3. Prerequisites. 4. Grading. 1. Theory and application

Laboratory Exercise #11 A Simple Digital Combination Lock

Laboratory Exercise #10 An Introduction to High-Speed Addition

ww.padasalai.net

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

An introduction to flash memory in Linux

Laboratory Exercise #8 Introduction to Sequential Logic

ISSP User Guide CY3207ISSP. Revision C

PHY 123 Lab 4 - Conservation of Energy

NINE CHOICE SERIAL REACTION TIME TASK

ECE3510 Lab #5 PID Control

CHEOPS Feasibility Checker Guidelines

Outline. policies for the first part. with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014

Training Path FNT IT Infrastruktur Management

TitriSoft 2.5. Content

ON SITE SYSTEMS Chemical Safety Assistant

I/O Devices. Device. Lecture Notes Week 8

Computer Architecture

PHY 123 Lab 6 - Angular Momentum

Chemistry 14CL. Worksheet for the Molecular Modeling Workshop. (Revised FULL Version 2012 J.W. Pang) (Modified A. A. Russell)

SRV02-Series Rotary Experiment # 7. Rotary Inverted Pendulum. Student Handout

URP 4273 Section 8233 Introduction to Planning Information Systems (3 Credits) Fall 2017

Double Inverted Pendulum (DBIP)

Orbit Support Pack for Excel. user manual

In-System Serial Programming (ISSP) Guide

Department of Electrical and Computer Engineering The University of Texas at Austin

Data byte 0 Data byte 1 Data byte 2 Data byte 3 Data byte 4. 0xA Register Address MSB data byte Data byte Data byte LSB data byte

Quick Start Guide New Mountain Visit our Website to Register Your Copy (weatherview32.com)

DISCRETE RANDOM VARIABLES EXCEL LAB #3

URP 4273 Section 3058 Survey Of Planning Information Systems (3 Credits) Spring 2017

Compiling Techniques

CSE370: Introduction to Digital Design

OHW2013 workshop. An open source PCIe device virtualization framework

Laboratory 3 Measuring Capacitor Discharge with the MicroBLIP

Output Module (last updated 8/27/2015)

BCMB/CHEM 8190 Lab Exercise Using Maple for NMR Data Processing and Pulse Sequence Design March 2012

Inverted Pendulum System

Geodatabase Best Practices. Dave Crawford Erik Hoel

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

Economic and Social Council Distr. LIMITED


WeatherHawk Weather Station Protocol

ST-Links. SpatialKit. Version 3.0.x. For ArcMap. ArcMap Extension for Directly Connecting to Spatial Databases. ST-Links Corporation.

Rotary Motion Servo Plant: SRV02. Rotary Experiment #01: Modeling. SRV02 Modeling using QuaRC. Student Manual

MS4525HRD (High Resolution Digital)

Lab 2: Photon Counting with a Photomultiplier Tube

PHY 111L Activity 2 Introduction to Kinematics

Hands-on Lab 3. System Identification with Experimentally Acquired Data

PAID INVOICE TAX REPORT

Athena Visual Software, Inc. 1

Exp. #2-4 : Measurement of Characteristics of Magnetic Fields by Using Single Coils and a Computer Interface

,- # (%& ( = 0,% % <,( #, $ <<,( > 0,% #% ( - + % ,'3-% & '% #% <,( #, $ <<,(,9 (% +('$ %(- $'$ & " ( (- +' $%(& 2,#. = '%% ($ (- +' $ '%("

High-Performance Scientific Computing

C101-E112. BioSpec-nano. Shimadzu Spectrophotometer for Life Science

Timing Results of a Parallel FFTsynth

Motion II. Goals and Introduction

Chapter: 22. Visualization: Making INPUT File and Processing of Output Results

Antonio Falabella. 3 rd nternational Summer School on INtelligent Signal Processing for FrontIEr Research and Industry, September 2015, Hamburg

ISIS/Draw "Quick Start"

Static and Kinetic Friction

Planning Softproviding Meat User Documentation

7600 Series Routers Adjacency Allocation Method

Chem Page IX - 1 LAB MANUAL Differential Scanning Calorimetry 09_dsc131.docx EXPERIMENT IX

LED Lighting Facts: Manufacturer Guide

Environmental Systems Research Institute

Collisions and conservation laws

EBIS-PIC 2D. 2D EBIS Simulation Code. Version 0.1. Copyright ( ) January FAR-TECH, Inc Science Center Dr., Ste 150. San Diego CA 92121

User's Guide. DISTO online. Leica Geosystems

A clock designed in close consultation with people living with Dementia.

Socket Programming. Daniel Zappala. CS 360 Internet Programming Brigham Young University

SuperCELL Data Programmer and ACTiSys IR Programmer User s Guide

Temperature Measurement and First-Order Dynamic Response *

At the end of the exam you must copy that folder onto a USB stick. Also, you must your files to the instructor.

1D-HAM. Coupled Heat, Air and Moisture Transport in Multi-layered Wall Structures. Manual with brief theory and an example. Version 2.

ArcGIS Earth for Enterprises DARRON PUSTAM ARCGIS EARTH CHRIS ANDREWS 3D

IFM Chemistry Computational Chemistry 2010, 7.5 hp LAB2. Computer laboratory exercise 1 (LAB2): Quantum chemical calculations

OECD QSAR Toolbox v.3.3

CSCE 155N Fall Homework Assignment 2: Stress-Strain Curve. Assigned: September 11, 2012 Due: October 02, 2012

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.

Royal Mail Postcode Delivery Points With Postcode Sector Delivery Points Summary

Lecture 4: Process Management

RTS2 Remote Telescope System

ES205 Analysis and Design of Engineering Systems: Lab 1: An Introductory Tutorial: Getting Started with SIMULINK

Assembly Programming through Arduino

A GUI FOR EVOLVE ZAMS

Application example. Measuring Force Sensors Rigid. Six series Nano, Mini, Gamma, Delta, Theta, Omega. Range of measurement, force ± 36 N..

OECD QSAR Toolbox v.3.4

Possible Prelab Questions.

MAT 343 Laboratory 6 The SVD decomposition and Image Compression

Mark Redekopp, All rights reserved. Lecture 1 Slides. Intro Number Systems Logic Functions

ncounter PlexSet Data Analysis Guidelines

Using the Stock Hydrology Tools in ArcGIS

O P E R A T I N G M A N U A L

University of Minnesota Nano Center Standard Operating Procedure

A short status. August 20, 2015

Lan Performance LAB Ethernet : CSMA/CD TOKEN RING: TOKEN

TECDIS and TELchart ECS Weather Overlay Guide

Transcription:

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University Prof. Sunil P Khatri (Lab exercise created and tested by Ramu Endluri, He Zhou and Sunil P Khatri) Laboratory Exercise #6 An Introduction to Linux Device Driver Development Objective The purpose of lab this week is to create device drivers in an embedded Linux environment. Device drivers are a part of the operating system kernel which serves as the bridge between user applications and hardware devices. Device drivers facilitate access and sharing of hardware devices under the control of the operating system. Similar to Lab 5, you will create a kernel module, which prints messages to the kernel s message buffer. However, this kernel module will also moderate user access to the multiplication peripheral created in Lab 3. You will then extend the capabilities of your kernel module, thereby creating a complete character device driver. To test your multiplication device driver, you will also develop a simple Linux application which utilizes the device driver, providing the same functionality as seen in Lab 3. System Overview The hardware system you will use this week is that which was built in Lab 4. Figure 1 depicts a simplified view of the hardware and software you will create in this lab. Please note the hardware/software boundary in the figure below. Above this boundary, the blocks represent compiled code executing within the ARM processor. Below this boundary, the blocks represent hardware attached to the microprocessor. In our particular case, the hardware is a multiplication peripheral attached to the ARM Processor. Obviously, other hardware/software interactions exist in our system, but Figure 1 focuses on that which you will provide. Also 1

2 Laboratory Exercise #6 notice the existence of the kernel-space/user-space boundary. The kernel module represents the character device driver executing in kernel space, while the user application represents the code executing in user space, reading and writing to the device file, /dev/multiplier. The device file is not a standard file in the sense that it does not reside on a disk, rather it provides an interface for user applications to interact with the kernel. User Application /dev/multiplier user space kernel space kernel module multiplication peripheral software hardware Figure 1: Hardware/Software System Diagram Procedure 1. Compile a kernel module that reads and writes to the multiplication peripheral and prints the results to the kernel message buffer. (a) Create a lab6 directory and copy the modules directory from your lab5 directory to your lab6 directory. (b) Navigate to the modules directory and ensure that the Makefile points to the Linux kernel directory. 2 ECEN 449

Laboratory Exercise #6 3 (c) Create a new kernel module source file called multiply.c. (d) Copy the xparameters.h and xparameters ps.h files in to modules directory (e) Copy the following skeleton code into multiply.c : # i n c l u d e <l i n u x / module. h> / Needed by a l l modules / # i n c l u d e <l i n u x / k e r n e l. h> / Needed f o r KERN and p r i n t k / # i n c l u d e <l i n u x / i n i t. h> / Needed f o r i n i t and e x i t macros / # i n c l u d e <asm / i o. h> / Needed f o r IO r e a d s and w r i t e s / # i n c l u d e x p a r a m e t e r s. h / needed f o r p h y s i c a l a d d r e s s o f m u l t i p l i e r / / from x p a r a m e t e r s. h / # d e f i n e PHY ADDR XPAR MULTIPLY 0 S00 AXI BASEADDR / / p h y s i c a l a d d r e s s o f m u l t i p l i e r / s i z e o f p h y s i c a l a d d r e s s range f o r m u l t i p l y / # d e f i n e MEMSIZE XPAR MULTIPLY 0 S00 AXI HIGHADDR XPAR MULTIPLY 0 S00 AXI BASEADDR+1 void v i r t a d d r ; / / v i r t u a l a d d r e s s p o i n t i n g t o m u l t i p l i e r / T h i s f u n c t i o n i s run upon module load. T h i s i s where you s e t u p data s t r u c t u r e s and r e s e r v e r e s o u r c e s used by t h e module. / s t a t i c i n t i n i t m y i n i t ( void ) { / Linux k e r n e l s v e r s i o n o f p r i n t f / p r i n t k ( KERN INFO Mapping v i r t u a l a d d r e s s... \ n ) ; / map v i r t u a l a d d r e s s t o m u l t i p l i e r p h y s i c a l a d d r e s s / / / use ioremap / w r i t e 7 t o r e g i s t e r 0 / p r i n t k ( KERN INFO W r i t i n g a 7 t o r e g i s t e r 0\n ) ; i o w r i t e 3 2 ( 7, v i r t a d d r + 0 ) ; / / base a d d r e s s + o f f s e t / W r i t e 2 t o r e g i s t e r 1 / p r i n t k ( KERN INFO W r i t i n g a 2 t o r e g i s t e r 1\n ) ; / / use i o w r i t e 3 2 p r i n t k ( Read %d from r e g i s t e r 0\n, i o r e a d 3 2 ( v i r t a d d r + 0 ) ) ; p r i n t k ( Read %d from r e g i s t e r 1\n, \\ use i o r e a d 3 2 ) ; p r i n t k ( Read %d from r e g i s t e r 2\n, i o r e a d 3 2 ( v i r t a d d r + 8 ) ) ; / / A non 0 r e t u r n means i n i t m o d u l e f a i l e d ; module can t be loaded. return 0 ; / T h i s f u n c t i o n i s run j u s t p r i o r t o t h e module s removal from t h e s y s t e m. You s h o u l d r e l e a s e ALL r e s o u r c e s used by your module h ere ( o t h e r w i s e be p r e p a r e d f o r a r e b o o t ). / s t a t i c void e x i t m y e x i t ( void ) { ECEN 449 3

4 Laboratory Exercise #6 p r i n t k (KERN ALERT unmapping v i r t u a l a d d r e s s s p a c e.... \ n ) ; iounmap ( ( void ) v i r t a d d r ) ; / These d e f i n e i n f o t h a t can be d i s p l a y e d by modinfo / MODULE LICENSE( GPL ) ; MODULE AUTHOR( ECEN449 S t u d e n t ( and o t h e r s ) ) ; MODULE DESCRIPTION( Simple m u l t i p l i e r module ) ; / Here we d e f i n e which f u n c t i o n s we want t o use f o r i n i t i a l i z a t i o n and c l e a n u p / m o d u l e i n i t ( m y i n i t ) ; m o d u l e e x i t ( m y e x i t ) ; (f) Some required function calls have been left out of the code above. Fill in the necessary code. Consult Linux Device Drivers, 3rd Edition for help. Note: When running Linux on the ARM processor, your code is operating in virtual memory, and ioremap provides the physical to virtual address translation required to read and write to hardware from within virtual memory. iounmap reverses this mapping and is essentially the clean-up function for ioremap. (g) Add a printk statement to your initialization routine that prints the physical and virtual addresses of your multiplication peripheral to the kernel message buffer. (h) Edit your Makefile to compile multiply.c. Compile your kernel module. Do not for get to source the settings64.sh file. (i) Load the multiply.ko module onto the SD card and mount the card within the ZYBO Linux system using /mnt as the mount point. Consult Lab 5 if this is unclear. (j) Use insmod to load the multiply.ko kernel module into the ZYBO Linux kernel. Demonstrate your progress to the TA. 2. With a functioning kernel module that reads and writes to the multiplication peripheral, you are now ready to create a character device driver that provides applications running in user space access to your multiplication peripheral. (a) From within the modules directory, create a character device driver called multiplier.c using the following guidelines: Take a moment to examine my chardev.c, my chardev mem.c and the appropriate header files within /home/faculty/shared/ecen449/module examples/. Use the character device driver examples provided in Linux Device Drivers, 3rd Edition and the laboratory directory as a starting point for your device driver. 4 ECEN 449

Laboratory Exercise #6 5 Use the multiply.c kernel module created in Section 2 of this lab as a baseline for reading and writing to the multiplication peripheral and mapping the multiplication peripheral s physical address to virtual memory. Within the initialization routine, you must register your character device driver after the virtual memory mapping. The name of your device should be multiplier. Let Linux dynamically assign your device driver a major number and specify a minor number of 0. Print the major number to the kernel message buffer exactly as done in the examples provided. Be sure to handle device registration errors appropriately. You will be graded on this! In the exit routine, unregister the device driver before the virtual memory unmapping. For the open and close functions, do nothing except print to the kernel message buffer informing the user when the device is opened and closed. Read up on put user and get user in Linux Device Drivers, 3rd Edition as you will be using these system calls in your custom read and write functions. For the read function, your device driver must read bytes 0 through 11 within your peripheral s address range and put them into the user space buffer. Note that one of the parameters for the read function, length, specifies the number of bytes the user is requesting. Valid values for this parameter include 0 through 12. Your function should return the number of bytes actually transfered to user space (i.e. into the buffer pointed to by char* buf). You may use put user to transfer more than 1 byte at a time. For the write function, your device driver must copy bytes from the user buffer to kernel space using the system call get user to do the transfer and the variable length as a specification of how many bytes to transfer. Furthermore, the device driver must write those bytes to the multiplication peripheral. The return value of your write function should be similar to that of your read function, returning the number of bytes successfully written to your multiplication peripheral. Only write to valid memory locations (i.e. 0 through 7) within your peripheral s address space. (b) Modify the Makefile to compile multiplier.c and run >make ARCH=arm CROSS COMPILE=arm-xilinx-linux-gnueabiin the terminal to create the appropriate kernel module. (c) As with multiply.ko, load multiplier.ko into your ZYBO Linux system. (d) Use dmesg to view the output of the kernel module after it has been loaded. Follow the instructions provided within the provided example kernel modules to create the /dev/multiplier device node. Demonstrate your progress to the TA. 3. At this point, we need to create a user application that reads and writes to the device file, /dev/multiplier, to test our character device driver, and provides the required functionality similar to that seen in Lab 3. ECEN 449 5

6 Laboratory Exercise #6 (a) View the man pages on open, close, read, and write from within the CentOS workstation. You will use these system calls in your application code to read and write to the /dev/multiplier device file. Accessing the man pages can be done via the terminal. For example, to view the man pages on open, type man open in a terminal window. (b) Within the modules directory, create a source file called devtest.c and copy the following starter text into that file: # i n c l u d e <s y s / t y p e s. h> # i n c l u d e <s y s / s t a t. h> # i n c l u d e < f c n t l. h> # i n c l u d e <s t d i o. h> # i n c l u d e <u n i s t d. h> # i n c l u d e < s t d l i b. h> i n t main ( ) { unsigned i n t r e s u l t ; i n t fd ; / f i l e d e s c r i p t o r / i n t i, j ; / loop v a r i a b l e s / char i n p u t = 0 ; / open d e v i c e f i l e f o r r e a d i n g and w r i t i n g / / use open t o open / dev / m u l t i p l i e r / / h a n d l e e r r o r opening f i l e / i f ( fd == 1){ p r i n t f ( F a i l e d t o open d e v i c e f i l e!\ n ) ; return 1; while ( i n p u t!= q ){ / c o n t i n u e u n l e s s u s e r e n t e r e d q / f o r ( i =0; i <=16; i ++){ f o r ( j =0; j <=16; j ++){ / w r i t e v a l u e s t o r e g i s t e r s u s i n g char dev / / use w r i t e t o w r i t e i and j t o p e r i p h e r a l / / read i, j, and r e s u l t u s i n g char dev / / use read t o read from p e r i p h e r a l / / p r i n t u n s i g n e d i n t s t o s c r e e n / p r i n t f ( %u %u = %u, r e a d i, r e a d j, r e s u l t ) ; / v a l i d a t e r e s u l t / i f ( r e s u l t == ( i j ) ) p r i n t f ( R e s u l t C o r r e c t! ) ; e l s e p r i n t f ( R e s u l t I n c o r r e c t! ) ; 6 ECEN 449

Laboratory Exercise #6 7 / read from t e r m i n a l / i n p u t = g e t c h a r ( ) ; c l o s e ( fd ) ; return 0 ; (c) Complete the skeleton code provided above using the specified system calls. (d) Compile devtest.c by executing the following command in the terminal window under the modules directory: >arm-xilinx-linux-gnueabi-gcc -o devtest devtest.c (e) Copy the executable file, devtest, on to the SD card and execute the application by typing the following in the terminal within the SD card mount point directory: >./devtest (f) Examine the output as you hit the enter key from the terminal. Demonstrate your progress to the TA. Deliverables 1. [5 points.] Demo the working kernel module and device driver to the TA. Submit a lab report with the following items: 2. [5 points.] Correct format including an Introduction, Procedure, Results, and Conclusion. 3. [4 points.] Commented C files. 4. [2 points.] The output of the picocom terminal for parts 2 through 4 of lab. 5. [4 points.] Answers to the following questions: (a) Given that the multiplier hardware uses memory mapped I/O (the processor communicates with it through explicitly mapped physical addresses), why is the ioremap command required? (b) Do you expect that the overall (wall clock) time to perform a multiplication would be better in part 3 of this lab or in the original Lab 3 implementation? Why? (c) Contrast the approach in this lab with that of Lab 3. What are the benefits and costs associated with each approach? (d) Explain why it is important that the device registration is the last thing that is done in the initialization routine of a device driver. Likewise, explain why un-registering a device must happen first in the exit routine of a device driver. ECEN 449 7