Windows Mobile ROM Customisation - part 1


Introduction

Windows Mobile, formerly Windows CE, is the operating system used by Microsoft Pocket PC and Smartphone PDA devices. It is essentially a scaled-down version of the Windows operating system found on desktop PCs (CE stands for Compact Edition). Therefore many of the applications, functionality and general ‘look and feel’ is very similar to Windows.

In the same way that PCs can be customised to your own preference, Windows Mobile PDAs can be customised, or tailored, to your specific requirements relatively easily.

Like its bigger brother, Windows Mobile employs a Registry to store all user and application-specific variables. This registry can be manipulated very easily to add, remove or edit entries to customise virtually every aspect of the device’s functionality: from simple entries adding an Internet connection, say, down to ‘brute-force’ entries disabling the WiFi and Bluetooth modules on the device entirely.

Perhaps the biggest difference between PCs and PDAs is the way in which memory, or to be more accurate, storage, works.

A PC typically has one or more hard drives on which the base operating system and all applications and user data is held permanently, and also non-permanent memory (RAM) into which the OS, applications and data is loaded while the PC is running.

PDAs handle this differently. All PDAs have permanent and non-permanent memory in the same way that PCs do. However this is divided up into ROM (Read Only Memory) and RAM (Random Access Memory).

The operating system, all applications and any pre-defined settings are all stored in the ROM. Anything you do to your PDA in terms of customisations to the operating system, new applications, new documents, sound files, images, etc is all stored into the RAM.

Essentially, PDAs are never ‘off’. Once you turn them on, any and all changes you make to them are stored in the RAM.

This becomes significant when you consider the ways in which PDAs can be reset. PCs can be ‘reset’ usually with a button on the front of the box, which effectively interrupts the power being fed to the CPU. Once the PC comes back on, all of your apps and documents are still there.

A PDA can be ‘soft’ reset in a similar way by pressing the stylus (or usually a paperclip in my case!) into the reset recess on the unit. All this does is to turn the unit off and on again.

PDAs also have the option of being ‘hard’ reset. This process usually involves a finger-crunching process of holding down several buttons while simultaneously jabbing the stylus (or paperclip) into the reset recess. This process effectively clears the RAM, returning the device to a factory-default, or out of the box state.

Well, having said that, that was certainly the case of older PDAs, which meant that if you forgot to charge your PDA it would undergo a hard reset even without the finger crunching.

Modern PDAs can store data into persistent storage that can preserve data even in the event of a power failure. However they can still be hard reset, meaning that any apps or changes to the operating system are lost, only the documents or original application installer files are kept (if you had the foresight to save them to the persistent storage (or a memory card).

“So what?”, I hear you cry, I knew that already.

When a device is hard reset, the contents of the RAM is cleared.

So, if an IT administrator had gone to great pains to set up a device with the correct settings for remote email, VPN access to the LAN, and installed some vital applications, all the user would need to do to lose all of that hard work would be to either assume the paperclip position or just not plug the thing in for a week.

What if it were possible to have a customised ROM: so that if that ‘user’ did forget to charge it or get the paperclip out, all of those settings would miraculously reappear?

Read on...


General Concepts

Today the term ‘Windows Mobile’ is largely considered to encompass all Microsoft PDAs, which it does, however this is very much an umbrella term: there are significant differences between the two principal branches of the Windows Mobile family: Pocket PC and Smartphone; and there is much confusion about the differences and capabilities of the two platforms.

Pocket PC

When a Pocket PC ‘cold boots’ (i.e. boots for the very first time, or following a hard reset), the following 6 principal memory areas are read from in sequence:

Boot Loader 
Splash and MFG Data 
WinCE ROM Image 
Radio Boot Loader 
Radio Image 
Extended ROM

The Boot Loader is the Pocket PC equivalent of a PC BIOS: it controls what happens when the PDA first powers on.

The other memory areas contain the Microsoft Operating System as well as hardware drivers for the different physical elements of the device. The Extended ROM area is where all of the ‘user-specific’ information is held. For example, a Vodafone-branded HTC P6300 will have a different Extended ROM from an O2-branded HTC P6300, say, despite the fact that they are identical devices from a hardware point of view.

It is the Extended ROM memory area that can be customised. You may have noticed when you power on a PDA for the first time, or following a hard reset, the device will prompt you to run through some configuration steps (calibrate the screen, set the date and time, etc). Once you have completed that step the familiar Windows interface is displayed for a few seconds before a message appears saying that the device is going to configure itself in 3 seconds. It is this stage that is controlled by the contents of the Extended ROM, and it is this step of the boot process that can be customised.

Extended ROM layout

When a Pocket PC device has finished loading the operating system and hardware drivers, it the looks to the Extended ROM. Within the Extended ROM is an autorun file. This is a simple text file, similar to the old ‘autorun.bat’ in DOS systems, that defines the location of registry files and application installers and runs them.

A typical config.txt file might look something like this:

LOCK:Enabled
SHOW:\Windows\Splash.bmp
XML:\Extended_ROM\My_GPRS_Settings.xml
XML:\Extended_ROM\My_MMS_Settings.xml
CAB:\Extended_ROM\MyApp1.cab
CAB:\Extended_ROM\MyApp2.cab
LOCK:Disabled
RST:Reset

The Lock command locks the tap screen so that the user cannot interrupt the boot process.

The Show command displays an image on the screen so that the user cannot see what happens in the background while the rest of the contents of the file is actioned.

The rest of the file is fairly self-explanatory: an XML command will call an XML configuration document, which will contain settings to be incorporated into the device’s registry: in the above example, 2 files are called: one creates a GPRS Internet connection and the other configures the MMS picture messaging settings. There is no reason why both files could not be incorporated into one larger file to simplify things.

The CAB command will call a CAB file, which in the Windows Mobile environment, can either be a simple archive file (like a ZIP file on a PC), or can be an executable if the archive contains an application installer file.

The Lock is then removed to re-enable the touch screen, then the device is soft reset to reboot it.

You can also use EXEC commands to call applications present in the WinCE ROM memory area. For example, the following command:

EXEC:\Windows\cusTSK.exe \Extended_ROM\MyTheme.tsk

Calls the cusTSK application to replace the default theme with a theme entitled ‘MyTheme’. We will look at themes in more detail later.

Once the device has rebooted, it is then ready to use.

The Config file can call as many or as few XML or CAB files as you desire: the only limiting factor is the size of the Extended ROM itself, which at the time of writing is usually 10MB on most Pocket PC devices.

Smartphone

Smartphone devices can also be both ‘soft’ and ‘hard’ reset. However the memory layout of these devices is different:

Boot Loader 
Splash and MFG Data 
WinCE ROM Image 
Radio Boot Loader 
Radio Image

You will notice straight away that there is no Extended ROM. This is deliberate, and simply down to the fact that in such a small form-factor device there is not sufficient room for an additional 10MB of storage.

Smartphone devices can be customised in a similar way to Pocket PC devices, however: the way to do it is to use a memory card (SD, MiniSD, MicroSD, etc). The memory card effectively becomes the Extended ROM.

You then save the necessary XML and CAB files to the memory card in the same way that you would with a Pocket PC. However the location of the files on the memory card needs to be specific.

Firstly, you need to create a folder on the memory card called ‘2577’.

Within this folder needs to be a copy of the ‘AutoRun.exe’ program file, as well as two XML files, ‘AutoConfig.xml’ and ‘Plugin.xml’.

The autorun.exe file is a specific program for the Smartphone operating system, but the XML files can be created yourself simply with any text editor.

When the device powers on and finished loading the operating system and hardware drivers, it will look for a 2577 folder, and if it finds one, it will run the autorun.exe program, which will then do whatever is listed in the AutoConfig file.

The AutoConfig file is used simply to copy files from the memory card to the appropriate location within the internal memory on the device. A typical file might look something like this:

<?xml version="1.0"?>
<!-- ===== Version : 10.707.1.2 ===== -->
<autorun>
<AutoConfig Version="1.15.405.3" Model="HTC_S710"/>
<Platform name="plugin">
<File Source="Cabs\MyApp1.CAB" Destination="\temp\MyApp1.CAB" />
<File Source="Cabs\MyApp2.CAB" Destination="\temp\MyApp2.CAB" />
</Platform>
</autorun>

Note that all paths are relative to the 2577 directory: so if a file has a source of “Cabs\...”, it actually lives in “\2577\Cabs\...”

Once the actions listed in the AutoConfig file have been completed, then the Plugin.xml file is actioned.

This file contains details on registry keys to be added to the device’s Registry. We will look at the format of these registry XML files in a moment.

Once the plugin.xml file has been read and actioned, the device can then be soft reset as required.

It is recommended that the memory card then be removed from the device once the process has completed!


Themes

Editing the Registry using XML

XML is the eXtensible Markup Language. There are many types of markup languages: HTML, for example, is the HyperText Markup Language and is the language used to write the structure of web pages. XML is similar, but it allows users to create their own tags (hence it is extensible) for their own purposes.

Using XML, registry keys can be added, removed or modified.

The [characteristic] tag will create (or overwrite) a registry key. The [nocharacteristic] tag will remove a registry key. For example:

<wap-provisioningdoc>
      <characteristic type="Registry">
            <characteristic type="Registry\HKLM\Software\Operator\MyApplication">
                  <parm name="MySetting" value="1" datatype="boolean">
            </characteristic>
      </characteristic>
</wap-provisioningdoc>

The above script will create a new folder under HKLM\Software\Operator called MyApplication, and within that folder create a key called MySetting with a value of 1. This is a very basic example, but virtually every aspect of a Windows Mobile device’s functionality can be configured via the Registry.

Let’s look at some specifics.


Themes (Pocket PC Only)

A theme file defines the colour scheme used by the device as well as the images for backgrounds.

A theme file has ‘.tsk’ extension, but it is actually just a CAB file that has been renamed. It contains an INF file with the necessary XML registry keys defining the colours to be used as well as the image files themselves and their locations.

Colours are defined in hexadecimal RRGGBB format (in the same way that HTML defines colours).

For devices that can be operated in both portrait and landscape mode, 2 versions of each image will be required, in the correct resolution. Separate images are also required for the general background, but also for the background of the Start menu, which when it slides down comes down in front of the Today screen and therefore also needs a background image.

The settings for colour values are defined in the Registry in the folder HKLM\Software\Microsoft\Color (note – American spelling)

For example, the Vodafone theme is defined with the following INF XML file (vodafone.inf):

[Version]
Signature = "$Chicago$"
CESignature = "$Windows CE$"
Provider = "Windows"
 
[CEDevice]
ProcessorType = 2577
UnsupportedPlatforms= "HPC","Jupiter"
VersionMin = 3.0
VersionMax = 100.0
 
[SourceDisksNames]
1 = ,"Other",,\
 
[SourceDisksFiles]
tdywater_240_320.jpg = 1
tdywater_320_240.jpg = 1
stwater_240_320.jpg = 1
stwater_320_240.jpg = 1
 
[DefaultInstall]
CopyFiles = Files.Common.Windows
AddReg=Registry.Common
 
[Files.Common.Windows]
tdywater_320_240.jpg,,,0x40000000
tdywater_240_320.jpg,,,0x40000000
stwater_240_320.jpg,,,0x40000000
stwater_320_240.jpg,,,0x40000000
 
[DestinationDirs]
Files.Common.Windows = 0,%CE2%;\Windows
DefaultDestDir = 0, InstallDir%
 
[Strings]
reg_path = Software\Microsoft\Color
reg_oem = Software\Microsoft\Today\Vodafone.tsk
 
[Registry.Common]
HKCU, Software\Microsoft\Today, DPI, 0x00010001, 192
;Here's the format (in hex): ,rr,gg,bb,00 ; Description
 
HKLM,%reg_path%,4,0x00000001,ff,ff,ff,00 ; COLOR_TODAYTEXT Today Screen Text Color
HKLM, reg_path%,5,0x00000001,ff,00,00,00 ; COLOR_STARTICONBACKGROUND
HKLM, reg_path%,6,0x00000001,aa,aa,aa,00 ; COLOR_TODAYSEPERATOR
HKLM, reg_path%,9,0x00000001,ff,ff,ff,00 ; COLOR_NAVBARTEXT
HKLM, reg_path%,11,0x00000001,aa,aa,aa,00 ; COLOR_NOTIFTRAY
HKLM,%reg_path%,12,0x00000001,c8,cc,c8,00 ; COLOR_NOTIFTRAYHILITE
HKLM,%reg_path%,13,0x00000001,ff,00,00,00 ; COLOR_BUBBLECAPTION
HKLM,%reg_path%,14,0x00000001,ff,00,00,00 ; COLOR_GRADIENTBUBBLECAPTION
HKLM,%reg_path%,15,0x00000001,ff,ff,ff,00 ; COLOR_INTGRADLEFT
HKLM,%reg_path%,16,0x00000001,ff,ff,ff,00 ; COLOR_INTGRADRIGHT
HKLM,%reg_path%,25,0x00000001,ff,00,00,00 ; COLOR_CRITGRADLEFT
HKLM,%reg_path%,26,0x00000001,ff,00,00,00 ; COLOR_CRITGRADRIGHT
HKLM,%reg_path%,27,0x00000001,ff,ff,ff,00 ; COLOR_BUBBLETITLE ff ff ff white text
HKLM,%reg_path%,28,0x00000001,ff,ff,ff,00 ; COLOR_CRITBUBBLETITLE ff ff ff white text
HKLM,%reg_path%,34,0x00000001,aa,aa,aa,00 ; COLOR_HOMEHIGHLIGHT grey bar
HKLM,%reg_path%,35,0x00000001,ff,ff,ff,00 ; COLOR_HOMEHIGHTLIGHTTEXT - white text
HKLM,%reg_path%,36,0x00000001,ff,ff,ff,00 ; COLOR_GRADLEFT
HKLM,%reg_path%,37,0x00000001,ff,ff,ff,00 ; COLOR_GRADRIGHT
HKLM,%reg_path%,38,0x00000001,99,99,99,00 ; COLOR_STARTMENU
HKLM,%reg_path%,39,0x00000001,ff,ff,ff,00 ; COLOR_STARTMENUTEXT - text color when pressing start
HKLM,%reg_path%,40,0x00000001,ff,00,00,00 ; COLOR_TAPANDHOLD - ring of fire tap and hold
 
;
HKCU,%reg_oem%,UseDefaultTitleColor,0x00010001,1 ; default title color - Not documented

 
HKCU,%reg_oem%,Color_Highlight,0x00000001,50,50,50,00 ; OEM Override - highlight bar
HKCU,%reg_oem%,Color_HighlightText,0x00000001,ff,ff,ff,00 ; OEM Override - White text
HKCU,%reg_oem%,Color_BtnFace,0x00000001,aa,aa,aa,00 ; OEM Override e.g. background of folder name in file explorer e.g my docs, scroll bar
HKCU,%reg_oem%,Color_BtnText,0x00000001,00,00,00,00 ; OEM Override - black text on buttons like in settings
HKCU,%reg_oem%,Color_SoftkeyBtnFace,0x00000001,6f,6f,6f,00 ; OEM Override -
HKCU,%reg_oem%,Color_MenuText,0x00000001,00,00,00,00 ; OEM Override - black text
 
;HKCU,%reg_oem%,Color_SoftkeyFlat,0x00000001,6f,,6f,6f,00 ; OEM Override - sf
 
;HKCU,%reg_oem%,Color_SoftkeyFlatCenter,0x00000001,ff,00,00,00 ; OEM Override
 

HKCU,%reg_oem%,Color_CaptionFlat,0x00000001,ff,00,00,00 ; OEM Override - drawn flat instead of with gradient
HKCU,%reg_oem%,Color_TitleFlat,0x00000001,ff,00,00,00 ; OEM Override
HKCU,%reg_oem%,Color_TitleFlatCenter,0x00000001,ff,00,00,00 ; OEM Override
HKCU,%reg_oem%,Color_TitleFlatDoneBtn,0x00000001,aa,aa,aa,00 ; OEM Override - done button top right
HKCU,%reg_oem%,Color_TitleFlatDoneBtn_Highlight,0x00000001,6f,6f,6f,00 ; OEM Override = done button when tapped
HKCU,%reg_oem%,Color_CommandBar,0x00000001,6f,6f,6f,00 ; OEM override - Command Bar at the bottom of PPC Today page
HKCU,%reg_oem%,Color_CommandBarText,0x00000001,ff,ff,ff,00 ; OEM Override
HKCU,%reg_oem%,Color_CommandBarSip_Highlight,0x00000001,6f,6f,6f,00 ; OEM Override
 
;
HKCU,%reg_oem%,Color_CommandBarText_Highlight,0x00000001,00,ff,00,00 ; OEM Override

 
 
[CEStrings]
AppName=Theme
InstallDir=%CE2%




You can also include XML tags to enable or disable Today screen plugins within the theme file by using the following XML:

[HKEY_LOCAL_MACHINE\Software\Microsoft\Today\Items\Plugin Name] 
"Enabled"=dword:1

The TSK file itself would contain the following files:

stwater_240_320.jpg
tdywater_240_320.jpg
stwater_320_240.jpg
tdywater_320_240.jpg
vodafone.inf

You will notice the different resolution versions of each image: one for the Today Screen background (TD) and one for the Start Menu background (ST).

The files are compressed into a single CAB file, then that CAB file is renamed to have a TSK extension. The Windows Mobile operating system knows then that the file is a theme file and should be treated like one.

We will look at how CAB files are made in a moment.


Themes (Smartphone Only)

Smartphone devices do not use a TSK file to define themes. Instead a single XML file is used to configure the necessary registry entries and define the image filenames and locations, and the image files must be saved to the correct location in a separate process (by, say, the plugin.xml document).

This file, as with Pocket PC, defines the colour scheme of the device as a whole and the behaviour of the Home Screen (note – on a Smartphone device you talk about the Home Screen rather than the Today Screen as you do on a Pocket PC device), including any plugin behaviour. The file needs to be named in the form ‘filename.home.xml’ and needs to be saved in the ‘\Application Data\Home’ directory.

An example might look like this:

<?xml version="1.0"?>
<home>
<author>HTC</author>
<contacturl></contacturl>
<title>HTC Home screen 1.11</title>
<version>1.11</version>
<default target width="240" target-height="320" font-face="Segoe Condensed" font-size="17" font-weight="bold" padding-left="5" padding-right="5" bgcolor="transparent" fgcolor="COLOR_HOMETEXT" padding-top="3" b-border-color="COLOR_HOMERULE" b-border-width="0" highlight="COLOR_HOMEHIGHLIGHT">
<format state="unselected" fgcolor="#000000" font-weight="bold" />
<format state="selected" fgcolor="#FFFFFF" font-weight="bold" />
</default>
<background bgimage="\Application Data\Home\HTC_WallpaperImg_320x240.bmp" valign="bottom" bgcolor="COLOR_TRAYGRADLEFT" />
<scheme>
<color name="COLOR_WINDOW" value="#FFFFFF" />
<color name="COLOR_WINDOWTEXT" value="#000000" />
<color name="COLOR_HIGHLIGHT" value="#8cc850" />
<color name="COLOR_HIGHLIGHTTEXT" value="#ffffff" />
<color name="COLOR_TRAYGRADLEFT" value="#82af55" />
<color name="COLOR_TRAYGRADRIGHT" value="#a0d264" />
<color name="COLOR_TRAYTEXT" value="#FFFFFF" />
<color name="COLOR_BTNFACE" value="#c0c0c0" />
<color name="COLOR_BTNTEXT" value="#000000" />
<color name="COLOR_SCROLLBAR" value="#8cc850" />
<color name="COLOR_HOMEHIGHLIGHT" value="#467D0A" />
<color name="COLOR_HOMETEXT" value="#000000" />
</scheme>
</home>
 



It is possible to define the colour scheme of the Home Screen and the rest of the operating system separately. Another file, named filename.scheme.xml can be saved in the same location. An example might look this this:

<scheme>
            <color name="COLOR_HIGHLIGHT" value="#666666" />
            <color name="COLOR_MENU" value="#FFFFFF" />
            <color name="COLOR_MENUTEXT" value="#000000" />
            <color name="COLOR_GRAYTEXT" value="#999999" />
      </scheme>




If you wanted to define plugin behaviour as well as colour and image information, an example might look like this:

<?xml
version="1.0"?>

<home>
<author>HTC</author>
<contacturl></contacturl>
<title>HTC Home screen 1.11</title>
<version>1.11</version>
<default target-width="240" target-height="320" font-face="Segoe Condensed" font-size="17" font-weight="bold" padding-left="5" padding-right="5" bgcolor="transparent" fgcolor="COLOR_HOMETEXT" padding-top="3"
b-border-color="COLOR_HOMERULE" b-border-width="0" highlight="COLOR_HOMEHIGHLIGHT">


<format state="unselected" fgcolor="#000000" font-weight="bold" />

<format state="selected" fgcolor="#FFFFFF" font-weight="bold" />
</default>

<background bgimage="\Application
Data\Home\HTC_WallpaperImg_320x240.bmp" valign="bottom" bgcolor="COLOR_TRAYGRADLEFT" />

<scheme>
<color name="COLOR_WINDOW" value="#FFFFFF" />
<color name="COLOR_WINDOWTEXT" value="#000000" />
<color name="COLOR_HIGHLIGHT" value="#8cc850" />
<color name="COLOR_HIGHLIGHTTEXT" value="#ffffff" />
<color name="COLOR_TRAYGRADLEFT" value="#82af55" />
<color name="COLOR_TRAYGRADRIGHT" value="#a0d264" />
<color name="COLOR_TRAYTEXT" value="#FFFFFF" />
<color name="COLOR_BTNFACE" value="#c0c0c0" />
<color name="COLOR_BTNTEXT" value="#000000" />
<color name="COLOR_SCROLLBAR" value="#8cc850" />
<color name="COLOR_HOMEHIGHLIGHT" value="#467D0A" />
<color name="COLOR_HOMETEXT" value="#000000" />
</scheme>

<!-- Date/Time/Carrier Plugin -->
<plugin clsid="{E09043DF-510E-4841-B652-388316977A7A}" name="carrier" height="44">
<allowselection/>
<label bgcolor="transparent" halign="left" font-weight="bold" y="1" x="10" w="200"
font-size="20">

<text><carrier/></text>
</label>
<label bgcolor="transparent" halign="left" font-weight="bold" y="23" x="10" textwidth="163">
<text><wifi/></text>
</label>
<clock>
<time font-weight="bold" font-size="20" valign="top" halign="right" y="0" x="0"
w="320" />

<date font-weight="bold" valign="top" halign="right" mode="short" y="25"
x="0" w="320" />

</clock>
</plugin>
<!-- Calendar-Plugin -->
<plugin clsid="{865A354A-4A96-4687-B001-C155DC0DBE76}" name="Calendar" height="45">
<label halign="left" h="20" x="10" y="27" w="245" padding-right="0" >
<text><time/> <location/></text>
</label>
<label halign="left" h="20" x="10" y="7" w="245" padding-right="0" >
<text><subject/></text>
</label>
</plugin>
</home>

So now you know how to create your own Windows Mobile Themes.

In my next post I will look at how to create CAB files, and how to customise some more interesting aspects of your device’s functionality.