EBC Exercise 26 Device Drivers

Chapter 8 of the text gives a nice example of a minimal device driver. The purpose of this lab is to implement that driver.

Compiling
Follow the 5 steps given in section 8.1.4 on page 205. You can get a copy of Listing 8-1 here (ECE497_Listings_for_Embedded_Linux_Primer_Chapter_8). Once finished you will have a file called  in   and have the kernel configure file and Makefile updated for the new driver. See section 4.4 on page 89 for help with modifying the config files.

Note: There is a typo in Listing 8-2.

If you have created the crossCompileEnv.sh file and sourced it, all you have to do to make the modules is cd to the top of the kernel directory and then: $ make modules Mine took a while the first time as it compiles all the modules. The second it only took 31 seconds.

Moving to Beagle
On the beagle edit /lib/modules/2.6.32/modules.dep and add /lib/modules/2.6.32/kernel/drivers/char/examples/hello1.ko: Then copy the file  on the host computer to   on your Beagle. This can be done with a single command though you may have to mkdir the char/examples directory on the Beagle first. $ cd …/drivers/char/examples $ rcp hello1.ko root@beagle:/lib/modules/2.6.32/kernel/drivers/char/examples I suggest putting the rcp in a file since you may use it several times while developing your code.

Now, on the Beagle, modprobe the module and check the log file. You should see your Init message. And then... should show your Exit message.
 * 1) /sbin/modprobe hello1
 * 2) dmesg | tail -4
 * 1) /sbin/modprobe -r hello1
 * 2) dmesg | tail -4

Module Parameters
Section 8.1.7 on page 211 of the text shows how to pass a parameter to a module. Modify your hello1.c to take a parameter as shown.

Try passing two parameters.

Module Utilities
Play with the mod utilities listed in section 8.2 on page 212.

Driver Methods
Section 8.3 on page 217 gives a longer example of how to use the file interface with modules. Implement the example. Be sure to fix the unsigned int format error. When compiling the  command be sure you are using the cross compiler for the ARM rather than the x86 compiler. If you sourced the crossCompilerEnv.sh file this should work: $ ${CROSS_COMPILE}gcc -o use-hello use-hello.c $ file use-hello The  command will tell you if you got the right compiler.

Some questions...
 * The major device number 234 is part of a range of unassigned numbers. What is the range?
 * What's the new line added to  do?
 * What does  do?
 * Once your device is running try .  Do you see your device?

Optional: Stretch time, see chapter 3 of Linux Device Drivers by Corbet, Rubini and Kroah-Hartman (on dfs) for answers. I though these would be easy, but after reading up on them, they look rather involved.
 * How can your driver find what the minor device number is?
 * Modify the driver to return some characters when  is read.