|
技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機 | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計 | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
[分享]動態(tài)模塊加載的例子--原創(chuàng) |
作者:billy1980 欄目:DSP技術(shù) |
[分享]動態(tài)模塊加載的例子--原創(chuàng) 動態(tài)模塊加載的例子 首先在/root/SAMPLE_MODULE目錄(可任何目錄,后文編譯時指定即可)下創(chuàng)建一個c文檔,代碼如下: SAMPLE_MODULE.c ------------------------------------------------------------------ #include <linux/config.h> #include <linux/DEVICE.h> #include <linux/fs.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/MODULE.h> #include <linux/platform_DEVICE.h> #include <linux/sched.h> #define SAMPLE_MAJOR 253 MODULE_LICENSE("GPL"); MODULE_AUTHOR("hhzhou - ShenOu Communication"); MODULE_DESCRIPTION("SAMPLE"); static int SAMPLE_open(struct inode *inode, struct file *file) { return 0; }; static int SAMPLE_release(struct inode *inode, struct file *file) { return 0; }; static ssize_t SAMPLE_read(struct file *file, CHAR *buf, size_t size, loff_t *loff) { return 0; }; static ssize_t SAMPLE_write(struct file *file, const CHAR *buf, size_t size, loff_t *loff) { return 0; }; int SAMPLE_ioctl(struct inode *inode, struct file *file, unsigned int ioctl_num, unsigned LONG ioctl_param) { return 0; }; static struct file_operations SAMPLE_fops = { .read = SAMPLE_read, .write = SAMPLE_write, .ioctl = SAMPLE_ioctl, .open = SAMPLE_open, .release = SAMPLE_release, }; static int __init SAMPLE_MODULE_init(void) { printk("init SAMPLE MODULE DEVICE\n"); register_chrdev(SAMPLE_MAJOR, "SAMPLE", &SAMPLE_fops); return 0; } static void __exit SAMPLE_MODULE_cleanup(void) { printk("cleanup SAMPLE MODULE DEVICE\n"); } MODULE_init(SAMPLE_MODULE_init); MODULE_exit(SAMPLE_MODULE_cleanup); -------------------------------------------------------------------- 第二步,建Makefile文檔 -------------------------------------------------------------------- obj-m += SAMPLE_MODULE.o -------------------------------------------------------------------- 如果是多文件的話,使用如下: -------------------------------------------------------------------- obj-m := SAMPLE_MODULE.o MODULE-objs := file1.o file2.o -------------------------------------------------------------------- 第三步,確定內(nèi)核支持insmod, rmmod, lsmod 如不支持,可重新編譯內(nèi)核 -------------------------------------------------------------------- Linux Kernel Configuration Loadable MODULE SUPPORT [*] Enable loadable MODULE SUPPORT [*] MODULE unloading Application Main Menu BusyBox [*] insmod [*] insmod: lsmod [*] insmod: modprobe [*] insmod: rmmod [*] insmod: 2.6 and above kernel MODULEs [*] insmod: MODEL version checks [*] insmod: load in kernel MEMORY -------------------------------------------------------------------- 第四步,編譯 注意路徑,按你自己的路徑改下即可 -------------------------------------------------------------------- make -C /HHBF531-R1/uClinux-dist/linux-2.6.x SUBDIRS=/root/SAMPLE_MODULE MODULEs -------------------------------------------------------------------- 好啦,SAMPLE_MODULE.ko就是我們需要的MODULE啦 使用insmod SAMPLE_MODULE.ko加載吧 |
2樓: | >>參與討論 |
作者: billy1980 于 2006/10/12 16:14:00 發(fā)布:
以上例子在HHBf531-startkit開發(fā)板上試過可以 以上例子在HHBf531-startkit開發(fā)板上試過可以 |
3樓: | >>參與討論 |
作者: weixiao11 于 2006/10/12 16:15:00 發(fā)布:
頂 |
4樓: | >>參與討論 |
作者: billy1980 于 2006/10/12 16:23:00 發(fā)布:
:)謝謝超級MM版主支持 :)謝謝超級MM版主支持 |
5樓: | >>參與討論 |
作者: weixiao11 于 2006/10/12 16:45:00 發(fā)布:
呵呵 不用這樣用全稱吧,簡稱我也接受的 |
6樓: | >>參與討論 |
作者: zxm2006 于 2006/10/12 16:53:00 發(fā)布:
感謝 |
7樓: | >>參與討論 |
作者: hardfire 于 2006/10/13 13:36:00 發(fā)布:
學(xué)習... 好。 |
8樓: | >>參與討論 |
作者: yingzi1010 于 2007/4/7 10:13:00 發(fā)布:
樓主能提一份Makefile嗎 謝謝 |
9樓: | >>參與討論 |
作者: hardfire 于 2007/4/7 12:59:00 發(fā)布:
up for yingzi up |
|
|
免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進入 |
Copyright © 1998-2006 udpf.com.cn 浙ICP證030469號 |