X86-based Redboot Boot Process Analysis

Source: Internet
Author: User

Redboot is a boot solution released by RedHat with eCos and is an open-source project.

The latest version of Redboot is Redboot-2.0.1, and RedHat will continue to support the project
Redboot supports arm, MIPS, mn10300, PowerPC, Renesas shx, v850, and x86 processors. It is a complete embedded system boot loader.

Redboot is stripped from ECOs and inherits the simplicity, lightness, flexibility, stability, reliability, and other quality advantages of ECOs. It can use X-modem or Y-
The modem protocol can be downloaded through the serial port or through the Ethernet port through the Bootp/DHCP service to obtain IP parameters, and the program image file is downloaded using TFTP, which is often used for debugging support and system startup.
Start (flash download updates and network startup ). Redboot can communicate with GDB through the serial port and Ethernet port, debug applications, and even interrupt applications running by GDB.
Redboot provides an interactive command line interface for managing flash images, image downloads, Redboot configurations, and other interfaces such as serial ports and Ethernet ports.
To load the system's boot script file from the TFTP server or from the flash download image file and save it to flash. The portable versions currently support single-board machines include:

-Ecos and Linux operating system boot

-Online flash read/write

-Supports downloading code from the string ports kermit and S-record.

-Monitoring command set: read/write I/O, memory, registers, memory, and peripheral test functions

Redboot is a standard embedded debugging and boot solution that supports almost all processor architectures and a large number of peripheral hardware interfaces. It is still being improved.

 

 

Now we will read the code to see how Redboot is started. This is the first step and an indispensable step for every system. This chapter is completed in several articles. This is the first part, mainly a summary.

Due to the close relationship between system startup and hardware, this part will be processed differently on different hardware platforms.

The following figure shows the Startup Process of a PowerPC device in embedded software development with ECOs.

Here, we will continue to introduce the startup process under the PC. You can read the code to understand the specific steps, or modify the code to re-compile and run the experiment described earlier to view the results. In the process of reading the code, it is best to combine the experiment to verify whether the system runs as we understand.

In the future, we will further analyze other code structures of the eCos operating system, such as scheduling and driver.
The Code of other architectures (such as MIPS arm) will also be analyzed and read.

The file that is run first in Redboot is usually named vectors. S.

Because we are in the i386 architecture, you can find the corresponding file in the following directory:
Package/hal/i386/ARCH/v2_0/src/vectors. s
 
The entry to program execution is_ Start

.
Slave_ Start
ToCall cyg_start

Complete the startup.
In the FunctionCyg_start
In red boot.

This is not a long piece of code, but completes the entire PC startup and initialization. A considerable part of the code is assembly, so to read the code, you must first have a basic understanding of the i386 architecture.

Although the Redboot startup process is relatively simple, it does not use the paging mechanism and does not distinguish the kernel and user States.
All codes are stored in a single segment for uniform addressing. Only two segments (selector) are used. One is code and the other is data. This is enough for Redboot (about K.

For an operating system, this is a fairly simplified operating system. Even so, the startup process is not clear at a glance. Therefore, some unnecessary content will be ignored here, such as support for SMP, FPU, and GDB.

The entire startup process is divided into the following parts:

1.
Boot-Loader:
This part of work is to load the code into the memory. For different devices, the code will be installed in different places, and usually the PC will be placed in the hard disk, some embedded devices place the code in
Rom (usually flash), which is placed in a floppy disk. Boot-loader loads the code of the floppy disk to the memory and then runs them.

2. enter the protection mode. After the cpu Of The i386 architecture is powered on, the default real-time mode and the memory access space is only 1 MB. This is only for compatibility with the initial 8086, So enter the protection mode.

3. initialize interrupt vectors and exceptions.

4. initialize Basic Input and Output devices, such as monitors, keyboards, and serial ports.

5. Other scattered initialization work.

The following describes the Startup Process in the running order.

 

_ Start
The first line is a macro.Hal_cpu_init
,
The macro is defined in the package/hal/i386/PCMB/v2_0/include/PCMB. inc file. Boot from a floppy disk, so
Hal_cpu_init is divided into two parts: one is the boot partition part (ended with 0xaa55), and the other is to enable the CPU to enter the protection mode.

Explanation: After the PC is powered on, it enters the bios, And the BIOS detects the disk (floppy disk and hard disk). If the first partition of the floppy disk (or hard disk) is the boot partition (ended at 0xaa55) load the content of the first partition of the floppy disk to the memory 0x7c00 and run it.

After the boot partition is run, the entire Redboot is partitioned one by one to the memory space with the starting address 0x3000.

Note: In this process, the content of the pilot partition will be loaded to 0x3000 again, and the code of the pilot partition will jump to 0x3000 immediately. The content at 0x7c00 will be overwritten later.

Before loading, two small tasks are executed:
1. Set the stack to 0x3000 at the top of the stack.
2. Get the extended memory and standard memory size through the interruption provided by the bios, and press it into the stack.

After the pilot partition code is complete, the program enters the protection mode. The approximate order is as follows:
1. Guanzhong disconnection
2. initialize gdt and IDT
3. Enter the protection mode
4. Set data segments
5. Reset the stack segment (because of the protection mode and actual mode, the memory addressing mode is different)

Gdt mainly uses two selectors: 0x08 (CODE) and 0x10 (data ).

All addressing spaces are from 0x00000000-0 xffffffff

Privileged level (DPL) is 0

IDT address: 0x1000

This part is complex. I will not describe it in detail here. If you have time, I will describe it in detail in the article on the i386 architecture. This part of information is also quite rich and can be searched online.

HereHal_cpu_init
The execution has ended, but the A20 address line needs to be activated to enter the protection mode. If you do not activate the A20 address line, you can only access the memory in 1 MB of space. If you activate A20, you can access all the memory. This task is in another macroHal_memc_init
In the packages/hal/i386/ARCH/v2_0/include/arch. inc file.

In this way, the task of loading and entering the protection mode is completed.

 

Do the following after entering the protection mode:

  • Set the interrupt stack space, which was previously defined in the memory space less than 0x3000. Pass
    Movl $ __interrupt_stack, % ESP
    Reset the stack at _ interrupt_stack and allocate a stack space of 40 kb.
    Stack size can also be adjusted by changing the CDL file.

 

  • Hal_idt_init (packages/hal/i386/PC/v2_0/include/platform. Inc)
    Set the IDT vector. This part will be introduced in the introduction to interruption.
  • BSS segment initialization (resetting)
    Explanation: BSS (block started by symbol) is used to store an internal storage area of uninitialized global variables in the program. It belongs to static memory allocation.

 

  • Hal_platform_init (packages/hal/i386/PC/v2_0/src/plf_misc.c)
    This part is important and has many contents. This mainly refers to initialization interruption, exceptions, and virtual vector tables.
    The virtual vector table Initialization is completed by calling the hal_if_init function.
    Three vector table, IDT, hal_vsr_table, and hal_virtual_vector_table are set in ECOs.
    The memory address is as follows:
    Idtstart = 0x00001000;
    Hal_vsr_table = 0x00001800;
    Hal_virtual_vector_table = 0x00001c00;

IDT is the actual interruption area of the hardware. When the interruption occurs, it enters the interrupt vector that calls IDT. While ECOs directs the IDT interrupt vector to hal_vsr_table
(It is suggested that hal_vsr_table is specially set to isolate different CPU interrupt mechanisms so that the interrupt processing method is consistent)

In the hal_platform_init function, Initialize all interrupts (and exceptions) and set them to the default interrupt processing routines to prevent unexpected interruptions and cause the program to enter an unknown state.

There are many processing mechanisms related to interruptions, exceptions, virtual vectors, and so on, which will be detailed in future articles.

  • Cyg_hal_invoke_constructors

This function mainly executes the relevant constructor. Because some ECOs code is written in C ++, some classes have constructor and need to be executed first, this part is processed.

 

  • Cyg_start
    Finally, enter the main function cyg_start. In this function, first initialize the peripheral device, and then start polling for user input commands.

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.