your Windows® embedded community
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.$(_TARGETPLATROOT)\drivers directory. $(_TARGETPLATROOT) is C:\WINCE400\PLATFORM\econtest1 in my setup. $(_TARGETPLATROOT)\kernel\hal\OEMIOCTL.c: #include
pkfuncs.h>extern PSMHAL_IOCtl(DWORD, LPVOID, LPVOID);
#define IOCTL_PSM_FLASH_CMD CTL_CODE(FILE_DEVICE_HAL,4066, METHOD_BUFFERED,FILE_ANY_ACCESS)OEMIoControl( ) function switch statement:case IOCTL_PSM_FLASH_CMD:
retval = PSMHAL_IOCtl(nInBufSize, lpInBuf, lpOutBuf);
break; $(_TARGETPLATROOT)\kernel\hal\sources SOURCELIBS=$(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET\BIN\PSMHal.lib \
$(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET\BIN\Registry.lib
- 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. /* 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 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. $(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET.buildpsm.bat from there. psmfsd.dll in the $(_TARGETPLATROOT)\drivers\PSM\SA11X0\WCE.NET\bin directory.; HIVE BOOT SECTION
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\PSMFSD]
Name="IPSM"
Folder="e-conSystems"
; END HIVE BOOT SECTION
; HIVE BOOT SECTION
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\FlshDrv]
"FolderName" = "MYIPSM" ; Folder name of your choice
[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 )
; HIVE BOOT SECTION
[HKEY_LOCAL_MACHINE\init\BootVars]
"SYSTEMHIVE"="system.hv"
"PROFILEDIR"="Profiles"
"Start DevMgr"=dword:1
"DefaultUser"="e-conSystems"
; END HIVE BOOT SECTION
- Include . . .
"Flags"=dword:1000
. . . in the driver keys that get loaded in the boot hive section. 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.NK.bin you should be able to get the PSM file storage and the registry backup working fine.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. plat_api.c and in the HAL files, the PSM file storage will start working. The registry backup is a tricky part.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.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. boot.hv needs to be mentioned between ;HIVE BOOT SECTION
....
...
...
;END HIVE BOOT SECTIONcommon.reg, platform.reg or project.reg.boot.hv, and which become part of system.hv."Flags"=dword:1000"SYSTEMHIVE"="system.hv"
"Start DevMgr"=dword:1system.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:2boot.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. 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. "MountFlags"=dword:6
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.