Mini2440 root_qtopia File System Startup Process Analysis

Source: Internet
Author: User

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

  1. Static void parse_inittab (void)
  2. {
  3. # If enable_feature_use_inittab
  4. Char * token [4];
  5. Parser_t * parser = config_open2 ("/etc/inittab", fopen_for_read );
  6. If (parser = NULL)
  7. # Endif
  8. {
  9. /* No inittab file -- set up some default behavior */
  10. /* Reboot on CTRL-alt-del */
  11. New_init_action (ctrlaltdel, "reboot ","");
  12. /* Umount all filesystems on halt/reboot */
  13. New_init_action (shutdown, "umount-a-r ","");
  14. /* Swapoff on halt/reboot */
  15. If (enable_swaponoff)
  16. New_init_action (shutdown, "swapoff-","");
  17. /* Prepare to restart init when a quit is already ed */
  18. New_init_action (restart, "init ","");
  19. /* Askfirst shell on tty1-4 */
  20. New_init_action (askfirst, bb_default_login_shell ,"");
  21. // Todo: vc_1 instead ""? "" Is console-> ctty problems-> angry users
  22. New_init_action (askfirst, bb_default_login_shell, vc_2 );
  23. New_init_action (askfirst, bb_default_login_shell, vc_3 );
  24. New_init_action (askfirst, bb_default_login_shell, vc_4 );
  25. /* Sysinit */
  26. New_init_action (sysinit, init_script ,"");
  27. Return;
  28. }

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

  1. #! /Bin/sh
  2. Path =/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
  3. Runlevel = s
  4. Prevlevel = N
  5. Umask 022
  6. Export path runlevel prevlevel
  7. #
  8. # Trap CTRL-C & C only in this shell so we can interrupt subprocesses.
  9. #
  10. Trap ":" int quit tstp
  11. /Bin/hostname friendlyarm
  12. /Bin/Mount-n-t proc NONE/proc
  13. /Bin/Mount-n-t sysfs NONE/sys
  14. /Bin/Mount-n-t usbfs NONE/proc/bus/USB
  15. /Bin/Mount-T ramfs NONE/dev
  16. Echo/sbin/mdev>/proc/sys/kernel/hotplug
  17. /Sbin/mdev-S
  18. /Bin/hotplug
  19. # Mounting file system specified in/etc/fstab
  20. Mkdir-P/dev/PTS
  21. Mkdir-P/dev/SHM
  22. /Bin/Mount-n-t devpts NONE/dev/PTS-o mode = 0622
  23. /Bin/Mount-n-t tmpfs/dev/SHM
  24. /Bin/Mount-n-t ramfs NONE/tmp
  25. /Bin/Mount-n-t ramfs NONE/var
  26. Mkdir-P/var/empty
  27. Mkdir-P/var/log
  28. Mkdir-P/var/lock
  29. Mkdir-P/var/run
  30. Mkdir-P/var/tmp
  31. /Sbin/hwclock-S
  32. Syslogd
  33. /Etc/rc. d/init. d/netd start
  34. Echo "">/dev/tty1
  35. Echo "Starting networking...">/dev/tty1
  36. Sleep 1
  37. /Etc/rc. d/init. d/httpd start
  38. Echo "">/dev/tty1
  39. Echo "Starting web server...">/dev/tty1
  40. Sleep 1
  41. /Etc/rc. d/init. d/LEDs start
  42. Echo "">/dev/tty1
  43. Echo "Starting LEDs service...">/dev/tty1
  44. Echo ""
  45. Sleep 1
  46. /Sbin/ifconfig lo 127.0.0.1
  47. /Etc/init. d/ifconfig-eth0
  48. /Bin/qtopia &
  49. Echo "">/dev/tty1
  50. Echo "Starting qtopia, please waiting...">/dev/tty1

Next we will analyze them one by one:

Copy code

    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

Set necessary environment variables for the startup environment;

Copy code

    1. /Bin/hostname friendlyarm

Set the machine name;

Copy code

    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

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

    1. Echo/sbin/mdev>/proc/sys/kernel/hotplug
    2. /Sbin/mdev-S
    3. /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

  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 0666
  7. Zero 0: 0 0666
  8. # Console Devices
  9. Tty [0-9] * 0: 5 0660
  10. VC/[0-9] * 0: 5 0660
  11. # Serial Port Devices
  12. S3c2410_serial0 0: 5 0666 = ttysac0
  13. S3c2410_serial1 0: 5 0666 = ttysac1
  14. Maid = ttysac2
  15. S3c2410_seri_3 0666 = ttysac3
  16. # Loop Devices
  17. Loop [0-9] * 0: 0 0660 = loop/
  18. # I2C Devices
  19. I2c-0 0: 0 0666 = I2C/0
  20. I2c-1 0: 0 0666 = I2C/1
  21. # Frame buffer devices
  22. FB [0-9]: 0 0666
  23. # Input devices
  24. Mice 0: 0 0660 = input/
  25. Mouse. * 0: 0 0660 = input/
  26. Event. * 0: 0 0660 = input/
  27. TS. * 0-0 0660 = input/
  28. # RTC Devices
  29. Rtc0 0: 0 0644> rtc
  30. RTC [1-9]: 0 0644
  31. # MISC Devices
  32. Mmcblk0p1 0: 0 0600 = sdcard */bin/hotplug
  33. 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

    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/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 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

    1. /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

    1. # MISC Devices
    2. Mmcblk0p1 0: 0 0600 = sdcard */bin/hotplug
    3. 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

  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
  10. /Etc/rc. d/init. d/LEDs start
  11. Echo "">/dev/tty1
  12. Echo "Starting LEDs service...">/dev/tty1
  13. Echo ""
  14. 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

  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. # These are standard services.
  9. #
  10. Ftp stream tcp Nowait root/usr/sbin/ftpd
  11. 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

    1. /Sbin/ifconfig lo 127.0.0.1
    2. /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

  1. #! /Bin/sh
  2. Echo-N try to bring eth0 interface up...>/dev/ttysac0
  3. # Determine whether the/etc/eth0-setting file exists
  4. If [-F/etc/eth0-setting]; then
  5. # Reading configuration file information
  6. Source/etc/eth0-setting
  7. # If the root file system is NFS, it indicates that the NIC has been configured with OK. No configuration is required here.
  8. If grep-Q "^/dev/root/nfs"/etc/mtab; then
  9. Echo-n nfs root...>/dev/ttysac0
  10. # Otherwise, configure the NIC according to the Mac, IP, mask, and gateway commands in the configuration file.
  11. Else
  12. Ifconfig eth0 down
  13. Ifconfig eth0 HW ether $ Mac
  14. Ifconfig eth0 $ IP netmask $ mask up
  15. Route add default GW $ Gateway
  16. Fi
  17. # Write the DNS settings in the configuration file to/etc/resolv. conf to take effect
  18. Echo nameserver $ DNS>/etc/resolv. conf
  19. # The configuration file does not exist. Use the default configuration
  20. Else
  21. # If the root file system is NFS, it indicates that the NIC has been configured with OK. No configuration is required here.
  22. If grep-Q "^/dev/root/nfs"/etc/mtab; then
  23. Echo-n nfs root...>/dev/ttysac0
  24. Else
  25. # Set the IP address of the NIC to 192.168.1.230
  26. /Sbin/ifconfig eth0 192.168.1.230 netmask 255.255.255.0 up
  27. Fi
  28. Fi
  29. 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

    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, start the qtopia GUI environment.

Copy code

    1. /Bin/qtopia &
    2. Echo "">/dev/tty1
    3. 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

  1. #! /Bin/sh
  2. # Tslib environment variable settings, including the touchscreen device file, tslib configuration file, tslib plug-in location, and touchscreen calibration data file
  3. Export tslib_tsdevice =/dev/input/event0
  4. Export tslib_conffile =/usr/local/etc/ts. conf
  5. Export tslib_plugindir =/usr/local/lib/TS
  6. Export tslib_calibfile =/etc/pointercal
  7. # Set the qtopia environment variable and set the qtopia main file location
  8. Export qtdir =/opt/qtopia
  9. Export qpedir =/opt/qtopia
  10. # Set path and LD_LIBRARY_PATH to include the executable files and shared library files of qtopia, so that qtopia can run correctly.
  11. Export Path = $ qtdir/bin: $ path
  12. Export LD_LIBRARY_PATH = $ qtdir/lib:/usr/local/lib: $ LD_LIBRARY_PATH
  13. # Qtopia automatically recognizes touchscreen and USB mouse by checking whether touchscreen information is included in/sys/devices/virtual/input/input0/uevent.
  14. Ts_info_file =/sys/devices/virtual/input/input0/uevent
  15. If [-e $ ts_info_file-a "/bin/grep-Q touchscreen <$ ts_info_file"]; then
  16. Export qws_mouse_proto = "tpanel:/dev/input/event0 USB:/dev/input/mice"
  17. If [-E/etc/pointercal-! -S/etc/pointercal]; then
  18. Rm/etc/pointercal
  19. Fi
  20. Else
  21. Export qws_mouse_proto = "USB:/dev/input/mice"
  22. >/Etc/pointercal
  23. Fi
  24. Unset ts_info_file
  25. Export qws_keyboard = TTY:/dev/tty1
  26. Export kdedir =/opt/KDE
  27. Export Home =/root
  28. # Start qtopia by calling/opt/qtopia/bin/qpe
  29. 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.

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.