What happens inside U-Boot from reset until it boots the kernel?
Short answer: U-Boot starts in architecture assembly (start.S), sets up the CPU and a temporary stack, runs board_init_f() (the pre-relocation init list: clocks, serial, DRAM), relocates itself to the top of DRAM, then runs board_init_r() (post-relocation init: MMC, flash, environment, network, console) and finally main_loop(), which either waits for commands or runs bootcmd after the bootdelay countdown.
In more detail
start.S/_start(e.g.arch/arm/cpu/armv8/start.S): exception vectors, disable interrupts, set the CPU mode/exception level, invalidate caches and TLBs, call low-levellowlevel_init, set up a stack in SRAM or cache.board_init_f()incommon/board_f.c: runs theinit_sequence_f[]list: timer, serial (so you see output early), console, CPU and board info, DRAM init (dram_init()), and calculates where to relocate. The global data structuregdlives in a reserved area because there is no.data/.bssyet.- Relocation (
relocate_code): U-Boot copies itself to the top of DRAM, fixes up addresses, clears BSS, and continues there. Now the full RAM is available. board_init_r()incommon/board_r.c: runsinit_sequence_r[]: malloc area, driver model (initr_dm), MMC/NAND/SPI flash, environment (env_relocateloadsbootcmd,bootargsetc. from storage), stdio and console, network, interrupts, and finally callsrun_main_loop().main_loop()incommon/main.c: prints the "Hit any key to stop autoboot" countdown. If interrupted, it gives the command prompt (=>); otherwise it runsbootcmd.
A common mix-up: board_init_f() runs before board_init_r(). The _f part runs from flash/SRAM with very little memory (originally "flash"), and the _r part runs after relocation to RAM.
What bootcmd typically does
load mmc 0:1 ${kernel_addr_r} Image
load mmc 0:1 ${fdt_addr_r} board.dtb
setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait
booti ${kernel_addr_r} - ${fdt_addr_r}
Modern U-Boot often uses distro boot / bootstd instead: it scans boot devices for an extlinux.conf or boot.scr and follows it.
SPL is a cut-down build of U-Boot (same source, CONFIG_SPL) that fits in SRAM; it runs board_init_f() style init, brings up DRAM, and loads U-Boot proper (or the kernel directly in Falcon mode).