| 1 |
Developing Windows Drivers |
| 2 |
========================== |
| 3 |
|
| 4 |
Prerequisites |
| 5 |
------------- |
| 6 |
|
| 7 |
Building Windows Drivers is only possible on Windows. |
| 8 |
|
| 9 |
1. Visual Studio 2019 Community or Professional Edition |
| 10 |
2. Windows Driver Kit (WDK) for Windows 10, version 1903 |
| 11 |
|
| 12 |
Follow the official instructions to obtain all of the above: |
| 13 |
https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk |
| 14 |
|
| 15 |
|
| 16 |
Build the Drivers |
| 17 |
----------------- |
| 18 |
|
| 19 |
Build from Visual Studio |
| 20 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 |
|
| 22 |
Open a solution (``*.sln``) with Visual Studio and build it (Ctrl+Shift+B). |
| 23 |
|
| 24 |
|
| 25 |
Build from Command-Line |
| 26 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 |
|
| 28 |
Run *Developer Command Prompt for VS 2019* from the Start menu. |
| 29 |
|
| 30 |
Navigate to the solution directory (with ``*.sln``), then run: |
| 31 |
|
| 32 |
.. code-block:: console |
| 33 |
|
| 34 |
msbuild |
| 35 |
|
| 36 |
To build a particular combination of configuration and platform: |
| 37 |
|
| 38 |
.. code-block:: console |
| 39 |
|
| 40 |
msbuild -p:Configuration=Debug;Platform=x64 |
| 41 |
|
| 42 |
|
| 43 |
Install the Drivers |
| 44 |
------------------- |
| 45 |
|
| 46 |
Disable Driver Signature Enforcement |
| 47 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 48 |
|
| 49 |
By default Windows prohibits installing and loading drivers without `digital |
| 50 |
signature`_ obtained from Microsoft. For development signature enforcement may |
| 51 |
be disabled as follows. |
| 52 |
|
| 53 |
In Elevated Command Prompt (from this point, sufficient privileges are |
| 54 |
assumed): |
| 55 |
|
| 56 |
.. code-block:: console |
| 57 |
|
| 58 |
bcdedit -set loadoptions DISABLE_INTEGRITY_CHECKS |
| 59 |
bcdedit -set TESTSIGNING ON |
| 60 |
shutdown -r -t 0 |
| 61 |
|
| 62 |
Upon reboot, an overlay message should appear on the desktop informing |
| 63 |
that Windows is in test mode, which means it allows loading unsigned drivers. |
| 64 |
|
| 65 |
.. _digital signature: https://docs.microsoft.com/en-us/windows-hardware/drivers/install/driver-signing |
| 66 |
|
| 67 |
Install, List, and Remove Drivers |
| 68 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 69 |
|
| 70 |
Driver package is by default located in a subdirectory of its source tree, |
| 71 |
e.g. ``x64\Debug\virt2phys\virt2phys`` (note two levels of ``virt2phys``). |
| 72 |
|
| 73 |
To install the driver and bind associated devices to it: |
| 74 |
|
| 75 |
.. code-block:: console |
| 76 |
|
| 77 |
pnputil /add-driver x64\Debug\virt2phys\virt2phys\virt2phys.inf /install |
| 78 |
|
| 79 |
A graphical confirmation to load an unsigned driver will still appear. |
| 80 |
|
| 81 |
On Windows Server additional steps are required if the driver uses a custom |
| 82 |
setup class: |
| 83 |
|
| 84 |
1. From "Device Manager", "Action" menu, select "Add legacy hardware". |
| 85 |
2. It will launch the "Add Hardware Wizard". Click "Next". |
| 86 |
3. Select second option "Install the hardware that I manually select |
| 87 |
from a list (Advanced)". |
| 88 |
4. On the next screen, locate the driver device class. |
| 89 |
5. Select it, and click "Next". |
| 90 |
6. The previously installed drivers will now be installed for |
| 91 |
the appropriate devices (software devices will be created). |
| 92 |
|
| 93 |
To list installed drivers: |
| 94 |
|
| 95 |
.. code-block:: console |
| 96 |
|
| 97 |
pnputil /enum-drivers |
| 98 |
|
| 99 |
To remove the driver package and to uninstall its devices: |
| 100 |
|
| 101 |
.. code-block:: console |
| 102 |
|
| 103 |
pnputil /delete-driver oem2.inf /uninstall |