编译我的hello.ko
一、環(huán)境:
1. PC: Fedora13:
2. 開(kāi)發(fā)板 ~ $ uname -a Linux (none) 2.6.24-rt1-hi3515v100 #7 Thu Nov 10 18:42:18 CST 2011 armv5tejl unknown ~ $
二. 編譯過(guò)程
1. 準(zhǔn)備模塊相關(guān)文件:源文件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. 準(zhǔn)備內(nèi)核源碼及配置
[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: 在函數(shù)‘traps’中: scripts/basic/fixdep.c:377: 警告:提領(lǐng)類型雙關(guān)的指針將破壞強(qiáng)重疊規(guī)則 scripts/basic/fixdep.c:379: 警告:提領(lǐng)類型雙關(guān)的指針將破壞強(qiáng)重疊規(guī)則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. 編譯模塊,并將模塊拷貝到目標(biāo)目錄(/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. 在開(kāi)發(fā)板上裝載和卸載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 $三、說(shuō)明
1.? 我的Fedora13的IP為:192.168.1.37,開(kāi)發(fā)板將Fedora13下的/tftpboot/DVR/ 掛載到 /mnt/nfs/ 下
2.? 我上面的運(yùn)行結(jié)果是串口下進(jìn)行的,所以能看到輸出的結(jié)果。如果是通過(guò)telnet上去的話,可能看不到輸出結(jié)果的,但是可以用cat /var/log/syslog 或 dmesg 查看。
3.? 我用的開(kāi)發(fā)板是基于海思Hi3515平臺(tái)的,所以用的.config來(lái)自于arch/arm/configs/hi3515v100_full_release_defconfig文件。
4.? 若要對(duì)內(nèi)核源代碼進(jìn)行清理,以便下次重新編譯,可以執(zhí)行"make clean"或"make distclean",這兩個(gè)的區(qū)別可以看內(nèi)核目錄下的Makefile文件,說(shuō)明很詳細(xì)!
四、總結(jié)
1. 對(duì)內(nèi)核源代碼的相關(guān)操作:
a)? 進(jìn)入內(nèi)核源代碼目錄
b) 生成.config文件,方法有很多,我是運(yùn)行"cp arch/arm/configs/hi3515v100_full_release_defconfig .config",根據(jù)不同的目標(biāo)環(huán)境,復(fù)制的源配置文件也不同。
c) 執(zhí)行: make prepare
d) 執(zhí)行: make scripts
2. 對(duì)自己編寫(xiě)的模塊的操作
a) 寫(xiě)好hello.c及Makefile文件(文件名必須為”Makefile", 不能為“makefile")
b) 編譯: make
3. 遇到錯(cuò)誤,可參考: http://blog.csdn.net/joeblackzqq/article/details/8694431
總結(jié)
以上是生活随笔為你收集整理的编译我的hello.ko的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: jdk自带常用命令行工具使用
- 下一篇: python随机出题_什么软件可以自制题