"Reprint" Mini2440 Boot configuration file description

Source: Internet
Author: User

For mini2440, although the root_qtopia of this filesystem is based on Qtopia, the initialization process is mostly done by BusyBox, and Qtopia (QPE) is only opened at the last stage of the boot.
Because INIT=/LINUXRC is available on the default kernel command line, the first program that runs after the file system is mounted is the LINUXRC under the root directory. This is a link to/bin/busybox, which means that the first program that runs after the system is the BusyBox itself. In this case, BusyBox will first attempt to parse/etc/inittab to obtain further initialization configuration information (refer to the Parse_inittab () function in BusyBox source init/init.c). In fact, Root_qtopia does not/etc/inittab this configuration file, according to BusyBox logic, it will generate the default configuration (partial):
static void Parse_inittab (void)
{
#if Enable_feature_use_inittab
Char *token[4];
parser_t *parser = Config_open2 ("/etc/inittab", Fopen_for_read);

if (parser = = NULL)
#endif
{


New_init_action (Ctrlaltdel, "reboot", "" ");

New_init_action (SHUTDOWN, "Umount-a-R", "");

if (Enable_swaponoff)
New_init_action (SHUTDOWN, "swapoff-a", "" ");

New_init_action (RESTART, "Init", "");

New_init_action (Askfirst, Bb_default_login_shell, "");
Todo:vc_1 instead of "" "?", "is console, Cttyproblems, angry users
New_init_action (Askfirst, Bb_default_login_shell, vc_2);
New_init_action (Askfirst, Bb_default_login_shell, vc_3);
New_init_action (Askfirst, Bb_default_login_shell, vc_4);

New_init_action (Sysinit, Init_script, "");
Return
}
......
One of the most important of these is that New_init_action (Sysinit, Init_script, "") also determines that the script that is initialized after that is init_script defined value. The default value for this macro is "/etc/init.d/rcs".
Here is the content of/etc/init.d/rcs in the file system, which is also the focus of our analysis.

#! /bin/sh

Path=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
Runlevel=s
Prevlevel=n
Umask 022
Export PATH runlevel Prevlevel

#
# Trap Ctrl-c &c only in this shell so we caninterrupt subprocesses.
#
Trap ":" INT QUIT TSTP
/bin/hostname Friendlyarm

/bin/mount-n-T proc None/proc
/bin/mount-n-T Sysfs None/sys
/bin/mount-n-T Usbfs none/proc/bus/usb
/bin/mount-t Ramfs None/dev

Echo/sbin/mdev >/proc/sys/kernel/hotplug
/sbin/mdev-s
/bin/hotplug

# mounting File system specified In/etc/fstab
Mkdir-p/dev/pts
Mkdir-p/DEV/SHM
/bin/mount-n-T devpts none/dev/pts-o mode=0622
/bin/mount-n-T Tmpfs tmpfs/dev/shm
/bin/mount-n-T Ramfs none/tmp
/bin/mount-n-T Ramfs None/var
Mkdir-p/var/empty
Mkdir-p/var/log
Mkdir-p/var/lock
Mkdir-p/var/run
Mkdir-p/var/tmp

/sbin/hwclock-s

Syslogd
/etc/rc.d/init.d/netd start
echo "" >/dev/tty1
echo "Starting networking ..." >/dev/tty1
Sleep 1
/ETC/RC.D/INIT.D/HTTPD start
echo "" >/dev/tty1
echo "Starting Web server ..." >/dev/tty1
Sleep 1
/etc/rc.d/init.d/leds start
echo "" >/dev/tty1
echo "Starting LEDs service ..." >/dev/tty1
echo ""
Sleep 1

/sbin/ifconfig Lo 127.0.0.1
/etc/init.d/ifconfig-eth0

/bin/qtopia &
echo "" >/dev/tty1
echo "Starting Qtopia, please waiting ..." >/dev/tty1
Here's a one-on-one analysis:
1. Start the environment to set the necessary environment variables;
Path=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:runlevel=sprevlevel=n umask 022 Export PATH runlevel prevlevel
2. Set the machine name;
/bin/hostname Friendlyarm
3. Mount the "virtual" file system,
/bin/mount-n-T proc None/proc
/bin/mount-n-T Sysfs None/sys
/bin/mount-n-T Usbfs none/proc/bus/usb
/bin/mount-t Ramfs None/dev
Here is Mount/proc,/sys, and mount a ramfs on the/dev directory, equivalent to "overwrite" the read/dev directory on the original nandflash with a writable empty SDRAM.
It is important to note that/sys and Ramfs/dev are the keys to creating the device nodes correctly. For the 2.6.29 kernel, there is no DEVFS support, the creation of a device node can only be done by the file system in two ways:
1) before making the file system image, use Mknod to manually create all (including possible) device nodes in the system and make the node files into the file system image.
2) in the file system initialization process, through the/sys directory output information, in the/dev directory in the dynamic creation of the system is currently the actual device node.
Obviously, Method 1) has great limitations, limited to the situation of no device dynamic increase or decrease, not suitable for many equipment hot-plug situation, such as U disk, SD card and so on. Method 2) is the current practice of Linux on most PCs (based on UDEV implementations). There are two prerequisites for this approach:/sys directory mount and a writable/dev directory.
That's why we need to mount/sys and Ramfs in the/dev directory here. In fact, this approach was first designed for hot-swappable, and you can understand that when the system starts up, all the devices are "plugged in" all of a sudden.
One thing to note here is that before the file system initializes, there must be a device node in the original/dev directory:/dev/console.
4. Hot Swap Supported
Echo/sbin/mdev >/proc/sys/kernel/hotplug
/sbin/mdev–s
/bin/hotplug
These are some of the two things I said above:
1) Establish the necessary device node in the/dev directory through mdev-s;
2) The HotPlug handler of the kernel is Mdev, that is, when the device is hot-swappable, the Mdev receives messages from the kernel and responds accordingly, such as mounting a USB flash drive.
For Mdev, it is important to note that there is a/etc/mdev.conf file in the file system that contains the configuration information for Mdev. With this file, we can customize the names or links of some device nodes to meet specific needs. This is the content of mdev.conf in Rootqtopia:

# system All-writabledevices
Full 0:0 0666
Null 0:0 0666
PTMX 0:0 0666
Random 0:0 0666
TTY 0:0 0666
Zero 0:0 0666

# Console Devices
tty[0-9]* 0:5 0660
vc/[0-9]* 0:5 0660

# Serial Port Devices
S3c2410_serial00:5 0666 =TTYSAC0
S3c2410_serial10:5 0666 =ttysac1
S3c2410_serial20:5 0666 =TTYSAC2
S3c2410_serial30:5 0666 =TTYSAC3

# Loop devices
loop[0-9]* 0:0 0660 =loop/

# I²c Devices
i2c-0 0:0 0666 =i2c/0
I2c-1 0:0 0666 =I2C/1

# Frame Buffer Devices
FB[0-9] 0:0 0666

# Input Devices
Mice 0:0 0660 =input

mouse.* 0:0 0660 =input/
event.* 0:0 0660 =input/
ts.* 0:0 0660 =input/

# RTC Devices
RTC0 0:0 0644 >RTC
Rtc[1-9] 0:0 0644

# Misc Devices
MMCBLK0P1 0:0 0600 =sdcard*/bin/hotplug.sh
SDA1 0:0 0600 =udisk */bin/hotplug.sh
As can be seen, the original serial port driver registered device name is S3C2410_SERIAL0,S3C2410_SERIAL1 and S3c2410_serial2, and Mdev will be in the/dev directory corresponding to generate TTYSAC0, TtySAC1 and ttySAC2 to conform to the application's habit of serial device names.
Similarly,/dev/sdcard and/dev/udisk always point to the first partition of the SD card and the USB flash drive respectively. (So, with those who do not have the partition table SD card or USB flash drive Brothers know the reason ...) )
5. Mount some other common file systems
# mounting File system specified In/etc/fstab
Mkdir-p/dev/pts
Mkdir-p/DEV/SHM
/bin/mount-n-T devpts none/dev/pts-o mode=0622
/bin/mount-n-T Tmpfs tmpfs/dev/shm
/bin/mount-n-T Ramfs none/tmp
/bin/mount-n-T Ramfs None/var
Mkdir-p/var/empty
Mkdir-p/var/log
Mkdir-p/var/lock
Mkdir-p/var/run
Mkdir-p/var/tmp
As noted in the note, this is used to mount other commonly used file systems and create the necessary directories in the/var directory (also Ramfs, writable).
6. Set the system time
/sbin/hwclock-s
From the hardware RTC, but there seems to be a problem. The next step is to start the system service, including log record, network, Httpserver and custom "marquee service" ...
"Additional Notes on mdev.conf"
# Misc Devices
Mmcblk0p1 0:0 0600 =sdcard */bin/hotplug
SDA1 0:0 0600 =udisk */bin/hotplug
This configuration means that when the SD card or USB stick is inserted/unplugged, the message is passed to the custom hot-swappable handler,/bin/hotplug.
This app is a friendly arm developed for automatic mounting of removable devices, is currently SD card and U disk. Its logic is simple, the SD card or the first partition of the USB stick as a fat/fat32 mount to/sdcard or/udisk.
But this also brings a problem, when the SD card or USB flash drive does not have a partition table or the first partition is not fat/fat32 format, it will not play, the brothers should be careful:)
7. Start a range of services:
Syslogd
/etc/rc.d/init.d/netd start
echo "" >/dev/tty1
echo "Starting networking ..." >/dev/tty1
Sleep 1
/ETC/RC.D/INIT.D/HTTPD start
echo "" >/dev/tty1
echo "Starting Web server ..." >/dev/tty1
Sleep 1
/etc/rc.d/init.d/leds start
echo "" >/dev/tty1
echo "Starting LEDs service ..." >/dev/tty1
echo ""
Sleep 1
n syslog-for logging kernel and application debug information
N Netd-inetd, a gatekeeper process for launching various network-related services
n Httpd-http Server caretaker process
N leds-Marquee Caretaker process
Where the inetd configuration file is/etc/inetd.conf, which is the file content:

#/etc/inetd.conf:see inetd (8) for furtherinformations.
echo Stream TCP nowait root internal
echo dgram UDP wait root internal
Daytime stream TCP nowait root internal
Daytime Dgram UDP Wait root internal
Time stream TCP nowait root internal
Time Dgram UDP Wait root internal

# these is standard services.
#
FTP Stream TCP nowait root/usr/sbin/ftpd/usr/sbin/ftpd
Telnet Stream TCP nowait root/usr/sbin/telnetd/usr/sbin/telnetd-i
As you can see, there are two network services launched here:
1) FTP Server and
2) Telnet Server.
For specific information such as ports and protocols for network services, refer to/etc/services,/etc/protocol.
8. Configure the network device (NIC)
/sbin/ifconfig Lo 127.0.0.1/etc/init.d/ifconfig-eth0:
1) Set the native loopback address to 127.0.0.1
2) Run the NIC setup script/etc/init.d/ifconfig-eth0
This is/etc/init.d/ifconfig-eth0 's content, adding some of my notes
#!/bin/sh
Echo-n Try to bring eth0 interfaceup......>/dev/ttysac0
#判断/etc/eth0-setting file exists
if [-f/etc/eth0-setting]; Then
#读取配置文件信息
Source/etc/eth0-setting
#如果根文件系统为nfs, the NIC has been configured OK, there is nothing to configure
If Grep-q "^/dev/root/nfs"/ETC/MTAB; Then echo-n NFS root ... >/dev/ttysac0
#否则, configure the NIC with the Ifconfig command according to the Mac, IP, mask and gateway in the configuration file
Else
Ifconfig eth0 Down
ifconfig eth0 hw ether $MAC
Ifconfig eth0 $IP netmask $Mask up
Route add default GW $Gateway fi
#将配置文件中的DNS设置写入/etc/resolv.conf Make it effective
echo nameserver $DNS >/etc/resolv.conf
#配置文件不存在, use the default configuration else
#如果根文件系统为nfs, the NIC has been configured OK, there is nothing to configure
If Grep-q "^/dev/root/nfs"/ETC/MTAB; Then
Echo-n NFS root ... >/dev/ttysac0
Else
#将网卡的IP地址设定为192.168.1.230
/sbin/ifconfig eth0 192.168.1.230 netmask 255.255.255.0 up
Fi
Fi
echo Done >/dev/ttysac0
As you can see, automatic recognition of NFS is accomplished by judging if there are NFS Mount records in the/etc/mtab.
This is the/etc/eth0-settings file in the root Qtopia file system:
ip=192.168.1.230
mask=255.255.255.0
gateway=192.168.1.1
dns=192.168.1.1
Mac=08:90:90:90:90:90
Finally, finally, start the Qtopia GUI environment
/bin/qtopia &
echo "" >/dev/tty1
echo "Starting Qtopia, please waiting ..." >/dev/tty1
As you can see, this qtopia is started by running/bin/qtopia. In fact,/bin/qtopia is also a script, its task is to set Qtopia to run the necessary environment, finally by calling Qpe executable file really start Qtopia. This is the whole content of it, and I added some notes:

#!/bin/sh

Export Tslib_tsdevice=/dev/input/event0
Export tslib_conffile=/usr/local/etc/ts.conf
Export Tslib_plugindir=/usr/local/lib/ts
Export tslib_calibfile=/etc/pointercal
Export Qtdir=/opt/qtopia
Export Qpedir=/opt/qtopia
Export path= $QTDIR/bin: $PATH
Exportld_library_path= $QTDIR/lib:/usr/local/lib: $LD _library_path


Ts_info_file=/sys/devices/virtual/input/input0/uevent
If [-E $TS _info_file-a "/bin/grep-q touchscreen < $TS _info_file"]; Then
Export qws_mouse_proto= "Tpanel:/dev/input/event0usb:/dev/input/mice"
If [-e/etc/pointercal-a!-s/etc/pointercal]; Then
Rm/etc/pointercal
Fi
Else
Export qws_mouse_proto= "Usb:/dev/input/mice"
>/etc/pointercal
Fi
Unset ts_info_file

Export Qws_keyboard=tty:/dev/tty1
Export KDEDIR=/OPT/KDE

Export Home=/root

EXEC $QPEDIR/bin/qpe 1>/dev/null2>/dev/null
#!/bin/sh
# (1) Tslib environment variable settings, including touchscreen device file, tslib configuration file, tslibplug-in location and touchscreen calibration data file
Export Tslib_tsdevice=/dev/input/event0
Export tslib_conffile=/usr/local/etc/ts.conf
Export Tslib_plugindir=/usr/local/lib/ts
Export tslib_calibfile=/etc/pointercal
# (2) Qtopia environment variable setting, set Qtopia main file location
Export Qtdir=/opt/qtopia
Export Qpedir=/opt/qtopia
# (3) Set path and Ld_library_path to include Qtopia executable files and shared library files for Qtopia to run correctly
Export path= $QTDIR/bin: $PATH
Exportld_library_path= $QTDIR/lib:/usr/local/lib: $LD _library_path
# (4) Qtopia automatically identify touchscreen and USB mouse by judging if the/sys/devices/virtual/input/input0/uevent contains touchscreen information
Ts_info_file=/sys/devices/virtual/input/input0/uevent
If [-E $TS _info_file-a "/bin/grep-q touchscreen < $TS _info_file"]; Then
Export qws_mouse_proto= "Tpanel:/dev/input/event0usb:/dev/input/mice"
If [-e/etc/pointercal-a!-s/etc/pointercal]; Then
Rm/etc/pointercal
Fi
Else
Export qws_mouse_proto= "Usb:/dev/input/mice" >/etc/pointercal
Fi
Unset ts_info_file
Export Qws_keyboard=tty:/dev/tty1export Kdedir=/opt/kde
Export Home=/root
# (5) real start Qtopia by calling/opt/qtopia/bin/qpe
EXEC $QPEDIR/bin/qpe 1>/dev/null2>/dev/null
To this end, the entire process of file system initialization to the final start of the Qtopiagui environment is over. As you can see, the friendly arm of the "little secret" is actually here, it is very simple: as long as we can calm down to look at the script carefully, look at the source code, coupled with some knowledge of the background, to figure out an embedded system is so simple.


Usually/LINUXRC this file only in
1. Use of initial Ramdisk (INITRD)
2. INIT=/LINUXRC is specified on the kernel command line
In both cases, the mini2440 Root_qtopia belongs to case 2),
In Root_qtopia,/LINUXRC is a symbolic link to/bin/busybox, which means that the entire file system's entry becomes the main () function of BusyBox. BusyBox supports this way to initiate initialization of the busybox itself and the entire file system.

"Reprint" Mini2440 Boot configuration file description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.