/etc/init.d/rcs Analysis

Source: Internet
Author: User
Tags mkdir

As a result of INIT=/LINUXRC, the first program to run after the file system is mounted is the LINUXRC of the root directory, which is a link to/bin/busybox, that is, the first program to run after the system is the BusyBox itself.

BusyBox will first attempt to parse the/etc/inittab to obtain further initialization configuration information (refer to the Parse_inittab () function in the BusyBox source code init/init.c). In fact, there is no/etc/inittab this profile in Root_qtopia, and it will generate the default configuration according to BusyBox's bare metal. One of the most important, is new_init_action (Sysinit,init_script, ""), it is decided that the next initialization of the script is init_script defined value, the default value of this macro is "Etc/init.d/rcs."

The following is the content of the/etc/init.d/rcs in the file system and the focus of our analysis

1.path=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:

2.runlevel=s

3.prevlevel=n

4.umask 022

5.export PATH RunLevel Prevlevel

# #为启动环境设置必要的环境变量;

1./bin/hostname Friendlyarm

# #设置机器名字;

1./bin/mount-n-T proc None/proc

2./bin/mount-n-T Sysfs None/sys

3./bin/mount-n-T Usbfs none/proc/bus/usb

4./bin/mount-t Ramfs None/dev

# #挂载 the "virtual" file System "/proc" and "/sys", and mount a Ramfs in the/dev directory, which is equivalent to "overwrite" a writable empty SDRAM on the Nandflash read/dev directory on the original.

# #这里要注意的是,/sys and Mount Ramfs's/dev is the key to properly creating device nodes. For the 2.6.29 kernel, there is no DEVFS support, and the creation of a device node can only be done by the file system in two ways:

1 Make the file system mirror before the Mknod manually create all the system (including possible) device nodes, and 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 dynamically create the current actual device node in the system.

Obviously, Method 1 has a lot of limitations, limited to the device dynamic increase or decrease in the situation, not suitable for many devices hot plug the situation, such as U disk, SD card and so on. Method 2 is the practice of Linux on most PCs today (based on UDEV implementations). This approach has 2 prerequisites: a/sys directory mount and a writable/dev directory. That's why we need to mount/sys and Ramfs in the/dev directory, which is, in fact, designed for hot-swappable, and you can understand that when the system starts, all the devices are "plugged in" all of a sudden.

One thing to note here is that before file system initialization runs here, there must be a device node in the original/dev directory:/dev/console.

In fact, to understand the "program" This kind of thing, there is no good way, nothing more than 2 things, source code and script

1.echo/sbin/mdev>/proc/sys/kernel/hotplug

2./sbin/mdev-s

3./bin/hotplug

# #这几个就是用来完成上面所说的两个东西: 1) to create the necessary device nodes in/dev directory by mdev-s 2) to set the HotPlug handler of the kernel as Mdev, that is, when the device is hot-swappable, the Mdev accepts messages from the kernel and responds accordingly. such as Mount U disk.

For Mdev, it should be noted that there are/etc/mdev.conf files in the file system that contain MEDV configuration information. With this file, we can customize some of the device node names or links to meet specific needs. This is the content of mdev.conf in root qtopia:

1. #system all-writable Devices

2.full 0:0 0666

3.null 0:0 0666

4.PTMX 0:0 0666

5.random 0:0 0666

6.tty 0:0 0666

7.zero 0:0 0666

8.

9. #console Devices

10.tty[0-9]* 0:5 0660

11vc/[0-9]* 0:5 0660

12.
# Serial Port Devices
S3c2410_serial0 0:5 0666 =ttysac0
S3c2410_serial1 0:5 0666 =ttysac1
S3c2410_serial2 0:5 0666 =ttysac2
S3c2410_serial3 0:5 0666 =TTYSAC3
18. # Loop devices
loop[0-9]* 0:0 0660 =loop/
21st.
# I2C Devices
i2c-0 0:0 0666 =i2c/0
I2c-1 0:0 0666 =I2C/1
25.
# Frame Buffer Devices
FB[0-9] 0:0 0666
28.
# Input Devices
Mice 0:0 0660 =input/
mouse.* 0:0 0660 =input/
event.* 0:0 0660 =input/
ts.* 0:0 0660 =input/
64K
# RTC Devices
RTC0 0:0 0644 >RTC
Panax Rtc[1-9] 0:0 0644
38.
# Misc Devices

Mmcblk0p1 0:0 0600 =sdcard */bin/hotplug
SDA1 0:0 0600 =udisk */bin/hotplug

You can see that the original serial port driver registered device name is s3c2410_serial0, S3c2410_serial1 and
S3c2410_serial2, while Mdev corresponds to generating ttySAC0, ttySAC1 and ttySAC2 in the/dev directory to match
The custom of the application for serial device names. Similarly,/dev/sdcard and/dev/udisk always point to the SD card and
U disk's first partition. (So, with those who do not have the partition table SD card or U disk's brother know why ...) )


/etc/init.d/rcs content Analysis (2) August 20, 2010 10:13

1. #mounting File system specified In/etc/fstab

2.mkdir-p/dev/pts

3.mkdir-p/DEV/SHM

4./bin/mount-n-T devpts none/dev/pts-o mode=0622

5./bin/mount-n-T Tmpfs tmpfs/dev/shm
6./bin/mount-n-T Ramfs none/tmp
7./bin/mount-n-T Ramfs None/var

8.mkdir-p/var/empty

9.mkdir-p/var/log

10.mkdir-p/var/lock

11.mkdir-p/var/run

12.mkdir-p/var/tmp

As noted in the note, this is used to mount other common file systems, and in the/var directory (the same
Ramfs, writable) create the necessary directory.

1./sbin/hwclock-s

To set the system time, get it from the hardware RTC, to get the right time, you must first set the correct
Time (how to set up RTC see User manual instructions), the current friendly arm of the Development Board is not set when the actual time
, but the system defaults.

The next step is to start the system services, including log logs, networks, HTTP servers, and custom "marquee suits."
Service "...
1. syslogd
2./etc/rc.d/init.d/netd Start
3. echo "" >/dev/tty1 4. echo "Starting networking ..." >/dev/tty1
5. Sleep 1
6./etc/rc.d/init.d/httpd Start
7. Echo "" >/dev/tty1
8. Echo "Starting Web server ..." >/dev/tty1
9. Sleep 1
/etc/rc.d/init.d/leds start
echo "" >/dev/tty1
echo "Starting LEDs service ..." >/dev/tty1
echo ""
1

Start a series of services:
Syslog-For logging kernel and application debug information
NETD-INETD, a caretaker process that mounts various network-related services
Httpd-http Server caretaker Process
LEDs-The guard process of the Lantern Valley
Where the inetd configuration file is/etc/inetd.conf, which is the contents of the file
1. #/etc/inetd.conf:see inetd (8) for further informations.
2. Echo Stream TCP nowait root internal
3. echo dgram UDP wait root internal

4. Daytime stream TCP nowait root internal
5. Daytime Dgram UDP wait root internal
6. Time stream TCP nowait root internal
7. Time Dgram UDP wait root internal
8.
9. # These are standard services.
10. #
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, the network services started here are two: 1 FTP server and 2 telnet server. About the network
The service port and the Protocol and so on specific information, may refer to/etc/services,/etc/protocols

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

To configure a network device (NIC):
1) Set the local loop address for 127.0.0.1
2) Run the network card setup script/etc/init.d/ifconfig-eth0
This is the content of/etc/init.d/ifconfig-eth0, adding some of my comments
Copy Code
1. #!/bin/sh

2.
3. Echo-n Try to bring eth0 interface up......>/dev/ttysac0
4.
5. #判断/etc/eth0-setting file exists
6. if [-f/etc/eth0-setting]; Then
7. #读取配置文件信息
8. source/etc/eth0-setting
9.
#如果根文件系统为nfs, the network card has been configured OK, there is no need to configure any
One. If Grep-q "^/dev/root/nfs"/ETC/MTAB; Then
Echo-n NFS root ... >/dev/ttysac0
#否则, according to the Mac, IP, mask and gateway in the configuration file, configure the network card accordingly via the Ifconfig command
. else
Ifconfig eth0 Down
ifconfig eth0 hw ether $MAC
Ifconfig eth0 $IP netmask $Mask up
Route add default GW $Gateway
Fi
20.
#将配置文件中的DNS设置写入/etc/resolv.conf Make it effective
echo nameserver $DNS >/etc/resolv.conf

#配置文件不存在, using the default configuration
. else
25.
#如果根文件系统为nfs, the network card has been configured OK, there is no need to configure any
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.
64K
echo Done >/dev/ttysac0
As you can see, NFS Automatic identification is achieved by determining whether there is an NFS mount record in/etc/mtab.
This is the/etc/eth0-settings file in the root Qtopia file system

This is the/etc/eth0-settings file in the root Qtopia file system
Copy Code
1. ip=192.168.1.230
2. mask=255.255.255.0
3. gateway=192.168.1.1
4. dns=192.168.1.1
5. mac=08:90:90:90:90:90

Finally, finally, start the Qtopia GUI environment
Copy Code
1./bin/qtopia &
2. echo "" >/dev/tty1
3. 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, and finally through the call Qpe executable file really start
Qtopia. This is the whole story, and I added some comments:

1. #!/bin/sh

2.
3. #tslib environment variable settings, including touchscreen equipment files, tslib configuration files, Tslib plug-in locations and touchscreen calibration data files

4. Export Tslib_tsdevice=/dev/input/event0
5. Export tslib_conffile=/usr/local/etc/ts.conf
6. Export Tslib_plugindir=/usr/local/lib/ts
7. Export Tslib_calibfile=/etc/pointercal

8. #Qtopia environment variable settings, set the Qtopia main file location
9. Export Qtdir=/opt/qtopia
Export Qpedir=/opt/qtopia

#设定PATH and Ld_library_path to include Qtopia executables and shared library files to facilitate qtopia to run correctly
Export path= $QTDIR/bin: $PATH
Export ld_library_path= $QTDIR/lib:/usr/local/lib: $LD _library_path
14.

#通过判断/sys/devices/virtual/input/input0/uevent contains touchscreen information to make Qtopia automatically recognized touchscreen
and USB mouse
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/event0 Usb:/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

27.
Export Qws_keyboard=tty:/dev/tty1
Export KDEDIR=/OPT/KDE
30.
Export Home=/root
32.
#通过调用/opt/qtopia/bin/qpe really started Qtopia
EXEC $QPEDIR/bin/qpe 1>/dev/null 2>/dev/null

So far, the whole process of file system from initialization to final boot Qtopia GUI environment is over, everybody
It can be seen that the friendly arm of the "little secret" is actually here, at the very simple point: as long as we can calm down to seriously look
Look at the script, look at the source code, plus some background knowledge, figuring out an embedded system is so simple

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.