導航:首頁 > 源碼編譯 > 編譯驅動的必要條件

編譯驅動的必要條件

發布時間:2022-05-22 06:22:45

『壹』 vs2010如何編譯驅動

1、安裝VS2010,安裝WDK 7.0(DDK);

2、新建VC++->Empty Project

3、打開Configuration Manager 並新建一個名稱為「 dirver 」的Solution Configuration 並將「dirver」 設為Active Solution Configuration .

4、打開View-> property Manager。

5、在"dirver" solution configuration 上點擊右鍵,選擇Add new property Sheet。取名為「dirverProperty」. 並對他進下以下設置。

5.1. C\C++ - General - Debug Information Format = Program Database (/Zi)
5.2. C\C++ - Preprocessor - Preprocessor Definitions = _X86_ [add also DBG for Debug config]
【WIN32;_DEBUG;_X86_;i386;STD_CALL;CONDITION_HANDLING;WIN32_LEAN_AND_MEAN;NT_UP;SRVDBG;DBG;_IDWBUILD;_WIN32_WINNT=0x0400;% (PreprocessorDefinitions)】
5.3. C\C++ - Code Generation - Enable C++ Exceptions = No
5.4. C\C++ - Code Generation - Basic Runtime Checks = Default
5.5. C\C++ - Code Generation - Buffer Security Check = No (/GS-)
5.6. C\C++ - Advanced - Calling Convention = __stdcall (/Gz)
5.7. C\C++ - Advanced - Compile As = Compile as C Code (/TC) [if you are going to use plain C]
5.8. Linker - General - Output File = $(OutDir)\$(ProjectName).sys
5.9. Linker - General - Enable Incremental Linking = Default
5.10. Linker - Input - Additional Dependencies = ntoskrnl.lib hal.lib $(NOINHERIT) [add here needed libs here e.g. ntoskrnl.lib hal.lib]
【不知道上面是不是筆誤,應該為:ntoskrnl.lib;hal.lib;%(AdditionalDependencies)】
5.11. Linker - Input - Ignore All Default Libraries = Yes (/NODEFAULTLIB)
5.12. Linker - Manifest File - Generate Manifest = No
5.13. Linker - System - SubSystem = Native (/SUBSYSTEM:NATIVE)
5.14. Linker - System - Driver = Driver (/DRIVER)
5.15. Linker - Advanced - Entry Point = DriverEntry
5.16. Linker - Advanced - Base Address = 0x10000
5.17. Linker - Advanced - Randomized Base Address = Disable (/DYNAMICBASE:NO)
【這個也是錯誤的:應該置空】
5.18. Linker - Advanced - Data Execution Prevention (DEP) = Disable (/NXCOMPAT:NO)
【這個也是錯誤的:應該置空】

6. Config VC++ Directories
6.1 Open Open up property manager by clicking on Menu View->Property Manager.
6.2 Expand the project node and then the Configuration|Platform nodes, you will see "Microsoft.cpp.<Platform>.users" file for each Configuration|Platform. These are the files

for the global settings, similar to the old tools/Options/VC++ Directories.
6.3 Multi-Select "Microsoft.cpp.<Platform>.users", right click and bring up the property page window
6.4 In the property page window, click on "VC++ Directories" (for example) in the left pane, add new paths for the directories such as "Include Directories". separated by

semicolons
(eg:Include Directories config As:
$(ddkroot)\INC
$(ddkroot)\INC\WNET
$(ddkroot)\INC\DDK\WNET
Library Directories config As:
$(ddkroot)\LIB\WNET\I386
)
6.5 Make sure to save the settings before shutting down Visual Studio.
6.6 Re-launch Visual Studio and the new settings will be in effect.
6.7 Note: If you would like to only change the settings for one project, you can right click on the project and bring up the property page. Change the settings for 「VC++

Directories」, these settings will be persisted to the project file.
七. OK. Have done. Now you can test it with simple code, e.g.:

#include "ntddk.h"

NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
return STATUS_UNSUCCESSFUL;
}

特別說明:
1.
Visual Studio 2010 在智能設備開發方面只支持Windows Phone OS 7.0。如果你要為Windows CE 5.0和Windows Mobile 6.5開發應用程序,請安裝Visual Studio 2008。
2.
做驅動開發時,SDK的版本要和WDK的版本一致,即Win7 WDK要配Win7 SDK,否則會出現編譯錯誤。VS2010里集成了Windows SDK 7.0A。
3.
如果出現類似如下編譯錯誤,解決方法是:拷貝C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sal.h,然後覆蓋掉C:\WinDDK\7600.16385.1\inc\api\sal.h。

C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing ')' before 'const'
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing '{' before 'const'
.......

『貳』 linux驅動開發 前 為什麼要配置編譯內核

編譯前當然要配置一下內核啊,make menuconfig ,生成默認配置文件 .config ,這個文件是設置 cpu 體系,及很多驅動選項的,你沒配置這個,怎麼可能編譯那

前面那個說 linux 和微軟競爭是扯淡的那位,我只能說你根本不懂內核編譯,無知

新下載的內核都是沒有默認 .config 需要你找到一個默認的config 文件,比如 arch/arm/configs/ 下是 arm cpu 很多的默認配置,當然你也可以把你以前的 config 文件拷貝到新內核目錄下。

.config 是配置編譯內核的最初步驟,你要編譯驅動程序,就必須要了解這個,多上網查下資料

然後重新編譯

『叄』 如何使用ubuntu來編譯驅動

工具/原料

Ubuntu12.04操作系統和測試驅動程序(beep_arv.c)
方法/步驟

在介紹2種方法前,必須知道的知識點:
1.關聯文件Makefile:
Makefile:分布在Linux內核源代碼中的Makefile用於定義Linux內核的編譯規則;
2.管理文件Kconfig:
給用戶提供配置選擇的功能;
配置工具:
1)包括配置命令解析器;
2)配置用戶界面;menuconfig || xconfig;
3)通過腳本語言編寫的;

3.
---tristate 代表三種狀態:1.[ ]不選擇,2.[*]選擇直接編譯進內核,載入驅動到內核里,3.[m]動態載入驅動;
---bool 代表兩種狀態,1.[ ]不選擇,2.[*]選擇;
---"Mini2440 mole sample"這個是在make menuconfig時刷出的提示字元;
---depends on MACH_MINI2440 這個配置選項出現在make menuconfig菜單欄下,在內核配置中必須選中、MACH_MINI2440;
---default m if MACH_MINI2440 這個如果選中了MACH_MINI2440,默認是手
動載入這個驅動;
help:提示幫助信息;
在了解了基本的知識點,便開始進行第一種添加驅動的方法,本次交流是以beep_arv.c蜂鳴驅動程序為基礎的
方法一:
1)進入內核的驅動目錄;
#cp beep_arv.c /XXX/.../linux-XXXl/drivers/char
2)進入Kconfig添加驅動信息;
#cd /XXX/linux-XXX/.../drivers/char
#vim Kconfig
添加基本信息:
config BEEP_MINI2440
tristate "---HAH--- BEEP"
default
help
this is test makefile!

3)進入Makefile添加驅動編譯信息;
#vim Makefile
添加基本信息:
obj-$(CONFIG-BEEP_MINI2440) +=beep_drv.o

方法一結果:
在--Character devices下就能看到配置信息了;

方法二:
1)進入驅動目錄,創建BEED目錄;
#cd /XXX/.../linux-XXX/drivers/char
#mkdir beep
2)將beep_arv.c驅動程序復制到新建目錄下;
#cp beep_arv.c /XXX/.../linux-XXXl/drivers/char/beep
3)創建Makefile和Kconfig文件
#cd char/beep
#mkdir Makefile Kconfig
#chmod 755 Makefile
#chmod 755 Kconfig

4)進入Kconfig添加驅動信息;
#vim Kconfig
添加基本信息:
config BEEP_MINI2440
tristate "---HAH--- BEEP"
default
help
this is test makefile!

5)進入Makefile添加驅動編譯信息;
#vim Makefile
添加基本信息:
obj-$(CONFIG_BEEP_MINI2440) +=beep_drv.o

6)並且要到上一級目錄的Makefile和Kconfig添加驅動信息;
#cd ../
#vim Makefile
#vim Kconfig

『肆』 如何編譯驅動程序

驅動的編譯和上層應用程序的編譯完全不同,作為初學者應該先了解一下,即使你還不懂得怎麼寫驅動程序。
首先安裝DDK,然後隨便找一個例子來測試。在菜單中找到BUILD環境菜單執行,不同的系統要使用不同的BUILD環境。會打開一個DOS窗口,這時CD到那個例子程序,輸入 build –cZ回車就可以了。 驅動程序都是用一個由DDK提供的叫build.exe的工具編譯的。此程序以一個名為SOURCES的文件作為輸入,該文件中包含目標可執行文件的名稱、類型和要創建的可執行文件的路徑,注意這個文件沒有後綴名。
SOURCES的文件格式:
TARGETNAME=drivername ,
- 本參數用於指定生成的設備驅動程序名稱(不需後綴名),所產生的文件
- 為drivername.sys.

TARGETPATH=./lib
- 本參數用於指定生成的設備驅動程序所存放的路徑. 一般採用./lib.

TARGETTYPE=DRIVER
- build能夠生成許多不同的目標對象,設備驅動程序一般選用 DRIVER.

INCLUDES=path1;path2;...
- 本參數是可選的, 用於指定其他的#include文件的搜索路徑.

TARGETLIBS=lib1;lib2;...
- 本參數是可選的, 用於指定其他的lib庫文件的搜索路徑.

SOURCES=file1.c file2.c ...
- 本參數用於指定需被編譯的全部源文件名稱, 後綴名不能省略,文件名之間用空格分開.
SOURCES文件是必需的,如果沒有它則表示沒有任何源文件需要編譯。
如果要換行可以用 『/』 符號,表示對上一行的繼續。

也可以創建DIRS文件,DIRS文件用於指定在當前目錄下必須創建的子目錄。
DIRS文件格式:
DIRS文件的內容由一系列用空格分開的目錄名組成
DIRS = /
subdir1 /
subdir2 /
subdir3
DIRS文件是可選的。

有的時候,會提示找不到依賴的文件(.h,.lib 之類),其實設置好 source 文件的
INCLUDES和TARGETLIBS就可以,我第一次編譯時就碰到這個問題,和VC環境區別較大,但習慣就好。

『伍』 如何編寫驅動程序

代碼:

#include&lt;linux/mole.h&gt;

#include&lt;linux/kernel.h&gt;

#include&lt;asm/io.h&gt;

#include&lt;linux/miscdevice.h&gt;

#include&lt;linux/fs.h&gt;

#include&lt;asm/uaccess.h&gt;

//流水燈代碼

#define GPM4CON 0x110002e0

#define GPM4DAT 0x110002e4

static unsigned long*ledcon=NULL;

static unsigned long*leddat=NULL;

//自定義write文件操作(不自定義的話,內核有默認的一套文件操作函數)

static ssize_t test_write(struct file*filp,const char __user*buff,size_t count,loff_t*offset)

{

int value=0;

int ret=0;

ret=_from_user(&value,buff,4);

//底層驅動只定義基本操作動作,不定義功能

if(value==1)

{

*leddat|=0x0f;

*leddat&=0xfe;

}

if(value==2)

{

*leddat|=0x0f;

*leddat&=0xfd;

}

if(value==3)

{

*leddat|=0x0f;

*leddat&=0xfb;

}

if(value==4)

{

*leddat|=0x0f;

*leddat&=0xf7;

}

return 0;

}

//文件操作結構體初始化

static struct file_operations g_tfops={

.owner=THIS_MODULE,

.write=test_write,

};

//雜設備信息結構體初始化

static struct miscdevice g_tmisc={

.minor=MISC_DYNAMIC_MINOR,

.name="test_led",

.fops=&g_tfops,

};

//驅動入口函數雜設備初始化

static int __init test_misc_init(void)

{

//IO地址空間映射到內核的虛擬地址空間

ledcon=ioremap(GPM4CON,4);

leddat=ioremap(GPM4DAT,4);

//初始化led

*ledcon&=0xffff0000;

*ledcon|=0x00001111;

*leddat|=0x0f;

//雜設備注冊函數

misc_register(&g_tmisc);

return 0;

}

//驅動出口函數

static void __exit test_misc_exit(void)

{

//釋放地址映射

iounmap(ledcon);

iounmap(leddat);

}

//指定模塊的出入口函數

mole_init(test_misc_init);

mole_exit(test_misc_exit);

MODULE_LICENSE("GPL");

(5)編譯驅動的必要條件擴展閱讀:

include用法:

#include命令預處理命令的一種,預處理命令可以將別的源代碼內容插入到所指定的位置;可以標識出只有在特定條件下才會被編譯的某一段程序代碼;可以定義類似標識符功能的宏,在編譯時,預處理器會用別的文本取代該宏。

插入頭文件的內容

#include命令告訴預處理器將指定頭文件的內容插入到預處理器命令的相應位置。有兩種方式可以指定插入頭文件:

1、#include&lt;文件名&gt;

2、#include"文件名"

如果需要包含標准庫頭文件或者實現版本所提供的頭文件,應該使用第一種格式。如下例所示:

#include&lt;math.h&gt;//一些數學函數的原型,以及相關的類型和宏

如果需要包含針對程序所開發的源文件,則應該使用第二種格式。

採用#include命令所插入的文件,通常文件擴展名是.h,文件包括函數原型、宏定義和類型定義。只要使用#include命令,這些定義就可被任何源文件使用。如下例所示:

#include"myproject.h"//用在當前項目中的函數原型、類型定義和宏

你可以在#include命令中使用宏。如果使用宏,該宏的取代結果必須確保生成正確的#include命令。例1展示了這樣的#include命令。

【例1】在#include命令中的宏

#ifdef _DEBUG_

#define MY_HEADER"myProject_dbg.h"

#else

#define MY_HEADER"myProject.h"

#endif

#include MY_HEADER

當上述程序代碼進入預處理時,如果_DEBUG_宏已被定義,那麼預處理器會插入myProject_dbg.h的內容;如果還沒定義,則插入myProject.h的內容。

『陸』 在Linux上編譯驅動程序問題,怎麼解決

可以用ln -s命令創建一個軟連接,也就是快捷方式

它的功能是為某一個文件在另外一個位置建立一個同不的鏈接,這個命令最常用的參數是-s,具體用法是:ln -s 源文件 目標文件。
當 我們需要在不同的目錄,用到相同的文件時,我們不需要在每一個需要的目錄下都放一個必須相同的文件,我們只要在某個固定的目錄,放上該文件,然後在其它的 目錄下用ln命令鏈接(link)它就可以,不必重復的佔用磁碟空間。

例如:ln -s /bin/less /usr/local/bin/less

-s 是代號(symbolic)的意思。
這 里有兩點要注意:第一,ln命令會保持每一處鏈接文件的同步性,也就是說,不論你改動了哪一處,其它的文件都會發生相同的變化;第二,ln的鏈接又軟鏈接 和硬鏈接兩種,軟鏈接就是ln -s ** **,它只會在你選定的位置上生成一個文件的鏡像,不會佔用磁碟空間,硬鏈接ln ** **,沒有參數-s, 它會在你選定的位置上生成一個和源文件大小相同的文件,無論是軟鏈接還是硬鏈接,文件都保持同步變化。

『柒』 為什麼linux 需要把驅動編譯到內核

因為linux的驅動是內核的一部分,內核啟動時會檢測硬體需要按需載入相應的驅動,如果在編譯內核時沒有為你的選擇的硬體編譯相應的模塊,內核是無法載入相應的驅動的,這時候就需要你自己動手編譯驅動模塊了。

『捌』 如何編譯驅動(sys)程序。懸賞100分!

我看了,他是dev project!
你下個dev C++就可以編譯了

不過少了一個文件

can't open font file `../sys/binary/agony.sys': No such file or directory

我去目錄看了下沒有。。
是個資源文件

『玖』 linux下怎麼編譯安裝驅動

linux 編譯安裝驅動有兩種,動態載入與靜態載入
動態載入
一,編譯,在指點內核樹下編譯,生成.o文件或.ko文件
二,將生成的.o或.ko文件拷到相應目錄,一般是/lib/mole/kernel下面
三,用insmod命令載入,用rmmod命令卸載
靜態載入
靜態載入主要就是編譯內核。就是將編寫好的驅動放進內核相應的目錄下面。然後編譯內核。然後運行編譯好的內核。

『拾』 如何編譯一個linux下的驅動模塊

這是一個簡單而完整的實例,對於理解Linux下的驅動模塊是非常有幫助的。

1.源碼如下:
/*
* hello.c -- the example of printf "hello world!" in the screen of driver program
*/
#include <linux/init.h>
#include <linux/mole.h>
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the mole ,it is necessary */
static int hello_init(void)
{
printk(KERN_ALERT "Hello World enter!\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "Hello world exit!\n");
}
mole_init(hello_init); /* load the mole */
mole_exit(hello_exit); /* unload the mole */
進入目錄:
[root@Alex_linux /]#cd /work/jiakun_test/moletest
[root@Alex_linux moletest]# vi hello.c
然後拷入上面書上的源碼。
2.編譯代碼:
1>.首先我在2.4內核的虛擬機上進行編譯,編譯過程如下:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
其中-I選項指定內河源碼,也就是內核源碼樹路徑。編譯結果:
hello.c:1:22: net/sock.h: No such file or directory
hello.c: In function `hello_init':
hello.c:6: warning: implicit declaration of function `printk'
hello.c:6: `KERN_ALERT' undeclared (first use in this function)
hello.c:6: (Each undeclared identifier is reported only once
hello.c:6: for each function it appears in.)
hello.c:6: parse error before string constant
hello.c: In function `hello_exit':
hello.c:11: `KERN_ALERT' undeclared (first use in this function)
hello.c:11: parse error before string constant
hello.c: At top level:
hello.c:13: warning: type defaults to `int' in declaration of `mole_init'
hello.c:13: warning: parameter names (without types) in function declaration
hello.c:13: warning: data definition has no type or storage class
hello.c:14: warning: type defaults to `int' in declaration of `mole_exit'
hello.c:14: warning: parameter names (without types) in function declaration
hello.c:14: warning: data definition has no type or storage class
在網上查詢有網友提示沒有引入kernel.h
解決:vi hello.c
在第一行加入:#include <linux/kernel.h>
再次編譯仍然報KERN_ALERT沒有聲明
修改編譯條件-I,再次編譯:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
[root@Alex_linux moletest]#ls
hello.c hello.o Makefile
[root@Alex_linux moletest]#
2>.接著我嘗試在2.6內核的虛擬機上進行編譯
編譯過程如下:
[root@JiaKun moletest]# ls
hello.c makefile
[root@JiaKun moletest]# vi hello.c
[root@JiaKun moletest]# make
make -C /mylinux/kernel/2.4.18-rmk7 M=/home/alex/test/moletest moles
make: *** /mylinux/kernel/2.4.18-rmk7: No such file or directory. Stop.
make: *** [moles] Error 2
[root@JiaKun moletest]# vi makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
scripts/Makefile.build:17: /home/alex/test/moletest/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/alex/test/moletest/Makefile'. Stop.
make[1]: *** [_mole_/home/alex/test/moletest] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
make: *** [moles] Error 2
[root@JiaKun moletest]# mv makefile Makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
CC [M] /home/alex/test/moletest/hello.o
Building moles, stage 2.
MODPOST
CC /home/alex/test/moletest/hello.mod.o
LD [M] /home/alex/test/moletest/hello.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
[root@JiaKun moletest]# ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile Mole.symvers

3.執行代碼,載入驅動模塊:
2.4內核載入模塊:
insmod ./hello.o
但是此時並沒有輸出printk列印的信息。但是可以在/var/log/messages 中看到列印的信息,這是由於KERN_ALERT優先順序不夠高。這里
需要修改為:KERN_EMERG。再次編譯,載入模塊即可以看到結果
2.6內核載入模塊:
[root@JiaKun moletest]# insmod hello.ko
[root@JiaKun moletest]#
Message from syslogd@ at Sat Jul 26 19:52:44 2008 ...
JiaKun kernel: Hello, world
有的朋友可能會出現insmod命令找不到的錯誤,這可能有下面幾個原因:
<1> 你的系統沒有安裝mole-init-tools工具,關於此問題,只需安裝即可,但是一般裝完系統是有這個命令的。
<2> 環境變數沒有添加導致不能使用該命令。使用echo $PATH即可查看PATH環境變數,發現沒有/sbin這個路徑,所以你當然不能使用insmod這個命令了。解決的方法很簡單,只需在命令行輸入:
PATH = "$PATH:/sbin"即可添加。(insmod在/sbin這個目錄下,你可以使用whereis insmod查看)。
<3> insmod這個命令需要在root許可權下才能使用。
載入完成後你可以輸入lsmod查看hello這個模塊哦。

4.卸載驅動模塊:rmmod hello.
載入模塊後就可在屏幕上看到如下信息:Hello world enter.
卸載時就可在屏幕上看到如下信息:hello world exit.
[root@JiaKun moletest]# rmmod hello.ko
[root@JiaKun moletest]#
Message from syslogd@ at Sat Jul 26 19:52:58 2008 ...
JiaKun kernel: Goodbye, cruel world

另外,如果有多個文件,則按下列方式編寫Makefile文件(file1.c、file2.c):
obj -m := molename.o
mole-objs := file1.o file2.o

閱讀全文

與編譯驅動的必要條件相關的資料

熱點內容
ubuntu壓縮zip 瀏覽:2
vigenere演算法的方法是什麼 瀏覽:666
pdf保護破解 瀏覽:341
仿微信聊天系統源碼廣州公司 瀏覽:106
怎麼查看我的世界伺服器日誌 瀏覽:430
怎麼從程序員走到成功 瀏覽:824
把軟體放入文件夾中如何移出 瀏覽:209
紅包源碼企業即時聊天軟體 瀏覽:581
xp安裝python 瀏覽:10
西門子參數編程讀取半徑值 瀏覽:403
洗首飾解壓小視頻 瀏覽:966
01背包問題的演算法解決 瀏覽:373
sd卡放哪個文件夾 瀏覽:301
解釋器模式java 瀏覽:104
android垂直自動滾動條 瀏覽:153
計算器java小程序 瀏覽:27
java的簡稱 瀏覽:68
雲伺服器公網ip地址 瀏覽:581
php對資料庫操作 瀏覽:237
java爬圖片 瀏覽:866