What is boot Loader

Source: Internet
Author: User
What is boot Loader 2009-07-22 10:18:45 Tags: embedded system Loader bootloader boot loader original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://yunli.blog.51cto.com/831344/181630

In embedded systems you may often hear the word boot loader (boot loader), what does boot loader mean? Is there something similar to the role or concept of boot loader in our regular contact? One thing I must have guessed, you are now reading this article with a computer. If you are a little familiar with the composition of the computer, you must know the BIOS (Basic input/output System). The BIOS is used in the computer to start the computing system, after the completion of a certain hardware initialization and human-computer interaction, it loads on the hard disk operating systems, and eventually run the operating system. The boot loader in the embedded system is similar to the BIOS, and after the initialization of the processor-related hardware resources, the final load is usually the application stored in Flash, of course, in the embedded system, the operating system and the application are generally in the same executable file , which is very different from our computer.

The BIOS is identical to the boot loader, such as:
1) Complete the initialization of the processor's normal minimum system. The concept of a minimum system is easy to understand by example, for example, for our computers, it is not necessary to use Ethernet for initialization, so the initialization of the Ethernet card is not included in the minimized system, and its initialization can be done in the operating system rather than in the BIOS. Similarly, in an embedded system, we usually do not need to use the USB device during the initialization process, so the initialization of the USB device does not need to be included in the smallest system, but can be initialized in the application that is loaded by the boot loader.
2) Both will have to load the other program at the end, and give the operation right to the loaded program. For the BIOS, the program that is loaded is usually the operating system, and of course, if you are installing the system then the BIOS may be loading the installer on the CD. For loader, it loads an executable program that includes a real-time operating system (or not a real-time operating system) and our application.
3) If the BIOS or boot loader program is too large, it will usually be compressed using compression technology. For the BIOS, it will certainly be compressed using compression technology, because the BIOS with the rapid development of the computer industry and more complex, for example, the previous BIOS does not need to support the USB mouse and keyboard, but now have to support, which means that the BIOS has a USB mouse and keyboard driver. On the other hand, the volume of the computer is large, so the BIOS chip (actually a flash chip) capacity will be as small as possible to improve profits, such as may control its capacity in 512K bytes. Similar to BIOS, if flash in our embedded system is tense, we have to use compression technology for boot loader to save flash space. Some people may ask, BIOS or boot loader, if compression technology is used to compress it, who is responsible for the decompression when they run it? The answer is their own, very interesting. In fact, we say that the use of compression technology is not for all programs (or data) using compression technology. Among them, there must be a part of the uncompressed part, which ensures that the processor can run this part of the code directly when it starts. The trick is that the code without compression includes an understanding of the pressure program (which is a few functions from the C program point of view), which extracts the compressed parts into memory. Of course, the processing of the program is very technical, to ensure that the program in the process of operation, the compression of some code is transparent, which in the specific code analysis we look at.

BIOS and boot loader in addition to the same, there are differences, they are:
1) BIOS is often much more complex than boot loader because our computer hardware environment is much more complex than embedded systems. In the computer industry, to ensure that the operating system is designed to run as much as possible on different motherboards, this requires the help of the BIOS to block some hardware information. The operating system's access to some hardware resources on the motherboard needs to be done through the BIOS, which is called the function (or function) of the BIOS. The advantage of this is that the operating system developer does not care about how the specific hardware on the motherboard is designed, while the motherboard design vendor is responsible for implementing the BIOS to access the hardware resources on the motherboard. In general, it is the motherboard on the processing of complex hardware resources to the motherboard manufacturers to complete, rather than operating system manufacturers to care, because when said this is very reasonable and effective.
2) After the BIOS has finished loading the operating system, it will also reside in memory so that the operating system can invoke its functionality while it is running, but boot loader is not required. Usually, boot loader after the program has been loaded, jump to the loaded program no longer exist, here is called the jump is sometimes referred to as the run to the loaded program.
3) boot loader is usually written in combination with a compilation and a C program, but the BIOS is often written in a compilation to save program space.

Let's take a look at what the boot loader will do during the boot process. Before we discuss this, we need to understand what the difference between the processor of the embedded system and our computer processor is. For the processor of the embedded system, it should be called the microcontroller, namely the English microcontroller, and our computer processor should be called the microprocessor, namely microprocessor. Microcontroller in addition to the function of the microprocessor (that is, through operations to deal with certain transactions), often integrated with a lot of other hardware modules, such as SDRAM memory controller, I²C Controller, SD card controller and so on. Just like the name of the microprocessor, it only has the processing function, and the other control chips are done through the chipset (what is the chipset, which I intend to explain later in another article). While we're describing microprocessors and microcontrollers as a simplified word for processors, it's important to understand the differences. Let's take a look at what the boot loader do and they have:
1) Initialize the PLL clock. Often when the processor starts, for better device compatibility, its operating frequency is very low, in the boot loader program at a specific location, you need to increase the processor clock frequency to speed up the operation. Once the speed is adjusted is often not changed, the reason is often, because if the processor supports the power-saving mode function, it will also cause the PLL clock changes (the faster the power consumption of the clock).
2) Initialize the SDRAM memory controller. Often loader itself needs to use memory, for example, most boot loader will load itself into memory. The configuration of the memory is typically the configuration that includes the line address and the column address, and the automatic refresh frequency. Once configured, there is no need to change it later.
3) Initialize the interrupt Controller and interrupt service program.
4) Initialize the chip-select address register and read-write timing for each address space.
5) Initialize stack register. For example, the ESP register needs to be initialized in x86, and the R1 register needs to be initialized in PowerPC.
6) Initialize the other hardware devices that need to be accessed in the boot loader. For example, we usually have a serial port as the console, which requires initializing the corresponding serial port in the boot loader and accepting the user's command in response to the user's request. As you can imagine, there is a certain command handler in the boot loader.
7) The boot loader itself into memory, if you need to decompress, then you have to do the decompression operation. As mentioned earlier, the boot loader is loaded into memory in order to run the program faster.
8) Load the application that needs to be run and eventually run the loaded application.

It should be noted that in embedded systems we have to do a part of the same work as boot loader in our applications. For example, for the re-initialization of the interrupt service program, because the program in boot loader is set as the Interrupt service program in boot loader, the program in the boot loader is no longer present when the application is loaded, so We need to reinitialize the Interrupt service program to point to the function in the loaded program. For the initialization of SDRAM memory and the initialization of the PLL, there is usually no need to redo it in the application.

While there is no specific processor and operating system to explain here, the overall process is almost the same for any processor and operating system, except that the instruction set of the processor is different.     Finally, I want to leave a question to the reader, the question is as follows. We say that the boot loader is usually written in combination with the C language, can it all be written in C? Why.


Please reply to your answer later, my answer will be given in a later article (see "boot loader can all be written in C program").



can boot loader all be written in C program?

In the article "What is boot loader," I throw a question that is as follows: we say that boot loader is usually written in combination with the C language, can it all be written in C? Why.


The answer to this question is: No. All the code in the C program appears as a function. It may be said that in C can also embed assembly code, can be used in this way to achieve the entire boot loader it. Take a look at the topic and only consider that all the code can only be in the form of a function. What kind of environment does a function call in the C program have? Stack. When we write a C program, after the function name is enclosed in curly braces, the opening curly braces can actually be understood as having a piece of assembly code (which is explained later in the article) to manipulate the stack. Where does the stack come from? Obviously, the stack is a piece of memory area, that is to say we use C program to write code, we must ensure that the memory is initialized and ready to use. Recall that we mentioned in the article "What is Boot loader", the initialization of the SDRAM memory chip is an important step in boot loader. In other words, we must ensure that the SDRAM memory chip is initialized to make a C function call. Therefore, it is not feasible to implement boot loader completely in C language.
Please leave a message if you feel that there are some areas in this article that need improvement or are not clear. If you want to participate in the discussion of embedded system development related topics, please join the Technical Circle (g.51cto.com/ultraembedded).

This article is from the "Levin" blog, make sure to keep this source http://yunli.blog.51cto.com/831344/181630

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.