Moving

Dear readers (if any!): i decide to move my blog to WordPress @ http://lcalligaris.wordpress.com/

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Welcome Windows Embedded Compact!

Windows Embedded Compact 7 Public Community Technology Preview (Public CTP) is finally available for downloading:

In the next blog entries I'll try to address some of the new features of the new version of my favourite OS.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

NNTP bridge for MS forums

For those who wants to use their newsreader to interact with MS forums there's a new tool: the NNTP Bridge application serves as a channel that enables access for NNTP newsreaders to read and write content to Microsoft Forums. You can download the applcation and documentation from http://connect.microsoft.com/MicrosoftForums (registration required).

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Windows Embedded Forums

Here are the forums about Windows Embedded:

The first forum has been online for some time while those about Windows Embedded Compact have been welcomed by Olivier Bloch a couple of hours ago. As I discuss in the previous post the public MS newsgroups will close between June 1, 2010 and October 1, 2010, starting from those with less traffic. The embedded NG's will be probably close at the beginning of the period since, for some reasons I do not understand, they're not so popular as those devoted to, let's say, Office. The forums will substitute the newsgroups so prepare to switch over soon!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

MS Newsgroups transition to MS forums

As many developers and MVP's I read and write on MS newsgrousp like microsoft.public.windowsce.platbuilder and others.

Maybe you do not know that, in a few weeks those newsgroups (all MS newsgroups actually) will be closed and they will be substituted by formus. Following you can find the MS communicate:

"Starting in early summer 2010, Microsoft will begin progressively closing down the Microsoft public newsgroups to enrich conversations in the rapidly-growing forum platform.  This decision is in response to worldwide market trends and evolving customer needs.

Microsoft continues to invest in forums to reduce customer effort, consolidate community venues and make it easier for active contributors to retain their influence. Forums provide a healthy community environment with less spam and make answers easier to find by customers and search engines.  Additionally, forums offer a better user and off-topic management platform that will improve customer satisfaction by facilitating discussions in a clean space. 

We understand that some newsgroups are still active, and important to the community.  In the coming days and weeks, we will be rolling out tools and resources to minimize disruption to the community discussions.

We are working diligently on providing additional resources and information in local languages later this week.  In the meantime, please refer to the official Microsoft Newsgroup website
http://www.microsoft.com/communities/newsgroups/default.mspx concerning this issue.  The Microsoft Newsgroup website will be made available in additional languages in the next few days."
 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Learning Windows CE

Maybe you didn't notice that Windows Embedded CE Developer Center web site has a Learn section: in this section you can find a lot of interesting content in various formats (video, text, slide presentations, MSDN links, etc.) about several Windows Embedded CE development areas, specifically:

  • General Content
  • OS Design & Build
  • BSP & Other Hardware
  • Application Development
  • Communication & Connectivity
  • Silverlight for Windows Embedded

For each area you can find entry-level, intermediate and advanced content.

Some of the things you'll find aren't really new but the I think that having a lot of interesting information concentrated in a single site is valuable.  From the same site you can download the free guide to Windows Embedded CE Exam Preparation Kit written by MS and Adeneo and a free electronic copy of Windows Embedded CE 6.0 Fundamentals book, by Stanislav Pavlov and Pavel Belevsky.

Last but not least, another interesting site, in my opinion is the Windows Embedded CE Developers Wiki , especially the BSP section.

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Flash device driver in Windows Embedded CE 6.0

In previous version of Windows CE the flash drivers followed a model based on FAL (Flash Abstraction Layer): the developer had to write the FMD (Flash Media Driver) layer and link it with fal.lib to create a DLL which exposed a block (DSK_Xxx) stream interface. Starting with Windows Embedded CE 6.0 R2 MS introduces a new model based on a MDD/PDD layer structure. The MDD part is implemented in a DLL (flashmdd.dll) exposing a block (DSK_Xxx) stream interface which handles some specific IOCTL_FLASH_XXX codes; the DLL calls the PDD DLL which the developer has to write according to the interface specified by MS; this interface is similar to the MDD (a block stream interface driver) which handles some specific IOCTL_FLASH_PDD_XXX codes. The FAL/FMD model is still supported.
In addition, in Windows Embedded CE 6.0, you have a new partion driver (flashpart.dll) specifically designed for flash block devices. This partition driver has to be used with the MDD DLL since it's aware of the specific IOCTL_FLASH_XXX codes that the MDD DLL implements.

MS provides a library (flashpddwrapper.lib) which gives the developer the opportunity to reuse the FMD code in the new architecture: this library exposes the PDD interface to the MDD DLL but internally calls the old FMD entry point. 

Notice that the shared source for Windows Embedded CE 6.0 includes the FAL library source code which was not available before: the FAL is implemented in C++  while in previous versions it was implemented in C. Other source code which is available (in the public part of %_WINCEROOT%) includes flashpddwrapper and some specific FMD. Some of these FMD (for example the sample RAM flash driver) are linked in two different ways to create a flash driver which uses the FAL (for example ramfmd) and another one which benefits from the new model (flashpdd_ram). 

Flash driver architecture before Windows Embedded CE 6.0 R2

FAL.LIB + FMD.LIB (developer)

Flash driver architecture after Windows Embedded CE 6.0 R2

MDD/PDD

FLASHMDD.DLL

FLASHPDD.DLL (developer)


MDD/PDD wrapping the FMD

FLASHMDD.DLL

FLASHPDD.DLL (FLASHPDDWRAPPER.LIB + FMD.LIB (developer))


FAL/FMD 

FAL.LIB + FMD.LIB (developer)

For additional info see MSDN documentation.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Get last error and set it meaningfully

Very often I read posts in the newsgroups like:

I call function Foo(dwParam) and it returns FALSE. What's wrong?

If I cannot tell it immediately -for example because the dwParam is clearly wrong - my standard answer is:

Have you called GetLastError()? Which error value it returns?

GetLastError (if the call that fails actually sets an error and the error is meaningful) can be very helpful to detect why the call is failing. If you do not understand exactly what the code means and you have the code you may figure out where and why the failing function is calling SetLastError with that specific code.

Take in account that the error value you get is per thread -the kernel structure modeling the thread has a DWORD member named dwLastError: Since GetLastError retrieves the latest error this means that, if the failing function you are investigating does not uses SetLastError(), the error you get is related to a previous call to another function so can be misleading (or it can be 0 since a function you call before succeded and set the error to ERROR_SUCCESS.

The error codes are defined in the documentation but, for a more complete list and meaning you can check  %_WINCEROOT%\PUBLIC\COMMON\SDK\INC\winerror.h.

When you write your own code is a good practice to use SetLastError(dwError) with a meaningful error value; if you do not find an adapted system value for the error you can define your own: an error code which has bit 29 set  is guaranteed not to conflict with any system error code.

The error codes are DWORD's which should be formatted as follows - according to winerror.h:

Bits 31 & 30 are the severity code where

          00 - Success
          01 - Informational
          10 - Warning
          11 - Error

Bit 29 is the Customer code flag

Bit 28 is a reserved bit

Bits 28-16 are the facility code,  which -more or less- identifies the subsytem generating the error, Internet, Storage, etc

Bits 15-0 are the actual error code

 

Take in account that the severity code is almost not used in winerror.h codes: for example ERROR_INVALID_PARAMETER which is undoubtly an error (neither a warning nor an information) has a value of 0x57L, not 0xC0000057L.

On the contrary the severity bits are used in Windows NT-based OS NTSTATUS error codes: for example STATUS_UNSUCCESSFUL which is the more generic error that you will have has a value of 0xC0000001L.

By the way, most DDK functions returns an NTSTATUS code so there's no need to call a function like GetLastError to have more information about the error itself.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Windows Embedded CE 6.0 R3 released

Windows Embedded CE 6.0 R3 is finally available for download here. This intermediate release (while we wait for Windows Embedded Compact in 2010) brings several features, the most important of which is probably Silverlight for Windows Embedded. Download a free trial of Expression Blend to create new user interface experience for your embedded device!

For more info on the features included in CE 6.0 R3 check the following links:

Note that Office and PDF viewers for Windows Embedded CE 6.0 are available as a separate download here while Mobile QQ Messenger Client can be downloaded here (both the packages are from 3rd party providers).

CE 6.0 R3 includes the Adobe Flash Lite Plug-In for IE browser: if you are interested in developing Flash applications you can find a lot of info and resources from Adobe site.

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

A curious issue with PCI bus driver & hive based registry

Recently we faced a strange problem on one of our x86 systems: after some successfull boots the system was unable to start the OS anymore but deleting the 'Documents and Settings' folder on the storage device (we included the hive based registry in the OS) the system behave normally.

After some investigation we found out that when the system was not booting correctly the USB OHCI driver was performing an endless loop waiting for the host controller to reset (thus preventing the device manager to load the other drivers - never
write an XXX_Init routine which can spin forever!).

The code looks like:

m_portBase->HcCommandStatus.HCR = 1;

while (m_portBase->HcCommandStatus.HCR == 1)
   ;
 
With the debugger we found out that all the memory area used to map the USB controller registers was 0xFF (!), thus the bit was never cleared. This looked very strange so we started looking at the system registry founding out that the BAR (Base Address Registry) of the USB host on the PCI bus was 0x80003000 while the device was actually mapped at 0xDA000 (both flat physical addresses).

An additional information: our BIOS implements legacy USB support which means that the BIOS maps the USB host at 0x80003000 when it assigns the resources to the PCI bus. If the legacy USB support is enabled the BIOS maps the USB host at 0xDA000 (under the 1MB limit), configures it and tries to find possibly connected manageable USB devices (i.e. storage and keyboard). If such devices are not detected the controller is remapped back at 0x80003000 otherwise it remains at 0xDA000 (this allow the BIOS to boot the OS from a USB disk redirecting INT13 on the USB - but this is another story...). 

After accusing one collegue of mine (he wrote the BIOS after all!) we realized that you could trigger the problem this way:

  • Connect the USB keyboard to the system, turn it on and boot a clean OS (no hives on the storage).
  • Turn off the system, disconnect the keyboard and turn the system on: the OS does not boot anymore.

or

  • Turn on the system (no USB keyboard) and boot a clean OS (no hives on the storage).
  • Turn off the system, connect the keyboard and turn the system on: the OS does not boot anymore.

Looking at the PCIBUS code the problem became clear: on a cold boot the bus driver enumerates the PCI devices and build the  'Instance' keys based on the 'Template' keys. Under the 'Instance' key the bus driver saves relevant informations like the SysIntr value and the BAR's (look here for more information).

The PCIBUS driver is quite smart so, in subsequent boots, it enumerates the PCI devices and analyze the 'Instance' keys (using the hive based registry they're already set up) first - this allow the bus driver not to load a driver for a device which is not present anymore. If it founds that there is already an 'Instance' key for a specific device (with matching PCI ID's and location in terms of bus/device/function) it says "Ha ha! Here it is, do not bother to recreate the 'Instance' key and all its values for this device, neither the BAR value".

Do you see the problem? When you boot the first time with the USB keyboard connected the BIOS maps the USB host at 0xDA000 which is the address saved in the hive under the 'Instance' key. Some time later you will turn on the system without the keyboard, the BIOS will map the host at 0x80003000 but the USB host device driver will retrieve the wrong 0xDA000 BAR from the registry, thus accessing unused RAM instead of the controller registers.

I cloned the PCIBUS and modified it so that it ignores the 'Instance' key for PCI USB hosts, deletes it and recreates it at every boot based on the 'Template' key. 

 

  

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati