Summary of Boot Loader startup process and development experience

Source: Internet
Author: User

Windows CE inherits the rich functions of windows, but windows
CE is not a general installation version of the operating system. In the world of various embedded devices, a CE system is usually only generated for a certain hardware platform.

 

Generally, the development process of Windows CE can be divided into three steps: 0al (OEM transaction action layer), driver, and application development. Among them, the most basic step of 0al development is the board-level support package (BSP), while the bootloader design plays a critical role in BSP development.

 

 

1. What is bootloader?

The startup code of an embedded system is generally composed of two parts: the Boot Code and the initialization code of the operating system execution environment. The guiding code is generally composed of two parts: the first part is the board-level and Chip-Level Initialization code. The main function is to set the Register to initialize the hardware, for example, set the clock and interrupt control registers to complete memory ing and MMU initialization. The second part is the loader, which loads or copies the images of the operating system and applications from the read-only memory to the system's ram for execution.

 

(1) What is board-level BSP?

BSP (board support package) is a board-level support package between the main board hardware and the operating system, mainly to support the operating system, so that it can better run on the hardware motherboard. Different operating systems correspond to different forms of BSP. For example, the BSP of wince and the BSP of Linux are completely different from the interface definition although the functions are the same as those of a CPU. Therefore, BSP must be written according to the definition form of the System BSP, so as to maintain the correct interface with the upper-level OS, good support for upper-level OS.

 

(2) What is boot loader?

One important component of BSP is bootloader, which is a small program that runs before the operating system kernel runs. Through this applet, You can initialize hardware devices and create a map of memory space, so as to bring the system's hardware and software environment to a suitable state and prepare an environment for calling the operating system kernel.

 

In general, in the embedded world, bootloader is heavily dependent on hardware, so it is almost impossible to build a general bootloader. Different CPU architectures have different bootloaders. In addition to the CPU architecture, bootloader also depends on the configuration of specific embedded board-level devices. That is to say, for two different insert boards, even if they are built based on the same CPU structure, to enable the bootloader program running on a board to run on another board, you usually need to modify the source program of the bootloader.

 

2. Comparison of bootloader in PC and Embedded Systems

(1) differences between the boot program on PCs and Embedded Systems

Generally, on PC hardware platforms, bootloader does not need to perform initialization after CPU power-on because the hardware is not started through bootloader (but through BIOS. In a desktop system, the following types of devices can be used as boot devices: hard disk, USB disk, disc drive, and boot ROM of Nic. However, no matter which boot device is selected, the operating system will read the content of the device's start address into the memory, and the BIOS will hand over the control to the boot loader. If the boot device is an IDE hard disk, the boot loader is usually loaded into the first sector (usually called the Main Boot Sector, MBR), then the content is read into the memory and then run.

 

On an embedded platform, the boot loader is the first piece of code executed on the hardware. It usually places the boot program at the starting address of the memory that is not easy to lose or the initial value of the PC register when the system is cold-started. In embedded systems, there are usually no firmware programs like bios, so the boot task of the entire system is completely completed by bootloader. After the boot program completes its own tasks, the control is also handed over to the operating system. Therefore, bootloader is the first program to be executed, so it must include the power-on initialization program.

 

(2) differences between BSP in embedded and desktop windows

In fact, the desktop windows or Linux systems running on PCs also have BSP, but the PCs all adopt a uniform x86 system architecture. In this way, the Operating System BSP is a single and definite structure relative to the X86 architecture, it is easy to support normal operating of OS on x86 without any modification. Therefore, it is meaningless to talk about BSP on a PC.

 

For embedded systems, the situation is completely different. Currently, there are multiple types of embedded CPUs (such as x86, arm, MIPS, and so on) on the market, and for the sake of performance, the peripheral devices have different options and definitions. Therefore, an embedded operating system has different BSP for different CPUs, and even for the same CPU, the BSP varies depending on the peripherals. Therefore, writing and modifying BSP Based on hardware design is an important part to ensure the normal operation of the embedded system.

 

(3) differences between embedded BSP and PC motherboard BIOS

The bios on the PC motherboard is responsible for detecting and initializing system devices when the computer is turned on, loading the operating system, and scheduling the commands that the operating system sends to the hardware. Its firmware code is fixed during the chip production process and cannot be modified by users. Then, prepare for downloading and running the operating system, load the operating system from the hard disk to the memory, and pass some hardware interface settings to the system. After the operating system is normal, the role of the BIOS is basically completed, which is why the BIOS must be shut down again.

 

From this perspective, the role of the pc bios is like the bootloader in the embedded system, which is the underlying boot software. It initializes the Basic settings of the motherboard and prepares the hardware for receiving external programs. However, unlike bootloader, the BIOS also transmits some parameter settings while loading the OS, while bootloader is just a simple loading system. Although the initial part of BSP is similar to that of bios, most of the operations are different from those of BIOS. Because BSP also contains basic drivers related to the system, programmers can program and modify BSP and add any drivers or programs unrelated to the system in BSP, you can even put all the upper-layer development in bsp. However, you cannot change or compile the BIOS program. You can only modify and set the parameters. Of course, some basic hardware drivers are not included.

3. Boot Loader Startup Process

Most bootloaders have two different operating modes: Start loading mode and download mode. The start loading mode is also called autonomous mode, that is
The bootloader loads the operating system to ram from a solid-state storage device on the target machine, and does not involve any user in the whole process. The download mode is on the target machine.
Bootloader downloads files from the host through serial port connection or network connection. Files downloaded from the host are usually first saved to the ram of the target machine by boot loader, and then written to the Flash solid-state storage device on the target machine. This mode is usually used when the kernel and root file system are installed for the first time, or when the system is updated. Generally, boot loader in embedded systems is usually used in the boot loading mode. The loading process of boot loader is also the focus of our discussion.

 

(1) start part

The startup part mainly implements the hardware initialization function. Under the bootloader directory of the reference board, some. s files may be init. s or reset. S. Such files are the first code to be executed after the CPU is powered on. Access oal.exe and use the startup function to initialize the hardware. The startup function is the entry function of the boot loader. This function is generally written in assembly language and closely related to the CPU. It can initialize core hardware such as CPU and memory.

 

The startup. s code is shared with the bootloader startup code of the hardware platform. If it is a hot start, that is, the bootloader program has been started before the function is called, and the initialization of basic hardware is complete, it will jump directly to the oalstartup function; otherwise, you must initialize the hardware, such as hardware interruption shielding, memory, system clock frequency, and power management. After the system hardware initialization is complete, startup calls the oalstartup function. The oalstartup function mainly transfers the oemaddresstable table to the kernel,

Then, call the kernelstart function to jump to the kernel. Therefore, this part of work is a major focus of bootloader.

 

(2) master part

After the startup function initializes CPU and other core hardware and jumps to the main function, the system will transfer to the C language code execution environment. At this time, functions are divided into three modules: blcommon, download function, and Flash function. Among them, the blcommon module is provided by Microsoft and executes some logical functions. Therefore, developers are advised not to modify it. The functions in download function and flash function are closely related to the hardware platform. Therefore, the function implementation must be modified for each hardware platform.

 

Among them, the blcommon library is linked with the bootloader program. The entrance point of the blcommon library is the bootloadermain function, which redirects to the entry after the startup Assembly function is completed. The main function calls the bootloadermain () function in blcommon for the main task. This is the main function of Bootloader and controls the complete execution process of bootloader. This part of the code is implemented in C language and is part of blcommon code. It can be used to perform complicated operations. Such as checking the validity of memory and flash, detecting external device interfaces, detecting serial ports and sending debugging information to connected hosts, waiting for commands through serial ports, starting network interfaces, establishing memory ing, etc. completed.

 

(3) download Part

Generally, after the platform debugging is completed, CE can be automatically loaded without manual intervention. This is also one of the functions of bootloader. In the debugging phase, this requires operations through the commands supported by loader. These commands can not only complete Part of the hardware platform testing, you can also download the CE image, the most important feature of the CE bootloader program. If the hardware debugging function can be replaced by other programs without being put into bootloader, downloading the image file is a required function of bootloader.

 

The CE image file is usually called NK. bin. It is a Windows CE binary data format file that contains not only valid program code, but also control information added according to certain rules. Of course, you can also choose to generate code files in. SRE format, but in the same format as the previous one, its code is much longer and the download time is also longer.

 

(4) Support for the doc Section

For the wince operating system, rich multimedia features are a major feature. However, the problem is that if graphic interfaces and Chinese support are selected, the system can easily be larger than the order of hundreds of kb for embedded systems. The doc (Disk On Chip) provides a relatively low-cost large storage capacity solution.

 

Doc is essentially a kind of flash in NAND format controlled by software. It supports wince through the software layer tffs. Because DOC files cannot be directly accessed like memory, the process of loading wince is special. special code must be added to bootloader before using Doc to store the wince image file.

4. Summary of Boot Loader development experience

(1) In an embedded system, bootloader has a similar significance and function as bios on a PC. It initializes the main components on the Development Board, such as CPU, SDRAM, Flash, and serial port, you can also use bootloader to download files to the Development Board and start the system. Therefore, a powerful bootloader is equivalent to a micro operating system.

 

(2) From the CE bootloader development process, we can see that bootloader has some hardware debugging functions in addition to the main functions of downloading ce images and images. Of course, these functions are not necessary and have different definitions with different users, but this is a part that cannot be skipped in the Development of Ce systems.

 

(3) Development of embedded system applications is different from that of PCs. The development process also involves comprehensive consideration of software and hardware and upper-layer application development; PC Application Development is built on a customized hardware and operating system platform. Developers only need to call the interfaces and services provided by the system to complete the corresponding functions. Considering the cost constraints, the hardware platform of embedded systems is usually customized according to applications,

The MPU, memory, and peripheral devices usually used have multiple options, making the guiding design of the platform very complicated. Therefore, it takes a long process to implement from scratch. The common practice is to use the bootloader routine of the standard development board provided by Microsoft for each type of CPU, find the specimen program closest to the hardware platform from these routines, and then make corresponding changes based on the hardware platform.
 
All in all, bootloader is the first and key step for developing the wince system. Only when a stable loader program is obtained can the BSP of Wince be further developed and the success of the entire embedded system be achieved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.