Windows CE: Drivers can delay o/s boot.


When building a custom Windows CE 5.0 operating system there's a good chance you may be developing drivers for the system - Drivers can slow the boot process of your device, but how ?


You should be aware of the load order of drivers on your device - take a look at the following information on MSDN - Note that drivers are loaded serially, if your drivers xxx_Init function pauses for several seconds waiting for some hardware to be available then you've paused the boot sequence by several seconds - drivers must be loaded serially since you may have one driver that requires another driver to already be loaded/initialized.


I've created a "dummy" stream driver for an emulator o/s image (I used the Stream Driver Wizard to create the boilerplate code)


Notice the call to Sleep(5000); in the DEM_Init( ); function - when I boot a debug build of the o/s image the debug stream pauses for 5 seconds on the DEM_Init function, this delays the boot of the operating system for 5 seconds - not a good user experience!


// Driver Init...
DWORD DEM_Init( LPCTSTR pContext, LPCVOID lpvBusContext)
{
  OutputDebugString(L"Demo - DEM_Init - Context: ");
  OutputDebugString(pContext);
  OutputDebugString(L"\n");
  hMem=LocalAlloc(LPTR,0x2000);   // 0x1000 Unicode Characters


  OutputDebugString(L"Demo Driver - SLEEPING.....\n");
 Sleep(5000);
  OutputDebugString(L"Demo Driver - END SLEEPING.....\n");


  OutputDebugString(L"DemoDriver - ~ DEM_Init\n");
  return 0x1234;
}


One way to work around this is to spin up a thread in your drivers xxx_Init function and then return immediately, your spawned thread can then wait on resources and initialize the driver.


- Mike

Comments (2)

  1. Mark Miller says:

    It’s also worth adding a call to DisableThreadLibraryCalls((HMODULE) hinstDll) in the DllEntry. This will stop your DLL from being called on every Thread Attach/Detach in the device.exe process space.

Skip to main content