Friday, October 23, 2009

Thursday, October 22, 2009

What is the difference between *.nb0 and *.bin(nk.nb0 or nk.bin) !!! [WinCE]

Whenever we run the command romimage with one of the bib file like ce.bib then we get two images.
  1. nk.nb0 ( in case of ce.bib but name can vary like sam.nb0 depending on the target image name you want)
  2. nk.bin
So what is the difference between these two -

In case of .bin file, the following stuffs getting added one by one -

1. Image hdr "B000FF"

2. Image start address and image size.

3. Now make entry of dll/files under module sections.

4. Make entry for dll/files under FILES section in  bib file here( ce.bib) in nk.bin with proper offset and entry point with allignment.

5. Allocate the space for rom header but that will be filled later after toc and other stuff. And as all information related to toc and other stuff will be ready after build process hence we will fill it after build process.

6. Now make entry in TOC about all dll.

7. Now wrtite the toc information into kernel which is available for TOC entry.

8. Write ROM Signature with it's offset.

8. Next all xip or files get entered into files. Hence depending on the need only the size of the file grows. Not like the nknb0 which takes all space allocated to OS.

Now lets give a look at nk.nb0 -
1. There no compression or ToC in nk.nb0. So it does not require support to get executed. The nk.nb0 can execute on self.
2. It's size can be determine from config.bib by getting the size of OS size. If the image is lesser then also it will consume the whole space and filled the rest of the area with zero.

This apply to both nk.nb0 or any type of .nb0.

I am planning to add more stuff here related to differences.

Tuesday, October 20, 2009

A thought!!! [WinCE]

I was thinking about WinCE once. How can any improvement is possible in WinCE. I thought one part. Basically this part can be implemented by OEM as well but because of the special attribute of Microsoft to make OEM less worried about writing code and after that also they should get better performance by the WinCE compare to other competitive company.

Here I am going to suggest Microsoft that include DMA as native driver. These days every OEM always use DMA controller to do most of their transfer stuff and there is sort of standard in it too.Using those feature they can ask users to just fill some of their prototype and get the best DMA driver of it.

In the driver, even there can implement fuzzy logic which will increase the performance of the WinCE. As everybody know he benefit of fuzzy but many of coder don't use this technique as it is some what complex because it will affect RAM performance too. I guess MS can do it.

Saturday, October 17, 2009

What should be prefix name? [WinCE]

One day, I was writing a sample driver. In the registry file platform.reg, while making entry for my sample driver, by mistake, I used S8M as prefix and it works fine.
I was surprised. Because I referred the link http://msdn.microsoft.com/en-us/library/aa447463.aspx
Which clearly says that "When you implement the stream interface, you designate the three-letter prefix. It can be any three letters, although you should use a common prefix, if your driver is the same class of device as other drivers".

It means it should not support other type of prefix.But it does. Just by seeing at the logic, I think that is correct way as other name like SM8 or 8SM does not work.
I am thinking whether it is wrong or write. But logically I agree this bug or wrong logic is correct but at the same time, MS should clearify in the same in their msdn part too. I think the time has come when people rely on article to resolve their problem. At this time it is must.
I would like everybody to share their reason to support or not support.

Thursday, October 15, 2009

How to remove all prints from WinCE Image!!! [WinCE]

It is a common practice to remove all prints from the image which is going to ship to customer.

Now, depending on the requirement you can disable prints.
 Like, if you want to disable debugmsg and retailmsg, then set WINCE_SHIP=1. It does not mean that it will work for other OAL prints related funtion. But if you want that there should not be any prints at all then, you need to disable com port itself.

You need to check function OEMWriteDebugByte, which is taking care of debug port.

Wednesday, October 14, 2009

A Shortcut to Build your image!!!! [WinCE]

Hi,

Many times we see a problem of this dll is missing. What we do. We just find out the module compile it again and get dll and then build rel then make image. But think a scenario, when you have to include a dll which you can get only after sysgen the project. Looks cumbersome but there is a solution for it. The solution will give just a temporary solution so don't blindly rely on it.
Simply open ce.bib, then comment the particular dll by using semicolon(;).
Then run the command by opening the command window from menu bar(I guess name is like release to with msdos option. )
romimage                                                                   /location of ce.bib/ce.bib

This will give output file. Also you always need to modify ce,bib whenever you wan to build an image.

Why we should not use platform builder to include or exclude a module!!! [WinCE]

Many time we wish to remove or add a module in project. We usually follow two technique.
1. Edit the dirs file
2. Right click the module in platform builder and select exclude from build.

Both works fine.
But in few scenario, second option can cause problem.
Suppose you have two folder lets say A and B.
After building A, we get A.lib. And similarly after building B, we get B.dll but this B.dll uses A.lib to build successfully. Now if you want to remove B, so you would like to remove A and B, both. So you might use the sequence, First A then B or B first then A.
So in the same way, actually module get deleted from dirs file also. So once you plan to include, the module will be added at the end of dirs file. Hence once you choosed B first and then A. In that case, either the b.dll will not be build successfully or it will be build with old A.lib, hence your changes in A.Lib will not be reflected(if you are not going to build A.lib again).

Hence  it is wisely suggested that always edit dirs directly.

Tuesday, October 13, 2009

How VirtualAlloc works!!! [WinCE]

VirturlAlloc internally call SC_VirtualAlloc.

As you know that this api take parameters like the desired address of area assigned and size of file and flags related to action on the region given and access type on the region.

Now I will explain only the use case in which it will give the desired result not the else part.

;)

It start with checking the desired address whether it is inside kernel address and also check for access type and action on region whether it's supported or not.

Check if the request region is under secure VA. If not then calculate the base address of the region assigned just by left shifting the address asked for. Now check the address that it's come under first mapper add or not if yes then check for the process to check the remotely memory is accessed by the current process.

Now check for the allocate type.

Now check whether the request is for slot 0. If yes then take the 64k booundary. and check for the free region.

To check for NULL block.


If the request is not for Slot 0 then use filesystem to reserve the region.

Check the condition like requested region is more than 32MB then find the continuous memory.

* Still Not Completed

Saturday, October 10, 2009

How mounting works with FAT Filesystem [WinCE]

Mounting means attaching a disk to a filesystem.
When mount option get selected in the storage manager, these are following operations performed:

  1. It asked for device information. It will check against read only and set the variable as if after set, it will be read-only disk.

  1. Now it will get device info and will set FAT FS for the device flag variable.

  1. Find out the total number of sectors.

  1. There is read and write operation performed on the disk for which we allocate a buffer. It’s an interesting operation. There is two term FAT Cache and Data Cache comes into picture. FAT Cache is cache of actual sector which comprises the FAT table. Necessity of FAT Cache is that it allow to access very large chunk of files hence we have to traverse in the table of 2^17 for 32k clusters. So with increasing the FAT cache size will resolve the traversing so long. Data Cache is to keeping the cache of file names with a directory. Like to create a new file in a directory will lead to check all file name and then only we can use the new file name.
Using the registry you can increase or decrease

[HKEY_LOCAL_MACHINE\System\StorageManager\FATFS]
            "FatCacheSize"=0xXXXXX  - Size of the FAT Table Cache
            "DataCacheSize"=0xXXXX - Size of the Data Cache

It also checks for cache ID. If it does not exist it also means that the area if for boot and it’s cache disable so there will be normal read and write operation will happen but if it is under cache ID the read or write operation will only perform on the cache. No direct access will be on the sector.

It also finished the reading and writing of disk.

  1. Now it will find the volume. It also means that it will check for the same volume name and will add the new disk name to the disk link list structure.
  2. It will now mount the volume with the filesystem. In turn will perform the following operation:
    1. Open the volume – It first tries to find the volume. If it does not exist then will create one. Then initialize the volume. This operation makes sure that all registry entry parameter is added with volume. Also the volume structure contains all information from size of volume to cluster related parameter. The cluster related value will contain take care of root directory to nested one.
    2. Refresh the volume – This operation required as it can have many open handle. We do even if we have invalid volume.
    3. Format volume if it unformatted or invalid or read only or other invalid conditions – This will format the volume again if required.
    4. Register the volume with filesystem – It will give a name to the volume.
    5. Close the volume – Close the volume handle. This operation comes in picture only if we can’t allocate enough buffers or there is any problem in registering with the file system.

Note: In all these operation, we are using HeapAlloc not VirtualAlloc. The reason is that it will allocate the size of memory asked for not in 4k chuck or what ever like VirtualAlloc.

Friday, October 9, 2009

How KernelRelocate works? [WinCE]

KernelRelocate is one of the most interesting function I found in WinCE. Frankly, I am feeling happy to share the details and how exactly it works.

The pTOC variable is in nk.exe which is feed by ROMIMAGE

This function copies all the copy entries described by the pTOC to RAM. The process of changing an EXE or DLL program file after it has been loaded to reflect the actual load address is called “fixing up”. The variable pTOC actually have information about all dll and exe and where it has to be relocated. It know where RAM starts as ROMIMAGE use config.bib to feed the information. The information is feed by ROMIMAGE tool.

There is basic requirement of the relocation that when nk.exe call any of the dll or exe. It actually calls at RAM location to execution function instead of where it was copied by steploader. Also a steploader just copied data bit by bit although that is RAM. But NK.exe always access different address.

This is actually what is happening. pTOC variable have every information about RAM and where the dll and exe is lie in.


  1. //
  2. // KernelRelocate: move global variables to RAM
  3. //
  4. static BOOL KernelRelocate (ROMHDR *const pTOC)
  5. {
  6. ULONG loop;
  7. COPYentry *cptr;
  8. if (pTOC == (ROMHDR *const) -1) {
  9. return FALSE; // spin forever!
  10. }
  11. // This is where the data sections become valid... don't read globals until after this
  12. for (loop = 0; loop <>ulCopyEntries; loop++) {
  13. cptr = (COPYentry *)(pTOC->ulCopyOffset + loop*sizeof(COPYentry));
  14. if (cptr->ulCopyLen)
  15. memcpy((LPVOID)cptr->ulDest,(LPVOID)cptr->ulSource,cptr->ulCopyLen);
  16. if (cptr->ulCopyLen != cptr->ulDestLen)
  17. memset((LPVOID)(cptr->ulDest+cptr->ulCopyLen),0,cptr->ulDestLen-cptr->ulCopyLen);
  18. }
  19. return TRUE;
  20. }

Monday, October 5, 2009

Who calls all Stream interface function!!! [WinCE]

Hello Developers,
Since so many days, I was thinking that it will be better if everybody know, which function calls all stream interface function.. Like xxx_Init or whatever.

Find out the crisp form of information.

1. XXX_Init - Called by ActivateDeviceEx. If it is BuiltIn driver then BusEnum will call it.
2. XXX_Open - Called by CreateFile which in turn return a handle for the Handle.
3. XXX_Close - Called by CloseHandle.
4. XXX_Read - Called by ReadFile function
5. XXX_Write - Called by WriteFile
6. XXX_IOControl - Called by DeviceIoControl
7. XXX_Seek - Called by SetFilePointer
8. DllEntry - Called by LoadLibrary.
9. XXX_DeInit - DeactivateDevice. Also check for XXX_PreDeinit.
10. XXX_PreClose - Same as case of XXX_PreDeinit
11. XXX_PowerUp - Called by DevMgrPowerOffHandler by Device manager. In turn, OS kernel.

12. XXX_PowerDown - Called by DevMgrPowerOffHandler by Device manager. In turn, OS kernel.



Sunday, October 4, 2009

How Warm Boot is Implemented? [WinCE]

Usually Images stored in Flash media in the following manner:
1. Store eboot(include piece of code which will copy NK.BIN to RAM too) and NK.BIN in FLASH together.
2. At startup, eboot copy nk.bin into RAM and then jump to address (0x800XYYYY address of NK.BIN in RAM) when image is copied.
3. In warm boot, we issue JUMP instruction to PC to start from NK.BIN address at RAM(0x800XYYYY).
Warm boot is use to retain data into image even after reset. Cold boot will restored the system to it's previous state.
4. Before validating the warm boot, re validate flow as well.

Note: the following line

memset((LPVOID)RomHdr.ulRAMStart, 0, RomHdr.ulRAMEnd - RomHdr.ulRAMStart)

Clears the RAM addresses, make sure it is not getting called.

Monday, September 28, 2009

How to get finer control over driver loading!!! [WinCE]

Refer simply the link

Download and follow instruction. Learn how to do it.

Hav fun with WinCE

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