Export (0) Print
Expand All

How to Develop a Boot Loader (Windows Embedded CE 6.0)

1/5/2010

A boot loader manages the boot process of the target device by initializing the target device, downloading the run-time image, and booting the run-time image on the target device.

After you develop a boot loader, you can use the boot management capabilities of your boot loader to save time during the OS development process.

Without a boot loader, you must transfer a run-time image to your target device through a slow, manual process.

With a boot loader, you can quickly download a new development run-time image to your target device.

For more information about boot loaders, see Boot Loaders.

  • The boot loader described in this topic is developed for an example hardware platform containing the following hardware specifications:
    • ARM V4I CPU
    • 64 MB RAM
    • 32 MB Intel Strataflash (28F128)
    • A supported Ethernet controller, such as NE2000 or SMC9000. As a simplification for this boot loader development process, the controller is built-in and not a PCI or PCMCIA device.
    The following table shows the memory map for this hardware platform.

    Physical address Length Description

    0000.0000 - 01FF.FFFF

    32 MB

    Flash

    A000.0000 - A3FF.FFFF

    64 MB

    RAM

    The boot loader design assumes that the CPU begins fetching code at physical address 0 following a reset.
  • You are developing a new boot loader, using as much from the included support libraries as possible.
  • Your reference OS is Windows Embedded CE 6.0.
  • You have access and familiarity with Platform Builder for Windows Embedded CE 6.0 and the build process. Platform Builder includes with all the sources and libraries needed to support boot loader development.
  • You have available documentation, such as databooks or datasheets and the latest errata, on the hardware platform, CPU, peripheral chips, and other hardware on which your boot loader will run.
  • This procedure used a sample boot loader with the following design simplifications:
    • The boot loader resides in system flash memory and runs at every hardware reboot.
    • Use Ethernet for the download transport. This is built in with no PCMCIA or PCI interface.
    • Download a Windows Embedded CE .bin file, for example, Nk.bin, to RAM.
    • There is no support for booting a local run-time image, although the flash memory routines are covered. Memory management unit (MMU) or caches are not used. The ROMOFFSET configuration option in the run-time image Config.bib file should reflect the fact that all addresses are physical.

When designing your own boot loader, you can implement enhancements within the framework presented in this topic. For example, you may support a removable Ethernet adapter using PCMCIA or Compact Flash memory or use USB as your download transport.

You might want to store the run-time image in NAND flash memory. For more information about memory design tradeoffs, see the article System Memory Management in Windows CE .NET.

For more information about the hardware platform description and design of the boot loader described in this process, see Boot Loader Design.

Although the boot loader and the OEM adaptation layer (OAL) typically share hardware platform initialization code, the steps in the following procedure focus on the boot loader. However, keep code sharing in mind when organizing the source files.

The following procedure explains the boot loader development process from the beginning. However, you can save development time by modifying an existing boot loader image for a hardware platform of similar design.

Platform Builder for CE 6.0 includes tested boot loader source code for various hardware platforms, which you can use as the basis for further development.

To develop a boot loader, follow the steps in the table below.

Ee479056.note(en-US,WinEmbedded.60).gifNote:
In the following steps, code examples are used to demonstrate each step. In some cases, these examples are code fragments and might be brought together from different parts of the boot loader development process. Because of this, not all code examples compile.

Step Topic

1. Build a complete platform based on a sample BSP for the CPU you intend to target.

For example, if you intend to target x86, then build a sample platform (i.e. PDA, Webpad) based on the CEPC BSP before creating your own boot loader.

Your new boot loader will link to libraries (i.e. BLCOMMON, Ethdbg) that are built once when the sample platform is initially created.

Creating an OS Design with the Windows Embedded CE OS Design Wizard

2. Create a directory for your new boot loader code.

For example: %_WINCEROOT%\Platform\MyPlatform\Src\Bootloader\Eboot.

The boot loader code directory is typically in a hardware platform directory.

You must include the directory in the hardware platform dirs file to build it as part of Platform Builder.

Not applicable

3. Set up a command-line build shell to create and build the boot loader.

Ee479056.note(en-US,WinEmbedded.60).gifNote:
All further steps rely on the assumption that the boot loader development process takes place in a build shell environment.

Setting Up a Command-Line Build Shell

4. Generate all static libraries required by the boot loader image.

  • At the command prompt, enter the following command:
    sysgen
    

For more information about Sysgen.bat, see Sysgen Tool.

Not applicable

5. Create a file for your boot loader's StartUp function, and then establish a function framework as a starting point.

Creating a File for the Boot Loader StartUp Function

6. Create a sources file and makefile file in the boot loader directory.

Creating the Boot Loader Sources and Makefile Files

7. Build your first boot loader executable (.exe) file.

Building the Boot Loader Source Code

8. Implement the boot loader's StartUp function.

Implementing the Boot Loader StartUp Function

9. Create a boot loader main function.

This is typically using C programming language.

Starting with this step, all boot loader code should be able to operate in C instead of assembly language.

Ee479056.note(en-US,WinEmbedded.60).gifNote:
If you build during this step, you receive a number of undefined values, because BLCOMMON expects to call a number of functions that have not yet been implemented. Therefore, you should at least implement stub versions of these functions.

Creating the Boot Loader Main Function

10. Create stub versions for a number of OEM functions, including generic hardware platform routines and flash memory operations.

Creating Stubs for the Boot Loader OEM Functions

11. Add the new source files, Main.c. and Flash.c, created in the previous step to the SOURCES line in the sources file.

  • Add a TARGETLIBS entry that includes references to the BLCOMMON, GSNull, and FullLibc libraries.

Editing the Boot Loader Sources File

12. Create the .bib file, which will be used by Romimage.exe to convert the boot loader .exe file into .bin and .nb0 files.

Creating the Boot Loader .bib File

13. Rebuild the boot loader.

Ee479056.note(en-US,WinEmbedded.60).gifNote:
After this point, the basic boot loader source infrastructure is in place.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
To complete the remaining steps of this procedure, you must do the following:
  • Fully implement the routines that were stubbed
  • Add incremental functionality to the boot loader
  • Rebuild the boot loader
  • Test the functionality of the loader up to that point

Rebuilding the Boot Loader

14. Implement the following serial debug functions in your boot loader code:

These functions are required BLCOMMON callback functions that you must implement in your boot loader code.

You can use other libraries to help implement the functions.

You can copy and possibly modify much of the code from existing hardware platforms.

You should choose a hardware platform that is as similar to your own as possible to minimize the need for changes.

Implementing the Serial Debug Functions

15. Rebuild the boot loader and verify that your code works by testing it on the target device.

You should now be able to verify the following:

  • The startup code initializes the CPU
  • The debug routines initialize and write debug text to the serial universal asynchronous receiver-transmitter (UART).

If you encounter problems, verify that you correctly implemented serial debug functions.

Rebuilding the Boot Loader

16. Create the driver globals and boot args shared data areas.

Creating Driver Globals and Boot Args

17. Implement the remaining hardware platform initialization code by implementing the OEMPlatformInit function.

Implementing the OEMPlatformInit Function

18. Add Ethernet debug libraries that have routines referenced in OEMPlatformInit to the TARGETLIBS entry in the boot loader sources file.

Ee479056.note(en-US,WinEmbedded.60).gifNote:
After this point in the development process, the CPU, board-level logic, and network controller are all initialized.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
To complete the remaining steps in this procedure, you must do the following:
  • Obtain an IP address, either statically or through Dynamic Host Configuration Protocol (DHCP) from a server.
  • Connect to Platform Builder and establish a Trivial File Transfer Protocol (TFTP) connection.
  • Add code to act as a bridge between BLCOMMON callbacks and the Ethernet controller access primitives.
  • Handle flash memory images, which are images built to reside in flash memory after being downloaded from the development workstation.

Editing the Boot Loader Sources File

19. Implement the following Ethernet controller-related functions:

Implementing the Ethernet Controller-Related Functions

20. Implement the OEMPreDownload function.

Implementing the OEMPreDownload Function

21. Test boot loader communications by doing the following:

  • Verify that the code can obtain an IP address from the DHCP server and can retrieve the user settings from Platform Builder.
  • Verify that your device name appears in Platform Builder.

Not applicable

22. Create a test .bin file to download from Platform Builder.

Creating a Test .bin File for Download

23. Verify that the boot loader can use Platform Builder to download a .bin file.

Verifying .bin File Download

24. Implement the OEMLaunch function.

Ee479056.note(en-US,WinEmbedded.60).gifNote:
After you complete this step, you have essentially completed development of the boot loader.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
The boot loader should now be able to
  • Initialize the hardware platform.
  • Obtain an IP address from a DHCP server.
  • Establish contact with Platform Builder.
  • Download a .bin file.
  • Obtain user preferences from Platform Builder.
  • Execute the downloaded run-time image.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
To complete the remaining steps in this procedure, you must add support for writing the downloaded boot loader image to flash memory.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
By doing so, the boot loader can update its own saved image.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
You can also do the following:
  • Save user settings, such as a static IP address and subnet mask, in flash memory and then restore these settings after a reset.
  • Add optional functionality such as memory range verification, run-time image signature checking, and NAND flash memory support.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
For more information about design tradeoffs, especially NOR versus NAND flash memory, see this Microsoft Web site.

Implementing the OEMLaunch Function

25. Implement the OEMIsFlashAddr function.

Implementing the OEMIsFlashAddr Function

26. Implement the OEMMapMemAddr function.

Implementing the OEMMapMemAddr Function

27. Implement the following flash memory erase functions:

Implementing the Flash Memory Erase Functions

28. Implement the OEMWriteFlash function.

Implementing the OEMWriteFlash Function

29. Modify the .bib file to produce a boot loader image that downloads to flash memory.

Ee479056.note(en-US,WinEmbedded.60).gifNote:
After you complete this step, you have completed development of a basic Ethernet boot loader that can download a run-time image to RAM or to flash memory. You can now add additional functionality to enhance the basic boot loader.
Ee479056.note(en-US,WinEmbedded.60).gifNote:
The following list shows some of the additional functionality you can include in an enhanced boot loader:
  • Ability to load run-time images from local storage instead of over the network
  • Support for run-time image signing or checking for bad images
  • Support for multiple region .bin files or multi-XIP
  • Ability to handle NAND flash memory
Ee479056.note(en-US,WinEmbedded.60).gifNote:
Because the boot loader can have many variations, the following steps show only a few enhancements you can add to a basic boot loader.

Modifying the .bib File to Produce a Downloadable Image

30. To add support for download progress indication, implement the OEMShowProgress function.

You do not need to add functionality to the OEMShowProgress function, but you must leave the stub version in your boot loader code to prevent errors when the compiler compiles the code.

Adding Support for Download Progress Indication

31. To verify the RAM or flash memory used by the run-time image before the run-time image is downloaded completely, add support for memory verification.

Adding Support for Memory Verification

32. If you are developing a multi-BIN run-time image and you would find multi-BIN run-time image notification useful, add support for multi-BIN run-time image notification.

Adding Support for Multiple-BIN Image Notification

33. To have your boot loader validate the run-time image before downloading or running it, add support for run-time image signatures.

Adding Support for Image Signatures

Community Additions

ADD
Show:
© 2015 Microsoft