I also want to learn how to build an embedded Linux system V0.1
Source: Internet
Author: User
Article Title: I also want to learn how to build an embedded Linux system V0.1. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Chapter 1 Preface
Purpose
This article describes the general process of establishing and developing an embedded Linux system. A small Linux system can be transplanted to other hard disks, floppy disks, USB disks, and flash rom ......
What exactly should I do to build an embedded Linux system?
What exactly do I need to do to build an embedded Linux system? That is, what is the content of this article? I will first introduce a context, which can be used as an outline of our subsequent work:
Step 1: Create a cross-compilation environment
Readers without cross-development experience may be unable to accept this concept at the moment. First of all, we need to understand two concepts: Generally, the machines we work on are called development machines and hosts. the systems we make will be placed on a certain machine, such as a mobile phone or another PC, this host is called the target host.
We generally have a set of development tools on the development machine. We call them native development kits. we generally use them to write programs. So what is the cross-compiling environment? In fact, it is not mysterious at all, that is, installing a development tool on the development machine, the program compiled by this development tool, such as the kernel, system work or our own program, is run on the target host.
So some beginners may ask, simply using native development tools to compile programs for the target host is not enough? At least I thought so. Generally, our development machines are both X86 platforms, and native development kits are also used for X86 platforms. our target hosts may be PowerPC, IXP, MIPS ...... Therefore, our cross-compilation environment is for a specific type of platform.
Generally, the cross-development environment requires binary tools, compilers, and C-linked libraries. The three types of software commonly used in embedded development are:
Binutils
Gcc
UClibc
Of course, the tool suite included in GNU is not only here, but you also need to select it based on your actual needs.
Step 2: compile the kernel
Development tools are for a certain type of hardware platform, and the same is true for the kernel. In this step, we need to use the tool created in step 1 to compile the kernel. this is very simple for people with kernel compilation experience;
Step 3: Create a root file system
That is, to create the bin, dev, proc ...... This pile of directories and some necessary files; in addition, we also need to install some common tool software for our target system, such as ls, ifconfig ...... Of course, one way is to find the source code of these tools and compile it with the cross-compilation tool established in the first step. However, these software are large in quantity and some are large in size, this step is not suitable for embedded systems. we generally use busybox to complete this step, including the system boot software init;
Finally, we need to create initialization boot files for the system, such as inittab ......
Step 4. start the system
In this step, we copy all the established targets, files, programs, kernels, and modules to the target memory, such as hard disks. Then install bootloader for the system. for embedded systems, there are many boot programs available for us. However, many of them have restrictions on hardware platforms. Of course, if you are working on X86, you can directly use lilo for guidance. In fact, this article uses lilo.
In this step, the target storage device is mounted to the target machine. if it succeeds, the system can be started.
Of course, for some special platforms, it cannot be copied like a hard disk, and requires a card reader, burning ...... But the basic methods are the same!
Step 5: Optimize and personalize the system
Through the first four steps, we have obtained a system that can work normally. In this step, it is time to make full use of your imagination ......
Working environment of this article
Project root directory/home/kendo/project ------> I specify it to PATH: $ PRJROOT
Subdirectory and description
Contents
Boot loader target board loader, such as lilo
Build-tools build the tool source code for the cross-compilation platform
Debug debugging tools and all related packages
All documents used in the doc project
Images compiled kernel image and root file system
Linux kernel source code of each kernel version
Root file system created by rootfs
System application systems to be used by the sysapps target board, such as thttpd and udhcpd.
Tmp stores temporary files
Tool-compiled cross-platform development tool chain and C-linked Library
In another post published in CU with the same name, I described a method for creating a cross-compiling environment manually. Currently, there are two methods to create a cross-compilation environment, including creating a root file:
Manual creation
Personalization of the largest program can be achieved. The disadvantage is that the process is complicated and especially prone to errors. pay attention to this "pole" word, including experienced developers;
Automatic creation
It is convenient.
Because the previous article described the general method for creating a cross-compiling environment by hand, this article does not intend to repeat this step. if you are interested, you can search for the post, note that when preparing the tool chain, you should pay attention to the matching of each tool version and the patches required for each tool. I suggest you search for these two items on google, prepare a list. otherwise ......
This chapter describes how to automatically create a cross-compiling environment. Purpose: for commercial hardware platforms, manufacturers will provide you with an Development Kit. I have used IXP425 and MIPS from XX manufacturers, which is very convenient. I remember my first contact with embedded development, I used this development kit to automatically create a cross-compiling environment, compile the kernel, create a root file system, and create a Ram Disk three or four times. I still don't know what I did, oh, silly enough ......
Therefore, it is recommended that readers who do not have experience in this area should first try the manual creation method, and the following content in this chapter, it is sent to a friend who has been deeply hurt by it and does not want to experience this job again, but wants to improve the rate of interaction and work on a general platform without a commercial development kit.
Build a cross-development tool chain
Preparation tools:
Buildroot-0.9.27.tar.tar
Only one software is required? Yes, you don't need to prepare others. buildroot is actually a collection of scripts and patches. you only need to specify the corresponding version in buildroot for other required software, such as gcc and uClibc, it will be automatically downloaded for you.
In fact, it takes time for buildroot to download all the work required to the internet. unless you have enough bandwidth, software download may take up to 80% of the time, all the required work chains are on my local hard drive. After I decompress buildroot, I create a new dl folder and copy the compressed package of the source code of all tools, buildroot does not need to be downloaded online.
Copy it to $ {PRJROOT}/build-tools and decompress it.
[Root @ skynet build-tools] # tar jxvf buildroot-0.9.27.tar.tar
[Root @ skynet build-tools] # cd buildroot
Configure it:
[Root @ skynet build-tools] # make menuconfig
Target Architecture (i386) ---> select the hardware platform. here is i386.
Build options ---> compile options
What is important under this option is ($ {PRJROOT}/tools) Toolchain and header file location? Where is the compiled tool chain?
If you like me, all the toolkit is local and you don't need to download it online automatically, you can clear the wget command option;
Toolchain Options ---> Toolchain Options
--- The Kernel Header Options Header file will be automatically downloaded, but it should be the same version as the Kernel you will use;
[] Use the daily snapshot of uClibc? Use snapshot of the nearest uClibc
Binutils Version (binutils 2.15.91.0.2) ---> Binutils Version
GCC compiler Version (gcc 3.4.2) ---> gcc Version
[*] Build/install c ++ compiler and libstdc ++?
[] Build/install java compiler and libgcj? Supported languages, I did not select java
[] Enable ccache support? Enable the support of ccache. it is used for caching the header file during compilation and compiling the program. it will be a little slow for the first time, but the speed will be very satisfactory in the future ......
--- Gdb Options select gdb support based on your needs
Package Selection for the target --->
I did not select any one of these items, because I plan to manually create a tool chain such as the root file system and busybox.
Target Options ---> File system type. select ext2 as needed;
Compile the configuration:
[Root @ skynet build-tools] # make
This job takes a lot of time. my toolkit is all local, and it also takes me an hour and 13 minutes. if you want to download it all, it will take me an hour or two to get the network speed normally.
After a long wait (in fact, it is not long. I played a few games and it soon passed ):
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