Erster Versuch einen Treiber zu schreiben

Alles rund um die Systemverwaltung, die Administration und Konfiguration Eures Linuxsystems

Moderator: Moderatoren

Antworten
Benutzeravatar
homer65
Hacker
Hacker
Beiträge: 331
Registriert: 6. Jan 2005, 05:24
Wohnort: Bochum

Erster Versuch einen Treiber zu schreiben

Beitrag von homer65 » 20. Mär 2005, 21:22

Hallo Community,
mache die ersten Versuch einen Treiber zu schreiben. Habe mir dazu das Buch
"LINUX Gerätetreiber" von Alessandro Rubini besorgt. Aber schon mit dem ersten einfachen Beispiel gibt es Schwierigkeiten. In dem Beispiel wird ein:
#include <linux/module.h>
verwendet. Beim kompile mit gcc erhalte ich eine Unmenge an Fehlermeldungen. Ich weiß mir keinen Rat. Was kann zu so vielen Fehlermeldungen führen? Muß beim Compile irgendetwas beachtet werden?
Wer kann mir helfen?
Habe ein Suse 9.2
Christian

Werbung:
Benutzeravatar
snaewe
Hacker
Hacker
Beiträge: 415
Registriert: 13. Dez 2004, 16:32
Wohnort: Zu Hause

Beitrag von snaewe » 21. Mär 2005, 09:19

Da hier keiner eine Glaskugel hat (naja, fast keiner...) könntest du ja mal nur zum Spass die Fehlermeldungen, die der Compiler ausspuckt, hier posten.

Stefan
Der Name Windows stammt ursprünglich aus dem Indianischen und
bedeutet: "Weißer Mann, der auf eine Sanduhr starrt."

Benutzeravatar
homer65
Hacker
Hacker
Beiträge: 331
Registriert: 6. Jan 2005, 05:24
Wohnort: Bochum

Beitrag von homer65 » 21. Mär 2005, 16:35

Also gut hier ist der Source des Miniprogramms:
#define MODULE
#include <linux/module.h>
int init_module(void)
{
printk("<1>Hallo Welt\n");
return 0;
}
void cleannup_module(void)
{
printk("<1>Ade\n");
}
Und nun alle Fehlermeldungen:
gcc -c -o/home/christian/SimpleEdit/T01/test001.o /home/christian/SimpleEdit/T01/test001.c
In file included from /usr/include/linux/sched.h:12,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/jiffies.h:16: error: parse error before "jiffies_64"
/usr/include/linux/jiffies.h:20: error: parse error before "get_jiffies_64"
In file included from /usr/include/linux/cpumask.h:77,
from /usr/include/linux/sched.h:15,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/bitmap.h: In function `bitmap_zero':
/usr/include/linux/bitmap.h:110: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h:110: error: (Each undeclared identifier is reported only once
/usr/include/linux/bitmap.h:110: error: for each function it appears in.)
/usr/include/linux/bitmap.h: In function `bitmap_fill':
/usr/include/linux/bitmap.h:125: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_copy':
/usr/include/linux/bitmap.h:131: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_and':
/usr/include/linux/bitmap.h:142: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_or':
/usr/include/linux/bitmap.h:151: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_xor':
/usr/include/linux/bitmap.h:160: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_andnot':
/usr/include/linux/bitmap.h:169: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_complement':
/usr/include/linux/bitmap.h:178: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_equal':
/usr/include/linux/bitmap.h:187: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_intersects':
/usr/include/linux/bitmap.h:196: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_subset':
/usr/include/linux/bitmap.h:205: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_empty':
/usr/include/linux/bitmap.h:213: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_full':
/usr/include/linux/bitmap.h:221: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_shift_right':
/usr/include/linux/bitmap.h:235: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_shift_left':
/usr/include/linux/bitmap.h:244: error: `BITS_PER_LONG' undeclared (first use in this function)
In file included from /usr/include/linux/sched.h:15,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:80: error: parse error before "DECLARE_BITMAP"
/usr/include/linux/cpumask.h:81: error: parse error before "_unused_cpumask_arg_"
/usr/include/linux/cpumask.h:84: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpu_set':
/usr/include/linux/cpumask.h:86: error: `cpu' undeclared (first use in this function)
/usr/include/linux/cpumask.h:86: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:90: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpu_clear':
/usr/include/linux/cpumask.h:92: error: `cpu' undeclared (first use in this function)
/usr/include/linux/cpumask.h:92: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:96: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_setall':
/usr/include/linux/cpumask.h:98: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:98: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:102: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_clear':
/usr/include/linux/cpumask.h:104: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:104: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:111: error: parse error before "cpumask_t"
/usr/include/linux/cpumask.h: In function `__cpu_test_and_set':
/usr/include/linux/cpumask.h:113: error: `cpu' undeclared (first use in this function)
/usr/include/linux/cpumask.h:113: error: `addr' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:117: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_and':
/usr/include/linux/cpumask.h:120: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:120: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:120: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:120: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:124: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_or':
/usr/include/linux/cpumask.h:127: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:127: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:127: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:127: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:131: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_xor':
/usr/include/linux/cpumask.h:134: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:134: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:134: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:134: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:139: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_andnot':
/usr/include/linux/cpumask.h:142: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:142: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:142: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:142: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:146: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_complement':
/usr/include/linux/cpumask.h:149: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:149: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:149: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:153: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_equal':
/usr/include/linux/cpumask.h:156: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:156: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:156: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:160: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_intersects':
/usr/include/linux/cpumask.h:163: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:163: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:163: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:167: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_subset':
/usr/include/linux/cpumask.h:170: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:170: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:170: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:174: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_empty':
/usr/include/linux/cpumask.h:176: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:176: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:180: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_full':
/usr/include/linux/cpumask.h:182: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:182: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:186: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_weight':
/usr/include/linux/cpumask.h:188: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:188: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:193: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_shift_right':
/usr/include/linux/cpumask.h:196: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:196: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:196: error: `n' undeclared (first use in this function)
/usr/include/linux/cpumask.h:196: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:201: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_shift_left':
/usr/include/linux/cpumask.h:204: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:204: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:204: error: `n' undeclared (first use in this function)
/usr/include/linux/cpumask.h:204: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:208: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__first_cpu':
/usr/include/linux/cpumask.h:210: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:210: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:214: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__next_cpu':
/usr/include/linux/cpumask.h:216: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:216: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h:216: error: `n' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:265: error: parse error before '*' token
/usr/include/linux/cpumask.h: In function `__cpumask_scnprintf':
/usr/include/linux/cpumask.h:267: error: `buf' undeclared (first use in this function)
/usr/include/linux/cpumask.h:267: error: `len' undeclared (first use in this function)
/usr/include/linux/cpumask.h:267: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:267: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:273: error: parse error before "cpumask_t"
/usr/include/linux/cpumask.h: In function `__cpumask_parse':
/usr/include/linux/cpumask.h:275: error: `buf' undeclared (first use in this function)
/usr/include/linux/cpumask.h:275: error: `len' undeclared (first use in this function)
/usr/include/linux/cpumask.h:275: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:275: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:343: error: parse error before "cpu_possible_map"
/usr/include/linux/cpumask.h:344: error: parse error before "cpu_online_map"
/usr/include/linux/cpumask.h:345: error: parse error before "cpu_present_map"
In file included from /usr/include/linux/sched.h:21,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/asm/mmu.h:13: error: field `sem' has incomplete type
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/list.h:699:2: warning: #warning "don't include kernel headers in userspace"
In file included from /usr/include/asm/siginfo.h:4,
from /usr/include/linux/signal.h:7,
from /usr/include/linux/sched.h:25,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/asm-generic/siginfo.h:58: error: size of array `_pad' is too large
In file included from /usr/include/linux/sched.h:27,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/fs_struct.h:9: error: parse error before "rwlock_t"
/usr/include/linux/fs_struct.h:13: error: parse error before '}' token
In file included from /usr/include/linux/sched.h:29,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/completion.h:15: error: parse error before "wait_queue_head_t"
/usr/include/linux/completion.h: In function `init_completion':
/usr/include/linux/completion.h:26: error: dereferencing pointer to incomplete type
/usr/include/linux/completion.h:27: error: dereferencing pointer to incomplete type
In file included from /usr/include/linux/sched.h:30,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/pid.h: At top level:
/usr/include/linux/pid.h:18: error: field `task_list' has incomplete type
/usr/include/linux/pid.h:19: error: field `hash_chain' has incomplete type
/usr/include/linux/pid.h:24: error: field `pid_chain' has incomplete type
In file included from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/sched.h:93: error: parse error before "process_counts"
In file included from /usr/include/linux/sched.h:102,
from /usr/include/linux/module.h:9,
from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/timer.h:11: error: field `entry' has incomplete type
In file included from /home/christian/SimpleEdit/T01/test001.c:2:
/usr/include/linux/module.h:553: error: parse error before "MOD_INC_USE_COUNT"
/usr/include/linux/module.h:565: error: parse error before "MOD_DEC_USE_COUNT"

Benutzeravatar
snaewe
Hacker
Hacker
Beiträge: 415
Registriert: 13. Dez 2004, 16:32
Wohnort: Zu Hause

Beitrag von snaewe » 21. Mär 2005, 20:26

Du brauchst noch ein passendes Makefile (wenn das nicht in dem
Buch erklärt ist, schmeiss es weg...)

Hier gibt's ein Online-Buch, wo alles genau erklärt ist (sogar auf deutsch).

(Ach ja, es soll wahrscheinlich 'cleanup_module()' (mit einem n) heissen, oder? )

Stefan
Der Name Windows stammt ursprünglich aus dem Indianischen und
bedeutet: "Weißer Mann, der auf eine Sanduhr starrt."

Benutzeravatar
homer65
Hacker
Hacker
Beiträge: 331
Registriert: 6. Jan 2005, 05:24
Wohnort: Bochum

Beitrag von homer65 » 21. Mär 2005, 21:49

Na dann mal danke für den Buchtip.
Hab mal blitzschnell durchgeblättert und das Makefile gefunden.
Leider bleiben die Fehlermeldungen gleich:

christian@linux-notebook:~/SimpleEdit/T01> make mod1
cc mod1.c -o mod1
In file included from /usr/include/linux/sched.h:12,
from /usr/include/linux/module.h:9,
from mod1.c:2:
/usr/include/linux/jiffies.h:16: error: parse error before "jiffies_64"
/usr/include/linux/jiffies.h:20: error: parse error before "get_jiffies_64"
In file included from /usr/include/linux/cpumask.h:77,
from /usr/include/linux/sched.h:15,
from /usr/include/linux/module.h:9,
from mod1.c:2:
/usr/include/linux/bitmap.h: In function `bitmap_zero':
/usr/include/linux/bitmap.h:110: error: `BITS_PER_LONG' undeclared (first u
...

Benutzeravatar
snaewe
Hacker
Hacker
Beiträge: 415
Registriert: 13. Dez 2004, 16:32
Wohnort: Zu Hause

Beitrag von snaewe » 22. Mär 2005, 07:05

Dann zeig mal dein Makefile.

Stefan
Der Name Windows stammt ursprünglich aus dem Indianischen und
bedeutet: "Weißer Mann, der auf eine Sanduhr starrt."

Benutzeravatar
homer65
Hacker
Hacker
Beiträge: 331
Registriert: 6. Jan 2005, 05:24
Wohnort: Bochum

Beitrag von homer65 » 23. Mär 2005, 13:20

Hab mal ein neues Linux (Fedora CORE 3) installiert. Da funktioniert der kompile tadellos. Ob es was mit der alten Installation (SUSE 9.2) zu tun hatt? Vielleicht habe ich mir da ja was zerschossen? Aber was?

taki
Advanced Hacker
Advanced Hacker
Beiträge: 974
Registriert: 30. Apr 2004, 17:40
Wohnort: Berlin
Kontaktdaten:

Beitrag von taki » 23. Mär 2005, 14:17

Sieht mir so aus, als ob die Header nicht zur Kernelsource passen.
Evtl. war auch die Kernelsource nicht korrekt konfiguriert.
SuSE 12.3 kernel 3.7.10-1.16-desktop, K Desktop Environment Version 4.10.5 r1 - Medion Titanium Aldi v. 03/2009

Benutzeravatar
homer65
Hacker
Hacker
Beiträge: 331
Registriert: 6. Jan 2005, 05:24
Wohnort: Bochum

Beitrag von homer65 » 23. Mär 2005, 14:37

Tja, möglich möglich. Aber wie kann man da sicher sein? Und was kann man dagegen unternehmen? Jetzt sag nicht den Kernel neu bauen. Das wär für mich noch absolutes Neuland.

jengelh
Guru
Guru
Beiträge: 4039
Registriert: 20. Nov 2004, 17:42
Kontaktdaten:

Beitrag von jengelh » 23. Mär 2005, 19:26

homer65 hat geschrieben: christian@linux-notebook:~/SimpleEdit/T01> make mod1
cc mod1.c -o mod1
Das ist immer noch kein korrektes makefile.
Schau die mal den Code von http://linux01.org:2222/f/oops_ko.tbz2 an, dass müsste helfen. (Aber nicht ausführen ;-) )

Benutzeravatar
homer65
Hacker
Hacker
Beiträge: 331
Registriert: 6. Jan 2005, 05:24
Wohnort: Bochum

Beitrag von homer65 » 23. Mär 2005, 21:09

Na gut, dann mal das Makefile:

ifneq ($(KERNELRELEASE),)
obj-m := mod1.o
else
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif

Das mit dem Link verstehe ich nicht. Sehe nur Hieroglyphen???

Benutzeravatar
homer65
Hacker
Hacker
Beiträge: 331
Registriert: 6. Jan 2005, 05:24
Wohnort: Bochum

Beitrag von homer65 » 23. Mär 2005, 22:10

So jetzt hab ich's. Hab die Datei entpackt und daraus folgendes Makefile entnommen:
#~~syntax:makefile

all: modules

modules: ;
make -C /lib/modules/`uname -r`/build/ SUBDIRS=$$PWD modules;

mod1.ko: all;

clean:
make -C /lib/modules/`uname -r`/build/ SUBDIRS=$$PWD clean;

obj-m += mod1.o

Damit funktioniert das kompilieren. Hab zwar keine Ahnung wo da die feinen Unterschiede liegen. Aber danke. :lol:

Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste