Monday, September 28, 2009

How to make Passive KITL work!!! [WinCE]

Hi,
Search Just in time debugger in your msdn for WinCE or help to know how to make Passive KITL work.
Note your Active KITL should already be working.

Have fun @ WinCE

Loading a driver using KITL!!! [WinCE]

Apart from loading driver directly from image, you can use KITL to do for you.

Remove driver entry from platform.bib. Add entry into platform.reg.
To make it work, enable SYSGEN_SHELL=1 which supports \Release which used to permit to use _FLATRELEASEDIR.

This should be your registry entry.

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SAM]
"Dll"="\Release\sample.dll"
"Prefix"="SAM"
"Index"=dword:1
"Order"=dword:1

Have fun with WinCE!!!

Saturday, August 22, 2009

How ActivateDeviceEx or ActivateDevice works? [WinCE]

Basic difference between these two API is that 1st load and register a device driver under Active key in registry while 2nd only load the driver.
Here I will details about only ActivateDeviceEx. It takes four parameter
1. Registry path to determine all sub key information like prefix, order and dll information.
2. REGINI pointer: every structure variable determine the value to be added to active key. Before going further, I would like to clear what is a active key. If using tools in platform builder, you can see in the registry, there is a node called "active" . Basically it contains all driver and their key which are active at the paticular time. To determine whether your driver is active or not, you can verify it by looking the registry entry.
3. cRegEnts - count the number of structure regini pointer pointer
4. lpvParam - Bus specific variable, we know that ActivateDevice calls xxx_Init, so this is second parameter during that course. So you can fill the variable and later you can access the same in init function.

Let begin with how everything goes fine:)

It will start with reading the registry entry in a structure.
Check for operation flag, like for load, unload or none.
Check for boot phase like phase 1 or 2. Usually there is two boot phase, and depending on boot phase setting in flag subkey, it determine to load in particular boot phase.
Once all this done, it will create a entry for the driver in the active key.It work like if there is already existing entry then it will format then will add new structure which can contain fresh subkey values.
Now it initializes the subkey variable using the registry entry made by us with RegSetValue API.
Next it will read the parent BUS driver specific registry entry by check bus parent and bus name using the active key.
It will check the index value if exist, if not then it will create unique Index for it. Else will create the same except we will assign 0 if index value mention is 10. It work in three steps by verifying bus name and device name and then if not duplicate then it will create new structure for the device and keep with itself in a link list sort of structure.
There is bug here in code - I tested and verified. If you have a device with index not mention with same prefix as of three device then one of them will not get loaded. I will debug and send it to MS.

Now check for naked device name and also allocate the total space needed.
Most important is that this step will store the address of each standard exported function. Then check for init and deinit exist and remove entry which are not present in exported function list.
In the last and final step, add device handle and device name.
This this point everything was related with setting registry variable and registry related stuff,. Now we will launch the device by calling xxx_Init function.
Now there will security check on the launch parameter or un-launch. There will OEMCetifyTrust in this process and then there will check on registry entry again. Then there will be call to Init or DeInit depending on flags entry.

Everything is Microsoft copyright. The way explained is mine. That's it for now. See you at next article.







Saturday, May 23, 2009

How NAND Flash driver works!!! [WinCE]



This article includes the basic NAND driver porting as well as the key problem developer usually face during development. 

The article is explain in the following points:

  1. What is NAND Flash driver.
       Flash memory is non-volatile, which means that no power is needed to maintain the information stored in the chip. In addition, flash memory offers fast read access times (although not as fast as volatile DRAM memory used for main memory in PCs) and better kinetic shock resistance than hard disks. In devices, it is used as boot as well storage devices like SD Card. We flash the step loader image in NAND and while booting, the processor start boot time; we configure the processor to boot from NAND. Later processor boot from NAND and we see the image up. Also in the image we can see the NAND Flash folder which can be used as storage space. The storage space will be space left after flashing step loader.

2. Overview knowledge before devlopment start
       The flash driver is devided in two parts in WinCE 6.0. 
1. Stream driver which is under public or private. It is provided by microsoft and we have to plug in the our code with it.
2. This is called PDD which implement the platform depending on our NAND flash controller and NAND flash. 
The upper layer is called FAL, Flash Abstraction layer and this is implemented by MS. Hence we need to implement just the funtion required by the FAL. This is a normal disk storage stream driver.


3. Porting function required

These functions are required to be implemented and implementation depends on the Flash controller and flash card type. Thease function are called by the FAL. If you don't support all functionality then also you have to define this function as empty function. 

4. Registry setting and it’s significance.
When we write NAND Flash driver, our aim is that our NAND device should work as booting device as well as persistent storage device.
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\NANDFLASH\FATFS]
 "Flags"=dword:14
 "FormatExfat"=dword:1 ; to format the NAND with exFat file system
"CheckForFormat"=dword:1 ; it is used to tell the OS that format or not it if it is a clean boot or normal one.
"EnableWriteBack"=dword:1 ; This is cache properties whether to enable write through cache or write back.
Similarly you can set properties for cache filter.

5. Refering question and solution in one page



Refereces:
www.e-consystems.com/images/fmd%20blockdig.jpg

Thank you very much

~~Mike


Saturday, March 7, 2009

How ExitThread works!!! [WinCE]


This function ends a thread.This API takes exit code for the calling thread. To retrieve a thread's exit code, use the GetExitCodeThread function.
The steps are:
  1. It will release the owner process by using API GetCurrentThreadId which gives it current thread and check for the current process which own the thread and if it's the same application which own the thread then release all CS.
  2. Check for thread type:
    1. If it is the primary thread then
      1. Kill all other thread.
      2. Detach all DLL from the process.
      3. Call Dllmain function of dll with thread detach ioctl.
      4. Call core dll to detach the thread.
      5. Close all handle
    2. Else
      1. Get the thread attach status and call dllmain of dll with thread detach ioctl.
  3. Now it will call NKTerminateThread.
Note: If the primary thread calls ExitThread, the application will exit.