WEC-2013-Logo

On continuation of Windows Embedded Compact 2013 porting blog series, I would like to share about the change in STARTUPTEXT macro and its effect on WinCE2013. Before that we have to understand the purpose of this macro.

STARTUPTEXT is used in assembly file (.s) before the first assembly routine to indicate the linker in order to place the code very first location in the CODE section.

startup

Figure 1) sample startup.s file

This is mapped to .astart segment as shown below in earlier versions of Windows CE. You can find the below macro definition in \<_WINCEROOT>\PUBLIC\COMMON\SDK\INC\kxarm.h

startuptext

Figure 2) STARTUPTEXT Macro in earlier version of Windows CE.

You can see the below map file of the sample executable where the StartUp routine is placed very first in the code section.

MAP-WEC7
map file WEC7

Figure 3) .MAP file for an executable in WEC7

Now come back to WinCE2013. Here this macro is mapped to TEXTAREA which is .text segment as shown below.

startuptext-wec2013

Figure 4) STARTUPTEXT macro in WinCE2013

Because of this change, the StartUp code is linked in .text segment, which is the 3rd segment of code section as shown below.

map-wec2013-1

map-wec2013-2

Figure 5) .Map file for an executable in WinCE2013

Even changing the STARTUPTEXT Macro to .astart segment won’t work out here, since the linker is ignoring the .astart segment when we simply replace the .text to .astart. Due to this reason, you can’t expect the entry point of the executable at 0th location. Which means in an .nb0 file, you can’t expect the entry point routine (StartUp) immediately after the 4KB jump page introduced by ROMIMAGE tool. This is vary based on the location where the .text segment is started in the executable. In our example, it is 0x000040e0 (0x1000 + 0x000030e0) as shown below.startup_lst

Figure 6) Startup.lst file

nbo_file

Figure 7).nb0 file

As I already mentioned in the previous article, ROMIMAGE tool generate jump instruction((BLX BaseAddress+000040e1) at the beginning of the 4K page (jump page) for .nb0 and generate the start address (BaseAddress+000040e1) for nk.bin.

Considerations

There are some size constrained binaries specifically pre bootloaders such as XLDR/IPL are loaded by processor boot ROM from NAND/SD card to a small size SRAM and this will load the Eboot to DDR and jump to Eboot. Mostly this is an .nb0 file since the processor boot ROM doesn’t have intelligence to read the .bin format. Due to the size constraints for the XLDR, the jump page is removed to reduce the binary size in few processor BSPs. This works in earlier versions of Windows CE since the StartUp entry point is always start after the jump page when STARTUPTEXT is used. But for Windows Embedded Compact 2013, you can’t cut the jump page. Since the Startup entry point is not fixed and it is based on the .text segment starting location. This entry point is known only to the jump instruction in the jump page.

Cutting the jump page is not the right way to reduce the binary size for XLDR/IPL until you did some tweaks (which I will explain in the next part ) to fix the entry point at the beginning, instead you can find some other ways such as removing unnecessary debug messages and code from the source files and its included libraries.

 

Figure 1) sample startup.s file

Figure 1) sample startup.s file