Compiling Linux kernel using Cross Compiler
Hi,
I am working on Linux kernel 2.6. I have created a simple kernel module.I have compiled it by preparing a sample makefile for the same. I could see that module compiles successfully and creates a .ko file for the same when i give make command on the terminal.I have also installed the module and i have dmesg' it to see the output on the terminal and it works.
Now I have ARM GNU cross compiler and I would like to compile the same kernel module using that cross compiler.The problem starts now when i start compiling it.
The options to be used for cross compiling any simple .c file would be tjis way:
arm-none-linux-gnueabi-gcc -static hello_proc.c -o hello
Now I am using the same option for cross compiling the kernel module.But after compiling I obtain lot of errors which look this way:
arm-none-linux-gnueabi-gcc -static -c -o hello_proc.o hello_proc.c
hello_proc.c:9:17: error: init.h: No such file or directory
hello_proc.c:10:26: error: linux/module.h: No such file or directory
hello_proc.c:11:27: error: linux/proc_fs.h: No such file or directory
hello_proc.c:17: error: expected declaration specifiers or '...' before 'off_t'
hello_proc.c: In function 'hello_read_proc':
hello_proc.c:20: warning: incompatible implicit declaration of built-in function 'strlen'
hello_proc.c:25: error: 'EINVAL' undeclared (first use in this function)
hello_proc.c:25: error: (Each undeclared identifier is reported only once
hello_proc.c:25: error: for each function it appears in.)
hello_proc.c:30: error: 'offset' undeclared (first use in this function)
hello_proc.c:35: warning: incompatible implicit declaration of built-in function 'strcpy'
hello_proc.c: At top level:
hello_proc.c:45: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hello_init'
hello_proc.c:61: warning: data definition has no type or storage class
hello_proc.c:61: warning: parameter names (without types) in function declaration
hello_proc.c:63: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hello_exit'
hello_proc.c:68: warning: data definition has no type or storage class
hello_proc.c:68: warning: parameter names (without types) in function declaration
make: *** [hello_proc.o] Error 1
hence I request you to tell me if the way i am compiling a kernel module using a cross compiler is right or wrong?
My kernel module looks like this:
/*
* "Hello, world!" minimal kernel module - /proc version
*
* Valerie Henson <val@nmt.edu>
*
*/
//#include <linux/init.h>
#include<init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
/*
* Write "Hello, world!" to the buffer passed through the /proc file.
*/
static int hello_read_proc(char *buffer, char **start, off_t offset, int size, int *eof,void *data)
{
char *hello_str = "Hello, world!\n";
int len = strlen(hello_str); /* Don't include the null byte. */
/*
* We only support reading the whole string at once.
if (size < len)
return -EINVAL;
/*
* If file position is non-zero, then assume the string has
* been read and indicate there is no more data to be read.
*/
if (offset != 0)
return 0;
/*
* We know the buffer is big enough to hold the string.
*/
strcpy(buffer, hello_str);
/*
* Signal EOF.
*/
*eof = 1;
return len;
}
static int __init hello_init(void)
{
/*
* Create an entry in /proc named "hello_world" that calls
* hello_read_proc() when the file is read.
*/
if (create_proc_read_entry("hello_world", 0, NULL, hello_read_proc,
NULL) == 0) {
printk(KERN_ERR
"Unable to register \"Hello, world!\" proc file\n");
return -ENOMEM;
}
return 0;
}
module_init(hello_init);
static void __exit hello_exit(void)
{
remove_proc_entry("hello_world", NULL);
}
module_exit(hello_exit);
|