[Windows Mobile Software Development] Ameet:
Reduce ULDR Partition Size

“ULDR” stands for “Update Loader”, and is part of the Image Update system. This system allows deployed devices to be updated with new software after they ship. The Update Loader reads a configuration stored in persistent memory and downloads and installs new versions of operating system or OEM files

Also known as part00 in the ROM, is something we all wish to get rid of and use the space as additional storage memory. This tutorial currently aims at reducing the size of this partition by 3.0 MB

Tools you need

NBSplit.exe

NBMerge.exe

Hex editor

Ervius's Payload Reducer

IMPORTANT NOTES

The template OS.nb used is the same OS.nb in which the XIP is inserted at 320000 and of size 320000

For best results use Ervius's Payload Reducer to reduce the size of payload from shipped ROM use nbmerge.exe to cook OS.nb as template for further cooking

This ROM is assumed to be from Diamond and check your device values as per the guide below

The hex offsets of (L)ogical (B)lock (A)ddress and number of sectors and imgfs block address are mentioned in tutorial above or in the post #8 below

Process

Extract OS.nb.payload from the OS.nb (nbsplit.exe –kaiser (check your device) OS.nb)

Run the OS.nb.payload through Ervius's Payload Reducer tool to remove all files from the imgfs and keep only the partition headers

Open this OS.nb.payload in your hex editor. We need to change LBA values of the partitions and number of sectors of ULDR partition since we are reducing the size

In the MBR region (partition Flag 20) LBA of ULDR partition remains same since we are not moving it anywhere. The existing number of sectors of ULDR is 3E 06 from little endian it will be 063E. We are removing 0600 sectors from this partition (0600 * 800 (size of sector, see post #8 for screenshots) = 300000) so, 063E – 0600 = 00 3E. Write it in little endian at hex offset 1CA and 1CB to 3E 00

To physically reduce the partition, remove all data between hex offsets 0x20000 till 0x31FFFF. This will make the XIP start from hex offset 0x20000 till 0x33FFFF and the imgfs partition start at 0x340000

Now since we have reduced the size of ULDR partition, the LBA values of XIP and imgfs partitions will have to be changed in the MBR region

Now change the LBA of XIP. To calculate that, use this method

In Hex calc

Logical Block Address (LBA) = Previous Partition LBA + Previous Partition number of sectors

e.g. (ULDR LBA) 00 00 00 02 + (ULDR no of sectors) 00 00 00 3E = 00 00 00 40

since the coding is in little endian, we have to reverse these values to 40 00 00 00

Go to offset 0x1D6 and change the values to 40 00 00 00 till 1D9

Now change the LBA of imgfs. To calculate that, use this method

In Hex calc

Logical Block Address (LBA) = Previous Partition LBA + Previous Partition number of sectors

e.g. (XIP LBA) 00 00 00 40 + (XIP no of sectors) 00 00 06 40 = 00 00 06 80

since the coding is in little endian, we have to reverse these values to 80 06 00 00

Go to offset 0x1E6 and change the values to 80 06 00 00 till 1E9

We have changed the LBA and number of sectors in MBR, but the OS needs to know the block address of imgfs in MSFLSH50 region

To calculate that, use this method

In Hex calc

MSFLSH50 Block Address = imgfs partition starting address / 20000 (see post #8 for screenshots, shown here is for Diamond)

e.g. (imgfs starting address) 340000 (shown above) / 20000 = 1A

Go to offset 0x81C and change the value to 1A

Save and close the os.nb.payload file in hex editor. Insert the new XIP into this file using this command

“insert.exe -i xip_out.bin -o OS.nb.payload -d 0x00020000 -s 0x00320000” (check your insert start address, shown here is for Diamond) (ignore this if the XIP is already inserted and shifted to this location with this size)

The value (02) seen at hex offset 0x1BF should not be changed or touched since that value tells the OS that first partition starts from the third Sector of the ROM (0x800 (sector size) + 0x800 = hex offset 0x1000) Currently the reduced ULDR partition starts from third sector

Now create the OS.nb from the edited OS.nb.payload to be used as template for cooking using this command

“nbmerge.exe –kaiser (check your device) OS.nb” (without -conservative switch)

NOTE

For best results directly use the OS.nb.payload as template for cooking without merging it into OS.nb. For this you will need to edit the CreateROM.bat

Note the change in red and delete the blue lines from this bat file

copy ROM\OS.nb.payload temp\OS.nb.payload

..\TOOLS\NBSplit -kaiser OS.nb

Rem rename os.nb.extra os-new.nb.extra

!Aman!'s awesome tutorial on removing ULDR partition from devices which don't have the FAT partition (part03) can be refered here: http://xdaforums.com/showthread.php?t=446506