</>EmbeddedInterview

Explain full boot flow of i.MX8 in very brief.

MediumEmbedded Linux & Boot

The following is the corrected flow for NXP i.MX8QuadMax (QM) and i.MX8QuadXPlus (QXP).

1. Initial boot stages

Stage Explanation
Power ON / Reset Processor starts executing Boot ROM.
Boot ROM Identifies the boot device, such as eMMC, SD card or QSPI.
SECO Firmware Handles security and firmware authentication.
SCFW System Controller Firmware manages power, clocks, DDR initialization and hardware resources.
SPL (if enabled) Small bootloader that loads subsequent boot images.
ARM Trusted Firmware (BL31) Initializes EL3 secure monitor and transfers control to U-Boot.
U-Boot (BL33) Prepares the system and loads Linux.

Note: SPL is optional on i.MX8QM/QXP, depending on the boot configuration.

2. U-Boot initialization

Function Purpose
start.S Initializes CPU registers, execution state and masks interrupts.
_main() Sets up the initial stack and global data.
board_init_f() Early board initialization, UART and DRAM setup or detection.
relocate_code() Relocates U-Boot to its final location in DDR.
board_init_r() Initializes remaining hardware and software components.
env_init() Initializes environment handling during early boot.
console_init_f() / console_init_r() Initializes console functionality.
main_loop() Starts autoboot or provides the U-Boot command prompt.

Correction: board_init_f() executes before relocation and board_init_r() executes after relocation.

3. Loading the Linux kernel

U-Boot loads the following into DDR:

  • Image: Linux kernel binary.
  • DTB: Hardware description.
  • Initramfs: Optional temporary root filesystem.
  • Bootargs: Kernel command-line parameters, typically passed through the DTB.

Boot commands:

Command Purpose
bootm Boots legacy or FIT images.
bootz Boots ARM32 compressed zImage.
booti Boots ARM64 Image.

For i.MX8 ARM64:

booti ${loadaddr} - ${fdt_addr_r}

4. Jumping to the Linux kernel

U-Boot prepares the CPU, disables the MMU and transfers control to the kernel entry address.

ARM64 kernel entry is equivalent to:

kernel_entry(dtb_addr, 0, 0, 0);
Register Value
X0 Physical address of DTB
X1 0
X2 0
X3 0

Correction: ARM64 does not use the ARM32 machine ID (machid) boot mechanism.

5. Linux kernel initialization

head.S

Location: arch/arm64/kernel/head.S

  • Configures CPU execution state.
  • Creates initial page tables.
  • Enables MMU.
  • Sets up the kernel stack and exception vectors.
  • Calls start_kernel().

start_kernel()

Location: init/main.c

Function Purpose
setup_arch() Parses DTB, bootargs and physical memory information.
mm_init() Initializes memory management (name varies by kernel version).
sched_init() Initializes the process scheduler.
init_IRQ() Initializes interrupt handling and interrupt controller (GIC).
init_timers() Initializes kernel timers.
timekeeping_init() Initializes system timekeeping.
rcu_init() Initializes Read-Copy-Update synchronization.
console_init() Initializes kernel console.
workqueue_init_early() Initializes early workqueue infrastructure.
rest_init() Creates essential kernel tasks.

6. rest_init()

Creates two important tasks:

Task Purpose
kernel_init() — PID 1 Completes kernel initialization and launches userspace.
kthreadd() — PID 2 Manages the creation of kernel threads.
Idle task — PID 0 Executes when no runnable task is available.

7. kernel_init()

Function Purpose
kernel_init_freeable() Completes remaining kernel initialization.
smp_init() Brings additional CPU cores online.
workqueue_init() Completes workqueue initialization.
do_basic_setup() Initializes device infrastructure and runs initcalls.
do_initcalls() Executes built-in driver and subsystem initialization functions.
prepare_namespace() Mounts the root filesystem when no early userspace init is used.
free_initmem() Releases initialization-only memory.
run_init_process() Executes the first userspace program.

8. Userspace initialization

The kernel executes /init or /sbin/init (typically systemd on modern Linux distributions).

It performs:

  • Mounting /proc, /sys, /dev and additional filesystems as needed.
  • Starting system services and daemons.
  • Configuring networking.
  • Starting login prompts or graphical interfaces.

In Android, /init is normally the first userspace program.

9. Complete boot flow for interview

Power ON / ResetBoot ROMBoot device selectionSECO Firmware + SCFWSecurity, power, clocks and DDRSPL (Optional)Loads subsequent boot imagesARM Trusted Firmware (BL31)EL3 secure monitorU-Boot: start.S → _main()Early CPU initializationboard_init_f()Early board initializationrelocate_code()Relocate U-Boot in DDRboard_init_r() → main_loop()Hardware initialization and autobootbooti → Kernel entryPass DTB and jump to Linuxhead.SPage tables and MMUstart_kernel()Core kernel subsystemsrest_init()PID 1 and PID 2 creationkernel_init()Drivers and root filesystem/sbin/init or /initUserspace initializationSystem Ready

Remember: Boot ROM → SECO/SCFW → SPL (optional) → ATF → U-Boot → Linux Kernel → Init → Userspace.

The exact internal function sequence may vary slightly depending on the U-Boot version, Linux kernel version and board configuration.