Wednesday, December 19, 2007

Co-exist Two USB Wireless Drivers in NK.BIN Image

The registry of USB driver is look like below:

[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\Default\Default\Default\RT2870] "Dll"="RT2870.DLL"

When you tried to co-exist two usb drivers in registry, you have
[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\Default\Default\Default\RT2870] "Dll"="RT2870.DLL"
...
[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\Default\Default\Default\RT2501USB] "Dll"="RT2501USB.DLL"

Some how, the windows ce had a issue here. It will pop up a input dialog to ask you input a driver dll even the correct usb driver is loaded.

To fix this issue, check WINCE500\PUBLIC\COMMON\OAK\DRIVERS\USB\USBD\usbd.cpp
You will found the LoadRegisteredDriver() as below,

BOOL LoadRegisteredDriver(HKEY hkReg, SDevice * pDev,
LPCUSB_INTERFACE lpInterface, LPBOOL pfLoaded,
LPCUSB_DRIVER_SETTINGS lpDriverSettings)
{ …
while(RegEnumKeyEx(hkReg, iSubKey++, szDriverId, &cchDriverId, NULL,
NULL, NULL, NULL) == ERROR_SUCCESS)
{…
if(*pfLoaded)
AddDriverLib(pDev, hClientInstance);

}
return TRUE;
}


In red codes, you can understand it. When driver is loaded, the while loop must be broke and no more search this device in registry.

BOOL LoadRegisteredDriver(HKEY hkReg, SDevice * pDev,
LPCUSB_INTERFACE lpInterface, LPBOOL pfLoaded,
LPCUSB_DRIVER_SETTINGS lpDriverSettings)
{ …
while(RegEnumKeyEx(hkReg, iSubKey++, szDriverId, &cchDriverId, NULL,
NULL, NULL, NULL) == ERROR_SUCCESS)
{…

if(*pfLoaded)
{
AddDriverLib(pDev, hClientInstance);
break; // Add this!!!
}


}
return TRUE;
}

Then re-build all.