Home Einleitung Modul registriert sich mit einer Major Device Number
 

1.3 hello-4 auf COBRA unter Kernel 2.4

Jetzt wird nur das Makefile so abgeändert, daß nicht mehr unter SuSE Linux 9.1 alles funktioniert, sondern daß jetzt die Make-Tool-Chain vom COBRA-Board als Referenz-System verwendet wird.

zuvor sah das Makefile folgendermaßen aus:

ifneq ($(KERNELRELEASE),)
obj-m       := hello-4.o

else
KDIR        := /lib/modules/$(shell uname -r)/build
PWD         := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif

Hierzu muß KDIR geändert werden:

ifneq ($(KERNELRELEASE),)
obj-m       := hello-4.o

else
KDIR        := /home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/
PWD         := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif

Dies scheint aber nicht alles gewesen zu sein, denn der erste Output lautet:

andreas@gericom:~/Development/driver> make
make -C /home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/ SUBDIRS=/home/andreas/Development/driver modules
make[1]: Entering directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324'
. linux-2.4.x/.config; if [ "$CONFIG_MODULES" = "y" ]; then \
        [ -d linux-2.4.x/modules ] || mkdir linux-2.4.x/modules; \
        make ARCH=m68knommu CROSS_COMPILE=m68k-elf- -C linux-2.4.x modules; \
fi
make[2]: Entering directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/linux-2.4.x'
make -C  /home/andreas/Development/driver CFLAGS="-fno-builtin -nostdinc -D__KERNEL__ -I/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/linux-2.4.x/include  -Wall -Wstrict-prototypes -Wno-trigraphs -O1 -g -fno-strict-aliasing -fno-common -I/usr/local/lib/gcc-lib/m68k-elf/2.95.3/./include -pipe -DNO_MM -DNO_FPU -m5307 -Wa,-S -Wa,-m5307 -D__ELF__ -DMAGIC_ROM_PTR -DUTS_SYSNAME=\"uClinux\" -D__linux__ -O1 -DMODULE" MAKING_MODULES=1 modules
make[3]: Entering directory `/home/andreas/Development/driver'
make[3]: *** Keine Regel, um »modules« zu erstellen.  Schluss.
make[3]: Leaving directory `/home/andreas/Development/driver'
make[2]: *** [_mod_/home/andreas/Development/driver] Fehler 2
make[2]: Leaving directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/linux-2.4.x'
make[1]: *** [modules] Fehler 2
make[1]: Leaving directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324'
make: *** [default] Fehler 2
andreas@gericom:~/Development/driver>

Unter Kernel 2.4 muß man also Module doch etwas anders über das Makefile einbinden.

Die Lösung fand ich im Makefile von minix

Darin steht der wichtige für den Kernel 2.4 noch typische Befehl:

include $(TOPDIR)/Rules.make

Damit erweiterte ich das Makefile zu dieser Form (also auch ein clean-Befehl wurde eingebaut):

ifneq ($(KERNELRELEASE),)
obj-m       := hello-4.o

include $(TOPDIR)/Rules.make

else
KDIR        := /home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/
PWD         := $(shell pwd)

CLEAN_FILES = \
        hello-4.o hello-4.ko hello-4.mod.o hello-4.mod.c

default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
        rm -f $(CLEAN_FILES)

endif

Damit ergab sich:

andreas@gericom:~/Development/driver> make clean
rm -f hello-4.o hello-4.ko hello-4.mod.o hello-4.mod.c
andreas@gericom:~/Development/driver> make
make -C /home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/ SUBDIRS=/home/andreas/Development/driver modules
make[1]: Entering directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324'
. linux-2.4.x/.config; if [ "$CONFIG_MODULES" = "y" ]; then \
        [ -d linux-2.4.x/modules ] || mkdir linux-2.4.x/modules; \
        make ARCH=m68knommu CROSS_COMPILE=m68k-elf- -C linux-2.4.x modules; \
fi
make[2]: Entering directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/linux-2.4.x'
make -C  /home/andreas/Development/driver CFLAGS="-fno-builtin -nostdinc -D__KERNEL__ -I/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/linux-2.4.x/include  -Wall -Wstrict-prototypes -Wno-trigraphs -O1 -g -fno-strict-aliasing -fno-common -I/usr/local/lib/gcc-lib/m68k-elf/2.95.3/./include -pipe -DNO_MM -DNO_FPU -m5307 -Wa,-S -Wa,-m5307 -D__ELF__ -DMAGIC_ROM_PTR -DUTS_SYSNAME=\"uClinux\" -D__linux__ -O1 -DMODULE" MAKING_MODULES=1 modules
make[3]: Entering directory `/home/andreas/Development/driver'
m68k-elf-gcc -fno-builtin -nostdinc -D__KERNEL__ -I/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/linux-2.4.x/include  -Wall -Wstrict-prototypes -Wno-trigraphs -O1 -g -fno-strict-aliasing -fno-common -I/usr/local/lib/gcc-lib/m68k-elf/2.95.3/./include -pipe -DNO_MM -DNO_FPU -m5307 -Wa,-S -Wa,-m5307 -D__ELF__ -DMAGIC_ROM_PTR -DUTS_SYSNAME="uClinux" -D__linux__ -O1 -DMODULE  -nostdinc -iwithprefix include -DKBUILD_BASENAME=hello_4  -c -o hello-4.o hello-4.c
make[3]: Leaving directory `/home/andreas/Development/driver'
make[2]: Leaving directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324/linux-2.4.x'
make[1]: Leaving directory `/home/andreas/Development/COBRA_rot/uClinux/uClinux-dist-20040218-cobra-20040324'
andreas@gericom:~/Development/driver> ls
hello-3.c      hello-3.o                            Makefile              qadc-1_0.c   V_1_4
hello-3.c~     hello-4.c                            Makefile~             qadc-1_0.c~
hello-3.ko     hello-4.c~                           myreadme-driver.txt   V_1_0
hello-3.mod.c  hello-4.o                            myreadme-driver.txt~  V_1_2
hello-3.mod.o  Linux-Modul-Programming.kateproject  myreadme.txt~         V_1_3
andreas@gericom:~/Development/driver> pwd
/home/andreas/Development/driver
andreas@gericom:~/Development/driver>

Copyright © Andreas Birkert
Letzte Aktualisierung am 25. Juni 2005
Home Einleitung Modul registriert sich mit einer Major Device Number