Booting is the primary aspect for utilizing / using a device. Booting is the first process on every machine. The booting process is handled by several application in several layer. Booting will initialize device to work before the device can be operated.
In OpenWRT, when the Machine gets powered, the boot process immediately take place. The machine can be connected over the JTAG Port port and some commands can be issued.
In this article we will discuss about Booting Process on OpenWRT environment.
The Three Stages
The booting process in OpenWRT box is similar to PC’s, especially to Linux and UNIX. It can be divided into three stages or Process Trinity, according to OpenWRT definition.
Boot loader is a special program for booting the device for first time. Mostly, OpenWRT use grub to initialize and parses any options that are presented at the boot menu. After initialization done, it would terminate and give control to kernel.
In OpenWRT, the process happened as following:
The bootloader on the flash gets executed
The bootloader performs the POST, which is a low-level hardware initialization
The bootloader decompresses the Kernel image from it’s (known!) location on the flash storage into main memory (=RAM)
The bootloader executes the Kernel with
When bootloader has done its tasks, the control is passed to kernel. Kernel then do following operations:
the Kernel further bootstraps itself
issues the command/ops-code
/etc/preinitdoes pre-initialization setups (create directories, mount fs, /proc, /sys, … )
mountsthe rootfs (root file system),
if “INITRAMFS” is not defined, calls
/sbin/init(the mother of all processes)
finally some kernel thread becomes the userspace
Init is a startup script invoked by kernel to starts some service / system non-related to kernel.
The user space starts when kernel mounts rootfs and the very first program to run is (by default)
/sbin/init. The interface between user space application and kernel is
clib and the syscalls kernel offers.
Init script is considered as the “Mother of All Processes” since its controls things like starting daemon, changing runlevels, setting up the console/pseudo consoles/tty access daemons, housekeeping chores, etc.
In OpenWRT, following are the processes happen on Init process:
/etc/inittabfor the “sysinit” entry (default is “::sysinit:/etc/init.d/rcS S boot”)
/etc/init.d/rcS S boot
rcSexecutes the symlinks to the actual startup scripts located in
after rcS finishes, system should be up and running