Programmtion kernel

rufa Messages postés 160 Date d'inscription   Statut Membre Dernière intervention   -  
 amounsh -
Bonjour, j'ai compilé un programme kernel qui affiche hello word:

hello.c
* Copyright (C) 1998 by Ori Pomerantz
*
* "Hello, world" - the kernel module version.
*/
/* The necessary header files */
/* Standard in kernel modules */
#include <linux/kernel.h> /* We’re doing kernel work */
#include <linux/module.h> /* Specifically, a module */
/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
/* Initialize the module */
int init_module()
{
printk("Hello, world - this is the kernel speaking\n");
/* If we return a non zero value, it means that
* init_module failed and the kernel module
* can’t be loaded */
return 0;
}
/* Cleanup - undid whatever init_module did */
void cleanup_module()
{
printk("Short is the life of a kernel module\n");
}

les erreurs suivantes son apparus:

abdelkader@abdelkader:~$ make hello
cc hello.c -o hello
In file included from /usr/include/asm-i486/local.h:4,


from /usr/include/asm/local.h:8,


from /usr/include/linux/module.h:20,


from hello.c:2:
/usr/include/linux/percpu.h: In function ‘__alloc_percpu’:
/usr/include/linux/percpu.h:44: error: ‘GFP_KERNEL’ undeclared (first use in this function)
/usr/include/linux/percpu.h:44: error: (Each undeclared identifier is reported only once
/usr/include/linux/percpu.h:44: error: for each function it appears in.)
In file included from /usr/include/asm/module.h:8,

from /usr/include/linux/module.h:22,

from hello.c:2:
/usr/include/asm-i486/module.h:60:2: error: #error unknown processor family
In file included
from hello.c:2:
/usr/include/linux/module.h: At top level:
/usr/include/linux/module.h:49: error: field ‘attr’ has incomplete type
/usr/include/linux/module.h:60: error: field ‘kobj’ has incomplete type
make: *** [hello] Erreur 1

le fichier make file :

# Makefile for a basic kernel module
CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX
hello.o: hello.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c hello.c
echo insmod hello.o to turn it on
echo rmmod hello to turn if off
echo
echo X and kernel programming do not mix.
echo Do the insmod and rmmod from outside X.


la distribution est debian version 4.0.
svp je veut comprend les erreurs pour que je puisse les résoudre.

3 réponses

bob031 Messages postés 8158 Date d'inscription   Statut Membre Dernière intervention   473
 
bonjour,

je dirai que le programme date de 1998 et qu'entre-temps, le noyau linux a subit pas de mal de changements !
0
rufa Messages postés 160 Date d'inscription   Statut Membre Dernière intervention   4
 
salut,mmmmmmmmmm oui ta sans doute raison,mais eceque tu peut me faire comprendre un peut les erreurs svp.
0
rufa Messages postés 160 Date d'inscription   Statut Membre Dernière intervention   4 > rufa Messages postés 160 Date d'inscription   Statut Membre Dernière intervention  
 
re,oui de 1999.
0
bob031 Messages postés 8158 Date d'inscription   Statut Membre Dernière intervention   473 > rufa Messages postés 160 Date d'inscription   Statut Membre Dernière intervention  
 
eceque tu peut me faire comprendre un peut les erreurs

je ne suis pas spécialiste du noyau linux.
en général, je tapes les messages d'erreur dans google
0
rufa Messages postés 160 Date d'inscription   Statut Membre Dernière intervention   4
 
salut et merci,j'ai compilé avec la version du kernel 2.6 "https://tldp.org/LDP/lkmpg/"
le programme est :

/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");

/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
mais dans la compilation avec make les erreurs:
cc hello.c -o hello
In

file included from /usr/include/asm-i486/local.h:4,

from /usr/include/asm/local.h:8,

from /usr/include/linux/module.h:20,

from hello.c:2:
/usr/include/linux/percpu.h: In function ‘__alloc_percpu’:

/usr/include/linux/percpu.h:44: error: ‘GFP_KERNEL’ undeclared (first use in this function)
/usr/include/linux/percpu.h:44: error: (Each undeclared identifier is reported only once
/usr/include/linux/percpu.h:44: error: for each function it appears in.)

In file included from
/usr/include/asm/module.h:8,

from /usr/include/linux/module.h:22,

from hello.c:2:
/usr/include/asm-i486/module.h:60:2: error: #error unknown processor family
In file included from hello.c:2:
/usr/include/linux/module.h: At top level:

/usr/include/linux/module.h:49: error: field ‘attr’ has incomplete type

/usr/include/linux/module.h:60: error: field ‘kobj’ has incomplete type

hello.c: In function ‘init_module’:
hello.c:6: error: ‘KERN_INFO’ undeclared (first use in this function)

hello.c:6: error: expected ‘)’ before string constant

hello.c: In function ‘cleanup_module’:

hello.c:12: error: ‘KERN_INFO’ undeclared (first use in this function)

hello.c:12: error: expected ‘)’ before string constant

hello.c:13:2: warning: no newline at end of file

make: *** [hello] Erreur 1

alors j'ai supprimé KERN INFO alors le résultat est :

cc hello.c -o hello

In file included from
/usr/include/asm-i486/local.h:4,

from /usr/include/asm/local.h:8,
from /usr/include/linux/module.h:20,
from hello.c:2:
/usr/include/linux/percpu.h: In function ‘__alloc_percpu’:

/usr/include/linux/percpu.h:44: error: ‘GFP_KERNEL’ undeclared (first use in this function)
/usr/include/linux/percpu.h:44: error: (Each undeclared identifier is reported only once
/usr/include/linux/percpu.h:44: error: for each function it appears in.)

In file included from
/usr/include/asm/module.h:8,

from /usr/include/linux/module.h:22,

from hello.c:2:
/usr/include/asm-i486/module.h:60:2: error: #error unknown processor family

In file included from
hello.c:2:
/usr/include/linux/module.h: At top level:

/usr/include/linux/module.h:49: error: field ‘attr’ has incomplete type

/usr/include/linux/module.h:60: error: field ‘kobj’ has incomplete type

hello.c:13:2: warning: no newline at end of file

make: *** [hello] Erreur 1

le fichier Makefile est :
obj-m += hello-1.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

svp aidai moi c'est pour mon projet de fin d'étude,merci d'avace.
0
rufa Messages postés 160 Date d'inscription   Statut Membre Dernière intervention   4
 
pour: hello.c:13:2: warning: no newline at end of file
c'est résolu,il suffit d'aller a la dernière ligne du programme et d'appuyer sur entre,il reste le plus difficile.
0
amounsh
 
esque vous arriver à corriger les probléme
merci
0