一、环境:
1. PC: Fedora13:
[feng@~ #2]$uname -a
Linux Fedora13 2.6.34.8-68.fc13.i686.PAE #1 SMP Thu Feb 17 14:54:10 UTC 2011 i686 i686 i386 GNU/Linux
[feng@~ #3]$
2. 开发板
~ $ uname -a
Linux (none) 2.6.24-rt1-hi3515v100 #7 Thu Nov 10 18:42:18 CST 2011 armv5tejl unknown
~ $
二. 编译过程
1. 准备模块相关文件:源文件hello.c及Makefile
[root@c #72]#pwd
/mnt/mdisk5/program/c
[root@c #69]#ls -a
. .. hello.c Makefile
[root@c #70]#cat hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
[root@c #71]#cat Makefile
ifneq ($(KERNELRELEASE), )
obj-m := hello.o
else
#KDIR ?= /mnt/mdisk5/kernel/linux-2.6.34.14
KDIR ?= /mnt/mdisk5/kernel/linux-2.6.24
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
cp hello.ko /tftpboot/DVR/
clean:
rm -f *.ko *.o *.mod.o *.mod.c Module.symvers modules.order .*.cmd
rm -rf .tmp_versions
endif
[root@c #72]#
2. 准备内核源码及配置
[feng@~ #52]$cd /mnt/mdisk5/kernel/linux-2.6.24/
[feng@linux-2.6.24 #53]$ls -a
. arch COPYING crypto drivers .gitignore hi_patchset init Kbuild lib .mailmap Makefile net REPORTING-BUGS scripts sound
.. block CREDITS Documentation fs .hil_config include ipc kernel linux_kbuild_export.sh MAINTAINERS mm README samples security usr
[feng@linux-2.6.24 #54]$cp arch/arm/configs/hi3515v100_full_release_defconfig .config
[feng@linux-2.6.24 #55]$ls -a
. arch .config CREDITS Documentation fs .hil_config include ipc kernel linux_kbuild_export.sh MAINTAINERS mm README samples security usr
.. block COPYING crypto drivers .gitignore hi_patchset init Kbuild lib .mailmap Makefile net REPORTING-BUGS scripts sound
[feng@linux-2.6.24 #56]$head -n10 .config
#
# Automatically generated make config: don't edit
# Linux kernel version: 2.6.24
# Fri Nov 20 09:15:27 2009
#
CONFIG_ARM=y
CONFIG_SYS_SUPPORTS_APM_EMULATION=y
# CONFIG_GENERIC_GPIO is not set
CONFIG_GENERIC_TIME=y
CONFIG_GENERIC_CLOCKEVENTS=y
[feng@linux-2.6.24 #57]$head -n10 Makefile
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 24
EXTRAVERSION =
NAME = Arr Matey! A Hairy Bilge R