Click here to learn
about this Sponsor:
Home  |  News  |  Articles  |  Forum

  Home arrow Windows For Devices Articles arrow Integrating the Intel Persistent Storage Manager with Windows CE 4.x

Integrating the Intel Persistent Storage Manager with Windows CE 4.x
By Harishankkar

Rate This Article: Add This Article To:

IntroductionThe Intel Persistent Storage Manager (IPSM) is the Windows CE file system driver for Intel flash memory. Intel provides the IPSM driver (through its local representatives) in the form of library files, but the source code is not readily available. Nevertheless, an IPSM implementation is possible based on the provided libraries.

Fortunately, Intel does provide the source to plat_api.c, the one file Intel recommends for modification. In order to implement IPSM, it is also necessary to modify several registry keys and a few OEM files.

This article explains how to integrate PSM for use on an Intel XScale SA-1110 processor-based board equipped with Intel StrataFlash flash memory. The process of integrating IPSM -- and making it work -- was somewhat challenging, due to the fact that the required information was not available in a single location. Instead, it was necessary to search through numerous sources for the relevant details. Thus, the main objective of this article is to make it easier for others to implement IPSM on their platforms.

The article is presented in two parts: the steps required to integrate IPSM from scratch; and, discussion of several key issues that related to the process.


Part I -- Integrating IPSM


The steps required to integrate IPSM are:

A. Setting up the PSM directory
  1. Get the IPSM from Intel. It unzips into a folder called PSM.
  2. Copy the PSM folder to the $(_TARGETPLATROOT)\drivers directory. $(_TARGETPLATROOT) is C:\WINCE400\PLATFORM\econtest1 in my setup.
B. Changing the HAL code
  1. Make the following changes in $(_TARGETPLATROOT)\kernel\hal\OEMIOCTL.c:
    • Add this line,if not present: #include pkfuncs.h>
    • Add these at the top of initialization:
      extern PSMHAL_IOCtl(DWORD, LPVOID, LPVOID);
      #define IOCTL_PSM_FLASH_CMD CTL_CODE(FILE_DEVICE_HAL,4066, METHOD_BUFFERED,FILE_ANY_ACCESS)

    • Add this to the OEMIoControl( ) function switch statement:
      case IOCTL_PSM_FLASH_CMD:
      retval = PSMHAL_IOCtl(nInBufSize, lpInBuf, lpOutBuf);
      break;
  2. Make the following changes in $(_TARGETPLATROOT)\kernel\hal\sources
      SOURCELIBS=$(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET\BIN\PSMHal.lib \
      $(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET\BIN\Registry.lib
  3. Look into $(_TARGETPLATROOT)\Inc\SA11X0BD.INC or \Platform\myPlatform\Kernel\Hal\ARM\MAP1100.H and check whether the memory is mapped and to what address it is mapped.
C. Making the PSM FileSystem Settings
  1. Change the PSM_OEMInfo structure in the PLAT_API.c to suit your platform. The contents and an example is given below.
      /* PhysicalReadStartAddress */ (VOID_PTR)0x08000000,
      /* PhysicalWriteStartAddress */ (VOID_PTR)0x08000000,
      /* PhysicalBurstReadStartAddress */ (VOID_PTR)0x08000000,
      /* VirtualReadStartAddress */ (VOID_PTR)0xa1000000,
      /* VirtualWriteStartAddress */ (VOID_PTR)0xa1000000,
      /* VirtualBurstReadStartAddress */ (VOID_PTR)0xa1000000,
      /* MaximumArrayLength */ 0x01000000,
      /* MaximumRegistrySize */ 0x00000000,
      /* ManagedAreaStart */ 0x00000000,
      /* ManagedAreaLength */ 0x01000000,
      /* ReadBusWidth */ 16,
      /* WriteBusWidth */ 16,
      /* BurstReadBusWidth */ 16

    The Readstartaddress, WriteStartAddress and BurstReadStartAddress (both physical and virtual) are the start addresses of the flash array.
    MaximumArrayLength is the maximum length of the flash array and MaximumRegistrySize is the size of the registry backup to be used. ManagedAreaStart is the start of the PSM area and ManagedAreaLength is the length of the PSM file storage and registry storage put together. The Bus width entries are the width of the bus connected to the flash.
D. Building the Driver
  1. Start the Platform Builder Environment.
  2. In the platform created make sure you have selected the hive-based REGISTRY.
  3. Open the build release directory (from the build menu).
  4. Change directory to $(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET.
  5. Run buildpsm.bat from there.
You will end up with psmfsd.dll in the $(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET\bin directory.

E. Making the registry settings (the tricky part . . .)

The registry key changes for Windows CE 4.0 and 4.2 have minor differences, as shown below.
  1. ; HIVE BOOT SECTION
    [HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\PSMFSD]
    Name="IPSM"
    Folder="e-conSystems"
    ; END HIVE BOOT SECTION

  2. ; HIVE BOOT SECTION
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\FlshDrv]
    "FolderName" = "MYIPSM" ; Folder name of your choice

  3. [HKEY_LOCAL_MACHINE\System\StorageManager\AutoLoad\psmfsd]
    "Dll"="psmfsd.dll"
    "Paging"=dword:1
    "MountFlags"=dword:2

    "Loadflags"=dword:1 ; REQUIRED ONLY FOR WINCE 4.2 (only difference )

  4. ; HIVE BOOT SECTION
    [HKEY_LOCAL_MACHINE\init\BootVars]
    "SYSTEMHIVE"="system.hv"
    "PROFILEDIR"="Profiles"
    "Start DevMgr"=dword:1
    "DefaultUser"="e-conSystems"
    ; END HIVE BOOT SECTION


  5. Include . . .

      "Flags"ť=dword:1000

    . . . in the driver keys that get loaded in the boot hive section.

F. Final build

After the above modifications, you will need to do a clean rebuild. You need to verify whether psmfsd.dll and flshdrv.dll are present in the image. Otherwise, you may have to copy them from some subdirectory of $(_TARGETPLATROOT)\drivers\PSM to the release directory, and make it part of the image.

With this NK.bin you should be able to get the PSM file storage and the registry backup working fine.


Part II -- Discussion of key issues


What exactly IPSM does, and how the filesystem works, is hidden within Intel's Intellectual Property. But, from the information available and the changes made, we can trace an outline of the IPSM.

Intel's psm driver contains a file manager that comes in the form of two libraries. Specifically, psmfsd.lib and psmhal.lib. psmfsd.lib get linked along with plat_api.c to create psmfsd.dll; and psmhal.lib gets linked with plat_api.c, which become part of the Hardware Adaptation layer / Board Support Package code.

Once the correct settings are made in plat_api.c and in the HAL files, the PSM file storage will start working. The registry backup is a tricky part.

In the RAM-based registry, the registry is in RAM and vanishes as soon as the power is switched off. To provide persistent storage to a RAM-based registry we need to allocate registry backup space in the Plat_Oem structure. Also, we (OEMs) have to implement the WriteRegistryToOEM() and ReadRegistryFromOEM() functions. These functions do a low-level write of the registry to the flash and read it back the same way. WriteRegistryToOEM() is called whenever RegFlushKey() is called to store the registry on the flash. While booting, a call to ReadRegistryFromOEM() is made and if it is successful the registry is loaded from the flash. That's the backup procedure in the RAM-based registry.

In a hive-based registry, there are two files named boot.hv and system.hv (the names can be changed using registry settings). When using the hive-based registry, we have two boot phases: the first boot phase makes use of boot.hv to bring up the most important components; during the second phase, system.hv is taken from the filesystem and used to complete the boot process. To reach the filesystem and get to system.hv, it is required that the PSM driver be loaded. But, the PSM driver is loaded based on the registry, only. So, the keys that load PSM have to be in the boot hive section (boot.hv). There are a few other keys that need to be loaded before system.hv is loaded. These are also part of boot.hv.

Whatever has to go into boot.hv needs to be mentioned between
    ;HIVE BOOT SECTION
    ....
    ...
    ...
    ;END HIVE BOOT SECTION

either in common.reg, platform.reg or project.reg.

Care should be taken to decide which keys become part of boot.hv, and which become part of system.hv.

"Flags"=dword:1000

This setting in the registry flag tells the Device Manager to load the driver in the first boot phase with the boot registry, and not to load it a second time in the second boot phase with the system registry. It prevents the driver from being started twice.

"SYSTEMHIVE"="system.hv"
"Start DevMgr"=dword:1


These keys tell the booting OS to start the device manager in order to reach system.hv (the system hive registry file). The device manager has to be started at this stage because, to get the system.hv file from the filesystem, the necessary drivers need to be loaded -- and only the device manager can do this.

"MountFlags"=dword:2

This says that the filesystem may contain a registry.

The boot process

The booting consists of two phases. Initially, the system boots with boot.hv. In this phase, after Nk.exe, coredll.dll, filesys.exe, fsdmgr.dll, etc. load, the psm driver psmfsd.dll and regenum.dll are loaded. Once this is done, the filesystem becomes accessible and system.hv is taken from the flash.

What happens when booting for the first time?

This interesting situation is handled differently. First, the flash is examined for proper format. Because a fresh flash is not PSM-formatted, PLAT_FormatRecovery() is called, a decision on the format and format options is made, and formatting is done. This formatting may take some time, which is the reason why the boot process might appear to have halted when PSM is enabled for the first time. Since there is no system.hv in the filesystem at this point, the default system.hv is taken from the NK.bin image and stored in the flash.

PSM as the root filesystem

To make IPSM become the root filesystem, the ROM-only filesystem has to be enabled in place of the RAM/ROM filesystem. Also, the mountflags should be . . .

"MountFlags"=dword:6

. . . which means the mounted filesystem may contain root and also the system hive. The remainder of the settings are similar.

In this case, we have the windows directory in ROM, and the rest in the IPSM. But, unfortunately, the program files folder seems to vanish. Well, there is a way to handle this situation -- and that will be the subject of a subsequent article.

To be continued . . .


About the Author


Maharajan Veerabag is a Technical Lead at e-con Systems in Chennai, India. His software specialities include device drivers and OS internals, and he has hands-on experience in both Windows CE and Windows XP Embedded and in porting embedded OSes. He holds a Bachelor of Engineering, and his hobbies include music, puzzles, and debugging.





Discuss Integrating the Intel Persistent Storage Manager with Windows CE 4.x
 
Hi, I have a Handheld Motorola HC700 with windows CE but this cant load the OS, hang...
>>> Post your comment now!
 
 
 
>>> More Windows For Devices Articles Articles          >>> More By Harishankkar
 



Windows XP for Embedded Applications
This white paper describes the benefits of using Windows XP when developing embedded applications.

A Manager's Guide to Selecting a Mobile Device Operating System
This white paper offers a comparative review of Microsoft Windows CE and Windows Mobile.

Visual Basic 6.0 to .NET Migration
This paper focuses on the methodology and techniques which Infosys (Microsoft Technology Center) has developed for migrating VB 6.0 Applications to .NET. Our approach ensures a smooth, cost effective, and efficient migration.

Mobile Device Security: Securing the Handheld, Securing the Enterprise
This whitepaper identifies security threats to corporate data on mobile devices and details how mobile devices can become a "backdoor" to the enterprise.

Mobile Device Security: The Eight Areas of Risk
It's common knowledge that adding mobile devices to your network increases security risks. There are multiple facets to mobile security, all of which should be paid close attention to. This E-Guide presents a more in depth look into the eight key areas of securing wireless devices.

Quality Assurance and .NET
This paper discusses best practices for functional, regression and load testing of .NET applications.

SCADA Security in Integrated Networks
As businesses leverage their SCADA systems by integrating them into the business networks, they must also assure the security of the SCADA system.

The Advantages of Small Form Factor HMI
HMIs have mutated and changed with new requirements, and they have become more flexible and capable. And while they've been doing that, they've become smaller and more useful.

9 Critical Requirements for Web Application Security
Learn why your Web applications expose dangerous security breaches and what’s required to effectively protect your Web applications and the sensitive information behind them.

Got a HOT tip?   please tell us!
Free weekly newsletter
Enter your email...
Click here for a profile of each sponsor:
PLATINUM SPONSORS
(Become a sponsor)

ADVERTISEMENT
(Advertise here)

Updated! The latest Windows-powered...

mobile phones!

other cool
gadgets

HOT TOPICS
Microsoft targets PNDs with new embedded OS
Microsoft tips .NET MF 3.0 highlights
Microsoft previews Windows Embedded Standard
Microsoft offers free Windows CE 6.0 textbook
Microsoft renames embedded operating systems
Microsoft unveils Windows Mobile 6.1
New Atom models target low-cost PCs
REFERENCE GUIDES
Windows Device Showcase
Intro to Windows Embedded
Intro to Shared Source
Real-time Windows Embedded
Windows Embedded books
Join our Windows Embedded discussion forums:
Windows XP Embedded
Windows CE
Windows Mobile


Windows Embedded developer newsgroups
Windows CE
XP Embedded
PocketPC
Smartphone

Microsoft's Windows Embedded resources
Embedded dev center
Mobile dev center
Windows CE tutorials
XP Embedded tutorials
Windows Embedded seminars
Windows Embedded application categories
3rd-party partners


BREAKING NEWS

• Pico-ITX PC takes to the road and the skies
• Thin client offers legacy ports
• Boards add watchdog functionality to PC/104-Plus systems
• 11.6-inch netbook has AMD processor
• Microsoft planning riposte to Google's "Chrome OS"?
• Embedded student competition winner is buggy (on purpose)
• Asus preps convertible netbooks
• Media-savvy reference design sports touchscreen, DVB-H
• Sony joins the netbook fray
• 2010 Census kicks off with Windows Mobile
• Sprint offers 99-cent netbook
• SODIMM module has industrial focus
• Microsoft picks finalists in Embedded Development competition
• Cortex-A8 SBCs target signage and kiosks
• Student competition offers a different kind of fireworks


MOST POPULAR (last 90 days)
• "Netbook" uses Intel's Atom N270
• Windows CE takes on Linux in low-end netbooks
• HTC ups Touch resolution
• Microsoft unleashes new embedded OS
• Windows Mobile phone gets 800 x 480 display
• HTC spins WiMAX phone?
• Smart camera sports Atom
• Dual-core AMD netbook gets rave review
• Windows Mobile 7 "delayed"
• GPS phone uses new Marvell "Tavor" chip
MOST POPULAR (Classics from the vault)
Windows XP Embedded USB boot
Troubleshooting Windows XPe's blue screen "Stop 0x0000007B" error
Asus reveals $190 mini notebook
Windows Mobile 6 SDKs available for download
Windows Mobile VPN client plays with Cisco
HTC adds GPS to Windows Mobile Touch line
Microsoft unveils Windows Mobile 6.1
Guide to HTC's Windows Mobile smartphone platforms
• HTC releases Touch Diamond ROM upgrade
Customizing Windows XP Embedded thin clients

Also visit our sister sites:

Sign up for WindowsForDevices.com's...


Or, follow us on Twitter...