LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Linux Device Driver (http://www.linuxquestions.org/questions/linux-software-2/linux-device-driver-253779/)

malacma 11-11-2004 05:07 PM

Linux Device Driver
 
Hi!

i'm trying to install a module into the Linux Red Hat 9 Kernel, using the insmod directive. It happens that when i try to insmod dParalela.o the follow message appears;

[root@Webthread tcd]# gcc -O2 -c -pthread -D__KERNEL__ -D_MODULE_ -DOUTSIDE_KERNEL dParalela.c
[root@Webthread tcd]# insmod -f dParalela.o
dParalela.o: couldn't find the kernel version the module was compiled for
[root@Webthread tcd]#

please somebody help me!!!

Thanks a LOT!!!

here the code i've denveloped....

/*
Diretiva de ompilação no GCC LINUX
gcc -O2 -pthread -c dParalela.c
*/

#include <linux/kernel.h>
#include <linux/module.h>
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <linux/version.h>

#define MODULE
#define MODULE_VERSION "1.00001"
#define MODULE_NAME "Device Paralela"

#define __NO_VERSION__

#define BIT0LIGALED1 3
#define BIT1LIGALED2 15
#define BIT2LIGALED3 9
#define BIT3LIGALED4 10
#define DESLIGALEDCTR 11
#define PORTADEDADOS 0x378
#define PORTADESTATUS (PORTADEDADOS + 1)
#define PORTADECONTROLE (PORTADEDADOS + 2)
#define SINALINTERRUPCAO 0x10
#define INTERRUPCAO 7
#define DEVICE_NAME "dParalelaV1.00001" //Nome que aparece em /proc/devices

static int Major; //Major numero a ser registrado pelo device
static unsigned char estado=0; //Estado do Device aberto

pthread_t thread_paralela; //Thread para escrever na saida
char *n_thread = "Thread dParalelaV1.00001"; //Nome da thread
int i_thread = 0; //Número Thread

void libera_stream(void){
int flsh = fflush(NULL);
if(flsh == errno){
printk("<1>Não consegui liberar os streams de saída.....");
}
}

void zera_paralela(void){
outb(0x00,PORTADEDADOS); //Apaga o LED de status
outb(0x00,PORTADESTATUS); //Desabilita a porta
outb(0x00,PORTADECONTROLE); //Desabilita a porta
outb(PORTADECONTROLE,DESLIGALEDCTR);
free_irq (INTERRUPCAO,NULL); //Libera a interrupção
MOD_DEC_USE_COUNT; //Decrementa o contador de uso do kernel
libera_stream();

}

void interrupcao_paralela(void){
estado++;
if (estado == 0xFF){
estado = 0;
}
outb(estado, PORTADEDADOS);
printk("<1>Estado = %d\n",estado);
MOD_INC_USE_COUNT; //Incrementa o contador de uso do módulo no Kernel
outb(PORTADECONTROLE,BIT0LIGALED1); //Liga led 1 de controle;
getchar();
outb(PORTADECONTROLE,BIT1LIGALED2); //Liga led 2 de controle;
getchar();
outb(PORTADECONTROLE,BIT2LIGALED3); //Liga led 3 de controle;
getchar();
outb(PORTADECONTROLE,BIT3LIGALED4); //Liga led 4 de controle;
getchar();
libera_stream();
}

int init_module(void) {
Major = register_chrdev(0, DEVICE_NAME,NULL); //Registra no Kernel o major do Device

if (Major < 0) {
printk ("<1>Não foi possível registrar este device de paralela com o major n°: %d\n", Major);
return Major;
}
else{
printk ("<1>Módulo do device acoplado no Kernel com o numero Major:%d\n", Major);
return Major;

int rv = 0;
rv = request_irq(INTERRUPCAO,NULL,NULL,"Paralela Device Driver",NULL); //Solicita IRQ faltam as operações....

if(rv){ //Valida para ver se conseguiu fazer a interrupção
printk("<1>Não foi possível habilitar a interrupção N° %d\n", INTERRUPCAO);
}
else{
printk("<1>Modulo Device Driver paralela inicializado\n");
i_thread = pthread_create( &thread_paralela, NULL, (void*)&interrupcao_paralela, (void*) n_thread);

if(i_thread == 0){
printk("<1>%dThread de controle acionou o dispositivo\n",thread_paralela);
return 0;
}
else{
printk("<1>Não foi possível criar Thread de controle para escrever no dispositivo\n");
}
}
pthread_exit(NULL);
}

}

void cleanup_module(void) {
i_thread = pthread_create( &thread_paralela, NULL, (void*)&zera_paralela, (void*) n_thread);
if(i_thread == 0){
printk("<1>%dThread de controle Liberou o dispositivo\n",thread_paralela);
}
pthread_exit(NULL);
int ret = unregister_chrdev(Major, DEVICE_NAME); //Remove o módulo do kernel

if (ret < 0){
printk("Erro ao remover o módulo Device Driver paralela: %d\n", ret);
}
else{
printk("<1>Modulo Device Driver paralela finalizado\n");
}
}

MODULE_AUTHOR("Luís Augusto Machado Moretto");
MODULE_DESCRIPTION("TCD - Teste da Paralela - SO/2004-2");
MODULE_LICENSE("GPL");
EXPORT_NO_SYMBOLS;

rjlee 11-12-2004 05:09 AM

It looks like you are compiling the module without the #define statement that tells it to embed versioning information in the module file.

Is your /usr/src/linux tree configured in the same way as the kernel you're actually running? If this isn't the case, it's likely that your module won't be runnable anyway, especially if you're using your distribution's defaults which tend to differ from the source defaults.

If it is, have you tried insmod --force? It can overcome some problems like that.

klopex 11-12-2004 10:02 AM

I am currently struggling with a slightly different module/kernel version problem. Perhaps something I found will help...

In the Oreilly book "Linux Device Drivers" Second Edition (available for free download from http://www.xml.com/ldd/chapter/book/ ) in chapter 11 it discusses module versioning. Try looking there for some help!

klopex

nirav.jani 12-07-2004 08:50 AM

Hello,
Uptill I know this type of problem is generated when your kernel is not compiled with your current gcc version, so try to compile your kernel using curent gcc you will solve this problem, that is one way another way you can found at following link
just check it out
http://www.linuxforum.com/forums/ind...owtopic=115437
I have solved my problem using above solution also,
Nirav

clnbabu 09-03-2007 03:32 PM

pci driver
 
i wamt to develope a add on realy card based on pci...please help me out how to proceed for that.

us_ed 09-05-2007 04:09 AM

Hi all
OS Scientific Linux 5.0
Driver matrox_driver-x86_32-src-4.4.0.tar.gz from Matrox.com for Millenium G450
Configure without error
make :
mga_dacG.c:121: error: 'UCHAR' undeclared (first use in this function)
after i add #include "binding.h" in mga_dacG.c
old error disappeared
and add new
mga_driver.c:2049: error: 'struct <anonymous>' has no member named 'pMgaHwInfo'

johnhamiltion 09-05-2007 07:43 AM

You guys should try reading Greg Kroah-Hartman's book

"Linux Device Drivers 3."

You can download it (as a single web-page) from

johnhamiltion 09-06-2007 08:30 AM

Greg Kroah-Hartman writes a good book, doesn't he?

us_ed 09-07-2007 03:37 AM

Thank!
i am will thought.

ComputerGreek 09-16-2007 07:31 AM

[QUOTE=johnhamiltion;2881911]You guys should try reading Greg Kroah-Hartman's book

"Linux Device Drivers 3."

You can download it (as a single web-page) from

ComputerGreek 10-09-2007 06:14 AM

Not much happens here, does it.


All times are GMT -5. The time now is 10:52 PM.