Creating Universal Drivers with WDK 10
- Posted: Jul 29, 2015 at 9:52AM
By Adam Shapiro – Senior PM EPIX
One of the new features available with the Windows Driver Kit 10 is the ability to create Universal Drivers for all Windows 10 versions. With a Universal driver, you can write the driver once, and compile the single source for each different architecture. The same source is used to create a driver for the Desktop, Mobile and IOT versions of Windows. This enables your driver to run on Phones, Tablets, Desktops, Servers, and Development board devices, without any code changes.
Creating Universal Drivers with WDK 10 and Visual Studio provides some big benefits to both the driver developer as well device manufacturers.
Essentially, the set of API's a Universal Driver can call is the intersection or overlap of API's from Desktop, Mobile and IOT versions of Windows 10. For the most part, these API's are common to all versions. A Universal Windows driver calls only device driver interfaces (DDIs) that are part of UWP. If you are writing a new driver, you should create compile the driver as Universal. In addition, you should take advantage of the WDF frameworks when creating new drivers, as WDF is supported on all Windows 10 versions.
If you are porting an existing driver to Windows 10, most kernel mode drivers will build for Universal with little or no modification. In many cases, you can recompile an existing kernel-mode driver that runs on Windows 8.1 as a Universal Windows driver, as long as the driver does not work with any user-mode components. WDM and KMDF drivers that work with Windows 8.1 should recompile as Universal Windows drivers targeting Windows 10 with no conversion required. However, some User mode drivers may need to be modified since not all Win32 APIs are available as part of Windows Universal Platform. For these Win 32 APIs, replacement APIs may be available in some cases in Mobile and IOT. In rare instances, you may need to rewrite the driver of a replacement API is not available.
Typically when you test and debug a driver, the debugger and driver run on separate computers. The computer that runs the debugger is called the host computer, and the computer that runs the driver is called the target computer. The target computer is also called the test computer.
So far you've used Visual Studio to build a driver on the host computer. Now you need to configure a target computer. You first need to provision a computer for driver deployment and testing (WDK 10). Then you can deploy, install, load, and debug your driver:
See the MSDN topic: Provision a computer for driver deployment and testing (WDK 10).
There are a few differences in deploying a driver to a desktop system compared to a mobile/IOT system. If you are building a universal or mobile driver package, you must use a universal INF file. If you are building a desktop driver package, you don't have to use a universal INF file, but doing so is recommended because of the performance benefits.
A universal INF file uses a subset of the INF syntax that is available to a Windows driver. A universal INF file installs a driver and configures device hardware, but does not perform any other action, such as running a co-installer. Some editions of Windows, such as Windows 10 Mobile, do not support the Plug and Play mechanism for driver installation. Therefore, driver installation takes place on an offline image of the target system. When Microsoft Visual Studio builds your driver for such a target system, it generates an XML-based configuration file that contains all of the registry settings to be applied. As a result, an INF file for such a system must perform only additive operations that do not depend on the runtime behavior of the system. An INF file with such restricted syntax is called a universal INF file.
InfVerif (InfVerif.exe) is a tool that you can use to test a driver INF file. In addition to reporting INF syntax problems, the tool reports if the INF file is universal. When you build a driver in Microsoft Visual Studio 2015 with Windows Driver Kit (WDK) 10, the compiler runs the tool automatically as part of the build process. Alternatively, you can run the InfVerif.exe tool from the command line.
The verification tool is part of the WDK 10 installation, and can be found in the \tools subdirectory of your WDK 10 installation, c:\Program Files(x86)\Windows Kits\10\tools\.
If you are deploying a driver to a mobile device, you need to add a package file to your project. WDK 10 includes PkgGen, a tool that generates package files. You run PkgGen in Visual Studio when you build your driver, do the following:
To add the Package file:
Once you have provisioned the target computer, phone, tablet or IOT device and modified the INF and created the deployment package (for Mobile) you can deploy the driver. First, set the target device for deploying the driver.
Wait until your driver has been deployed, installed, and loaded on the target computer. This might take a minute or two.
Try creating a Universal Driver for your next driver project!