Saturday, August 9, 2014

Lab - character device driver

In this lab you'll create a character device driver
you'll change the clipboard driver to support 2 devices and to allocate major number statically

Test for the complete driver:

# mknod /dev/clip1 c 237 0
# mknod /dev/clip2 c 237 1


# insmod chardrvex.ko
# echo "abc" > /dev/clip1
# echo "xyz" > /dev/clip2
# cat /dev/clip1
value=abc
# cat /dev/clip2
value=xyz

Instructions

  • Start with charDrvEx module
  • change the init function:
    • allocate another buffer for the second instance
    • change the major number allocation to static (237,0) , (237,1)
  • change the read,write operations to use the correct buffer 
  • complete exit function implementation 
  • test your work
  • write a user space application to test your work

Lab - hardware access

RTC emulation in qemu:

Base address: 0x101e8000

Registers:


Offset Description Access
0 Value R
4 Match RW
8 Set W
... ... ...

continue with the proc interface lab, print the current RTC value  

Lab - proc interface

Start with module parameters lab

Add proc file:   /proc/driver/myfile with read operation

# insmod mymod.ko irq=8 debug=1 name=fpga channels=0x200,0x300

.....



# cat /proc/driver/myfile
irq:8
debug:1
name:fpga
channels:0x200,0x300


note that the user can change the parameters value after module load via sysfs interface so you need to generate the output dynamically

Lab - module parameters

in this lab you'll create a module with the following parameters:

# insmod mymodule.ko   irq=10 name=mydev debug=1 channels=0x100,0x200,0x300
  1. Create a new kernel module (can be based on mod1 source)  
  2. Create the parameters:
    1. irq - integer , default value = 6
    2. name - char pointer 
    3. debug - integer, default value = 0 (no debug)
    4. channels - integer array, size = 8 
  3. Add module init function
    1. if debug=1 write to the kernel log all parameters 
    2. if debug=0 write to kernel log "module init"
  4. Add module exit function
  5. Create files on /sys/module/ to access all parameters
  6. Test your work

Labs instructions

To run eclipse: 

# cd /opt
# ./run_eclipse &


To run qemu:

# cd /opt/armsystem/output
# ./run_qemu &


Copy user application to the target

# cp  [source app]   /opt/armsystem/output/rootfs


Copy kernel module to the target

# cp [source module]  /opt/armsystem/output/rootfs/lib/modules/2.6.32