Snapshot Boot Sample Code (Compact 2013)
3/26/2014
Sample code for taking a snapshot and restoring from a snapshot is available under the common platform directory. The common code does not include BSP specific changes that you will need to make.
Take a Snapshot
%_WINCEROOT%\platform\common\src\common\snapshot\ssbmode\main.c
One approach to taking a snapshot is to start an application after the OS boots, to wait until the system is in the state that you want to save as your snapshot, and then to issue the call to take the snapshot.
The sample code in main.c illustrates this approach. This code compiles into an application named SSBMode.exe that can be registered to start when your device boots. For instance, given the OS registry keys that are shown in the following example, SSBmode.exe is given a launch priority of Launch888 so that it will run after everything else has launched on boot, and a Depend888 key to indicate that it should not launch until device.dll (x0014), gwes.dll (x1e00), and services.exe (x003c) have loaded. The values that identify these services are in public\common\oak\files\common.reg.
[HKEY_LOCAL_MACHINE\init]
"Launch888"="ssbmode.exe"
"Depend888"=hex:14,00,1e,00,3c,00 ; depends on device, gwes, services
After SSBMode.exe launches, it delays for the duration specified in a registry key. This delay provides the opportunity to start any applications that you want to include in the snapshot. After the specified delay, Ssbmode.exe calls IOCTL_KLIB_MAKESNAP to take the snapshot.
Restore a Snapshot
%_WINCEROOT%\platform\common\src\common\boot\blcommon\snapboot.c
The sample code in this file demonstrates how to restore a snapshot image to memory. SnapRestore illustrates how to validate the snapshot header, verify that the MMU is enabled, validate the page table, and then either restore an uncompressed snapshot directly to memory, or decompress a compressed snapshot image to memory. SnapRestore() is written for an ARM processor.
To use this code, you will have to modify your boot loader so that can detect when there is a snapshot to boot from, and then call SnapRestore() with a reader function of type PFN_SnapReadAtOffset (defined in snapboot.h) that can read your snapshot image from your persistent storage.
Utility Code
- %_WINCEROOT%\platform\common\src\common\snapshot\RLE2\rle.c
This sample code provides run-length encoding routines for compressing and decompressing memory that you may use to compress and decompress a snapshot.
- %_WINCEROOT%\platform\common\src\common\boot\blcommon\mapsnap.c
If you are working with an ARM CPU, see MDMapSnapPages() which takes the page tables restored from the snapshot and sets up the page tables on the rebooted device.
%_WINCEROOT%\public\COMMON\oak\inc\snapboot.h
This file contains SnapChkSum which is a sample checksum function that is used to validate the integrity of the snapshot.It also contains GetSnapshotState which returns the stage of the taking a snapshot process.