Customizes the Startup Program of the embedded Linux System

Source: Internet
Author: User
Tags network function

 

AbstractThe characteristics of an embedded system determine its specific functions, rather than being a general computer system. To develop embedded products based on the Linux operating system, you must customize the Startup Program. This article describes how to start a Linux operating system, how to add your own startup services to an embedded Linux system, and how to specify the main functional program to run after startup.
KeywordsEmbedded Linux boot program

1. concepts and features of embedded systems [1]
Reference a definition from the Association of Electrical Engineers IEE for embedded systems: an embedded system is a device used to control or monitor large-scale systems such as machines, devices, or factories. However, with the development of embedded systems, this definition became not very accurate. For example, small devices such as mobile phones, PDAs, and electronic dictionaries are controlled by internal embedded systems, but they cannot be called Large-Scale Systems.
I think it is more accurate to define some documents as follows: an embedded system is a combination of computer software and hardware. It is centered on applications, based on computer technology, and can be tailored to hardware and software, dedicated computer systems that meet strict requirements on functions, reliability, cost, volume, and power consumption in practical applications.
Embedded systems have the following features:
1. embedded systems are the product of combining advanced computer technology, semiconductor technology, and electronic technology with specific applications in various industries. That is to say, the embedded system is not as common as the general computer, but associated with specific applications to be applied. The embedded systems of each industry have different functions. Therefore, no company's operating system or processor can monopolize the market on the embedded system.
2. An embedded system provides a single function, which is intended for users, products, and specific applications. Generally, it only implements specific functions in a certain industry.
3. low cost, small size, low power consumption, and high reliability, with limited operation speed and storage capacity.
4. the embedded system itself is not capable of further development. It must be developed on the relevant development platform.
5. Fully automated operation cycle, which repeatedly executes a specific program
The soul of the embedded system should be its embedded operating system. This article uses embedded Linux, and the hardware base is based on x86 embedded motherboard. According to the characteristics of the above embedded system, in order to make the embedded system have the characteristics of a product or instrument, it is not allowed to enter the desktop system after boot like a general computer, instead, you need to run the specified service and a specific user application. This article will discuss how to enable Linux to execute specified services and run specific user programs after it is turned on.

Ii. Linux Startup Process
Let's take a look at the Linux system.Startup Process.When a boot program (such as lilo) loads a Linux kernel image and starts it, It initializes the kernel first, mainly to detect the entire hardware environment. After the kernel Initialization is complete, the system starts the INIT process, which is the first user-level process of the system.. Linux has many running levels, which are composed of Files/Etc/inittabThe file determines that the functions at all levels are as follows:
0: Stop or stop the system.
1: single-user mode
2: multi-user mode, but no network function
3: multi-user mode with network functions
4: Reserved. You can define your own startup mode.
5: graphic interface login Mode
6. restart the system.
After the INIT process runs, it accesses the/etc/inittab file, which determines the level at which the system runs. Because of the characteristics of the embedded system, we need to let the system run on Level 1, that is, the single-user mode. This only requires the ID: 3: initdefault row in the/etc/inittab file, change 3 to 0. At the same timeEach level also corresponds to a script directory for starting various services, usually under/etc/rc. d/.
Then the INIT process starts/etc/rc. d/rc. sysinit and/Etc/rc. d/rcN. dThe initialization process in the directory. At last, init will run the user login program, and the login: login information will be displayed on the terminal. After the user successfully logs on, the shell program will be started. After the shell is started, it will read and execute the file/Etc/profile,/Etc/bashrc, and files in the user's main directory. bashrc, these files are responsible for creating the user's own environment.

3. Set specific services and boot programs
As described above, add a specified service and customize a specific startup program from the configuration file/Etc/rc. d/rcN. D and/etc/profileStart.
1. Add a specified service: operations required by users during system startup, such as initializing user applications or new hardware developed by users. You can add your own script program to complete these tasks. The main steps are as follows:
(1) Compile a startup service script file in the format of any script file in the system directory/etc/rc. d/init. d.
(2) copy the written script file to the/etc/rc. d/init. d directory. Because/etc/rc. d/rcN. D is only/etc/rc. d/init. d, So copy the real file to the directory of the latter.
(3) create a link to the script file under/etc/rc. d/rcN. D of the corresponding running level n. If the running level is 2, n = 2, and the directory is/etc/rc. d/rc2.d. If the Script Name Is initform and the Link name is my_initform, enter the following command: ln-S/etc/rc. d/init. d/initform/etc/rc. d/rc2.d/my_initform.
After completing the preceding steps, the system automatically executes the services in the script initform after the system is started..
2. Run a specific user application: It mainly refers to a GUI application. If the original system directly enters the desktop system after it is started, the desktop program should be blocked in the corresponding script, and thenModify the/etc/profile script to customize your own program. The procedure is as follows:
(1) run the corresponding desktop system program in the startx script. For example, the desktop system program named qvwm (the Desktop System of Hongqi embedded Linux) is modified as follows:
......
# Xinit/usr/bin/qvwm
# Add "#" to block this line of script
(2) Modify/etc/profile and start the user application. For example, if your application name is start_initform and is in the/root/directory, add the following lines at the end of the application:
......
Export lc_all = zh_cn.gb2312
# Setting up the cultural environment
CD/root/
# Switch to the current application directory
Xinit./start_initform
# Run the specified user application
After the modification is complete, restart the system. After the system initialization is complete, the user-specified service is executed and the user application program is finally run to meet the requirements of the embedded system..

References
1. Li shanping, Liu wenfeng, Wang huanlong. Linux and embedded systems. Tsinghua University Press, 2002
2. Design and Application of embedded Linux. Tsinghua University Press, 2002
3 Wang Xuelong. Design and Application of Embedded Linux system. Tsinghua University Press, 2001
4 Yu mingyu, Chen xiangming, Fang Han. authoritative guide to Linux program design-Mechanical Industry Press, 2001
5 Lenovo software superstar studio. proficient in Linux system management and application development technology. Tsinghua University Press, 2001
6 Li master chen. advanced object-oriented Window Programming in Linux. Science Press, 2001
7 Xu qianyang. Reference Manual for Linux function library. China Youth Publishing House, 2002

 

Appendix: a startup instance

Suppose the name of the compiled application is "write". This is the program that runs automatically after you start the system.

The starting sequence of the system to be implemented is:

① Vivi, ② kernel, ③ root file system, ④ your program "write", you only need to re-build the file system.

You need to modify the existing file system in two ways:

1) copy your program "write" to the system root directory and change the file attributes (enter the command: chmod 777 write)

2) modify the RC under the rootfs/usr/etc file. local file (this file specifies some programs to be started after the file system is started) Add/write as follows/Write CD/qtopia/bin in the last row. /qpe-qws

3) recreate the file system./mkcramfs rootfs 2410f. cramfs

4) re-burn the file system 2410f. cramfs

 

 

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.