WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Simple device driver trouble  (Read 2558 times)

Offline jjacobs

  • Newbie
  • *
  • Posts: 34
Simple device driver trouble
« on: May 19, 2010, 03:50:32 PM »
I need to write a device driver for a piece of hardware my company manufactures.  This board has 8 serial ports that sit on an ISA bus. There are 4 ISA slots on the mother board.

I downloaded the 2.6.29.1 kernel source code and placed it on my hard drive. I ran make headers_install in the source directory.

I also made a Makefile in the directory where my test code resides it has one line and it looks like this:
obj-m := first.o

I've been having trouble compiling the simplest device driver example from the linux device driver how to's I've found.  

The code is in a file called first.c and looks like this:

#define __KERNEL__
#define MODULE
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk(KERN_ALERT, "Hello, world\n");
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_ALERT, "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

I compile with the line:
make -C pathtosource M=`pwd` modules

I get ther error:
  ERROR: Kernel configuration is invalid.
         include/linux/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.


  WARNING: Symbol version dump /mnt/hda3/MyKernel/linux-2.6.29.1/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /mnt/hda3/DriverTest/first.o
/mnt/hda3/DriverTest/first.c:1: error: code model 'kernel' not supported in the 32 bit mode
/mnt/hda3/DriverTest/first.c:1: sorry, unimplemented: 64-bit mode not compiled in
make[1]: *** [/mnt/hda3/DriverTest/first.o] Error 1
make: *** [_module_/mnt/hda3/DriverTest] Error 2
make: Leaving directory `/mnt/hda3/MyKernel/linux-2.6.29.1'

Are there any device driver experts about that can give some advice? Do I need to compile a custom kernel?

This is the location of the howto I'm using:
http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0%2C1

I notice that the author says,
"First, you need to have a complete, compiled kernel source-code-tree."
Is there a list of kernel options for tinycore anyplace?  On my machine uname -a shows:

Linux box 2.6.29.1-tinycore #1337 SMP Fri Apr 10 19:12:39 EEST 2009 i686 GNU/Linux
« Last Edit: May 19, 2010, 07:34:24 PM by jjacobs »

Offline popolon

  • Newbie
  • *
  • Posts: 5
Re: Simple device driver trouble
« Reply #1 on: May 19, 2010, 05:04:15 PM »
The kernel options for tinycore are here:
http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/2.x/release/src/config-2.6.29.1-tinycore
I think you must copy the config file to .config in the source tree and then "make oldconfig". Not 100% sure, i'm no expert but it worked for me building a module.
You should also probably use the patched kernel source from the same place as the config (linux-2.6.29.1-patched.tar.bz2)

Offline jjacobs

  • Newbie
  • *
  • Posts: 34
Re: Simple device driver trouble
« Reply #2 on: May 19, 2010, 06:41:04 PM »
Thanks popolon,

I'm compiling the kernel after applying the patch. I will give an update after the compilation completes.

Offline jjacobs

  • Newbie
  • *
  • Posts: 34
Re: Simple device driver trouble
« Reply #3 on: May 20, 2010, 12:47:59 PM »
It now compiles and I get first.ko amongst other outputs.  When I insmod first.ko I don't see the print on the terminal, and I don't see the message in /var/log/syslog. If I do lsmod though I see first, and first is removed after rmmod. I verified its removal via a second lsmod.

I think I'm on the right track though somewhat disappointed that I didn't see the messages.

Offline ^thehatsrule^

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 1726
Re: Simple device driver trouble
« Reply #4 on: May 20, 2010, 01:52:46 PM »
Make sure syslog is running, or check dmesg?

Offline jjacobs

  • Newbie
  • *
  • Posts: 34
Re: Simple device driver trouble
« Reply #5 on: May 20, 2010, 01:58:16 PM »
Thanks ^thehatsrule^,

Yahoo dmesg shows the prints!

And after starting syslogd I see the messages file with the prints in /var/log.
« Last Edit: May 20, 2010, 02:01:59 PM by jjacobs »