编译我的hello.ko

本文档介绍了在Fedora13环境下编译Linux内核模块hello.ko的步骤,包括环境配置、模块源文件准备、在开发板上的装载与卸载,并提供了相关问题解决参考链接。
摘要由CSDN通过智能技术生成

一、环境:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值