2
votes

I'm trying to get the examples from Linux Device Drivers, ed 3 (ldd3) working before I start working with the book so that I can have a set of working examples that I can use.... I'm getting the following errors (seeing error in Debian squeeze and also Crunchbang Linux):

inp.c:33:20: error: [u]asm/io.h:[/u] No such file or directory

when I looked at the makefile I found this (which I think is the problem):

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
INCLUDEDIR = $(KERNELDIR)/include

contents of /lib/modules/uname -r/build which is a link to /usr/src/linux-headers-2.6.39-bpo.2-486/

    $ uname -r
    2.6.39-bpo.2-486

$ ls /lib/modules/`uname -r`/build
arch  include  Makefile  Module.symvers  scripts

$ ls /lib/modules/`uname -r`/build/include
config  generated  linux

The directory that make is looking does not have the required files. I found the files required under /usr/src/linux-headers-2.6.39-bpo.2-common/ and the missing asm/io.h file @ /usr/src/linux-headers-2.6.39-bpo.2-common/include/asm-generic/

$ ls /usr/src/linux-headers-2.6.39-bpo.2-common/
arch  include  Kbuild  Makefile  scripts

$ ls /usr/src/linux-headers-2.6.39-bpo.2-common/include/
acpi         crypto  Kbuild  linux     media  net     rdma   scsi   staging  trace  xen
asm-generic  drm     keys    math-emu  mtd    pcmcia  rxrpc  sound  target   video

Do I have to install any package to get the files in that directory... I've already installed linux-headers-uname -r package (in both Debian and Crunchbang)... In gnewsense I found the files in /lib/modules/$(shell uname -r)/build... but it was a older kernel... so not sure if the directory structure under linux change... or is it distro specific... please let me know how do I get the compilation going.... I'm not very good with Makefiles so how can I change the makefile so that it will look for the header files in the other directories....

Thanks, asp5

1
Just a quick note: I don't think your /lib/modules/$(uname -r)/build/ directory is populated correctly. Are you sure you've got the right packages installed? ls /lib/modules/$(uname -r)/build | wc -l on my system shows "27". .../include/ has 24 items, including .../include/asm (symlink to asm-x86).sarnold
@sarnold: I have installed the linux-headers-uname -r package which I think should install all the required headers (in Debian and derivatives)... can you tell me which distro are you using and the kernel version... I can see many items in that directory when I use gnewsense distro... but unfortunately am not able to get it work on my new laptop... anyways I seem to have the right packages installed but the compilation does go smoothly... Thanks.asp5

1 Answers

1
votes

First things first, LDD3 is quite old and I wouldn't be surprised if header files might have moved around. Javier Martinez Canillas has updated the LDD3 sources for more modern kernels.

When investigating this a little further, I found that the asm symlink has been broken for a while. (io.h appears to have stored in asm-generic/ for some reason.) In case you're curious, I filed a bug report at Ubuntu for the broken symlinks.

For whatever it's worth, I can build a module referencing either <asm/io.h> or <asm-generic/io.h> (though as Hasturkun reminds me, you shouldn't use asm-generic directly):

$ cat > Makefile
obj-m = foo.o
$ cat > foo.c
#include <linux/module.h>
#include <linux/sched.h>
#include <asm/io.h>
int init_module() { return 0; }
void cleanup_module() { }
$ make -C /lib/modules/`uname -r`/build M=$PWD
make: Entering directory `/usr/src/linux-headers-2.6.38-12-generic'
  LD      /home/sarnold/tmp/module/built-in.o
  CC [M]  /home/sarnold/tmp/module/foo.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/sarnold/tmp/module/foo.mod.o
  LD [M]  /home/sarnold/tmp/module/foo.ko
make: Leaving directory `/usr/src/linux-headers-2.6.38-12-generic'
$ cat > foo.c
#include <linux/module.h>
#include <linux/sched.h>
#include <asm-generic/io.h>
int init_module() { return 0; }
void cleanup_module() { }
$ make -C /lib/modules/`uname -r`/build M=$PWD
make: Entering directory `/usr/src/linux-headers-2.6.38-12-generic'
  CC [M]  /home/sarnold/tmp/module/foo.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/sarnold/tmp/module/foo.mod.o
  LD [M]  /home/sarnold/tmp/module/foo.ko
make: Leaving directory `/usr/src/linux-headers-2.6.38-12-generic'
$