linux模組載入記錄

來源:互聯網
上載者:User

hello程式

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

 

makefile內容

ifeq ($(KERNELRELEASE),)KERNELDIR ?=/root/Desktop/linux-2.6.32.2PWD := $(shell pwd)modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modulesmodules_install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_installclean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions.PHONY: modules modules_install cleanelse    obj-m := hello.oendif

 

終端執行make出現如下的錯誤:

 

ERROR: Kernel configuration is invalid.include/linux/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it.
原因是因為沒有編譯核心,解決方案如下

編譯核心的步驟:

1. cp menu_mini2440_x35 .config

2.修改核心目錄下的Makefile

ARCH      ?=arm

CROSS_COMPILE ?=arm-linux-

 

3.make menuconfig

4.make

做完這幾步之後在hello目錄下執行make即可出現hello.ko檔案

將hello.ko檔案拷貝到開發板執行

[root@FriendlyARM share]# insmod hello.ko Hello world[root@FriendlyARM share]# lsmodhello 505 0 - Live 0xbf000000[root@FriendlyARM share]# rmmod hello Hello world exitrmmod: module 'hello' not found

對於裝置,載入完驅動之後要建立節點檔案

mknod  /dev/beep  c  major  0

beep  為裝置名稱

c 代表位字元裝置

major 代表為主裝置號

0 代表為次裝置號

帶參數的執行結果如下:

[root@FriendlyARM share]# insmod hello_ext.ko howmany=4 whom="jiejie"Hello jiejieHello jiejieHello jiejieHello jiejie[root@FriendlyARM share]# rmmod hello_ext.ko [root@FriendlyARM share]# rmmod hello_ext     Hello world exitrmmod: module 'hello_ext' not found

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.