Embedded Linux: Hardware, Software and Interfacing Serving the Embedded Linux Community Since 2001    
 Welcome to Embedded Linux: Hardware, Software and Interfacing
 Friday, September 10 2010 @ 11:54 AM MDT

2.6.10 Kernel Module Compilation

   

SoftwareStarting with Ubuntu 5.10 and the helloworld module at http://www.embeddedlinuxinterfacing.com/source/helloworld_proc_module_symbol.c
1) uname -a to determine what version of the kernel we're running.
In our case, the output was:

Linux tbdev1 2.6.12-10-386 #1 Tue Jul 18 22:08:27 UTC 2006 i686 GNU/Linux
2) sudo apt-get install linux-source-2.6.12
3) cd /usr/src
4) sudo tar -xvjf linux-source-2.6.12.tar.bz2
5) sudo ln -s linux-source-2.6.12 linux to create /usr/src/linux
6) sudo apt-get install build-essential
7) cat /proc/version to see what version of gcc the kernel was compiled with

In our case, the output was:
Linux version 2.6.12-10-386 (buildd@terranova) (gcc version 3.4.5 20050809 (prerelease)
(Ubuntu 3.4.4-6ubuntu8.1)) #1 Tue Jul 18 22:08:27 UTC 2006
8) sudo apt-get install gcc-3.4 to have the command "gcc-3.4"

Now, we can issue make CC="gcc-3.4"

9) build the kernel using sudo make CC="gcc-3.4" bzImage so the kernel module build had something to link against.
10) Building a module in 2.6.10 isn't the same as 2.4, and we need a Makefile, so use the following:
CC="gcc-3.4"
ifneq ($(KERNELRELEASE),)
    obj-m       := helloworld_proc_module_symbol.o

else
    KDIR        := /usr/src/linux
    PWD         := $(shell pwd)

    default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif
clean:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean
11) wget http://www.embeddedlinuxinterfacing.com/source/helloworld_proc_module_symbol.c
12) make

Oops, the output shows some warnings about EXPORT_SYMBOL_NOVERS, and an unreferenced variable (int rv at line 170), and a redefinition of MODULE_VERSION. Some research shows the EXPORT_SYMBOLS_NOVERS macro is now deprecated. So, removing lines 213 and 214 will fix that warning. Removing line 170 (unreferenced variable, rv) will fix that warning. Modifying references of MODULE_VERSION to hwMODULE_VERSION will fix the redefinition warning. Note that a MODULE_VERSION macro added to 2.6.3(?), so a better solution would be to use another #define to indicate the version string, but this will do for a quick and dirty fix.

helloworld_proc_module-v1.2.c
Makefile

13) make clean;make ---> should now produce a clean (no warnings or errors) build of helloworld_proc_module_symbol.ko
15) sudo insmod helloworld_proc_module_symbol.ko
16) cat /proc/helloworld produces "helloworld Default"
17) sudo rmmod helloworld_proc_module_symbol


Access the Linux kernel using the /proc filesystem, from developerWorks




What's Related

Story Options

2.6.10 Kernel Module Compilation | 0 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Copyright © 2002-2008 Craig Hollabaugh
All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.06 seconds