1

I would like to establish a milestone roadmap for Linux initialization for me to easily understand. (For an embedded system) Here is what I got:

  1. Bootloader loads kernel to RAM and starts it
  2. Linux kernel enters head.o, starts start_kernel()
  3. CPU architecture is found, MMU is started.
  4. setup_arch() is called, setting CPU up.
  5. Kernel subsystems are loaded.
  6. do_initcalls() is called and modules with *_initcall() and module_init() functions are started.
  7. Then /sbin/init (or alike) is run.

I don't know when exactly devicetree is processed here. Is it when do_initcall() functions are beings processed or is it something prior to that? In general when devicetree is parsed, and when tree nodes are processed? Thank you very much in advance.

Any correction to my thoughts are highly appreciated.

mozcelikors
  • 2,582
  • 8
  • 43
  • 77

1 Answers1

4

It's a good question.

Firstly, I think you already know that the kernel will use data in the DT to identify the specific machine, in case of general use across different platform or hardware, we need it to establish in the early boot so that it has the opportunity to run machine-specific fixups.

Here is some information I digest from linux kernel documents.

In the majority of cases, the machine identity is irrelevant, and the kernel will instead select setup code based on the machine’s core CPU or SoC. On ARM for example, setup_arch() in arch/arm/kernel/setup.c will call setup_machine_fdt() in arch/arm/kernel/devtree.c which searches through the machine_desc table and selects the machine_desc which best matches the device tree data. It determines the best match by looking at the ‘compatible’ property in the root device tree node, and comparing it with the dt_compat list in struct machine_desc (which is defined in arch/arm/include/asm/mach/arch.h if you’re curious).

As for the Linux Initialization, I think there are something we can add in the list.

  1. Put on START button, reset signal trigger

  2. CS:IP fix to the BIOS 0XFFFF0 address

  3. Jump to the start of BIOS

  4. Self-check, start of hardware device like keyboard, real mode IDT & GDT

  5. Load Bootloader like grub2 or syslinux.

  6. Bootloader loads kernel to RAM and starts it (boot.img->core.img).

  7. A20 Open, call setup.s, switch into protected mode

  8. Linux kernel enters head.o, IDT & GDT refresh, decompress_kernel(), starts start_kernel()

  9. INIT_TASK(init_task) create

  10. trap_init()

  11. CPU architecture is found, MMU is started (mmu_init()).

  12. setup_arch() is called, setting CPU up.

  13. Kernel subsystems are loaded.

  14. do_initcalls() is called and modules with *_initcall() and module_init() functions are started.

  15. rest_init() will create process 1 & 2, in other word, /sbin/init (or alike) and kthreadd is run.

tyChen
  • 1,404
  • 8
  • 27