Http://hi.baidu.com/396954504/blog/item/8c391513eb8d202fdc54010a.html
For the Startup Process of the latest root_qtopia File System of mini2440, I have made some simple analysis here and shared some experiences with you. Please also point out the shortcomings in time.
In fact, although the root _ qtopia File System GUI is based on qtopia, the initialization and startup process is mostly completed by busybox, and qtopia (qpe) is only enabled at the final stage of startup.
The default kernel command line contains init =/linuxrc. Therefore, after the file system is mountedProgramIs the linuxrc in the root directory. This is a link to/bin/busybox. That is to say, the first program running after the system is started is busybox itself.
In this case, busybox first tries to parse/etc/inittab to obtain further Initialization Configuration Information (refer to busyboxSource codeThe parse_inittab () function in init/init. C ). In fact, root_qtopia does not have the/etc/inittab configuration file. According to the busybox logic, it will generate the default configuration.
Copy code
-
- 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
-
- {
-
- /* No inittab file -- set up some default behavior */
-
- /* Reboot on CTRL-alt-del */
-
- New_init_action (ctrlaltdel, "reboot ","");
-
- /* Umount all filesystems on halt/reboot */
-
- New_init_action (shutdown, "umount-a-r ","");
-
- /* Swapoff on halt/reboot */
-
- If (enable_swaponoff)
-
- New_init_action (shutdown, "swapoff-","");
-
- /* Prepare to restart init when a quit is already ed */
-
- New_init_action (restart, "init ","");
-
- /* Askfirst shell on tty1-4 */
-
- New_init_action (askfirst, bb_default_login_shell ,"");
-
- // Todo: vc_1 instead ""? "" Is console-> ctty problems-> 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 );
-
- /* Sysinit */
-
- New_init_action (sysinit, init_script ,"");
-
- Return;
-
- }
Among them, the most important one is new_init_action (sysinit, init_script, ""), which determines that the subsequent initialization script is the value defined by init_script. The default value of this macro is "/etc/init. d/RCS ".
The following is the content of/etc/init. d/RCS in the file system, which is also the focus of our analysis.
Copy code
-
- #! /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 can interrupt 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/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
-
-
Next we will analyze them one by one:
Copy code
- Path =/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
- Runlevel = s
- Prevlevel = N
- Umask 022
- Export path runlevel prevlevel
Set necessary environment variables for the startup environment;
Copy code
- /Bin/hostname friendlyarm
Set the machine name;
Copy code
- /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
Mount the "virtual" file system,/proc,/sys, and mount a ramfs in the/dev directory, it is equivalent to overwrite the read-only/dev directory on the original NAND Flash with a writable blank SDRAM.
Note that/sys and/dev with ramfs mounted are the key to creating a device node correctly. For kernel 2.6.29, devfs is no longer supported. To create a device node, there are only two ways to complete it by the file system:
1) SystemCompositionBefore creating a system image, use mknod to manually create all (including possible) device nodes in the system and add these node files to the file system image together;
2) during file system initialization, the actual device nodes in the system are dynamically created under the/dev directory based on the information output in the/sys directory.
Obviously, method 1) has great limitations. It is limited to scenarios where no devices are dynamically increased or decreased. It is not applicable to hot swapping of many devices, such as USB flash drives and SD cards. Method 2) is the current practice of Linux on most PCs (based on udev ). This method has two prerequisites: mounting the/sys directory and a writable/dev directory. This is why we need to mount/sys and ramfs in the/dev directory. In fact, this method was first designed for hot swapping. You can understand that when the system is started, all devices are "inserted" at once.
One thing to note here is that before the file system initialization runs here, the original/dev directory must have a device node:/dev/console.
Okay. Write it here today and continue tomorrow :)
Copy code
- Echo/sbin/mdev>/proc/sys/kernel/hotplug
- /Sbin/mdev-S
- /Bin/hotplug
These are two things I mentioned above: 1) create necessary device nodes in the/dev directory through mdev-S; 2) Set hotplug handler of the kernel to mdev, that is, when the device is hot-swappable, mdev receives messages from the kernel and responds accordingly, such as mounting a USB flash drive.
For mdev, note that the file system contains the/etc/mdev. conf file, which contains the mdev configuration information. Through 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 root qtopia:
Copy code
-
- # System all-writable Devices
-
- Full 0: 0 0666
-
- Null 0: 0 0666
-
- Ptmx 0: 0 0666
-
- Random 0: 0 0666
- Tty 0666
-
- Zero 0: 0 0666
-
-
- # Console Devices
-
- Tty [0-9] * 0: 5 0660
-
- VC/[0-9] * 0: 5 0660
-
-
- # Serial Port Devices
-
- S3c2410_serial0 0: 5 0666 = ttysac0
-
- S3c2410_serial1 0: 5 0666 = ttysac1
-
- Maid = ttysac2
- S3c2410_seri_3 0666 = ttysac3
-
-
- # Loop Devices
-
- Loop [0-9] * 0: 0 0660 = loop/
-
-
- # I2C Devices
-
- I2c-0 0: 0 0666 = I2C/0
-
- I2c-1 0: 0 0666 = I2C/1
-
-
- # Frame buffer devices
-
- FB [0-9]: 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 0644
-
-
- # MISC Devices
- Mmcblk0p1 0: 0 0600 = sdcard */bin/hotplug
-
- Sda1 0-0 0600 = udisk */bin/hotplug
We can see that the device names originally registered with the serial port driver are s3c2410_serial0, s3c2410_serial1 and s3c2410_serial, while mdev generates ttysac0 in the/dev directory, ttysac1 and ttysac2 conform to the application's preference for serial device names. Similarly,/dev/sdcard and/dev/udisk always point to the first partition of the SD card and USB disk respectively. (So, if you use an SD card or USB flash disk that does not have a partition table, you can find out why ...)
Copy code
- # 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/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 mentioned in the comments, this is used to mount other common file systems and create necessary directories under the/var directory (also ramfs, writable.
Copy code
- /Sbin/hwclock-S
Used to set the system time, obtained from the hardware RTC, but it seems that there is a problem
The next step is to start the system service, including log record, network, HTTP server, and custom "marquee service "...
Continue Tomorrow :)
In mdev. conf
Copy code
- # MISC Devices
- Mmcblk0p1 0: 0 0600 = sdcard */bin/hotplug
- Sda1 0-0 0600 = udisk */bin/hotplug
Some additional instructions:
When the SD card or USB flash drive is inserted/unplugged, the message is sent to the custom hot swappable handler,/bin/hotplug. this program is developed in a friendly way to automatically mount removable devices. Currently, it is an SD card and a USB flash drive. The logic is very simple. Mount the first partition of the SD card or USB flash drive as fat/FAT32 to/sdcard or/udisk.
But this also brings about a problem. When there is no partition table on the SD card or USB flash disk or the first partition is not in the fat/FAT32 format, it won't work anymore. You should be careful :)
This is the binary data segment in/bin/hotplug. You can see the logic I mentioned above:
201710d0h: 52 00 00 00 00 4D 00 00 00 00 00 41 00 00 00; r... m...
201710e0h: 43 00 00 00 54 00 00 49 00 00 00 4f 00 00 00; c... t... I... o...
201710f0h: 4E 00 00 00 00 00 00 00 00 00 45 00 00 00 00; n ...... D ...... E...
00001100 H: 56 00 00 00 4E 00 00 00 41 00 00 00 4D 00 00; V... n... a... m...
00001110 H: 45 00 00 00 00 00 00 61 00 00 00 64 00 00 00; e ...... a ...... d...
00001120 H: 64 00 00 00 00 00 00 72 00 00 00 65 00 00 00; d... r... e...
00001130 H: 6d 00 00 00 6f 00 00 00 00 00 00 65 00 00 00; m... o... V... e...
00001140 H: 00 00 00 00 2f 00 00 00 64 00 00 00 65 00 00;.../... d...
00001150 H: 76 00 00 00 2f 00 00 00 00 00 00 64 00 00 00; V.../... u... d...
00001160 H: 69 00 00 00 73 00 00 00 6B 00 00 00 00 00; I... s... k .......
00001170 H: 2f 00 00 00 64 00 00 00 65 00 00 00 76 00 00 00;/... d... e... V...
00001180 H: 2f 00 00 00 73 00 00 00 64 00 00 00 00 00;/... s... d... c...
00001190 H: 61 00 00 00 72 00 00 00 64 00 00 00 00 00; A... r... d .......
201711a0h: 4D 00 00 00 44 00 00 00 00 00 00 56 00 00 00; m... d... e... V...
201711b0h: 00 00 00 00 00 6D 00 00 00 00 00 00 00 00 00...
201711c0h: 62 00 00 00 00 6C 00 00 00 6B 00 00 30 00 00 00; B... l... k... 0...
Listen 11d0h: 70 00 00 00 31 00 00 00 00 00 73 00 00 00 00; P... 1 ...... S...
201711e0h: 64 00 00 00 61 00 00 00 00 00 00 00 00 00 00; D ...... a ...... 1 .......
201711f0h: 76 00 00 00 00 66 00 00 61 00 00 00 74 00 00 00; V... F... a... t...
00001200 H: 00 00 00 00 2f 00 00 00 64 00 00 00 65 00 00;.../... d...
00001210 H: 76 00 00 00 2f 00 00 00 00 00 00 61 00 00 00; V.../... w......
00001220 H: 74 00 00 00 63 00 00 00 68 00 00 00 64 00 00; t... c... h... d...
00001230 H: 6f 00 00 00 00 00 00 00 00 9A B2 01 81; o... g .?
00001240 H: B0 ;?
Copy code
-
- 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
Start a series of services:
Syslog-used to record kernel and application debug information
Netd-inetd: A guard process that mounts and starts various network-related services.
Httpd-HTTP server guard Process
LEDs-O & M Process
The configuration file of inetd is/etc/inetd. conf, which is the file content.
Copy code
-
- #/Etc/inetd. conf: see inetd (8) for further informations.
-
- 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 are standard services.
-
- #
-
- Ftp stream tcp Nowait root/usr/sbin/ftpd
- Telnet stream tcp Nowait root/usr/sbin/telnetd-I
We can see that there are two network services started here: 1) FTP server and 2) Telnet server. For more information about network service ports and protocols, see/etc/services,/etc/protocols.
Next
Copy code
- /Sbin/ifconfig lo 127.0.0.1
- /Etc/init. d/ifconfig-eth0
Configure the network device (NIC ):
1) set the local 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 content, added some of my comments
Copy code
-
- #! /Bin/sh
-
-
- Echo-N try to bring eth0 interface up...>/dev/ttysac0
-
-
- # Determine whether the/etc/eth0-setting file exists
-
- If [-F/etc/eth0-setting]; then
- # Reading configuration file information
-
- Source/etc/eth0-setting
-
-
- # If the root file system is NFS, it indicates that the NIC has been configured with OK. No configuration is required here.
-
- If grep-Q "^/dev/root/nfs"/etc/mtab; then
-
- Echo-n nfs root...>/dev/ttysac0
-
- # Otherwise, configure the NIC according to the Mac, IP, mask, and gateway commands 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
-
-
- # Write the DNS settings in the configuration file to/etc/resolv. conf to take effect
-
- Echo nameserver $ DNS>/etc/resolv. conf
-
- # The configuration file does not exist. Use the default configuration
-
- Else
-
-
- # If the root file system is NFS, it indicates that the NIC has been configured with OK. No configuration is required here.
- If grep-Q "^/dev/root/nfs"/etc/mtab; then
-
- Echo-n nfs root...>/dev/ttysac0
-
- Else
-
- # Set the IP address of the NIC to 192.168.1.230
-
- /Sbin/ifconfig eth0 192.168.1.230 netmask 255.255.255.0 up
-
- Fi
-
- Fi
-
-
- Echo done>/dev/ttysac0
We can see that automatic identification of NFS is implemented by checking whether NFS mounting records exist in/etc/mtab.
This is the/etc/eth0-settings file in the root qtopia File System
Copy code
- 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, start the qtopia GUI environment.
Copy code
- /Bin/qtopia &
- Echo "">/dev/tty1
- Echo "Starting qtopia, please waiting...">/dev/tty1
We can see that qtopia is started by running/bin/qtopia. In fact,/bin/qtopia is also a script. Its task is to set the necessary environment for qtopia to run, and finally start qtopia by calling the qpe executable file. This is all about it. I added some notes:
Copy code
-
- #! /Bin/sh
-
-
- # Tslib environment variable settings, including the touchscreen device file, tslib configuration file, tslib plug-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
-
- # Set the qtopia environment variable and set the qtopia main file location
-
- Export qtdir =/opt/qtopia
-
- Export qpedir =/opt/qtopia
-
- # Set path and LD_LIBRARY_PATH to include the executable files and shared library files of qtopia, so that qtopia can run correctly.
-
- Export Path = $ qtdir/bin: $ path
-
- Export LD_LIBRARY_PATH = $ qtdir/lib:/usr/local/lib: $ LD_LIBRARY_PATH
-
-
- # Qtopia automatically recognizes touchscreen and USB mouse by checking whether touchscreen information is included in/sys/devices/virtual/input/input0/uevent.
-
- 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-! -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
-
-
- # Start qtopia by calling/opt/qtopia/bin/qpe
-
- Exec $ qpedir/bin/qpe 1>/dev/null 2>/dev/null
So far, the entire process from the file system initialization to the final launch of the qtopia GUI environment has ended. You can see that the "little secret" of the friendly arm is actually here, it's easy to say: as long as you can calm down and take a closer look at the script and look at the sourceCodeWith some background knowledge, it is easy to understand an embedded system.
Reference
Reference: qiu1123, 23rd floor, published on:
Is the linuxrc file useless? Can you give me a brief introduction?
Normally, the file/linuxrc is only available in
1. Initial ramdisk (initrd) is used)
2. init =/linuxrc is specified on the kernel command line.
This is useful in both cases. root_qtopia of mini2440 belongs to situation 2). In root_qtopia,/linuxrc is a symbolic link pointing to/bin/busybox, that is, the portal of the entire file system becomes the main () function of busybox. busybox supports this method to start the initialization of busybox itself and the entire file system.