Xunwei 4412 study notes - compile and install the smallest Linux file system

Experimental environment: physical machine Ubuntu20.04/Windows 10 21H2

1. Make and install a minimal linux file system

1.1 compile uboot

Copy the following three folders to the same level directory of Ubuntu:

 

After the copy is complete, as shown in the figure:

 

Use the following command to decompress the uboot source code:

tar -vxf iTop4412_uboot_20180320.tar.gz

After decompression is complete, it will look like this:

 

You can compile the uboot source code by using the "build_uboot.sh" script in the iTop4412_uboot source code folder. During compilation, the following parameters need to be set according to the board model:

hardware classification

Script execution parameters

Core board SCP, 1G memory

SCP_1GDDR

Core board SCP, 2G memory

SCP_2GDDR

Core board POP, 1G memory

POP_1GDDR

Core board POP, 2G memory

POP_2GDDR

The development board used by the author is the core board SCP with 1G memory, so the parameter used when compiling is "SCP_1GDDR", enter the iToop4412_uboot directory, and use the following command to complete the compiling of uboot:

./build_uboot.sh SCP_1GDDR

After the compilation is complete, as shown in the figure

 

The compiled u-boot-iTop-4412.bin file is in the iTop4412_uboot directory, as shown in the figure:

 

 

1.2 Compile the linux kernel

First copy the iTop4412_Kernel_3.0_20191007.tar.gz kernel source code to Ubuntu, as shown in the figure

 

Then use the following command to decompress:

tar -vxf iTop4412_Kernel_3.0_20191007.tar.gz

After decompression is complete, it will look like this:

 

Then enter the "iTop4412_Kernel_3.0" directory to configure the compiled kernel.

 

If you need to compile the kernel for the smallest linux system, you need to select the configuration file of config_for_linux*. If you are compiling the kernel for Android, select config_for_android*. The same is true for other systems, where elite means the elite version and super means the all-around version.

Take the kernel required for compiling the minimum linux system as an example. Since the author uses the elite version of SCG1G, the following command needs to be used to configure the .config file:

cp config_for_linux_scp_elite .config

Once complete, use the following command to compile the kernel:

make zImage

It is measured that the Ubuntu20.04 LTS system will encounter errors caused by version problems during compilation, as shown in the figure

 

Solution: According to the error directory, find the timeconst.pl file, enter and find the sentence defined(@array), ignore defined according to the prompt in the brackets, and set:

if (!defined(@val)) {

Change to:

if (!(@val)) {

The detailed process is as follows. In the iTop4412_Kernel_3.0 kernel directory, use the following command to edit the timeconst.pl file:

vim /kernel/timeconst.pl

Then jump to the number of wrong lines, here is 373, use the following command in vim to jump:

373gg

After the jump is completed, as shown in the figure:

 

After modification, as shown in the figure:

 

Then save and exit, recompile, as shown in the figure after the compilation is complete:

 

The generated zImage file is in the ./arch/arm/boot directory, as shown in the figure

 

1.3 Download and configure Busybox

The production of the smallest linux file system can be completed by using the Busybox open source toolbox. Busybox is a software that integrates more than one hundred of the most commonly used linux commands and tools, including commonly used shell commands. Its official website is:

https://busybox.net/

Open the official website, as shown in the figure, the latest version is 1.35.0

 

After downloading, copy to Ubuntu, as shown in the figure:

 

Use the following command to decompress:

tar -vxf busybox-1.35.0.tar.bz2

After decompression is complete, as shown in the figure

 

Go to the busybox-1.35.0 directory generated by decompression, and then use the following command

make menuconfig

You can configure the linux file system. The actual measurement of Ubuntu20.04 LTS will pop up the following error:

 

This is because the Ubuntu system lacks a package ncurses devel, use the following command to install it:

apt install libncurses5-dev

After completion, use make menuconfig again to enter the menu configuration interface of buybox, as shown in the figure

 

Then, enter the Settings directory, scroll down, and find the "Cross compiler prefix" under "---Build Options" to configure the cross compiler for it.

 

Here, take the "arm-none-linux-gnueabi-" cross compiler installed earlier as an example, press Enter to enter "Cross compiler prefix", enter "arm-none-linux-gnueabi-" in the edit box, and then select "OK "OK, as shown in the figure:

 

Next, configure the file system installation directory for Busybox, which defaults to the "_install" directory of the current folder, as shown in the figure:

 

Here, create a filesystem directory outside the busybox-1.35.0 directory for busybox to install the file system, so you need to change "./_install" to "../filesystem", as shown in the figure:

 

Then select "Ok" and save to exit, as shown in the figure, select "Yes".

 

1.4 Improve the minimal linux file system

As shown in the figure, create a filesystem directory in the same directory as busybox-1.35.0.

 

Then, complete the files required by the minimum linux system in the filesystem, as follows:

Use the following command to create a series of folders in filesystem:

mkdir dev etc lib mnt proc sys tmp var

After completion, as shown in the figure

 

Then, enter the newly created etc directory, and use the following commands to create init.d and rc.d folders

mkdir init.d rc.d

After completion, as shown in the figure:

 

Then enter the newly created rc.d folder and use the following command to create the init.d folder

mkdir init.d

After completion, as shown in the figure:

 

Then return to the filesystem directory, enter the var directory, and use the following command to create folders required by other systems:

mkdir lib lock log run tmp

After completion, as shown in the figure:

 

The following operations need to use some initialization files provided by Xunwei, as shown in the figure, avoid opening them in windows after decompression.

 

Enter the created etc directory, copy the three files of eth0-setting passwd profile into it, and use the following command to change the permissions of these files to 755:

chmod 755 eth0-setting passwd profile

After completion, as shown in the figure:

 

Enter the init.d directory under the etc directory, copy the two files ifconfig-eth0 and rcS into it, and use the following command to change the permissions of these files to 755:

chmod 755 ifconfig-eth0 rcS

After completion, as shown in the figure:

 

Go to the etc/rc.d/init.d directory, copy the netd file in, and use the following command to change the permission of the file to 755:

chmod 755 netd

After completion, as shown in the figure:

 

Return to the system directory, enter the lib folder, and use the following command to copy the library files of the compiler into it:

cp /usr/local/arm/arm-2009q3/arm-none-linux-guneabi/libc/lib/* ./

After completion, as shown in the figure:

 

In this way, the file system of the smallest linux system has been perfected.

1.5 Compile the minimal linux file system

Enter the busybox-1.35.0 directory, and use the following commands in order to complete the compilation and installation of the minimal linux system:

make

make install

After using the make command, the Ubuntu20.04 LTS system will have the following error:

 

Edit the ipaddress.c file with the following command:

vim networking/libiproute/ipaddress.c

Then jump to line 345, as shown in the figure:

 

Add conditional compilation for IFA_F_DADFAILED, the program is modified to:

 

After saving and exiting, recompile and find that there are new errors. These errors are mainly caused by the mismatch between the cross-tool chain and the source code version. Just remove those undefined modules in the busybox configuration.

 

There are two here, namely nsenter and sync. Enter "/" in the make menuconfig of busybox to search for the module to obtain its location, and then remove the selected state.

The following are the results of searching for nsenter, and its location can be obtained as Linux System Utilities

 

After finding and selecting, enter "n" to remove the selected state, and enter "y" to enter the selected state.

 

Continue to find sync

 

Under the Coreutils menu, it also performs the deselection operation:

 

Finally, save and exit, and use make to compile again.

 

The compilation is passed, and finally use the following command to complete the installation of busybox:

make install

After success, the result is as shown in the figure:

 

1.6 Pack the smallest linux file system

After executing the above commands for compiling and installing busybox, use the make_ext4fs packaging tool to copy the linux_tools.tgz compressed file to the "/" directory.

  Then use the following command to decompress:

tar -vxf linux_tools

After completion, as shown in the figure:

 

After that, enter the same level directory as the previous filesystem, and use the following command to package the minimum linux file system:

make_ext4fs -s -l 314572800 -a root -L linux system.img filesystem

The last parameter filesystem indicates the directory where the file system template is located, that is, the perfect linux file system mentioned above, and the penultimate parameter system.img indicates that the file name generated after packaging is system.img.

It is actually measured that this command will report an error under the Ubuntu 20.04 LTS system, prompting an error when loading the shared library libc++.so.6

 

Just use the following commands to install the two libraries lib32c-dev and lib32stdc++6:

apt install lib32c-dev

apt install lib32stdc++6

After the installation is complete, use the package command again to package and generate the system image file system.img, as shown in the figure:

 

1.7 Burn the smallest linux file system

Use it in u-boot mode in HyperTerminal (or minicom) (if you only need to update the kernel, you don’t need to wipe the partition), wipe the partition, and enter fastboot mode

(Execute one by one command)

fdisk -c 0

fatformat mmc 0:1

ext3format mmc 0:2

ext3format mmc 0:3

ext3format mmc 0:4

fast boot

Use it under cmd.exe, and burn the required image into the development board through the otg line

In general, do not reprogram uboot (minimum linux, android and QT share one uboot, the first item is to reprogram uboot)

fastboot.exe flash bootloader u-boot-iTOP-4412.bin

fastboot.exe flash kernel zImage

fastboot.exe flash ramdisk ramdisk-uboot.img

fastboot.exe flash system system.img

fastboot -w

fastboot reboot

After the programming is completed, after the development board has loaded the kernel, use the following command to check the version of busybox:

ls -j

As shown in the figure, it means that the system packaged by busybox can run normally:

 

Guess you like

Origin blog.csdn.net/qq_41595148/article/details/128722117