[Résolu] compiler un module maison sous 2.6.26-2-686 Lenny

Bonjour,

J’avoue que je touche à ça pour la 1ere fois. Si je pouvais avoir un peu d’aide ou une indication, SVP.

En suivant le howto “http://tldp.org/HOWTO/Module-HOWTO/x839.html”, j’arrive à compiler le module en .o mais pas celui en .ko.

j’arrive à créer le .mod.c à partir du .o avec la commande:
usr/src/linux-kbuild-2.6.26/scripts/mod/modpost hello.o

mais la compilation du hello.mod.c plante… le début du listing d’erreurs est:
In file included from /usr/src/linux/include/linux/prefetch.h:13,
from /usr/src/linux/include/linux/list.h:6,
from /usr/src/linux/include/linux/module.h:9,
from hello.mod.c:2:
/usr/src/linux/include/linux/types.h:140: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘sector_t’
/usr/src/linux/include/linux/types.h:149: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘blkcnt_t’

la commande de compil est :
gcc -c -Wall -I /usr/src/linux/include -I /usr/src/linux/include/asm/mach-default hello.mod.c -o hello.mod.o

Voilà les lignes 139 à 144 du fichier /usr/src/linux/include/linux/types.h:140
#ifdef CONFIG_LBD
typedef u64 sector_t;
#else
typedef unsigned long sector_t;
#endif

Voilà le fichier généré hello.mod.c (rajout d’une 1ere ligne):

#include <linux/autoconf.h> //rajout perso
#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

MODULE_INFO(vermagic, VERMAGIC_STRING);

struct module __this_module
attribute((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

static const char __module_depends[]
__used
attribute((section(".modinfo"))) =
“depends=”;

Je crois avoir récupéré les sources avec la commande m-a prepare

pthp:/usr/src# ls -lh /usr/src
lrwxrwxrwx 1 root src 26 2009-07-13 11:42 linux -> linux-headers-2.6.26-2-686
drwxr-xr-x 4 root root 4.0K 2009-07-13 11:46 linux-headers-2.6.26-2-686
drwxr-xr-x 18 root root 4.0K 2009-07-13 11:46 linux-headers-2.6.26-2-common
drwxr-xr-x 3 root root 4.0K 2009-07-11 14:25 linux-kbuild-2.6.26
drwxr-xr-x 3 root root 4.0K 2008-11-26 16:20 modules

J’ai fait un petit link
/usr/src/linux/include# ln -s asm-generic asm

pthp:/usr/src# uname -a
Linux pthp 2.6.26-2-686 #1 SMP Sun Jun 21 04:57:38 UTC 2009 i686 GNU/Linux

Debian Lenny

Et voilà la compil du hello.c
gcc -c -Wall -I /usr/src/linux/include -I /usr/src/linux/include/asm/mach-default hello.c -o hello.o
=======hello.c=======
#define KERNEL /* We’re part of the kernel /
#define MODULE /
Not a permanent part, though. */

#include <linux/autoconf.h> // EBT

/* Standard headers for LKMs /
#include <config/modversions.h>
#include <linux/module.h>
#include <linux/tty.h> /
console_print() interface */

/* Initialize the LKM /
int init_module()
{
console_print(“Hello, world - this is the kernel speaking\n”);
/
More normal is printk(), but there’s less that can go wrong with
console_print(), so let’s start simple.
*/

/* If we return a non zero value, it means that

  • init_module failed and the LKM can’t be loaded
    */
    return 0;
    }

/* Cleanup - undo whatever init_module did */
void cleanup_module()
{
console_print(“Short is the life of an LKM\n”);
}

Merci

Résolu. J’ai changé de maître:
tldp.org/LDP/lkmpg/2.6/html/x181.html