2021 Linux technology summary: U-boot

1, Introduction to U-boot

A bootloader program (equivalent to the BIOS of windows) is required to start the Linux system. The purpose of bootloader is to copy the operating system image file to RAM and then jump to its entry for execution, mainly including:

  1. Initialize the exception vector table of arm and set the address of the exception vector table
  2. Set processor (and coprocessor) mode
  3. Board initialization:
    (1) DDR initialization
    (2) Clock system initialization
    (3) Load the operating system, device tree and virtual file system into DDR from the boot device
    (4) Initialize serial port
  4. Set parameters and jump to the operating system

U-boot is a commonly used bootloader program, which is mainly used for the boot loader of embedded systems. It can support a variety of different computer system structures, including PPC, ARM, AVR32, MIPS, x86, 68k, Nios and MicroBlaze. It is a set of free software distributed under the GNU General Public License.
U-boot official website: http://www.denx.de/wiki/U-Boot/WebHome However, it is recommended to use the U-boot boot boot program maintained on the official website of the semiconductor manufacturer.

2, U-boot startup process

2.1 search for u-boot entry

First, determine the transplanted source development board and compile it. After compilation, a link script will appear in the U-boot root directory: U-boot LDS file( lds official documents ), the connection script contents are as follows (the script contents of different boards may be different):

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
 . = 0x00000000;
 . = ALIGN(4);
 .text :
 {
  *(.__image_copy_start)
  *(.vectors)
  arch/arm/cpu/armv7/start.o (.text*)
  *(.text*)
 }
 . = ALIGN(4);
 .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
 . = ALIGN(4);
 .data : {
  *(.data*)
 }
 . = ALIGN(4);
 . = .;
 . = ALIGN(4);
 .u_boot_list : {
  KEEP(*(SORT(.u_boot_list*)));
 }
 . = ALIGN(4);
 .image_copy_end :
 {
  *(.__image_copy_end)
 }
 .rel_dyn_start :
 {
  *(.__rel_dyn_start)
 }
 .rel.dyn : {
  *(.rel*)
 }
 .rel_dyn_end :
 {
  *(.__rel_dyn_end)
 }
 .end :
 {
  *(.__end)
 }
 _image_binary_end = .;
 . = ALIGN(4096);
 .mmutable : {
  *(.mmutable)
 }
 .bss_start __rel_dyn_start (OVERLAY) : {
  KEEP(*(.__bss_start));
  __bss_base = .;
 }
 .bss __bss_base (OVERLAY) : {
  *(.bss*)
   . = ALIGN(4);
   __bss_limit = .;
 }
 .bss_end __bss_limit (OVERLAY) : {
  KEEP(*(.__bss_end));
 }
 .dynsym _image_binary_end : { *(.dynsym) }
 .dynbss : { *(.dynbss) }
 .dynstr : { *(.dynstr*) }
 .dynamic : { *(.dynamic*) }
 .plt : { *(.plt*) }
 .interp : { *(.interp*) }
 .gnu.hash : { *(.gnu.hash) }
 .gnu : { *(.gnu*) }
 .ARM.exidx : { *(.ARM.exidx*) }
 .gnu.linkonce.armexidx : { *(.gnu.linkonce.armexidx.*) }
}

ENTRY (_star) is the ENTRY function, which is defined in arch / arm / lib / vectors S, the file is the general arm exception table code, initialize the arm exception vector table, and set the address of the exception vector table. In the SECTIONS of the connection script, you can see that the starting code is vectors, and its address is u-boot Available in map:

 *(.vectors)
 .vectors       0x0000000087800000      0x300 arch/arm/lib/built-in.o

Through the connection script, we know the entry function:_ start, which includes:

_start:
/*
 *************************************************************************
 * Exception vectors as described in ARM reference manuals
 * Uses indirect branch to allow reaching handlers anywhere in memory.
 *************************************************************************
 */
_start:

#ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
	.word	CONFIG_SYS_DV_NOR_BOOT_CFG
#endif

	b	reset
	ldr	pc, _undefined_instruction
	ldr	pc, _software_interrupt
	ldr	pc, _prefetch_abort
	ldr	pc, _data_abort
	ldr	pc, _not_used
	ldr	pc, _irq
	ldr	pc, _fiq
It will jump to the reset function here on line 13, which is in arch / arm / CPU / armv7 / statr S (link script line 11),

3, U-boot migration

4, Other modifications

Keywords: Linux U-boot

Added by Gambler on Wed, 12 Jan 2022 05:40:28 +0200