Build Windows driver development environment


introduction

For Windows driver development, there are actually many useful documents in Microsoft’s official documents to explain and learn. Here, driver development is collectively classified as Windows hardware development ( https://learn.microsoft.com/zh-cn/windows-hardware/drivers/ ), and all the content we need can be found in the relevant documents of this link (because Windows is not open source, so we must rely on officially released materials for Windows-related learning ) .

To start learning Windows driver development, you first need to build your own development environment (so that you can try to demonstrate and verify it yourself during the learning process). Many development tasks under Windows rely on the establishment of a complex development environment, and this part of the workload is quite large (compared to the Linux environment). This is because the Windows development IDE is complicated to deploy, but it will save (cover up) a lot of operations when used.

The main content of this chapter is as follows:

  • Learn about the Windows driver development environment
  • Download the Windows driver development environment
  • Write a simple NT driver
  • After compiling the NT driver (indicating that the current development environment has been set up), the installation and debugging process of the driver will be demonstrated in the subsequent debugging.

Learn about the Windows driver development environment

The previous Windows driver development environment was mostly carried out through VC++, combined with the use of Windows Driver Development Kit (WDK) to complete the compilation. But when I came into contact with this part of the content, Windows had already updated and released Windows 11, so the part of Windows driver development tools has also been greatly changed and optimized.

Today, the Windows driver development environment and the Windows debugger are integrated into Microsoft Visual Studio. In this integrated driver development environment, most of the tools needed to code, build, package, deploy, and test drivers are available in the Visual Studio interface. Visual Studio can be said to be a powerful tool for software development in the Windows operating system. Through this IDE, we can develop Windows drivers, Windows interface application development, Windows program debugging, and so on.

Therefore, if we want to deploy the Windows driver development environment now, we need to install Visual Studio first, and then install the Windows Driver Development Kit (WDK). To learn how to get Visual Studio and the WDK, visit the WDK Setup and Downloads page ( WDK Setup and Downloads Page ). Debugging Tools for Windows ( Debugging Tools for Windows ) is included in the WDK installation.

The WDK uses MSBuild.exe, which is available in the Visual Studio user interface and as a command-line tool. Drivers created in the Visual Studio environment use project and solution files to describe a project or group of projects. The Visual Studio environment provides tools for converting legacy source and catalog files into project and solution files.

The Visual Studio environment provides templates for:

  • new driver
  • driver package
  • new test
  • Enhancements to Existing Tests
  • Custom driver deployment script

In the Visual Studio environment, you can configure the build process to automatically create and sign driver packages. Static and real-time analysis tools are available in Visual Studio. You can configure target computers for testing drivers and have your drivers automatically deployed to target computers every time you rebuild. You can choose from several runtime tests, or write your own.

Download the Windows driver development environment

Steps to download and install the Windows driver development environment:

  1. Select the appropriate version of Visual Studio to download and install;
  2. Select the corresponding WDK version to download and install;

Download and install the corresponding version of Visual Studio as needed

Due to the different kernel versions of the Windows operating system, we also need to consider the Windows version that the driver must adapt to when developing a Windows driver. Different versions of the target operating system need to use different versions of the VS development environment and different versions of the WDK package. For details, please refer to the following table content:

The following table indicates which versions of Visual Studio are required for different versions of the WDK.

Windows target version Visual Studio version
Windows 11 version 21H2, Windows Server 2022, Windows 10 version 2004, Windows 10 version 1903 Visual Studio Community 2019Visual Studio Professional 2019Visual Studio Enterprise 2019
Windows 10, version 1809, Windows 10, version 1803, Windows 10, version 1709 Visual Studio Community 2017Visual Studio Professional 2017Visual Studio Enterprise 2017
Windows 10, version 1703, Windows 10, version 1607 Visual Studio Express 2015 桌面版Visual Studio Community 2015Visual Studio Professional 2015Visual Studio Enterprise 2015
windows 8.1 update, windows 8.1 Visual Studio 2013
Windows 8 Visual Studio Professional 2012Visual Studio Ultimate 2012

When installing Visual Studio, select 使用 C++ 的桌面开发Workloads. The Windows 10 Software Development Kit (SDK) is included automatically and appears in the Summary pane on the right.

To develop an Arm/Arm64 driver, select 单个组件, then select 编译器、生成工具和运行时under 适用于 Arm/Arm64 的 Visual C++ 编译器和库.

It should be noted here that since my version is relatively high, I only need to download Visual Studio (the Windows SDK is included inside). If you are developing on a target system running Windows 10, version 1607 or Windows 10, version 1703, you should install Visual Studio 2015 before downloading and installing the version of the Windows SDK for your target Windows 10 version, as shown in the table below.

Windows target version Windows SDK version
Windows 10 version 1703 Windows SDK for Windows 10.0.15063.468
Windows 10 version 1607 Windows SDK for Windows 10.0.14393.795
Windows 8.1 Windows SDK for Windows 8.1
Windows 8 Windows SDK for Windows 8

The Windows SDK is not included with Visual Studio 2015, so the SDK must be installed separately. Later versions of Visual Studio include the Windows SDK.

The target Windows operating system version I chose here is Windows 10 22H2 version.
insert image description here
To choose the version of Visual Studio, you only need to consider the major version of Windows, but it should be noted that Windows 10 1903, Windows 10 1809, and Windows 10 1703 require different versions of Visual Studio, which correspond to 2019, 2017, and 2015 respectively.

Here we choose to download and use the Visual Studio 2019 Community Edition.

insert image description here
insert image description here
insert image description here
I have already installed it here, and I have installed different versions of Visual Studio at the same time due to different target versions. Here only the 2019 version needs to be installed, and the installation only needs to be selected使用C++的桌面开发

insert image description here
insert image description here
After the selection here is complete, execute the download and install. (This process may take a while, and make sure the network is normal)

After completion, start and open to see the startup interface of Visual Studio 2019.
insert image description here
Now we haven't installed the corresponding WDK (Windows Driver Development Kit), so there is no solution corresponding to the driver when we choose to create a new project.

Download and install the corresponding WDK toolkit

Just like selecting the version of Visual Studio, we also need to choose to install the corresponding WDK version according to the situation.

The WDK is integrated with Visual Studio and Debugging Tools for Windows (WinDbg). This integrated environment provides the tools needed to develop, build, package, deploy, test, and debug drivers. (Starting with Windows 10, version 1709, the WDK extensions for Visual Studio are installed by default when you install the WDK. These extensions are required to integrate the WDK with Visual Studio.)

Windows target version WDK and related downloads
Windows 11 version 22H2 Download the Windows Driver Kit (WDK)
Windows 11 version 21H2 Windows 11 Version 21H2 WDK
Windows Server 2022 WDK for Windows Server 2022
Windows 10, version 22H2, Windows 10, version 21H2, Windows 10, version 21H1, Windows 10, version 20H2, Windows 10, version 2004 WDK for Windows 10 Version 2004
Windows 10, version 1909, Windows 10, version 1903 WDK for Windows 10, version 1903
Windows 10 version 1809, Windows Server 2019 WDK for Windows 10, version 1809
Windows 10 version 1803 WDK for Windows 10, version 1803
Windows 10 version 1709 WDK for Windows 10, version 1709
Windows 10 version 1703 WDK for Windows 10, version 1703
Windows 10, version 1607, Windows 10, version 1511, Windows 10, version 1507, Windows Server 2016 WDK for Windows 10 Version 1607
Windows 8.1 Update WDK 8.1 Update Only (English) - Permanently Unavailable, WDK 8.1 Update Test Package Only (English) - Permanently Unavailable, WDK 8.1 Samples (Note: Drivers can be built for Windows 8.1 using any WDK from Windows 10, version 1607 to Windows 11, version 21H2.)
Windows 7 WDK 7.1.0
Windows 8 WDK 8 (English only) , WDK 8 Redistributables (English only) , WDK 8 Samples

Since we need the WDK corresponding to Windows 10 22H2, select the WDK for Windows 10 version 2004 according to the above table. (wdksetup.exe)

This installation process is very simple, you only need to continue to next to the end to complete the installation. When the WDK is installed here, we open Visual Studio 2019 again, and then select New Project, then we can select in the project type Driver, which means that our Windows driver development environment has been set up.

Write your first driver code

In the last part, we have completed the deployment of the Windows driver development environment. Here, try to write the simplest driver to verify our environment.

  1. Open Visual Studio 2019, select New Project, select the project type Driver, then select Kernel Model Driver(KMDF)and click 下一步.
    insert image description here

  2. Enter the new project name, storage path, and click 创建.
    insert image description here
    The IDE tool will automatically complete the basic file creation for us, and you can see the automatically created files in the solution explorer.
    insert image description here

  3. Do not change anything, directly select 生成- 生成解决方案, and an empty Windows driver file will be compiled and stored in the path we just saved. Here we
    insert image description here
    have completed the creation and compilation of the most basic Windows driver.
    In the following chapters, after we understand the concepts related to Windows drivers, we will add code, deploy, debug and other operations.

Summarize

This chapter briefly introduces the relevant knowledge about the Windows driver development environment, and conducts the deployment verification of the Windows driver development environment based on the Windows 10 22H2 operating system version. To complete the Windows driver development environment, you need to select the corresponding Visual Studio version and WDK (Windows Driver Kit) version according to the target operating system version you develop. The installation steps are also to install Visual Studio first and then install WDK. If it is a higher version of the Windows operating system, these two steps are completed (because the required Windows SDK has been integrated into Visual Studio), if it is a version below Visual Studio 2015, you need to download and install the Windows SDK separately.

Through the study of the content of this chapter, I believe that you have been able to deploy and complete the Windows driver development environment on your own machine. Later, you can concentrate on learning about Windows driver-related technical content.

References

https://learn.microsoft.com/zh-cn/windows-hardware/drivers/
https://learn.microsoft.com/zh-cn/windows-hardware/drivers/download-the-wdk
https://learn.microsoft.com/zh-cn/windows-hardware/drivers/other-wdk-downloads

Guess you like

Origin blog.csdn.net/qq_37596943/article/details/131429952