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.

Bootloader

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:

  1. The bootloader on the flash gets executed
  2. The bootloader performs the POST, which is a low-level hardware initialization
  3. The bootloader decompresses the Kernel image from it’s (known!) location on the flash storage into main memory (=RAM)
  4. The bootloader executes the Kernel with init=… option

Kernel

When bootloader has done its tasks, the control is passed to kernel. Kernel then do following operations:

  1. the Kernel further bootstraps itself
  2. issues the command/ops-code start_kernel
  3. /etc/preinit does pre-initialization setups (create directories, mount fs, /proc, /sys, … )
  4. the Kernel mounts the rootfs (root file system),
  5. if “INITRAMFS” is not defined, calls /sbin/init (the mother of all processes)
  6. finally some kernel thread becomes the userspace init process

Init

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:

  1. init reads /etc/inittab for the “sysinit” entry (default is “::sysinit:/etc/init.d/rcS S boot”)
  2. init calls /etc/init.d/rcS S boot
  3. rcS executes the symlinks to the actual startup scripts located in /etc/rc.d/S##xxxxxx with option "start":
  4. after rcS finishes, system should be up and running

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">