An Introduction to Linux Device Driver Development - Computer ...
An Introduction to Linux Device Driver Development - Computer ...
An Introduction to Linux Device Driver Development - Computer ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
4 Labora<strong>to</strong>ry Exercise #6<br />
{<br />
}<br />
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 ” ) ;<br />
iounmap ( ( void ∗) v i r t a d d r ) ;<br />
/ ∗ 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 ∗ /<br />
MODULE LICENSE( ”GPL” ) ;<br />
MODULE AUTHOR( ”ECEN449 S t u d e n t ( and o t h e r s ) ” ) ;<br />
MODULE DESCRIPTION( ” Simple m u l t i p l i e r module ” ) ;<br />
/ ∗ 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<br />
and c l e a n u p ∗ /<br />
m o d u l e i n i t ( m y i n i t ) ;<br />
m o d u l e e x i t ( m y e x i t ) ;<br />
(e) Some required function calls have been left out of the code above. Fill in the necessary code.<br />
Consult <strong>Linux</strong> <strong>Device</strong> <strong>Driver</strong>s, 3rd Edition for help.<br />
Note: When running <strong>Linux</strong> on the MicroBlaze, your code is operating in virtual memory, and<br />
‘ioremap’ provides the physical <strong>to</strong> virtual address translation required <strong>to</strong> read and write <strong>to</strong> hardware<br />
from within virtual memory. ‘iounmap’ reverses this mapping and is essentially the cleanup<br />
function for ‘ioremap’.<br />
(f) Add a ‘printk’ statement <strong>to</strong> your initialization routine that prints the physical and virtual addresses<br />
of your multiplication peripheral <strong>to</strong> the kernel message buffer.<br />
(g) Compile your kernel module. Do not for get <strong>to</strong> source the ‘compile settins.csh’ file.<br />
(h) Load the ‘multiply.ko’ module on<strong>to</strong> the CF card and mount the card within the XUP <strong>Linux</strong><br />
system using ‘/lib/modules/2.6.35.7’ as the mount point. Consult Lab 5 if this is unclear.<br />
(i) Use ‘insmod’ <strong>to</strong> load the ‘multiply.ko’ kernel module in<strong>to</strong> the XUP <strong>Linux</strong> kernel. Demonstrate<br />
your progress <strong>to</strong> the TA.<br />
2. With a functioning kernel module that reads and writes <strong>to</strong> the multiplication peripheral, you are now<br />
ready <strong>to</strong> create a character device driver that provides applications running in user space access <strong>to</strong><br />
your multiplication peripheral.<br />
(a) From within the ‘modules’ direc<strong>to</strong>ry, create a character device driver called ‘multiplier.c’using<br />
the following guidelines:<br />
• Take a moment <strong>to</strong> examine ‘my chardev.c’, ‘my chardev mem.c’ and the appropriate header<br />
files within ‘/homes/faculty/shared/ECEN449/module examples/’. Use the character device<br />
driver examples provided in <strong>Linux</strong> <strong>Device</strong> <strong>Driver</strong>s, 3rd Edition and the labora<strong>to</strong>ry direc<strong>to</strong>ry<br />
as a starting point for your device driver.<br />
4 ECEN 449