What is Boot Loader?
2014-03-22

What is Boot Loader


Tags: embedded system loader bootloader casual boot loader

Among the embedded systems you may often hear the boot loader ( boot loader ) the word , boot loader refers to what ? In our daily stuff in regular contact with the boot loader is not a role or a concept similar to it? One thing I will guess that you are now using a computer to see this article. If you are somewhat familiar with the composition of the computer, you must know that BIOS (Basic Input / Output System). BIOS in your computer is used to start the computing system , after the completion of certain hardware initialization and human-computer interaction , it loads the operating system is located in the hard disk , and finally run the operating system . Embedded systems and BIOS boot loader is similar to the role , but also after the completion of the associated hardware resources for the processor to initialize the final load is usually stored in FLASH application , of course, in which operating systems and embedded systems applications are generally in the same executable file , which is very different from our computers .

BIOS and boot loader have in common, such as :
    1 ) complete the normal minimum system initialization processor . Concept For minimum system through relatively easy to understand the embodiment , for example, our computer usually no need to use an Ethernet initialization , therefore , the minimum initialization of the system does not include an Ethernet card , its initialization fully into the operating system to do it, but not in the BIOS. Similar to that in embedded systems, we usually do not need to use the USB device in the initialization process, then the initialization of the USB device does not need to be included in the smallest system, but the application can be loaded boot loader go to initialize it .
    2 ) In the last two other programs had to be loaded and run right to the program is loaded. For the BIOS, the program they are usually loaded operating system, of course , if you are installing the system so the BIOS loads may be located in the CD-ROM installation procedure. For the loader, which loads an executable program , the executable program , including real-time operating system ( and some are not real-time operating system ) and our application .
    3 ) If the BIOS or boot loader program is too large , they usually use compression technology to compress . For the BIOS, it will certainly be using compression technology to compress , because the BIOS with the rapid development of the computer industry, but more complex, for example , does not require previous BIOS supports USB mouse and keyboard, but now you have to support , which means to have a USB mouse and keyboard BIOS drivers . The other hand, large shipments of the computer, so the BIOS chip ( in fact, a FLASH chip ) capacity will also have little control as possible in order to increase profits, such as the possibility to control the capacity of 512K bytes. Is similar with the BIOS , if our embedded systems FLASH nervous FLASH order to save space, we also have to boot loader uses compression technology. Some people may ask , BIOS is good , boot loader or, if using a compression technology for its compression , it is they who are responsible for when you run uncompress it? The answer is that they own , is very interesting! In fact , we say that they are not using compression technology for the entire program ( or data ) are used compression technology. Among them , there must be no part of the compressed portion , which ensures that the processor starts to run this part of the code directly . The trick is , there is no code which includes a compression decompression procedures ( from the perspective of a C program is several functions ) , it will be part of extracting compressed into memory . Of course , one of the procedures is very tricky , to ensure that the program runs in the process , for the compression part of the code to run is transparent, which in the specific code analysis, we will look at .

BIOS and boot loader in addition to similarities , there are differences, they are:
    1) BIOS often a lot more complicated than boot loader, because our computer hardware environment is much more complex than the embedded system . In the computer industry , in order to ensure that the operating system designed to run on a different motherboard as possible , which requires BIOS help to shield some hardware information. Access to some of the operating system on the motherboard hardware resources , the need to complete the BIOS , which is called the BIOS functions ( or should we say the function ) to complete. The advantage of this is very obvious , the operating system developers do not care about the specific hardware on the motherboard is how to design , while the design of the motherboard manufacturers are responsible for implementing the BIOS to access the access to the hardware resources on the motherboard . Overall, the motherboard is the hardware resources for complex processing tasks to the motherboard manufacturers to complete, rather than the operating system vendor to care , because when say this is very reasonable and effective .
    2) BIOS finished after loading the operating system , which will reside in memory , so that the operating system calls its function in the process of running , but you do not need such a boot loader . Usually after , boot loader to load the program finished , jump to the program is loaded after no longer exists , mentioned here will jump sometimes called run over to the loaded program .
    3) boot loader usually a combination of assembly and C program to write, but the BIOS in order to save space is often used in all procedures for the preparation of a compilation .

Here we take a look at boot loader in the boot process will do what thing. Before discussing these , we need to understand what is the difference with our embedded system processor computer processor is . Processors for embedded systems , precisely should be called microcontrollers, namely English, microcontroller, and we should be called the microprocessor computer processors , namely microprocessor. In addition to the micro- controller microprocessor functions ( that is, through operations to deal with certain matters ) , which is often a lot of other hardware integrated functional modules , such as SDRAM memory controller , I2C controller , SD card controller , and so on . As the name suggests microprocessor , it is only processing functions , the other is through the control chip chipset ( What's chipset, I'm going to come back with another article to explain ) to complete. Although we microprocessors and microcontrollers for use of such a simplified word processor to describe , but we need to understand the differences between them, which is very important . Here we take a look at boot loader to do something , they are:
    1 ) of the PLL clock is initialized. Often when the processor is started, in order to better device compatibility , the operating frequency is very low , at a specific location boot loader program , the need to improve the processor's clock frequency to run faster. Once the adjusted speed will not change often , the reason is often said , because if the processor supports power saving mode function , it can also cause changes in PLL clock ( clock , the faster and more power ) .
    2 ) initialize SDRAM memory controller. Usually need to use memory loader itself , for example, most of the boot loader will load itself into memory. Memory configuration generally includes configuration row and column addresses and the automatic refresh frequency configuration. Once configured, the back will not need to change .
    3 ) Initialize interrupt controller and the interrupt service routine.
    4 ) initialize each address space and the chip select address register read and write timing .
    5 ) initialize the stack (stack) register. For example, the need to initialize the ESP register x86 , PowerPC need to initialize the r1 register.
    6 ) For other hardware devices needed to access the boot loader initialized . For example, we usually have a serial port as a console (console), which requires the boot loader to initialize the appropriate serial port, and accept the user's command , in response to user requests. You can imagine, there are some command handler in the boot loader .
    7 ) The boot loader loads itself into memory , if necessary decompression, then had to do decompression operation . Mentioned earlier , the boot loader is loaded into memory in order to run programs faster .
    8 ) loading the application needs to run and the final run was loaded applications .

It should be noted that, in the embedded system applications in which we have to do the same part of the boot loader work . For example, for re-initialize the interrupt service routine , because the set is in the boot loader in the boot loader program as an interrupt service routine , when the application is loaded after , boot loader in the program will cease to exist , so we need re-initialized to point to the interrupt service routine is loaded program functions. For initialize SDRAM memory , PLL initialization, in applications usually do not need to re-do .

Although , in this we do not have the specific processor and operating system to explain, but regardless of what processor and operating system , the overall process is almost the same, but the processor's instruction set is different. Finally, I leave you to give the reader a problem , the problem is as follows .
    We say boot loader usually a combination of assembly and C language to write , it can not all be written in C language to do ? Why ?