[Original] describes BootLoader

Source: Internet
Author: User

I had nothing to do in the company yesterday, so I had a rare opportunity to add value to myself. I watched two video tutorials on WindowsCE and recorded the bootloader.

At the beginning, I was not very clear about the usage of bootloader. I only knew that it was called a system boot program. It was responsible for OS startup, but how was it started? What other functions does it have? How is it implemented? These are not clear. Now I understand it a bit.

The typical bootloader design divides the code into two stages, mainly to make a compromise on code portability and efficiency. Because bootloader is highly hardware-related, cpu initialization and other operations in different architectures are completely different. In the first phase of the Code, the main task is to initialize the hardware device, prepare the RAM space for the second phase of bootloader and initialize the stack. This part of content is generally implemented by assembly. In the second stage, the main task is to set the system clock, set the Translation Table, initialize the MMU, set the kernel startup parameters, and copy the kernel image from Nand Flash to the corresponding SDRAM, finally, jump to the kernel entry point.

On a PC, OS entry depends on the boot loader. The Boot Loader consists of the BIOS and the BootLoader located on the MBR on the disk. After the system is powered on, the BIOS is mainly responsible for hardware initialization and system resource allocation. Then, the BIOS will read the bootloader on the MBR into RAM, then, bootloader is mainly responsible for reading the OS kernel into RAM, so that the system can start normally.

In an embedded system, how does the OS run?

Embedded systems generally require off-chip storage, including data storage and code storage. Currently, the two popular types of memory are Nor Flash and Nand Flash.

NOR features In-chip execution (XIP, eXecute In Place), so that applications can run directly In flash memory without having to read the code into system RAM. NOR transmission efficiency is very high, in 1 ~ The small size of 4 MB has high cost efficiency, but the low write and erase speeds greatly affect its performance. Because the cost is relatively high and the efficiency is relatively low than that of Nand Flash, it is usually used for Nand Flash. If you use Nor, you can put the entire OS in it, because the code will automatically run in Nor flash, Nor flash will execute the program from its address 0.

Since the smallest Execution Unit of Nand Flash is not a byte but a page, it cannot run programs automatically. But how does it start the OS? In fact, some Nand Flash designs allocate a small space for bootloader, And the bootloader process is divided into two phases:

I. hardware initialization, allocating RAM space for the second stage, etc. All work in this stage is prepared for the second stage. Since the space allocated in this phase is relatively small, compilation is generally used to write this part of the code.

2. This part is the boot of the OS. At this stage, the bootloader will be read into the SRAM, and then the bootloader will gain ownership, it then reads the OS image in flash into RAM and runs the OS kernel to start the system.

Bootloader has two working modes: Download mode and normal working mode. The working mode has been mentioned above. It mainly refers to the download mode, which is a mode in which the system image file is updated. When a user presses a key or key combination, the system does not work normally, but enters the download mode, the image can be downloaded from the host to the local host using usb or Ethernet. This means that the bootloader will not be changed and will be saved, first, erase the original OS image in flash, and then download the new image file to flash. This is the process. It is actually advantageous to save the Bootloader. For example, when your machine downloads a power failure, the original OS is erased, but the new image file is not completely downloaded, however, if the bootloader is saved, it can still ensure that the image file can be downloaded again.

This is my own insights on bootloader, and I do not know whether it is correct or not. Some of the articles are based on the Internet. We hope that we will gradually become familiar with bootloader in the future.

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.