Device Driver Development for Beginners - Reloaded

Hi,

This is just a little starter for people interested in starting Kernel-Mode Development

By following an good thread on UIC forum, opened by a beginner that wanted to know how to start with Device Driver Development, I remembered that long time ago published a similar blog post on that subject.

Now I'm going to Reload and Expand it.

Development Tools

1. WDK/DDK - this is the proper Driver Development SDK given by Microsoft, latest edition can be dowloadedhttp://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx2. Visual Studio 2008/2010 - you can also develop without VS, but I always prefer all the Comforts given by a such advanced IDE, especially in presence of complex device drivers.
3. DDKWizard - DDKWizard is a so-called project creation wizard (for VisualStudio) that allows you to create projects that use the DDKBUILD scripts from OSR (also available in the download section from this site). The wizard will give you several options to configure your project prior to the creation. You can download it
http://ddkwizard.assarbad.net/4. VisualAssist - (Optional Tool) Visual Assist X provides productivity enhancements that help you read, write, navigate and refactor code with blazing speed in all Microsoft IDEs. You can Try/Buy it http://wholetomato.com/5. VisualDDK - Develop and Debug drivers directly from VS, enjoy debugging your driver directly from Visual Studio, speeding up debugging ~18x for VMWare and ~48x for VirtualBox. Download and Step by Step Quick Start Guide http://visualddk.sysprogs.org/quickstart/6. Virtual Machine - You need a Virtual Machine to perform efficient Driver Debugging, best options are VMWare or VirtualBox.

Building a Driver Development Environment

As you can see, a good comfortable Driver Development station is composed by a good amount of components, so we need an installation order.

1. Install your IDE - VisualStudio2008 or VisualStudio2010
2. Install WDK package
3. Install DDKWizard
4. Download and place ( usually into C:\WinDDK ) ddkbuild.cmd
5. By following DDKWizard pdf you will be driven to add an new Envirnment Variable directly releated to the OS version in which you are developing and successively add a reference of ddkbuild.cmd into VS IDE. DDWizard Manual is very well written.
6. After finishing DDKWizard integration you can test if your environment is correctly installed, by compilig your first driver. Steps are easy open VS and select DDKWizard templare (not EmptyDriver), you will see the skeleton of a Driver, all what you have to do is to Build Solution and Verify if No Compiling Errors occur, your station is correctly installed.
7. Install VirtualMachine
8. Integrate Debugging help of VisualDDK by following step by step quick start guide
9. Install Visual Assist (this can be done in every moment after VS Installation)

Additional Tools

* DeviceTree - This utility has two views: (a) one view that will show you the entire PnP enumeration tree of device objects, including relationships among objects and all the device's reported PnP characteristics, and (b) a second view that shows you the device objects created, sorted by driver name. There is nothing like this utility available anywhere else. Download it http://www.osronline.com/article.cfm?article=97* IrpTracker - IrpTracker allows you to monitor all I/O request packets (IRPs) on a system without the use of any filter drivers and with no references to any device objects, leaving the PnP system entirely undisturbed. In addition to being able to see the path the IRP takes down the driver stack and its ultimate completion status, a detailed view is available that allows you to see the entire contents of static portion of the IRP and an interpreted view of the current and previous stack locations. Download it http://www.osronline.com/article.cfm?article=199* DebugMon - Displays DbgPrint messages generated by any driver in the system (or the OS itself) in the application window. Can be used either in local mode or can send the DbgPrint messages to another system via TCP/IP. Download it http://www.osronline.com/article.cfm?article=99* DriverLoader - This GUI-based tool will make all the appropriate registry entries for your driver, and even allow you to start your driver without rebooting. It's even got a help file, for goodness sakes! If you write drivers, this is another one of those utilities that's a must have for your tool chest. x86 architecture. Dowload ithttp://www.osronline.com/article.cfm?article=157Now you have a full working Develop and Debug Station.

As you should imagine, dealing with driver development implies working with at Kernel Mode, a task pretty challenging, delicate and complex. A badly written driver lead to OS Crash and/or dangerous bugs, just think about a driver used in mission-critical applications like Surgery, a bug or a crash could lead to extremely big dangers. The driver need to be:

* Bug Free
* Fault Tolerant
* Ready to Endure all Stress Situations

This could be done, only by the driver coder, with a large knowledge of following fields:

* Hardware Architecture
* Operating System Architecture
* Kernel and User Mode Architecture
* Rock Solid C language knowledge
* Debugging Ability

Here i'm going to enumerate necessary Documentation/Book/Etc. necessary to acheive a *good and solid* background and advanced knowledge about driver coding.

Microsoft WDK Page: http://www.microsoft.com/whdc/devtools/WDK/default.mspxWill give you informations about:

1. WDM ( Windows Driver Model)
2. WDF (Windows Driver Foundation)
3. IFS Kit (Installable FileSystem Kit)
4. Driver Debugging
5. Driver Stress Testing ( DriverVerifier tool )

PC Fundamentals: http://www.microsoft.com/whdc/system/default.mspxDevice Fundamentals: http://www.microsoft.com/whdc/device/default.mspxThis will give you an large view of 'what mean developing a driver' which components are touched and which aspects you need to know.

It's also obviously necessary to have a Reference about kernel mode involved Functions and Mechanisms, the first best resource is always MSDN, here the starter link to follow MSDN->DDKhttp://msdn.microsoft.com/en-us/library ... 85%29.aspxHow to start Learning

As pointed out in the previous blog post, one of the best starting point, that will give you an on-fly-view of development topics is the Toby Opferman set of articles:

Driver Development Part 1: Introduction to Drivershttp://www.codeproject.com/KB/system/driverdev.aspxDriver Development Part 2: Introduction to Implementing IOCTLshttp://www.codeproject.com/KB/system/driverdev2.aspxDriver Development Part 3: Introduction to driver contextshttp://www.codeproject.com/KB/system/driverdev3.aspx 
Driver Development Part 4: Introduction to device stacks
http://www.codeproject.com/KB/system/driverdev4asp.aspx 
Driver Development Part 5: Introduction to the Transport Device Interface
http://www.codeproject.com/KB/system/driverdev5asp.aspx 
Driver Development Part 6: Introduction to Display Drivers
http://www.codeproject.com/KB/system/driverdev6asp.aspx 

It's really important to put in evicence MemoryManagement at KernelMode, the best starting point for these aspects are tutorials written by four-f; http://www.freewebs.com/four-f/ 

Handling IRPs: What Every Driver Writer Needs to Knowhttp://download.microsoft.com/download/ ... a/IRPs.docBook Resources

Tutorial are a great starting point, but a solid understanding is given by a set of 'abstracts', emerges the necessity of a good Book Collection:

Windows NT Device Driver Development (OSR Classic Reprints)http://www.amazon.com/Windows-Device-De ... 242&sr=8-2Windows-Internals-Including-Windows-PRO-Developerhttp://www.amazon.com/Windows%C2%AE-Int ... 160&sr=8-1The Windows 2000 device driver book: a guide for programmershttp://www.amazon.com/Windows-2000-Devi ... 0130204315Windows NT/2000 Native API Referencehttp://www.amazon.com/Windows-2000-Nati ... 201&sr=8-1Undocumented Windows 2000 Secretshttp://undocumented.rawol.com/Developing Drivers with WDFhttp://www.microsoft.com/whdc/driver/wdf/wdfbook.mspxWindows NT File System Internals, A Developer's Guidehttp://oreilly.com/catalog/9781565922495Web Resources

The first and most important resource about Windows Driver Development is OSROnline:http://www.osronline.com/I strongly suggest you to subscribe:

1. The NT Insider
2. NTDEV MailingList
3. NTFSD MailingList

NDIS Developer's Referencehttp://www.ndis.com/Information, Articles, and Free Downloadshttp://www.hollistech.com/resources.htmThe Undocumented Functionshttp://undocumented.ntinternals.netBlog MSDNhttp://blogs.msdn.com/iliastWindows Vista Kernel Structureshttp://www.nirsoft.net/kernel_struct/vista/Peter Wieland's thoughts on Windows driver developmenthttp://blogs.msdn.com/b/peterwie/USB Driver Developmenthttp://blogs.msdn.com/b/usbcoreblog/Hardware and Driver Developer Blogshttp://www.microsoft.com/whdc/resources/blogs.mspxDeveloper Newsgroups
• microsoft.public.development.device.drivers
• microsoft.public.win32.programmer.kernel
• microsoft.public.windbg

KernelmodeInfo Blog
CURRENT_IRQL 

j00ru//vx tech blog Coding, reverse engineering, OS internals Bloghttp://j00ru.vexillium.org/Nynaevehttp://www.nynaeve.net/DumpAnalysis Bloghttp://www.dumpanalysis.org/Analyze -v Bloghttp://analyze-v.com/Instant Online Crash Dump Analysishttp://www.osronline.com/page.cfm?name=analyzeWinsock Kernel (WSK)http://msdn.microsoft.com/en-us/library/ff571084.aspxTransport Driver Interface (TDI)http://msdn.microsoft.com/en-us/library/ms819740.aspxNetwork Driver Interface Specification (NDIS)http://blogs.msdn.com/b/ndis/System Internalshttp://www.microsoft.com/whdc/system/Sysinternals/default.mspxDriver development needs too many time patience and experience to be fully understood, in my opinion the best approach remains LbD ( Learning by Doing ) so, read, study and develop as many experience you build less BSODs and "trange behavior" you will obtain 

See you to the next post,
Giuseppe 'Evilcry' Bonfa

时间: 2024-10-03 12:45:09

Device Driver Development for Beginners - Reloaded的相关文章

A simple demo for WDM Driver development

Introduction A lot of articles have been investigating in application layer issues, like skin-based dialogs, MFC, ATL, thread, process, registry etc. It won't be easy to find any driver related articles posted with full source code. The root cause is

Samsung_tiny4412(驱动笔记10)----mdev,bus,device,driver,platform

/*********************************************************************************** * * mdev,bus,device,driver,platform * * 声明: * 1. 本系列文档是在vim下编辑,请尽量是用vim来阅读,在其它编辑器下可能会 * 不对齐,从而影响阅读. * 2. 由于本人水平有限,很难阐述清楚bus device driver platform的关系 * 所以强烈要求您详细参考本次

I.MX6 Linux I2C device& driver hacking

/******************************************************************************************* * I.MX6 Linux I2C device& driver hacking * 声明: * 1. 本文主要是对Linux I2C驱动进行代码跟踪,主要是为了能够对I2C驱动框架有个全面的了解: * 2. 本文源代码来自myzr_android4_2_2_1_1_0.tar.bz2: * 3. 如果你有兴趣,

I.MX6 ar1020 SPI device driver hacking

/************************************************************************************ * I.MX6 ar1020 SPI device driver hacking * 声明: * 1. 本文主要是解读I.MX6中ar1020 SPI设备注册,以及驱动调用流程: * 2. 本文主要使用了vim+ctags进行代码跟踪,所以几乎都是函数原型之间的调用: * * 2015-9-5 晴 深圳 南山平山村 曾剑锋 *

I.MX6 AD7606-4 device driver registe hacking

/********************************************************************** * I.MX6 AD7606-4 device driver registe hacking * 说明: * 看一下AD7606的驱动注册上是否存在一些问题. * * 2017-8-4 深圳 龙华樟坑村 曾剑锋 *********************************************************************/ /

Building and deploying a basic WDF Kernel Mode Driver

Building and deploying a basic WDF Kernel Mode Driver Introduction At the end of December 2005, Microsoft released the new Windows Driver Foundation. This is a new framework for building Windows device drivers. It is a lot more high level than the Wi

Developing a WDF USB Kernel Mode Driver for the OSR USB FX2

Developing a WDF USB Kernel Mode Driver for the OSR USB FX2 Introduction This article explains and demonstrates the steps involved in developing a kernel mode device driver using the WDF Kernel Mode Driver Foundation (KMDF). The specific USB device t

汇编教程:虚拟设备驱动程序结构

现在大家对vmm和vxd有了一定的了解,接下来我们来看一看如何编写vxd代码.首先,你必须具备Windows 95/98 Device Driver Development Kit.Window95 ddk只有MSDN 订户才能拿到,但Windows98 ddk却可以免费从Microsoft公司取得.尽管Windows 98 ddk是面向WDM的,但你还是可以用它来开发VxD程序.你可以从 http://www.microsoft.com/hwdev/ddk/install98ddk.htm?下

How to Develop and Test Device Drivers in Windows CE 5.0

Summary: This article provides an introduction to developing and testing a Windows CE 5.0 device driver. It provides step-by-step instructions for creating a stream driver, creating a custom Windows CE Test Kit (CETK) test, and writing an application