Summarize the OpenWrt start-up process: 1.cfe->2.linux->3./etc/preinit->4./sbin/init->5./etc/inittab->6./etc/init.d/ Rcs->7./etc/rc.d/s*->8.
OpenWrt is an open Linux platform, primarily for WiFi-free overhead.
Similar to the Linux distributions of Ubuntu, Red Hat, and so on, it also has its own start-up process. Below, I will take my Linksys WRT54G for platform Introduction, OPENWRT START process.
First of all, CFE (common firmware environment)--it is a bootloader, similar to U-boot,redboot, a little Broadcom the company's queen--
Start first. Its task is simply to create a simple environment for the system to run first. In addition to being able to jump to a specific address to start the operating system (such as Linux),
It also lets you download things up, like download a Linux, and then start it.
Also, it is worth mentioning that CFE will have 1, 2 seconds to wait for the kernel to be uploaded by TFTP and burn it to flash after it starts.
This gives a chance to revive some of the "brick" boards that are damaged by operating systems but CFE can still work. Please note that once Linux is started, Linux will take over the system.
At this time there is no CFE anything. The only connection is the CFE pass to the kernel a command-line argument that can be viewed with the following command after Linux is started:
root@openwrt:/# Cat/proc/cmdline
console=ttys0,115200 mtdparts=spi_flash:1m (u-boot) ro,3m (kernel),-(ROOTFS)
After that, the Linux system started up. It uses a script command similar to the following to parse CmdLine:
For x in $ (cat/proc/cmdline); Todo
Case $x in
init=*)
init=${x#init=}
;;
root=*)
root=${x#root=}
Case $ROOT in
label=*)
root= "/dev/disk/by-label/${root#label=}"
;;
uuid=*)
root= "/dev/disk/by-uuid/${root#uuid=}"
;;
Esac
;;
rootflags=*)
rootflags= "-O ${x#rootflags=}"
;;
cryptopts=*)
cryptopts= "${x#cryptopts=}"
;;
nfsroot=*)
nfsroot= "${x#nfsroot=}"
;;
nfsopts=*)
nfsopts= "-O ${x#nfsopts=}"
;;
boot=*)
boot=${x#boot=}
;;
resume=*)
Resume=${x#resume=}
;;
Noresume)
Noresume=y
;;
Quiet
Quiet=y
;;
Ro
Readonly=y
;;
rw
Readonly=n
;;
Debug
Debug=y
EXEC >/tmp/initramfs.debug 2>&1
Set-x
;;
break=*)
break=${x#break=}
;;
Break
Break=premount
;;
Esac
Done
For OpenWrt This cmdline means that the Root=/dev/mtdblock2 file system is on the third Flash partition (mtdblock0,1,2);
The ROOTFSTYPE=SQUASHFS,JFFS2 file system type is SQUASHFS and JFFS2 (why two types are not yet known,
However, it can be determined that OpenWrt uses a more complex file system to achieve SQUASHFS compression and JFFS2 writable.
Init=/etc/preinit performs this initialization, NOINITRD console=ttys0,115200
No INITRD and console port settings.
Init=/etc/preinit is the initialization that Linux will perform, as follows:
root@openwrt:/# Cat/etc/preinit
#!/bin/sh
# Copyright (C) 2006 openwrt.org
Export Path=/bin:/sbin:/usr/bin:/usr/sbin
. /etc/diag.sh
Failsafe_ip () {
Ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.2
}
Failsafe () {
[-N ' $ifname] && grep ' $ifname '/proc/net/dev >/dev/null && {
Failsafe_ip
Netmsg 192.168.1.255 "Entering failsafe!"
Telnetd-l/bin/login <>/dev/null 2>&1
}
Lock/tmp/.failsafe
Ash--login
}
Mount PROC/PROC-T proc
Mount Sysfs/sys-t Sysfs
size=$ (awk '/memtotal:/ {l=5242880;mt= ($2*1024);p rint ((S=MT/2) <l) && (mt>l)? Mt-l:s} '/proc/meminfo)
Mount Tmpfs/tmp-t tmpfs-o size= $size, nosuid,nodev,mode=1777
If grep devfs/proc/filesystems >/dev/null; Then
Mount Devfs/dev-t Devfs
M0=/dev/pty/m0
M1=/dev/pty/m1
Hotplug=/sbin/hotplug-call
elif [-X/SBIN/HOTPLUG2]; Then
Mount-t Tmpfs Tmpfs/dev-o size=512k
Mknod/dev/console C 5 1
/SBIN/HOTPLUG2--coldplug--set-rules-file/etc/hotplug2-init.rules
/sbin/hotplug2--no-coldplug--persistent--set-rules-file/etc/hotplug2-init.rules &
M0=/dev/ptmx
M1=/dev/ptmx
hotplug=
elif [-X/SBIN/UDEVD]; Then
Mount-n-T Tmpfs-o mode=0755 Udev/dev
/SBIN/UDEVD--daemon
/sbin/udevtrigger
/sbin/udevsettle
M0=/dev/pty/ptmx
M1=/dev/pty/ptmx
hotplug=
Fi
Mkdir-p/DEV/PTS/DEV/SHM
Mount Devpts/dev/pts-t devpts
# The Shell really doesn ' t like have stdin/out closed
# that ' s why we USE/DEV/PTY/M0 and M1 as replacement
# For/dev/console If there ' s no serial console available