Platform Builder 6.0 “工厂”如何“生产”驱动DLL文件?
好久以来,心中充满疑惑,通过一段时间的学习和积累,今天终于能一步步揭开驱动编译的神秘面纱,并记录下来和大家分享!
大家都很清楚,一个自己编写的驱动文件夹可以包含以下7个文件:
makefile:指出驱动程序的链接和编译方法,只是简单引用另外一个makefile文件:makefile.def
source:用于设置链接器和编译器,指出驱动程序的链接和编译方法
xxx.def:定义驱动导出的函数名称
xxx.c: 驱动的实现代码
xxx.h:驱动的头文件
xxx_iocontrol.h:驱动和应用程序共享的参数定义和命令码
xxx.reg:定义驱动的注册表信息
具体各文件内容介绍,参见博文:《WinCE流设备驱动简介及GPIO驱动的实现 》
http://blog.csdn.net/nanjianhui/archive/2008/07/18/2674753.aspx
我来讲下xxx.reg文件,它可以包含在驱动文件,也可以不包含(如上面范例)
包含在驱动文件
xxx.reg里内容如下
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/GPIO]
"Index"=dword:1
"Prefix"="PIO"
"Dll"="gpio.dll"
"Order"=dword:8
在paltform.reg里就包含这个文件就可以了
#include "$(_TARGETPLATROOT)/SRC/DRIVERS/GPIO/gpio.reg"
这两种现实方法如出一辙,可自行选择!
了解上面一些工作后,大家一定会想,pb是如何编译和链接驱动?
makefile本质上只是一个文本文件,是如何运行?NMake.exe就是用来解析并执行makefile的工具。
参见博文http://www.cnblogs.com/end/articles/698432.html
source和makefile.def又是什么关系呢?
参见博文http://www.mzdev.cn/documents/ce/20091010/10102WR009.html
最后,这些文件又有谁来执行编译呢?
说到这就不得不说build.exe工具了。
在WinCE中, Build.exe工具用来编译一个目录下以及该目录下面的子目录下的源代码。我们经常会用这个工具来重新编译BSP或者是工程中的某一个模块。由build.log文件为证。实际上,Build.exe主要依赖于dirs文件和sources文件来工作的。有了这两种文件,Build.exe就知道哪些目录需要进去查询,目录下的哪些文件需要被编译以及最终要生成的二进制文件的类型。
具体工作流程如下:
1. Build.exe搜索当前目录下的dirs文件,如果dirs文件存在,会根据当前dirs文件中的描述进入子文件夹,查找dirs文件和sources文件。
2. 如果在当前目录中没有dirs文件,Build.exe查找sources文件,sources文件中会包含所要编译的文件的文件名,以及被编译成什么类型。
3. 如果Build.exe找到sources文件以后,就会调用Nmake.exe来编译和连接相应的目标文件。一般,被编译成功的文件可能是.exe文件,.dll文件或者是.lib文件。
4. 一般和sources文件位于同一个目录下面还有一个Makefile文件,在BSP中,所有的Makefile文件都是一样的,包含了Makefile.def文件,该文件中会包含一些编译选项。所以Nmake.exe会利用Makefile.def文件中的选项来编译sources文件中定义的文件。
在WinCE6.0下面,Build.exe工具位于”/WINCE600/PUBLIC/COMMON/OAK/BIN/I386”目录下面,其实WinCE中的很多工具都在这个地方,具体使用格式如下:
Build [Parameter]
下面介绍一些具体的参数:
-?:帮助,现实所支持的所有参数。
-c:强制重新编译所有的文件。
-clean:删除所有的编译的目标文件。
常用的也就这几个,还有很多其他的参数。一般在运行Build的时候,会产生Build.log,Build.wrn和Build.err文件。Build.log是一个log文件,记录的编译的过程,有的时候我们在编译比较复杂的模块的时候,遇到错误时,这个文件对于找到错误非常的有用。Build.wrn记录了编译过程中的警告,如果编译结果没有警告,那么这个文件是空文件。Build.err记录了编译过程中的错误,如果编译没错误,这个文件也是个空文件。
举个GPIO驱动的例子里build.log文件,从中来解析pb是如何调用build.exe工具来完成驱动dll的”生产“的。
BUILD: [Thrd:Sequence:Type ] Message
BUILD: [00:0000000000:PROGC ] Build started with parameters: -c -------批注:Build -c 强制重新编译所有的文件
BUILD: [00:0000000001:PROGC ] Build started in directory: D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio
BUILD: [00:0000000002:PROGC ] Checking for D:/WINCE600/sdk/bin/i386/srccheck.exe.
BUILD: [00:0000000003:PROGC ] Running passes WCEFILES0, MIDL, MC, ASN, THUNK, PRECOMPHEADER, COMPILE, LIB, LINK, MANAGEDRESX, MANAGEDMOD, MANAGEDDLL, MANAGEDEXE, MANAGEDWIN for ARM.
BUILD: [00:0000000004:PROGC ] Ignoring build database (-c specified).
BUILD: [00:0000000005:PROGC ] Computing include file dependencies:
BUILD: [00:0000000006:PROGC ] Checking for SDK include directory: D:/WINCE600/sdk/CE/inc.
BUILD: [00:0000000007:PROGC ] Scan D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/
BUILD: [00:0000000008:PROGC ] Saving D:/WINCE600/PLATFORM/LPC32XX/Build.dat.
BUILD: [00:0000000009:INFO ] Done.
BUILD: [00:0000000010:INFO ] Will Build D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/gpio.c because target: obj/ARMV4I/retail/gpio.obj is missing.
BUILD: [00:0000000011:PROGC ] Building COMPILE Pass in D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/ directory.
BUILD: [00:0000000012:PROG ] 'NMAKE.EXE TargetCompilePass -i -c BUILDMSG=Stop. BUILDROOT=D:/WINCE600/PLATFORM/LPC32XX CLEANBUILD=1 NOLINK=1 NOPASS0=1'
BUILD: [01:0000000013:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/Sources.default
BUILD: [01:0000000014:INFO ] makefile.def: BUILDROOT is D:/WINCE600/PLATFORM/LPC32XX
BUILD: [01:0000000015:INFO ] makefile.def: Including D:/WINCE600/PLATFORM/LPC32XX/sources.cmn
BUILD: [01:0000000016:INFO ] makefile.def: Including D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/sources-------批注:Nmake.exe会利用Makefile.def文件中的选项来编译sources文件中定义的文件
BUILD: [01:0000000017:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/Sources.CE
BUILD: [01:0000000018:INFO ] Directory: D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio
BUILD: [01:0000000019:INFO ] TARGETNAME: gpio
BUILD: [01:0000000020:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/sources.ReleaseType_PLATFORM
BUILD: [01:0000000021:PROGC ] Compiling ./gpio.c
BUILD: [01:0000000022:INFO ] cl -nologo /Gy -Foobj/ARMV4I/retail/gpio.obj -c -IARM/ -I. -ID:/WINCE600/platform/LPC32XX/src/inc -ID:/WINCE600/platform/LPC32XX/src/inc/chip -ID:/WINCE600/platform/common/src/inc -ID:/WINCE600/public/common/sdk/inc -ID:/WINCE600/public/common/oak/inc -ID:/WINCE600/public/common/ddk/inc -ID:/WINCE600/sdk/CE/inc -I./Resource/0804 -Ox -Os -GF -Zi -FdD:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.pdb -D_CRT_SECURE_NO_DEPRECATE -D_USE_32BIT_TIME_T -DUNICODE -D_UNICODE -DUNDER_CE=600 -D_WIN32_WCE=0x600 -DWINCEOEM -DWINCEINTERNAL -DWIN32 -DSTRICT -DARM -DARMV4I -D_ARM_ -DNDEBUG=1 -DCEDDK_USEDDKMACRO -DINTERNATIONAL -DINTLMSG_CODEPAGE=1252 -WX -QRimplicit-import- -Zi -Zc:wchar_t- -Zc:forScope- -wd4867 -wd4430 -MT -U_MT -W3 /GR- -QRarch4T -DTHUMBSUPPORT -QRinterwork-return /GS D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/./gpio.c
BUILD: [01:0000000023:INFO ] gpio.c
BUILD: [00:0000000024:INFO ] Will Build D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/sdk/lib/ARMV4I/retail/ceddk.lib because target: D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.lib is missing.
BUILD: [00:0000000025:INFO ] Will Build D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/obj/ARMV4I/retail/gpio.obj because target: D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.lib is missing.
BUILD: [00:0000000026:INFO ] Will Build D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/ because target: D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.lib is missing.
BUILD: [00:0000000027:PROGC ] Building LIB Pass in D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/ directory.
BUILD: [00:0000000028:PROG ] 'NMAKE.EXE TargetLibFiles -i -c BUILDMSG=Stop. BUILDROOT=D:/WINCE600/PLATFORM/LPC32XX CLEANBUILD=1 LINKONLY=1 NOPASS0=1'
BUILD: [01:0000000029:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/Sources.default
BUILD: [01:0000000030:INFO ] makefile.def: BUILDROOT is D:/WINCE600/PLATFORM/LPC32XX
BUILD: [01:0000000031:INFO ] makefile.def: Including D:/WINCE600/PLATFORM/LPC32XX/sources.cmn
BUILD: [01:0000000032:INFO ] makefile.def: Including D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/sources
BUILD: [01:0000000033:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/Sources.CE
BUILD: [01:0000000034:INFO ] Directory: D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio
BUILD: [01:0000000035:INFO ] TARGETNAME: gpio
BUILD: [01:0000000036:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/sources.ReleaseType_PLATFORM
BUILD: [01:0000000037:PROGC ] Linking D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.lib
BUILD: [01:0000000038:INFO ] link -lib -out:D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.lib -def:D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.def -machine:thumb @C:/DOCUME~1/zhuyong/LOCALS~1/Temp/nm1F.tmp
BUILD: [01:0000000039:INFO ] Microsoft (R) Library Manager Version 8.00.50727.42
BUILD: [01:0000000040:INFO ] Copyright (C) Microsoft Corporation. All rights reserved.
BUILD: [01:0000000041:INFO ]
BUILD: [01:0000000042:INFO ] -nodefaultlib
BUILD: [01:0000000043:INFO ] -ignore:4001
BUILD: [01:0000000044:INFO ] /subsystem:windowsce,6.00
BUILD: [01:0000000045:INFO ] obj/ARMV4I/retail/gpio.obj
BUILD: [01:0000000046:INFO ] D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/sdk/lib/ARMV4I/retail/ceddk.lib
BUILD: [01:0000000047:INFO ] Creating library D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.lib and object D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.exp
BUILD: [00:0000000048:INFO ] Will Build D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/sdk/lib/ARMV4I/retail/ceddk.lib because target: D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll is missing.
BUILD: [00:0000000049:INFO ] Will Build D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/gpio.def because target: D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll is missing.
BUILD: [00:0000000050:INFO ] Will Build D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/sdk/lib/ARMV4I/retail/coredll.lib because target: D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll is missing.
BUILD: [00:0000000051:INFO ] Will Build D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/obj/ARMV4I/retail/gpio.obj because target: D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll is missing.
BUILD: [00:0000000052:INFO ] Will Build D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/ because target: D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll is missing.
BUILD: [00:0000000053:PROGC ] Building LINK Pass in D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/ directory.
BUILD: [00:0000000054:PROG ] 'NMAKE.EXE TargetExeFiles -i -c BUILDMSG=Stop. BUILDROOT=D:/WINCE600/PLATFORM/LPC32XX CLEANBUILD=1 LINKONLY=1 NOPASS0=1MAKEDLL=1'
BUILD: [01:0000000055:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/Sources.default
BUILD: [01:0000000056:INFO ] makefile.def: BUILDROOT is D:/WINCE600/PLATFORM/LPC32XX
BUILD: [01:0000000057:INFO ] makefile.def: Including D:/WINCE600/PLATFORM/LPC32XX/sources.cmn
BUILD: [01:0000000058:INFO ] makefile.def: Including D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio/sources
BUILD: [01:0000000059:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/Sources.CE
BUILD: [01:0000000060:INFO ] Directory: D:/WINCE600/PLATFORM/LPC32XX/src/drivers/gpio
BUILD: [01:0000000061:INFO ] TARGETNAME: gpio
BUILD: [01:0000000062:INFO ] makefile.def: Including D:/WINCE600/public/common/oak/misc/sources.ReleaseType_PLATFORM
BUILD: [01:0000000063:INFO ] set LIB=D:/WINCE600/sdk/CE/lib
BUILD: [01:0000000064:PROGC ] Linking D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll
BUILD: [01:0000000065:INFO ] link /LARGEADDRESSAWARE -out:D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll -dll -machine:thumb @C:/DOCUME~1/zhuyong/LOCALS~1/Temp/nm21.tmp
BUILD: [01:0000000066:INFO ] Microsoft (R) Incremental Linker Version 8.00.50727.42
BUILD: [01:0000000067:INFO ] Copyright (C) Microsoft Corporation. All rights reserved.
BUILD: [01:0000000068:INFO ]
BUILD: [01:0000000069:INFO ] -nodefaultlib
BUILD: [01:0000000070:INFO ] -entry:DllEntry
BUILD: [01:0000000071:INFO ] -pdb:D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.pdb
BUILD: [01:0000000072:INFO ] -pdbaltpath:gpio.pdb
BUILD: [01:0000000073:INFO ] /opt:ref
BUILD: [01:0000000074:INFO ] -debug -debugtype:cv -incremental:no
BUILD: [01:0000000075:INFO ] -map:D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.map
BUILD: [01:0000000076:INFO ] -savebaserelocations:D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.rel
BUILD: [01:0000000077:INFO ] -MERGE:.rdata=.text -merge:.astart=.text -align:4096 -ignore:4001,4070,4078,4086,4089,4096,4099,4108,4229 /STACK:65536,4096 -debugtype:cv,fixup -incremental:no
BUILD: [01:0000000078:INFO ] /subsystem:windowsce,6.00
BUILD: [01:0000000079:INFO ] /base:0x10000000
BUILD: [01:0000000080:INFO ] obj/ARMV4I/retail/gpio.obj
BUILD: [01:0000000081:INFO ] D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/sdk/lib/ARMV4I/retail/ceddk.lib
BUILD: [01:0000000082:INFO ] D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/sdk/lib/ARMV4I/retail/coredll.lib D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/oak/lib/ARMV4I/retail/corelib0.lib D:/WINCE600/OSDesigns/yy/yy/Wince600/LPC32XX_ARMV4I/cesysgen/oak/lib/ARMV4I/retail/corelib1.lib
BUILD: [01:0000000083:INFO ] D:/WINCE600/platform/LPC32XX/lib/ARMV4I/retail/gpio.exp
BUILD: [01:0000000084:INFO ] editbin /nxcompat D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll
BUILD: [01:0000000085:INFO ] Microsoft (R) COFF/PE Editor Version 8.00.50727.42
BUILD: [01:0000000086:INFO ] Copyright (C) Microsoft Corporation. All rights reserved.
BUILD: [01:0000000087:INFO ]
BUILD: [01:0000000088:INFO ]
BUILD: [01:0000000089:INFO ] copylink /S:a /D:f /E:a /R:n D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.map D:/WINCE600/OSDesigns/yy/yy/RelDir/LPC32XX_ARMV4I_Release/gpio.map
BUILD: [01:0000000090:INFO ] if exist D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.pdb copylink /S:a /D:f /E:a /R:n D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.pdb D:/WINCE600/OSDesigns/yy/yy/RelDir/LPC32XX_ARMV4I_Release
BUILD: [01:0000000091:INFO ] if exist D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.rel copylink /S:a /D:f /E:a /R:n D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.rel D:/WINCE600/OSDesigns/yy/yy/RelDir/LPC32XX_ARMV4I_Release/gpio.rel
BUILD: [01:0000000092:INFO ] copylink /S:a /D:f /E:a /R:n D:/WINCE600/platform/LPC32XX/target/ARMV4I/retail/gpio.dll D:/WINCE600/OSDesigns/yy/yy/RelDir/LPC32XX_ARMV4I_Release/gpio.dll -------批注:gpio.dll被自动的拷贝到工程的release目录下面
BUILD: [00:0000000093:PROGC ] Saving D:/WINCE600/PLATFORM/LPC32XX/Build.dat.
BUILD: [00:0000000094:INFO ] Done.
BUILD: [00:0000000095:PROGC ] Done.
BUILD: [00:0000000096:PROGC ] Files Warnings Errors
BUILD: [00:0000000097:PROGC ] Midl 0 0 0
BUILD: [00:0000000098:PROGC ] Message 0 0 0
BUILD: [00:0000000099:PROGC ] Precomp Header 0 0 0
BUILD: [00:0000000100:PROGC ] Resource 0 0 0
BUILD: [00:0000000101:PROGC ] MASM 0 0 0
BUILD: [00:0000000102:PROGC ] SHASM 0 0 0
BUILD: [00:0000000103:PROGC ] ARMASM 0 0 0
BUILD: [00:0000000104:PROGC ] MIPSASM 0 0 0
BUILD: [00:0000000105:PROGC ] C++ 0 0 0
BUILD: [00:0000000106:PROGC ] C 1 0 0
BUILD: [00:0000000107:PROGC ] Static Libraries 0 0 0
BUILD: [00:0000000108:PROGC ] Exe's 0 0 0
BUILD: [00:0000000109:PROGC ] Dll's 2 0 0
BUILD: [00:0000000110:PROGC ] Preprocess deffile 0 0 0
BUILD: [00:0000000111:PROGC ] Resx 0 0 0
BUILD: [00:0000000112:PROGC ] CSharp Compile 0 0 0
BUILD: [00:0000000113:PROGC ] Other 0 0 0
BUILD: [00:0000000114:PROGC ]
BUILD: [00:0000000115:PROGC ] Total 3 0 0
BUILD: [00:0000000116:PROGC ]
BUILD: [00:0000000117:PROGC ] 0 Warnings, 0 Errors
BUILD: [00:0000000118:PROGC ] GetSystemTimes (seconds): Idle: 20 Kernel: 22 User: 2
BUILD: [00:0000000119:PROGC ] Elapsed time (seconds): 12
上面只是我个人学习和总结,有不周全的和值得商酌的地方,请大家指出,共同进步!
感谢以上引用博文的网友,因为有了你们才有我的一点点进步!