最新免费av在线观看,亚洲综合一区成人在线,中文字幕精品无码一区二区三区,中文人妻av高清一区二区,中文字幕乱偷无码av先锋

登錄 免費注冊 首頁 | 行業(yè)黑名單 | 幫助
維庫電子市場網(wǎng)
技術(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)模塊加載的例子--原創(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
以上例子在HHBf531-startkit開發(fā)板上試過可以
以上例子在HHBf531-startkit開發(fā)板上試過可以

3樓: >>參與討論
weixiao11

 
4樓: >>參與討論
billy1980
:)謝謝超級MM版主支持
:)謝謝超級MM版主支持

5樓: >>參與討論
weixiao11
呵呵
不用這樣用全稱吧,簡稱我也接受的

6樓: >>參與討論
zxm2006
感謝
 
7樓: >>參與討論
hardfire
學(xué)習...
好。

8樓: >>參與討論
yingzi1010
樓主能提一份Makefile嗎
謝謝 

9樓: >>參與討論
hardfire
up for yingzi
up

參與討論
昵稱:
討論內(nèi)容:
 
 
相關(guān)帖子
求一份驅(qū)動的Makefile,謝謝
blackfin開發(fā)者技術(shù)交流Q Q 群
用 mdct36.asm 時(類型0,1,3)twid_coef參數(shù)如何求得?
nfs restart  問題
有沒有在HOST模式下用過ADSP-2189的?過來指點一下
免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進入


Copyright © 1998-2006 udpf.com.cn 浙ICP證030469號