一、环境:

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.14KDIR ?= /mnt/mdisk5/kernel/linux-2.6.24PWD := $(shell pwd)default:$(MAKE) -C $(KDIR) M=$(PWD) modulescp hello.ko /tftpboot/DVR/clean:rm -f *.ko *.o *.mod.o *.mod.c Module.symvers modules.order .*.cmdrm -rf .tmp_versionsendif
[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 Rat!HIL_CONFIG_FILE=.hil_config# *DOCUMENTATION*
# To see a list of typical targets execute "make help"
[feng@linux-2.6.24 #58]$make prepareHOSTCC  scripts/basic/fixdep
scripts/basic/fixdep.c: 在函数‘traps’中:
scripts/basic/fixdep.c:377: 警告:提领类型双关的指针将破坏强重叠规则
scripts/basic/fixdep.c:379: 警告:提领类型双关的指针将破坏强重叠规则HOSTCC  scripts/basic/docprocHOSTCC  scripts/kconfig/conf.oHOSTCC  scripts/kconfig/kxgettext.oSHIPPED scripts/kconfig/zconf.tab.cSHIPPED scripts/kconfig/lex.zconf.cSHIPPED scripts/kconfig/zconf.hash.cHOSTCC  scripts/kconfig/zconf.tab.o
scripts/kconfig/lex.zconf.c:1639: 警告:‘input’定义后未使用HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf -s arch/arm/Kconfig
arch/arm/Kconfig:11:warning: 'select' used by config symbol 'ARM' refers to undefined symbol 'HAVE_ARCH_KGDB'
.config:57:warning: trying to assign nonexistent symbol RADIX_TREE_CONCURRENT
.config:58:warning: trying to assign nonexistent symbol HAVE_IMMEDIATE
.config:86:warning: trying to assign nonexistent symbol LTT_TIMESTAMP
.config:87:warning: trying to assign nonexistent symbol HAVE_LTT_UNSTABLE_TSC
.config:88:warning: trying to assign nonexistent symbol HAVE_LTT_CLOCK
.config:89:warning: trying to assign nonexistent symbol HAVE_LTT_SYNTHETIC_TSC
.config:90:warning: trying to assign nonexistent symbol HAVE_LTT_DUMP_TABLES
.config:91:warning: trying to assign nonexistent symbol HAVE_OPROFILE
.config:92:warning: trying to assign nonexistent symbol HAVE_KPROBES
.config:218:warning: trying to assign nonexistent symbol PREEMPT_DESKTOP
.config:219:warning: trying to assign nonexistent symbol PREEMPT_RT
.config:220:warning: trying to assign nonexistent symbol PREEMPT_SOFTIRQS
.config:221:warning: trying to assign nonexistent symbol PREEMPT_HARDIRQS
.config:223:warning: trying to assign nonexistent symbol CLASSIC_RCU
.config:224:warning: trying to assign nonexistent symbol PREEMPT_RCU
.config:225:warning: trying to assign nonexistent symbol RCU_TRACE
.config:869:warning: trying to assign nonexistent symbol RMEM
.config:870:warning: trying to assign nonexistent symbol ALLOC_RTSJ_MEM
.config:1507:warning: trying to assign nonexistent symbol EVENT_TRACE
.config:1508:warning: trying to assign nonexistent symbol WAKEUP_TIMING
.config:1509:warning: trying to assign nonexistent symbol CRITICAL_IRQSOFF_TIMING
.config:1526:warning: trying to assign nonexistent symbol GCOV_PROFILE
.config:1527:warning: trying to assign nonexistent symbol KGDB
*
* Restart config...
*
*
* Kernel Features
*
Tickless System (Dynamic Ticks) (NO_HZ) [N/y/?] n
High Resolution Timer Support (HIGH_RES_TIMERS) [N/y/?] n
Preemption Model
> 1. No Forced Preemption (Server) (PREEMPT_NONE)2. Voluntary Kernel Preemption (Desktop) (PREEMPT_VOLUNTARY)3. Preemptible Kernel (Low-Latency Desktop) (PREEMPT) (NEW)
choice[1-3]:
Use the ARM EABI to compile the kernel (AEABI) [N/y/?] n
Memory model
> 1. Flat Memory (FLATMEM_MANUAL)
choice[1]: 1
64 bit Memory and IO resources (EXPERIMENTAL) (RESOURCES_64BIT) [N/y/?] n
*
* USB support
*
USB support (USB_SUPPORT) [Y/n/?] ySupport for Host-side USB (USB) [Y/n/m/?] yUSB verbose debug messages (USB_DEBUG) [N/y/?] n** Miscellaneous USB options*USB device filesystem (USB_DEVICEFS) [Y/n/?] yUSB device class-devices (DEPRECATED) (USB_DEVICE_CLASS) [Y/n/?] yDynamic USB minor allocation (EXPERIMENTAL) (USB_DYNAMIC_MINORS) [N/y/?] n** USB Host Controller Drivers*EHCI HCD (USB 2.0) support (USB_EHCI_HCD) [Y/n/m/?] yFull speed ISO transactions (EXPERIMENTAL) (USB_EHCI_SPLIT_ISO) [N/y/?] nRoot Hub Transaction Translators (EXPERIMENTAL) (USB_EHCI_ROOT_HUB_TT) [N/y/?] nImproved Transaction Translator scheduling (EXPERIMENTAL) (USB_EHCI_TT_NEWSCHED) [N/y/?] nISP116X HCD support (USB_ISP116X_HCD) [N/m/y/?] nOHCI HCD support (USB_OHCI_HCD) [Y/n/m/?] ySL811HS HCD support (USB_SL811_HCD) [N/m/y/?] nR8A66597 HCD support (USB_R8A66597_HCD) [N/m/y/?] n** USB Device Class drivers*USB Modem (CDC ACM) support (USB_ACM) [M/n/y/?] mUSB Printer support (USB_PRINTER) [N/m/y/?] n** NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'*** may also be needed; see USB_STORAGE Help for more information*USB Mass Storage support (USB_STORAGE) [M/n/y/?] mUSB Mass Storage verbose debug (USB_STORAGE_DEBUG) [N/y/?] nDatafab Compact Flash Reader support (EXPERIMENTAL) (USB_STORAGE_DATAFAB) [Y/n/?] yFreecom USB/ATAPI Bridge support (USB_STORAGE_FREECOM) [Y/n/?] yISD-200 USB/ATA Bridge support (USB_STORAGE_ISD200) [Y/n/?] yMicrotech/ZiO! CompactFlash/SmartMedia support (USB_STORAGE_DPCM) [Y/n/?] yUSBAT/USBAT02-based storage support (EXPERIMENTAL) (USB_STORAGE_USBAT) [Y/n/?] ySanDisk SDDR-09 (and other SmartMedia) support (EXPERIMENTAL) (USB_STORAGE_SDDR09) [Y/n/?] ySanDisk SDDR-55 SmartMedia support (EXPERIMENTAL) (USB_STORAGE_SDDR55) [Y/n/?] yLexar Jumpshot Compact Flash Reader (EXPERIMENTAL) (USB_STORAGE_JUMPSHOT) [Y/n/?] yOlympus MAUSB-10/Fuji DPC-R1 support (EXPERIMENTAL) (USB_STORAGE_ALAUDA) [Y/n/?] ySupport OneTouch Button on Maxtor Hard Drives (EXPERIMENTAL) (USB_STORAGE_ONETOUCH) [N/y/?] nSupport for Rio Karma music player (USB_STORAGE_KARMA) [N/y/?] nThe shared table of common (or usual) storage devices (USB_LIBUSUAL) [N/y/?] n** USB Imaging devices*USB Mustek MDC800 Digital Camera support (EXPERIMENTAL) (USB_MDC800) [M/n/y/?] mMicrotek X6USB scanner support (USB_MICROTEK) [M/n/y/?] mUSB Monitor (USB_MON) [Y/n/?] y** USB port drivers*** USB Miscellaneous drivers*EMI 6|2m USB Audio interface support (USB_EMI62) [M/n/y/?] mEMI 2|6 USB Audio interface support (USB_EMI26) [M/n/y/?] mADU devices from Ontrak Control Systems (EXPERIMENTAL) (USB_ADUTUX) [N/m/y/?] nUSB Auerswald ISDN support (EXPERIMENTAL) (USB_AUERSWALD) [M/n/y/?] mUSB Diamond Rio500 support (EXPERIMENTAL) (USB_RIO500) [M/n/y/?] mUSB Lego Infrared Tower support (EXPERIMENTAL) (USB_LEGOTOWER) [M/n/y/?] mUSB LCD driver support (USB_LCD) [M/n/y/?] mUSB BlackBerry recharge support (USB_BERRY_CHARGE) [N/m/y/?] nUSB LED driver support (USB_LED) [M/n/y/?] mCypress CY7C63xxx USB driver support (USB_CYPRESS_CY7C63) [N/m/y/?] nCypress USB thermometer driver support (USB_CYTHERM) [N/m/y/?] nUSB Phidgets drivers (USB_PHIDGET) [N/m/y/?] nSiemens ID USB Mouse Fingerprint sensor support (USB_IDMOUSE) [M/n/y/?] mElan PCMCIA CardBus Adapter USB Client (USB_FTDI_ELAN) [N/m/y/?] nApple Cinema Display support (USB_APPLEDISPLAY) [M/n/y/?] mUSB 2.0 SVGA dongle support (Net2280/SiS315) (USB_SISUSBVGA) [N/m/y/?] (NEW) USB LD driver (USB_LD) [M/n/y/?] mPlayStation 2 Trance Vibrator driver support (USB_TRANCEVIBRATOR) [N/m/y/?] nIO Warrior driver support (USB_IOWARRIOR) [N/m/y/?] nUSB testing driver (DEVELOPMENT) (USB_TEST) [M/n/y/?] m
#
# configuration written to .config
#CHK     include/linux/version.hUPD     include/linux/version.hSYMLINK include/asm-arm/arch -> include/asm-arm/arch-hi3515v100Generating include/asm-arm/mach-types.hCHK     include/linux/utsrelease.hUPD     include/linux/utsrelease.hSYMLINK include/asm -> include/asm-armCC      arch/arm/kernel/asm-offsets.sGEN     include/asm-arm/asm-offsets.hCALL    scripts/checksyscalls.sh
<stdin>:1097:2: warning: #warning syscall fadvise64 not implemented
<stdin>:1265:2: warning: #warning syscall migrate_pages not implemented
<stdin>:1321:2: warning: #warning syscall pselect6 not implemented
<stdin>:1325:2: warning: #warning syscall ppoll not implemented
<stdin>:1365:2: warning: #warning syscall epoll_pwait not implemented
[feng@linux-2.6.24 #59]$
[feng@linux-2.6.24 #59]$make scriptsCC      scripts/mod/empty.oHOSTCC  scripts/mod/mk_elfconfigMKELF   scripts/mod/elfconfig.hHOSTCC  scripts/mod/file2alias.oHOSTCC  scripts/mod/modpost.oHOSTCC  scripts/mod/sumversion.oHOSTLD  scripts/mod/modpostHOSTCC  scripts/kallsymsHOSTCC  scripts/conmakehash

3. 编译模块,并将模块拷贝到目标目录(/tftpboot/DVR/)

[root@c #72]#pwd
/mnt/mdisk5/program/c
[root@c #73]#cd
[root@~ #74]#cd /mnt/mdisk5/program/c/
[root@c #75]#ls -a
.  ..  hello.c  Makefile
[root@c #76]#make
make -C /mnt/mdisk5/kernel/linux-2.6.24 M=/mnt/mdisk5/program/c modules
make[1]: Entering directory `/mnt/mdisk5/kernel/linux-2.6.24'WARNING: Symbol version dump /mnt/mdisk5/kernel/linux-2.6.24/Module.symversis missing; modules will have no dependencies and modversions.CC [M]  /mnt/mdisk5/program/c/hello.oBuilding modules, stage 2.MODPOST 1 modulesCC      /mnt/mdisk5/program/c/hello.mod.oLD [M]  /mnt/mdisk5/program/c/hello.ko
make[1]: Leaving directory `/mnt/mdisk5/kernel/linux-2.6.24'
cp hello.ko /tftpboot/DVR/
[root@c #77]#modinfo hello.ko
filename:       hello.ko
license:        GPL
depends:
vermagic:       2.6.24-rt1-hi3515v100 mod_unload ARMv5
[root@c #78]#ls -a
.  ..  hello.c  hello.ko  .hello.ko.cmd  hello.mod.c  hello.mod.o  .hello.mod.o.cmd  hello.o  .hello.o.cmd  Makefile  Module.symvers  .tmp_versions
[root@c #79]#

4. 在开发板上装载和卸载hello.ko

/mnt/nfs $ cd
~ $ pwd
/root
~ $ df
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/mtdblock2           21020     21020         0 100% /
tmpfs                    22400         4     22396   0% /dev
tmpfs                    22400      7920     14480  35% /tmp
tmpfs                    22400         0     22400   0% /mnt
tmpfs                    22400         4     22396   0% /var
/dev/mtdblock1            2048       772      1276  38% /mnt/mtd
192.168.1.37:/tftpboot/DVR  19094240  13034976   5089312  72% /mnt/nfs
~ $ cd /mnt/nfs
/mnt/nfs $ ls
Wireless                  lvr_3515_pf_new           snap_20000101_000143.jpg
hello.ko                  lvrosd                    snap_20000101_000223.jpg
isp_config.ini            res                       snap_20000101_000657.jpg
lvftest                   screenshot_hisi           wiff
/mnt/nfs $ insmod hello.ko
Hello, world
/mnt/nfs $ lsmod | grep hello
hello                   1024  0
/mnt/nfs $ rmmod hello
Goodbye, cruel world
/mnt/nfs $ lsmod | grep hello
/mnt/nfs $ 

三、说明

1.  我的Fedora13的IP为:192.168.1.37,开发板将Fedora13下的/tftpboot/DVR/ 挂载到 /mnt/nfs/ 下

2.  我上面的运行结果是串口下进行的,所以能看到输出的结果。如果是通过telnet上去的话,可能看不到输出结果的,但是可以用cat /var/log/syslog 或 dmesg 查看。

3.  我用的开发板是基于海思Hi3515平台的,所以用的.config来自于arch/arm/configs/hi3515v100_full_release_defconfig文件。

4.  若要对内核源代码进行清理,以便下次重新编译,可以执行"make clean"或"make distclean",这两个的区别可以看内核目录下的Makefile文件,说明很详细!

四、总结

1. 对内核源代码的相关操作:

a)  进入内核源代码目录

b) 生成.config文件,方法有很多,我是运行"cp arch/arm/configs/hi3515v100_full_release_defconfig .config",根据不同的目标环境,复制的源配置文件也不同。

c) 执行: make prepare

d) 执行: make scripts

2. 对自己编写的模块的操作

a) 写好hello.c及Makefile文件(文件名必须为”Makefile", 不能为“makefile")

b) 编译: make

3. 遇到错误,可参考: http://blog.csdn.net/joeblackzqq/article/details/8694431

编译我的hello.ko相关推荐

  1. linux下驱动编译报错EEROR: *** [***.ko] undefined! 的错误原因和解决办法

    出现错误的原因:在编译驱动出现这种ERROR"xxx函数" [*.ko] undefined!错误一般是xxx函数找不到,或者说没定义,驱动编译的时候相关的函数没有找到! 有以下解 ...

  2. kali2022编译Linux内核驱动ko文件

    在Linux环境下编译.ko内核驱动文件(运行于本linux系统,非嵌入式),需要保证/lib/modules/xxx的版本与内核版本保持一致,否则编译后的驱动无法运行! 1.更新内核版本及heade ...

  3. 编译linux内核生成.ko,Linux内核编译完整过程

    通过网上的资料我自己的实际内核编译,我把对Linux内核编译的过程写在这里,也许对其他的Linux爱好者的编译学习有些帮助,其中很大部分是网上的资料,另外就是我在实际编译过程中的一些实际经验. 内核简 ...

  4. openwrt编译ifb.ko模块问题

    <*> kmod-ifb........................... Intermediate Functional Block support 开始时候怎么都编译不了ifb.k ...

  5. Android平台单独编译内核模块ko insmod

    第一次在android平台上单独编译内核模块并且insmod,过程比较难受,毕竟啥事第一次做都不怎么顺畅! 本文基于Android5.1 msm8909 因为笔者使用的平台物理串口只有两个,一个已经作 ...

  6. Linux kernel 编译 exfat.ko ntfs.ko 来支持exFat 和 NTFS 分区

    项目需求想让设备支持 exFat 和 NTFS 的文件格式. 默认的内核是不支持的,因为内核要限定1.5M之内, 所以很多东西都裁剪掉了. 而且不是所有项目都有这个需求,所以就需要编译为 ko ,按需 ...

  7. 多个.c文件编译成.ko文件

    以两个C文件为例: 将本该被分别编译成adc_device.ko和adc_driver.ko的adc_device.c.adc_driver.c编译成一个ko文件! 采用方法: 第一步.修改C文件 1 ...

  8. dpdk编译安装igb_uio报错 insmod: ERROR: could not insert module igb_uio.ko: File exists 问题

    前言 出错问题:insmod: ERROR: could not insert module igb_uio.ko: File exists 什么时候出现 insmod build/kmod/igb_ ...

  9. android ko 编译,如何把rtl8188EUS驱动编译生成ko模块并且下载到rk平台Android4.2.2上使用...

    下了rtl8188EUS_linux_v4.3.24_16705.20160509.tar.gz,看了里面的数据手册,发现有些看不懂,上网搜了一下,发现大部分博客都在扯淡...后来还是我把Makefi ...

最新文章

  1. php web server部署(PHP+Nginx+Redis+MySQL)
  2. 已解决AttributeError set object has no attribute items(亲测)
  3. ORA-01841: (完整) 年份值必须介于 -4713 和 +9999 之间, 且不为 0情况解决
  4. c语言远控,CC远控工具:WebSocket C2
  5. android工程怎么连手机,安卓手机怎么进工程模式 安卓手机进工程模式教程【详解】...
  6. 《Java核心技术卷一》读书笔记(二)
  7. 【ML】PAC learning model
  8. Java5线程并发库之同步集合
  9. 802.11n 重新扬帆
  10. 用友nc系统服务器是云端吗,用友NC服务器硬件配置要求
  11. 手机数控模拟器安卓版_CNC模拟器安卓中文版下载
  12. 字符编码——简体中文编码中区位码、国标码、内码、外码、字形码的区别及关系
  13. linux安装软件统一格式化,Ubuntu 14.04安装格式转换软件Format Junkie 1.07
  14. 【JAVA程序设计】(C00028)基于ssm的校园二手交易平台
  15. 2010-2019年款北汽原厂维修手册电路图线路图资料下载
  16. arcgis坐标转换
  17. (java)跳台阶:一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。
  18. gcat广告电商云南百收涉及传销新模式:社交电商消费返利
  19. 初学C语言1--C语言用什么软件编写
  20. windows_关闭windows休眠功能

热门文章

  1. 【评论】GNU/Linux下有多少是GNU的?
  2. date数据存入mysql_Date对象存入mysql数据库
  3. Memory-Associated Differential Learning论文及代码解读
  4. leetcode 331. 验证二叉树的前序序列化
  5. leetcode435. 无重叠区间(贪心算法)
  6. 如何使用Node.js,Express和MongoDB设置GraphQL服务器
  7. 小程序 graphql_GraphQL应用程序中的五个常见问题(以及如何解决)
  8. struct.error: cannot convert argument to integer解决办法
  9. 用cmd运行java可以javac不行(win10)
  10. Hello World(本博客启程篇)