12.7  Compile Your Kernel PlugIn Driver

12.7.1  On Windows

The sample WinDriver\samples\pci_diag\kp_pci Kernel PlugIn directory and the generated DriverWizard Kernel PlugIn <project_dir>\kermode directory (where <project_dir> is the directory in which you selected to save the generated driver project) contain the following Kernel PlugIn project files (where xxx is the driver name – pci for the sample / the name you selected when generating the code with the wizard):

  • x86\ – 32-bit project files:
    • msdev_2008\kp_xxx.vcproj – 32-bit MSDEV 2008 project.
    • msdev_2005\kp_xxx.vcproj – 32-bit MSDEV 2005 project.
    • msdev_2003\kp_xxx.vcproj – 32-bit MSDEV 2003 project.
    • msdev_6\kp_xxx.dsp – 32-bit MSDEV 6.0 project.
  • amd64\ – 64-bit project files:
    • msdev_2008\kp_xxx.vcproj – 64-bit MSDEV 2008 project.
    • msdev_2005\kp_xxx.vcproj – 64-bit MSDEV 2005 project.

The sample WinDriver\samples\pci_diag directory and the generated <project_dir>\ directory contain the following project files for the user-mode application that drives the respective Kernel PlugIn driver (where xxx is the driver name – pci for the sample / the name you selected when generating the code with the wizard):

  • x86\ – 32-bit project files:
    • msdev_2008\xxx_diag.vcproj – 32-bit MSDEV 2008 project.
    • msdev_2005\xxx_diag.vcproj – 32-bit MSDEV 2005 project.
    • msdev_2003\xxx_diag.vcproj – 32-bit MSDEV 2003 project.
    • msdev_6\xxx_diag.dsp – 32-bit MSDEV 6.0 project.
    • cbuilder4\xxx.bpr and xxx.cpp – Borland C++ Builder 4.0 project file and related CPP file. These files can also be used from version 5.0 and 6.0 of Borland C++ Builder.
    • cbuilder3\xxx.bpr and xxx.cpp – Borland C++ Builder 3.0 project file and related CPP file.
  • amd64\ – 64-bit project files:
    • msdev_2085\xxx_diag.vcproj – 64-bit MSDEV 2008 project.
    • msdev_2005\xxx_diag.vcproj – 64-bit MSDEV 2005 project.

The MSDEV directories listed above also contain xxx_diag.dsw/.sln workspace/solution files that include both the Kernel PlugIn and user-mode projects.

To build your Kernel PlugIn driver and respective user-mode application, follow these steps:

  1. Verify that the Windows Driver Kit (WDK) is installed.
  2. Set the BASEDIR environment variable to point to the location of the directory in which WDK is installed.
  3. Start Microsoft Developer Studio (MSDEV) and do the following:
    1. From your driver project directory, open the generated workspace/
      solution file – <project_dir>\ <MSDEV_dir>\xxx_diag.dsw/.sln, where <project_dir> is your driver project directory (pci_diag\ for the sample code / the directory in which you selected to save the generated DriverWizard code), <MSDEV_dir> is your target MSDEV directory (msdev_2008 / msdev_2005 / msdev_2003 / msdev_6) and xxx is the driver name (pci for the sample / the name you selected when generating the code with the wizard).

      Note that when selecting to generate code for the MSDEV IDE with the DriverWizard, the wizard automatically starts MSDEV and opens the generated workspace/solution file after generating the code files, unless you explicitly revoke this behavior by setting the "IDE to Invoke" option in the code generation dialogue to "None".

    2. To build the Kernel PlugIn SYS driver (kp_pci.sys – sample / kp_xxx.sys – generated wizard code):
      1. Set the Kernel PlugIn project (kp_pci.dsp/vcproj / kp_xxx.dsp/vcproj) as the active project.
      2. Select the active configuration for your target platform: From the Build menu, choose Configuration Manager... (MSDEV 2003/2005/2008) / Set Active Configuration... (MSDEV 6.0), and select the desired configuration.
        [Note]
        To build the driver for multiple operating systems, select the lowest OS version that the driver must support. For example, to support Windows 2000, XP, and higher, select either Win32 win2k free (release mode) or Win32 win2k checked (debug mode).
      3. Build your driver: Build the project from the Build menu or using the relevant shortcut key (e.g., F7 in MSDEV 6.0).
    3. To build the user-mode application that drives the Kernel PlugIn driver (pci_diag.exe – sample / xxx_diag.exe – generated wizard code):
      1. Set the user-mode project (pci_diag.dsp/vcproj – sample / xxx_diag.dsp/vcproj – generated wizard code) as the active project.
      2. Build the application: Build the project from the Build menu or using the relevant shortcut key (e.g., F7 in MSDEV 6.0).

12.7.2  On Linux

  1. Open a shell terminal.
  2. Change directory to your Kernel PlugIn directory. For example, when compiling the sample KP_PCI driver, run:
    cd WinDriver/samples/pci_diag/kp_pci When compiling the Kernel PlugIn driver for your generated DriverWizard Kernel PlugIn code, run the following command, where <path> represents the path to your generated DriverWizard project directory
    (e.g. /home/user/WinDriver/wizard/my_projects/my_kp/):
    cd <path>/kermode/linux/

  3. Generate the makefile using the configure script:

    ./configure --disable-usb-support

    [Note]
    The configure script creates a makefile based on your specific running kernel. You may run the configure script based on another kernel source you have installed, by adding the flag --with-kernel-source=<path> to the configure script. The <path> is the full path to the kernel source directory, e.g. /usr/src/linux.
    If the Linux kernel is version 2.6.26 or higher, configure generates makefiles that use kbuild to compile the kernel modules. You can force the use of kbuild on earlier versions of Linux, by passing the --enable-kbuild flag to configure.
  4. Build the Kernel PlugIn module using the make command.
    This command creates a new LINUX.xxx/ directory (where xxx depends on the Linux kernel), which contains the created kp_xxx_module.o/.ko driver.
  5. Move to the directory that holds the makefile for the sample user-mode diagnostics application.

    For the KP_PCI sample driver:
    cd ../LINUX/

    For the generated DriverWizard Kernel PlugIn driver:
    cd ../../linux/

  6. Compile the sample diagnostics program using the make command.