the helloworld module

After reading Linux Device Drivers, 3rd Edition Chapter 2. Building and Running Modules, i decide to build a helloworld module.

Preparing:

               GCC: v4.1.2, name:arm-none-linux-gcc

               kernel:linux-2.6.22

steps:

               1. source codes:

                    hello_world.c  Makefile

               2.set the env

                    export PATH=$PATH:$PWD/tools/bin:$PWD/tools/sbin:$PWD/tools/include

               3. make

souce codes:

hello_world.c

############################

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int __init hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}
static void __exit hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);

 

Makefile

##################################

#
# Makefile for kernel hello_world drivers.
#
PWD =$(shell pwd)
ARCH := arm
CROSS_COMPILE =arm-none-linux-gnueabi-
KERNEL_SRC =/evanwei/linux-evan/linux-2.6.22
obj-m := hello_world.o
module-objs := hello_world.o
all: 
  $(MAKE) -C $(KERNEL_SRC) M=$(PWD)  ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE)modules clean: 
 rm *.ko *.o

 

notes: according to Linux Device Drivers, 3rd Edition Chapter 2. Building and Running Modules,

          the makefile can be written like these:

           $(MAKE) -C $(KERNEL_SRC) M=$(PWD)  modules

but this would occur a error:
include/linux/calc64.h: 在函数 ‘do_div_llr’ 中:
include/linux/calc64.h:25: 错误:‘__LINUX_ARM_ARCH__’ 未声明 (在此函数内第一次使用)
include/linux/calc64.h:25: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
include/linux/calc64.h:25: 错误:所在的函数内只报告一次。)
In file included from include/asm/semaphore.h:13,
                 from include/linux/sched.h:59,
                 from include/linux/smp_lock.h:5,
                 from include/linux/hardirq.h:5,
                 from include/asm-generic/local.h:5,
                 from include/asm/local.h:1,
                 from include/linux/module.h:19,
                 from /evanwei/linux-evan/drivermodule/helloworld/hello_world.c:3:
include/asm/locks.h:15:5: warning: "__LINUX_ARM_ARCH__" is not defined
make[2]: *** [/evanwei/linux-evan/drivermodule/helloworld/hello_world.o] 错误 1
make[1]: *** [_module_/evanwei/linux-evan/drivermodule/helloworld] 错误 2
make[1]: Leaving directory `/evanwei/linux-evan/linux-2.6.22'

posted @ 2008-08-01 15:26  旅人  阅读(326)  评论(0编辑  收藏  举报