Bootloader introduction of embedded tour


From a software perspective, an embedded system is divided into three levels:

  1. The boot loader
    includes the boot program (optional) solidified in the firmware and the BootLoader.
  2. Linux kernel
    Custom kernel specific to embedded platform
  3. The file system
    includes system commands and applications.

BootLoader concept

BootLoader is a small program that runs before the operating system runs. Through this small program , the hardware device can be initialized to bring the software and hardware system of the system to a suitable state, so as to prepare for the final call to the operating system .

Why do I need to perform bootloader migration?

  1. Each different CPU architecture has a different BootLoader. In addition to relying on the architecture of the CPU , BootLoader also depends on the configuration of specific embedded board-level devices , such as the hardware address allocation of the board, and the type of peripheral chip.
  2. This means that for two different development boards, even if they are built based on the same CPU, if their hardware resources or configurations are inconsistent , the BootLoader program that you want to run on one development board can also be It runs on another board and still needs to be modified.

BootLoader startup process

The startup process of BootLoader can be divided into single-stage (Single-Stage ) and multi-stage (Multi-Stage). The usual BootLoader has more complicated functions and better portability. BootLoader started from solid-state storage devices mostly uses two stages, that is, the startup process can be divided into stage1 and stage2 : stage 1 completes the initialization of the hardware, prepares the memory space for stage 2, and copies stage 2 to the memory, the device stack, and then jumps to stage 2.

Stage 1 usually includes the following steps:

  • Hardware device initialization
  • Prepare RAM space for loading stage 2 of BootLoader
  • Copy stage 2 of BootLoader to RAM space
  • Set up the stack
  • Jump to the C entry point of stage 2

Stage 2 usually includes the following steps:

  • Initialize the hardware devices to be used in this stage
  • Read kernel image and root file system image from flash to RAM
  • Call kernel

Bootloader overview

Bootloader is divided into boot + loader

  • Boot purpose:
    jump to C language
    (1) turn off watchdog, turn off interrupt, turn off MMU and CACHE
    (2) configure system working clock
    (3) configure SDRAM controller (number of row addresses, number of column addresses, how many blocks, (Periodic charging)
    (4) Let sp (stack pointer) point to the readable and writable device area, satisfy the rule of decrementing the stack, SDAM —
    — Which mode is used, and which mode SP is to be initialized
    — For each mode The value cannot override other modes.
    (5) Code movement: The execution speed problem, move the program from the memory (nor-flash) to the fast memory;
    only execute a part of the code of the memory, and move the code stored in other locations to the memory, corresponding to the control of the memory Initialization of the device;
    (6) bl main
  • Loader purpose:
    execute application logic, light up, uart, load linux kernel

Create interface development project

  • Makefile
    1. Universal Makefile, support SD card startup and run ram directly under uboot
    (1) The address is different when the program is running
    DDR2:0x20000000
    SD:0x0
    (2) SD 16KB needs to add a header information, verify
    RAM: no need to add header information
    2. Variable collection
    IARGET:DEP target: rely on
    COMMAND command

Guess you like

Origin blog.csdn.net/qq_41782149/article/details/90258261