LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-08-2007, 10:11 PM   #1
maheshk114
LQ Newbie
 
Registered: Sep 2007
Posts: 1

Rep: Reputation: 0
help me ..inserting a modle


hi All

i was trying to insert a module ..but it is giving compilation error ..

[root@localhost test]# gcc -D__KERNEL__ -I/usr/src/linux/include -O -Wall -c hello1.c
In file included from /usr/src/linux/include/asm/thread_info.h:16,
from /usr/src/linux/include/linux/thread_info.h:21,
from /usr/src/linux/include/linux/preempt.h:9,
from /usr/src/linux/include/linux/spinlock.h:49,
from /usr/src/linux/include/linux/module.h:9,
from hello1.c:1:
/usr/src/linux/include/asm/processor.h:83: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared here (not in a function)
/usr/src/linux/include/asm/processor.h:83: error: requested alignment is not a constant
In file included from /usr/src/linux/include/linux/module.h:21,
from hello1.c:1:
/usr/src/linux/include/asm/module.h:64:2: #error unknown processor family

i am using linux-2.6.22.5/ from linux.org ..

please help me out guys ... this is my first linux kernel level program
 
Old 09-09-2007, 08:50 AM   #2
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
It would seem to me you need to #include /usr/src/linux/.config so that CONFIG_X86_L1_CACHE_SHIFT is defined properly. Naturally this assumes you've configured first.

As a general rule you don't want to compile as root, and especially not in /usr/src/linux - you ought to copy the source to some other location (like ~/src/linux) and build there, only installing as root.
 
Old 09-09-2007, 12:21 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
It seems like you are using an older (2.4) method on newer (2.6) kernels. Moreover, you are including your header files from /usr/src/linux instead of those matching to your particular kernel (this may point to your actual kernel sources, but this is not the recommended way).

First off, please don’t do this:
Quote:
Originally Posted by ciotog View Post
It would seem to me you need to #include /usr/src/linux/.config so that CONFIG_X86_L1_CACHE_SHIFT is defined properly.
Basically, on newer kernels, everyone is advised to use the kernel make system. This means you will change directory to your kernel build tree, run “make” from there with some magical options which make the make system compile and link your module. If you just want to use this without all the explanation, skip down to the Makefile at the end.

<EXPLANATION>
First, we need the kernel build tree: If you compiled your kernel from source and installed modules with “make modules_install” (on your 2.6 kernel), it should have created a directory “/lib/modules/`uname -r`” which has a two symlinks: “source” points to the kernel source tree, and “build” points to the kernel build tree (note, that in most cases, they are the same).

The build tree is needed intact for this to work. Next, we need to know some of the magical variables we pass to the make system. The first such option tells the make system you want to compile external module(s) which reside in the directory you specify. This is “M” variable (alternatively, you could use the older “SUBDIRS” variable).

The other variable will tell the make system what to compile (in this case, your one file: hello1.c) and how to link it (in this case, as a module). To specify linkage as a module, you use the variable “obj-m” (the value of this variable is the same name as the source file except the suffix is “.o” rather than “.c”).

Now, we should be set for making your module. Basically, this is what you do (replace “/path/to/your/source” with the location of “hello1.c”):
Code:
$ make -C /lib/modules/`uname -r`/build M=/path/to/your/source obj-m=hello1.o
You should end up with (among other new files) a file named “hello1.ko” in the directory you specified. This is your module which you can insert with “insmod hello1.ko” (as root). Alternatively, you can install the module like this:
Code:
# make -C /lib/modules/`uname -r`/build M=/path/to/your/source obj-m=hello1.o modules_install
and insert it with “modprobe hello1” (as root).
</EXPLANATION>

If you don’t want to do this by hand each time, you can create a Makefile that looks something like this:
Code:
ifndef KERNELDIR
	KERNELDIR  := /lib/modules/$(shell uname -r)/build
endif

obj-m := hello1.o

all:
	$(MAKE) -C $(KERNELDIR) M=$(PWD)

clean:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) clean

install:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
	/sbin/depmod -ae
Place this file in the same directory that contains hello1.c, and just run “make” to build your module.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting Manpages bhandu Linux - Software 2 03-20-2006 10:25 AM
inserting nvidia? lilili Slackware 32 01-15-2006 06:12 AM
Setting up linuxbox as a router for windowsbox (my modle on the inside) Lechium Linux - Newbie 8 06-20-2004 04:25 AM
Inserting Text wildcat22 Linux - General 8 04-25-2004 07:51 AM
Inserting modules wgodois Linux - Hardware 0 08-03-2003 09:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration