Tuesday, April 6, 2010

Enable RamDisk, and Mass Storage under Windows CE [Updates]

A Ram Disk is a storage disk located in RAM of your device, meaning its content isn't persistent between system boot. The RamDisk usually used for storing temporary content like software updates source binaries.

Reserve Memory space on target :

The Ram disk will be located at a customizable memory address and size on the device, and will be mounted on your root file system as any other file system. In order to reserve the physical memory area, you have to modify the config.bib file of your BSP and add a reserved section for RAM Disk as shown as below. It make sense to map this area on a physical portion of the RAM.

MEMORY


; Name Start Size Type
; ------- -------- -------- ----
BLDR 80000000 00058000 RESERVED
DRVGLOB 80058000 00001000 RESERVED
EMACBUF 80059000 0000E000 RESERVED
NK 80067000 01000000 RAMIMAGE
RAM 81067000 02BA7000 RAM ; 43.65 MB
RAMDISK 83C0E000 00300000 RESERVED ; 3.00 MB


In the example above, I reduced the size of RAM to have enough room for the RAMDISK section of 0x300000 (3MBytes).

Include RamDisk into OSDesign
Add the RamDisk support to your runtime image, by enabling the SYSGEN_RAMDISK variable into the OSDesign property window.

Configure RamDisk
The RamDisk driver is by default mounted by the storage manager and no configuration of the storage driver name allowed. So I prefer to make few registry modifications in my platform.reg to be able to fix the driver DSK name and index.

; HIVE BOOT SECTION

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\RamDisk]
"Dll"="ramdisk.dll"
"Prefix"="DSK"
"FriendlyName"="RAM Disk Driver"
"Order"=dword:0
"Ioctl"=dword:4
"IClass"=multi_sz:"{A4E7EDDA-E575-4252-9D6B-4195D48BB865}"
"Profile"="RAMDisk"
"Size"=dword:300000
"Address"=dword:83C0E000
"SectorSize"=dword:200
"index"=dword:9

[HKEY_LOCAL_MACHINE\System\StorageManager\AutoLoad\RAMDisk]
"DriverPath"="Drivers\\BuiltIn\\RamDisk"
"LoadFlags"=dword:1
"BootPhase"=dword:0

; END HIVE BOOT SECTION

Note that the Address and Size of the RamDisk driver definition match the values defined in the config.bib. The storage driver will then be accessible through DSK9:, and you can then easily configure a USB Function mass storage profile to point on this storage.

Configure USB Function Mass Storage
The USB Function driver loads profiles when device plugged to a host, the profile to be loaded by default is set through the registry.

[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers]

"DefaultClientDriver"=- ; erase previous default
[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers]
"DefaultClientDriver"="Mass_Storage_Class"

[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Mass_Storage_Class]
"DeviceName"=- ; erase previous default
[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Mass_Storage_Class]
"DeviceName"="DSK9:"


Note as the "DeviceName" is set to DSK9: matching the driver index described before for the RamDisk.
Note don't forget to add the USB Function driver of the BSP and set the following variables : SYSGEN_USBFN, SYSGEN_USBFN_STORAGE

To go further :
- RamDisk can be used in association to the ROM Only mechanism to reduce write access to the physical storage.
- RamDisk and USB Function, this to provide a way to drop files on your target using USB mass storage profile.

Special thanks to Juanito for the hints

[Updated on 08-22-2011] : fixed a platform configuration file name.

- Nicolas

2 comments:

Marcelo Ribeiro (marcelo@seva.com.br) said...

Very instersting, where can I take more details? Is there a platform example that make it simple? Thnk you.

Nicolas BESSON said...

I tried to realy simplified the whole process, so you should find in the BSP that you are using the named files to identify the modifications to perform.
There is no platform (publicly released) that implement such behavior, you have to experiment by yourself. But for this you need to have a good understanding of the config.bib and reg files role.
Hope that you will succeed.