Minimum Linux system programming: production and programming of Linux file system

Xunwei iTop4412 core board Exynos-4412 can not only run Android , but also can run simple Linux minimal file system. The smallest Linux system can be said to be "small but complete", although it does not have a graphical interface linux system can be used to learn linux system programming and is easy to understand.

I. Overview

1.Minimum Linux System summary

We always talk about Linux system, but what exactly is Linux system? What is a minimal linux system?

An operating system is macroscopically divided into two parts: kernel and shell (core and shell).

The kernel is the operating system kernel. The shell is on top of the kernel and provides an interface for interacting with users, including CLI (command line interface) and GUI (graphical user interface). In addition, there are basic runtime libraries (such as C library, posix) and other basic software.

Minimal Linux System is an ultra-small system that uses the Linux system kernel and some necessary packages (programs, drivers, etc.) to replace a complex operating system. A minimal Linux system is a runtime environment that does not support multi-user mode, does not run the X graphical interface, only uses a server or terminal user interface, and only runs N. Minimal Linux systems can achieve good performance on low-power devices and facilitate the deployment of Linux systems into existing environments. Minimal Linux systems boot more quickly and configuration changes can be completed in less time.

The minimum Linux system consists ofkernel, root file system, user space, driver, etc.. The kernel is stored on disk as an executable program and is responsible for handling hardware requests and virtual memory management. The root file system is used to store system files, including system applications, user accounts, and file manager configuration files. User space includes some application compilers, such as GCC, and corresponding library functions that can be used to run applications in kernel space. Finally, the driver controls the hardware through the Linux system kernel to enable the normal operation of these devices.

Using a minimal Linux system is an easy way to get the best performance and reliability for a variety of devices. This is because it can efficiently utilize the resources of low-power devices, reduce the time required for installation and configuration, and reduce maintenance costs. In addition, it can use virtual machines to run multiple applications, as well as allow developers to dynamically deploy and debug applications, which helps them better take advantage of the flexibility and reliability of Linux systems.

In short, a minimal Linux system is an ultra-small, efficient, and reliable Linux system that can easily run on a variety of low-power devices, using virtual machines to run multiple applications, allowing developers to easily install and configure the system , as well as implement configuration changes, etc. in less time. Therefore, minimal Linux systems provide the best operating environment and performance for such devices, making them relatively stable solutions.

2. Busybox Tool introduction

Creating a file system requires the use of the Busybox tool. BusyBox is a software that integrates more than a hundred of the most commonly used linux commands and tools. BusyBox Contains some simple tools, such as ls, telnet, and mount , grep, findecho etc., as well as some larger and more complex tools, such as and cat BusyBox the Swiss Army Knife of Linux tools. Simply put, BusyBox is like a big toolbox. It integrates and compresses many tools and commands of Linux . Contains the Android system’s own shell.

The download URL for Busybox is http://www.busybox.net/. This is an open source program and is constantly being updated. , the version used here is busybox-1.22.1.tar.bz2.

Second,BusyBox Minimum production structure

1. Create Busybox in the virtual machine

First, you can go to the virtual machine's Ubuntu directory " /home< Create a new directory " minilinux" under a i=4>". For the convenience of subsequent operations, you can also open all its permissions. The specific process is as shown in the figure below.
Copy "  busybox-1.22.1.tar.bz2 " to the Ubuntu virtual machine system directory "  /home/minilinux  ", and then execute the decompression command in the directory " /home/minilinux " ,As shown below.
tar -xvf busybox-1.22.1.tar.bz2

 2. PlacementBusybox

The operation here is the same as the transplantation of the root file system.

Enter the busybox-1.22.1 directory, as shown in the figure below.


Modify some configurations shown in the figure below, save and exit. As shown below. Execute the following command " source /etc/profile " to make the compiler take effect. As shown below

source /etc/profile

Enter the Busybox root folder and open the Makefile with gedit, as shown below:

The compilation configuration of Busybox uses the same command as the compilation configuration of Linux kernel. Let’s start configuring Busybox, as shown in the figure below, use Command " make menuconfig ", as shown in the figure below, and then the configuration interface of Busybox will appear.
make menuconfig 

 As shown above, select Busybox Settings, and then press Enter to enter Busybox Settings interface, as shown below.

In Busybox Settings there are two places that need to be modified in the configuration options. The first one is " Build Options-> Cross Compiler prefix ", It specifies what compiler to use to compile Busybox , select Build Options As shown above, then press Enter to enter the Build Options configuration interface, as shown below.
Select Build Options Configuration interface Cross Compiler prefix As shown above, then press Enter to enter the Cross Compiler prefix configuration interface, as shown below.

 Enter the cross-compilation tool used arm-none-linux-gnueabi-, as shown below.

Then press Enter to return to the Build Options configuration interface. At this time, you can see the cross-compilation tool you just set, as shown below.

 Then use the left and right keys of the keyboard to select Exit, as shown below.

Then press Enter to return to the Busybox Settings settings interface, as shown below.

 SelectInstallation Options as shown above, then press Enter to enter Installation Options Configuration interface, is as shown below.

Select BusyBox installation prefix As shown in the picture above, then press Enter to enter BusyBox installation prefix configuration interface.
Note: This interface is after setting up and compiling Busybox , and installing the final generated binary file into the directory), as shown below.

 Delete./_install in the above picture, and then enter "../system", That is to say, the final generated binary file will be installed in the system directory under the directory one level above the current directory. Note two points, system a> as shown below.

Then press Enter, return toInstallation Options, then use the right arrow key on the keyboard to move the cursor to "Exit", and then press Press Enter and return to Busybox Settings. Use the right direction key on the keyboard to move the cursor to "Exit a>”, as shown below.

Then press Enter to pop up the save configuration interface. Use the right direction key on the keyboard to move the cursor to " Yes", then press Enter to save the configuration and exit the configuration interface, as follows picture.

Then press Enter to save the configuration and exit the configuration interface. As shown below.

 3. Japanese style BusyBox

 NowBusybox configuration has been completed, now start compiling Busybox< a i=4>, enter the " make " command in the terminal of Ubuntu to start compilation Busybox, as shown below.

As shown below, the compilation is completed.

Now that the compilation is completed, you need to install the binary file generated by the compilation into the " ../system " directory just specified, use the command " < a i=2>make install ” Install the binary file to the “../system” directory, as shown below.

make install

As shown in the figure below, the execution is completed.

 3.Perfect minimum Linux Series sentence case

The file system produced by also requires dev, etc, lib, mnt, proc, sys, tmp, var folders, use the command " mkdir dev etc lib mnt proc sys tmp var  ” Create the folder as shown in the figure below.
mkdir dev etc lib mnt proc sys tmp var

Go to the etc folder you just created, as shown in the figure below.  

exist etc order to use under eyes vi or person < /span> Message entry below page eth0-setting text, existing eth0-setting erected vim
Allow:
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

Then save and exiteth0-setting, use " chmod 755 eth0-setting , as shown below. eth0- setting ” command modifies the permissions of  

 Use " mkdir init.d etc directory >" command to create the init.d folder, and use the command " cd init.d" command to enter < /span> folder, as shown in the figure below. init.d  

Use " vim ifconfig-eth0< under the init.d folder a i=4>” command to create the ifconfig-eth0 file, as shown in the figure below.   

Then enter the following content in the ifconfig-eth0 file, save and exit. As shown below.
#!/bin/sh
echo -n Try to bring eth0 interface up......>/dev/ttySAC2
if [ -f /etc/eth0-setting ] ; then
source /etc/eth0-setting
if grep -q "/dev/root / nfs " /etc/mtab ; then
echo -n NFS root ... > /dev/ttySAC2
else
ifconfig eth0 down
ifconfig eth0 hw ether $MAC
ifconfig eth0 $IP netmask $Mask up
route add default gw $Gateway
fi
echo nameserver $DNS > /etc/resolv.conf
else
if grep -q "^/dev/root / nfs " /etc/mtab ; then
echo -n NFS root ... > /dev/ttySAC2
else
/sbin/ifconfig eth0 192.168.253.12 netmask 255.255.255.0 up
fi
fi

echo Done > /dev/ttySAC2

Use the command "  chmod 755 ifconfig-eth0  " to modify the permissions of ifconfig-eth0, as shown below shown.

Then use " vim rcS ” command to create the rcS file, as shown below.    

Then enter the following content in the rcS file. And save and exit rcS , use the command "   chmod 755 rcS   " to modify rcS ’s permissions, as shown below.
#! /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 iTOP-4412
#/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
[ -e /proc/1 ] || /bin/mount -n -t proc none /proc
[ -e /sys/class ] || /bin/mount -n -t sysfs none /sys
[ -e /dev/tty ] || /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 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/log/boa
mkdir -p /var/lock
mkdir -p /var/run
mkdir -p /var/tmp
ln -sf /dev/ttyS2 /dev/tty2
ln -sf /dev/ttyS2 /dev/tty3
ln -sf /dev/ttyS2 /dev/tty4
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
#echo "*************************************" > /dev/ttySAC2
#echo " http://www.topeet.com.cn " > /dev/ttySAC2
#echo "*************************************" > /dev/ttySAC2
#echo "*************************************" #echo " http://www.topeet.com.cn " #echo "*************************************" mkdir /mnt/disk
sleep 1
/sbin/ifconfig lo 127.0.0.1
/etc/init.d/ifconfig-eth0

 

Next use the "   cd ../   " command to return to init.d The upper-level directory of , as shown in the figure below. etc

Next, use the command “vim passwd etc directory 4>”Create file passwd, as shown below.  

Enter the following content in the newly created passwd file.
root::0:0:root:/:/bin/sh
bin:*:1:1:bin:/bin:
daemon:*:2:2:daemon:/sbin:
nobody:*:99:99:Nobody:/:
The input result is as shown below,

Then save and exitpasswd, use " chmod 755 passwd ” command to modify the permissions of passwd , as shown in the figure below.

 Then use the command “ vim profile ” in etc Directory creation profile file, as shown in the figure below.

 Then enter the following content in profile .

#Ash profile
#vim: syntax=sh
#No core files by default
ulimit -S -c 0 > /dev/null 2>&1
USER="`id -un`" LOGNAME=$USER
PS1='[$USER@$HOSTNAME] \w# '
PATH=$PATH
HOSTNAME=`/bin/hostname` export USER LOGNAME PS1 PATH

Then save and exitprofile, use "  chmod 755 profile  ” command to modify the permissions of profile , as shown in the figure below.

 

Next use the " mkdir rc.d " command in etc Directory creates folderrc.d, as shown in the figure below.  

Next use the command "   cd rc.d/   " to enter rc.d directory a>  init.d folder, as shown in the figure below. ” Createrc.d mkdir init.d directory, use the command “   

Then in the init.d folder, use “ vim netd  ” command to create netd file, as shown in the figure below.  

 Then enter the following content in the netd file.

#!/bin/sh
base=inetd
# See how we were called. case "$1" in
start)
/usr/sbin/$base
;;
stop)
pid=`/bin/pidof $base`
if [ -n "$pid" ]; then
kill -9 $pid
fi
;;
esac
exit 0

 

 Then save and exitnetd, use "  chmod 755 netd  ” command to modify the permissions of netd , as shown in the figure below.

Using adhesive “  cd ../../../  ” Command returned system Meme.  Like below.

Then use the "  cd lib  " command to enter lib Directory, as shown below.  

Because the cross-compilation environment used is the same as the one used to compile the kernel, the compiler is /usr/local/arm/arm- 2009q3 , The binary file generated by Busybox compilation runs in the form of a dynamic link library, so you need to copy the library files in the compiler to the lib directory and use the following command :
cp -P /usr/local/arm/arm-2009q3/arm-none-linux-gnueabi/libc/lib/* ./ -lr

 The execution result is shown in the figure below.

After the library file copy is completed, use the "  cd ../ var " command to enter the var directory in the upper directory system.

then used “  mkdir lib lock log run tmp  ” instruction present var < a i=4>erect under the eye lib, lock, tmp 5th page , Shown below. , run, log

 

 At this step, the folder "system" is created. As shown below.

4.Installation and packaging software and compilation

torture package “ linux_tools.tgz ” to Ubuntu Regular “/” Please note that “/ ”.

Note that the root directory cannot be copied and pasted directly. You can copy it to the desktop first and then use the copy command to copy to the root directory. As shown below, this is one of the methods for reference only.

Use the decompression command "  tar -vxf linux_tools.tgz " to decompress, as shown in the figure below.

After installing the packaging and compilation tool “ make_ext4fs ”. Use the command " cd /home/minilinux/ " to enter the directory "/home/minilinux/", and then use the command " make_ext4fs -s -l 314572800 -a root -L linux system.img system ” generates system.img file System image, as shown below.

Then you can use the ls command to view the generated system.img.

So far, the production of linux file system has been completed, and the final generated binary file is system.img .

Five,Minimum Linux Linux

Finally, you need to burn the prepared system.img to iTOP-4412 , you can refer to ". The detailed process is described below. FilezImage "/zImageQT file systemQtE can use zImage On the development board, the programming method is the same as the Android file system programming. The uboot file does not need to be burned and is compatible with Android 4.0.3. Kernel
Description: Minimum linux System related to QtE4.7 System's U-boot mirror ( u- boot-iTOP-4412.bin ), Kernel
( zImage ) Commonly used for mirror images.

1. Brief introduction to Qt

Qt is a cross-platform graphical user interface application development framework based on C++. How to make it cross-platform? From the server host computer to the embedded GUI , everything is possible.
Qt General instruction box version, example Linux ( x86 ), Windows , Mac The system is dynamic.
The full name of QtE is Qt embedded , specifically referring to the embedded version. It is the Qt Embedded Linux fork platform, in the original Based on Qt, many excellent adjustments have been made to suit the embedded environment.
Although Qt is often used as a GUI library for developing graphical interface applications, This is not all of Qt ; in addition to drawing beautiful interfaces (including controls, layout, and interaction), Qt also includes many other functions, such as multi-threading , accessing databases, image processing, audio and video processing, network communications, file operations, etc., these Qt have all been built-in.
In summary, Qt is mainly used for desktop program development and embedded graphical interface development.

2. Programming method and process

Installed ADB driver and ready platform-tools Folder can be programmed.
ready to compile ’s QtE4.7 system’s kernel and root file system image, as shown in the figure below.
1 ) Open HyperTerminal, then power on and start the development board, press "Enter" to enter Uboot mode, As shown in the figure below, enter uboot mode.
2 ) Create eMMC partition and format it. If you have already done this step before, you can skip it and there is no need to partition and format it every time before programming. In HyperTerminal, enter the following partition and format commands.
As shown in the figure below, enter the partition command: fdisk -c 0
As shown in the figure below, enter the command: fatformat mmc 0:1
As shown in the figure below, enter the command: ext3format mmc 0:2
As shown in the figure below, enter the command: ext3format mmc 0:3

As shown in the figure below, enter the command:ext3format mmc 0:4 

As shown in the figure below, in the HyperTerminal, enter the command:fastboot 

Note: fastboot command needs to be compatible with PC USB_fastboot_tool tool is used together, and the fastboot command needs to be entered It can only be used in uboot mode.
3 ) OTG Line General Opening Board OTG Address PC Target USB Close contact. Removal of the hard case, please contact the driver.
4 ) Run on PC “05- USB_fastboot_tool"-->"platform-tools"File in the folder"cmd.exe"(< /span>’s own command line tool, if it is not compatible when used by the usercmd.exe system's Windows , please use the user's own Windows cmd.exe executable file is
(1 ) First open the "Start" menu of the computer desktop system, and enter " cmd ”.
(2) As shown below, the " cmd.exe " applet that comes with this operating system appears.
(3) As shown below, (different operating systems are slightly different), find the option "Open File Settings".

(4) As shown below, you can find the applet "cmd.exe" of the user's own operating system.  

Then we copy the " cmd.exe " program of our own operating system to " USB_fastboot_tool< /span> "cmd.exe " folder, overwrite "
Cover, so that when we run the cmd.exe program again, we can enter Windows a> Command line working mode. As shown below.
5) As shown in the figure below, in the Windows command line, enter to burn zImage kernel Command: fastboot.exe flash kernel zImage
As shown in the figure below, enter the flash ramdisk command: fastboot.exe flash ramdisk ramdisk- uboot.img

 

As shown in the figure below, enter the flash system file system command: fastboot.exe flash system system.img 

As shown in the figure below, enter the erase command:fastboot -w 

Note: The above fastboot.exe flash commands can be executed separately, so that only a single image can be burned.

6) In the Windows command line, enter the restart development board command: fastboot reboot

So far, the Linux minimum system has been programmed. After restarting the development board, you will enter the minimum system non-graphical interface. The super terminal is as shown below:

 

The development board is as shown below, that is, the minimum Linux system has been successfully produced and programmed.

Guess you like

Origin blog.csdn.net/Eva20192020/article/details/134361209