Buildroot compiles the root file system of the hisi platform

Buildroot compiles the root file system of the hisi platform


Record the experience of Buildroot building the root file system once. Use buildroot to build the root file system of the imx6ull platform, refer to the tutorial of the whole point atom, the process is very smooth, but it encounters many problems when changing to hisi, here is a record.

1. Download Buildroot source code

Enter Buildroot official website to download . Here directly download the latest version of the long-term supported release source code, the version is 2022.02.8.

Copy it to the shared folder of the docker compilation environment, and then decompress it. arm-hisiv300-linuxThe compilation toolchain has been installed in the docker environment . Since the docker container I use is ubuntu18, it is recommended to download the latest Buildroot directly, because using the old version may encounter more compilation problems, it is best to change to an older system. In order not to replace the system, the latest version of Buildroot is directly used here.

$ docker start hisi 
$ docker exec -it -u duapple hisi /bin/bash
duapple@92fa1c7e1a00:/media/data/hisi/buildroot-2022.02.8$ ls 
CHANGES  Config.in         DEVELOPERS  Makefile.legacy  arch   boot     docs  linux    support  toolchain
COPYING  Config.in.legacy  Makefile    README           board  configs  fs    package  system   utils

2. Menuconfig configuration

Generally speaking, you will first configlook for the supported chip board default configuration files from . Add it to the buildroot root directory and name it .config, so that you can use the default configuration of a certain chip. But there is no default configuration of hisi in the new version of Buildroot source code. In order to know how to configure the architecture, I found the Buildroot source code that was once adapted to the hisi platform on the Internet , and sudo make menuconfigchecked its default configuration with the main configuration Target options, Toolchain, System configuration, Filesystem images.

Since it is not built Kernelby Buildroot Uboot, there is no need to configure Kernel and Bootloaders. The cross-compilation toolchain is not built here, and the external toolchain, namely hisi's cross-compilation toolchain, is directly used.

Note, do not use this source code .config, you cannot copy it .configto the Buildroot source code directory we downloaded. Since the source code is 15 years old, there may be some compatibility issues in the configuration file, which will cause the configuration to fail to save and take effect. Therefore, open the menuconfig of the source code and perform corresponding configurations in the new source code. If it is a version of the Buildroot source code, it can be used directly. configThere are files in the directory of the source code hi3518e_defconfig, which can be used as our reference configuration.

Configure Target options

insert image description here

Configure Toolchain

Here an external toolchain is used. Toolchain gcc version can arm-hisiv300-linux-gcc -vbe checked by It is not consistent with the reference Buildroot.

insert image description here

Configure System configuration

Here you need to configure mdev, otherwise /devthe device will not be automatically generated and you cannot enter the console. In addition, you can also configure the welcome language and login password.

insert image description here

Configure Filesystem images

Here choose two common file system format configurations, jffs2 and squashfs. Note that the jffs2 block size of the hisi flash I used here is 64k, so 64kb needs to be configured. jffs2 supports writing, and squashfs can achieve maximum compression.

insert image description here

Cancel Kernel compilation

insert image description here

Cancel Uboot compilation

insert image description here

After the configuration is complete, exit and save the configuration. You can first copy a copy of the configuration to configsthe directory backup.

cp .config configs/hi3518e_defconfig

3. Compile Buildroot

Compiling the toolchain and Kernel will cause many problems, so choose not to compile the toolchain and Kernel. Directly use the Kernel provided by Hisi that can be directly compiled successfully. But there are still some problems to be solved.

Execute compilation:

sudo make 

After that, Buildroot will start downloading packages for compilation according to our configuration. During the software package download process, you may encounter unfixed software packages. We directly find the link in the output log and manually download it to the dldirectory. Then execute again sudo make. You can use proxychains to proxy wget, or download directly using your browser.

Next, wait slowly for the first compilation problem.

3.1 Download the software package manually

First of all, host-fakerootthe software package download does not move, and it stops when the download reaches 84%. Here, the compilation is terminated directly, the software package is manually downloaded, and then recompiled.

insert image description here

cd dl 
sudo wget https://snapshot.debian.org/archive/debian/20210907T092512Z/pool/main/f/fakeroot/fakeroot_1.26.orig.tar.gz

insert image description here

Recompile:

cd ../
sudo make 

In addition, if there are other software packages that cannot be downloaded, it can also be solved by manually downloading.

3.2 kernel header error

>>> toolchain-external-custom  Extracting
>>> toolchain-external-custom  Patching
>>> toolchain-external-custom  Configuring
Incorrect selection of kernel headers: expected 3.4.x, got 3.5.x
make: *** [package/pkg-generic.mk:283: /media/data/hisi/buildroot-2022.02.8/output/build/toolchain-external-custom/.stamp_configured] Error 1

According to the above error, according to the configuration of the old Buildroot, we configured the header file version 3.4.x, and here is the prompt to recognize it 3.5.x. So in menuconfig, modify it to be 3.5.x. Similarly, the gcc version has also been modified before, and our actual version shall prevail.

After modification, save, back up .config, and recompile.

3.3 arm-hisiv300-linux-gcc-ar:cannot find plugin liblto_plugin.so

Reference: https://developer.aliyun.com/ask/130445

Modify arm-hisiv300-linux-gcc-arthe soft link to arm-hisiv300-linux-ar .

sudo apt install lib32z1-dev
cd output/host/bin
sudo ln -sf /opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin/arm-hisiv300-linux-ar arm-hisiv300-linux-gcc-ar

3.4 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft/libm.so: file not recognized: Is a directory

Enter this /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft/directory. You can see that the links to the file dynamic library are linked to the directory. So the error libm.sois a directory, not a dynamic library.

insert image description here

The solution is to copy the dynamic library in the hisi toolchain to this directory and regenerate these soft links.

First enter the hisi cross-compilation toolchain directory, and then find these dynamic libraries.

duapple@92fa1c7e1a00:/media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_
arm9_soft$ cd /opt/hisi-linux/x86-arm/arm-hisiv300-linux/
duapple@92fa1c7e1a00:/opt/hisi-linux/x86-arm/arm-hisiv300-linux$ find . -name libm.so
./target/usr/lib/a9_softfp_vfp/libm.so
./target/usr/lib/a7_softfp_neon-vfpv4/libm.so
./target/usr/lib/libm.so
./target/usr/lib/a9_vfpv3_neon/libm.so
./target/usr/lib/a9_hard_neon/libm.so
./target/usr/lib/armv5te_arm9_soft/libm.so
./target/usr/lib/a9_soft/libm.so
./target/usr/lib/armv5te_arm9_vfp/libm.so
./target/usr/lib/a9_softfp_vfpv3-d16/libm.so
./target/usr/lib/a7_softfp_vfpv4/libm.so
./target/usr/lib/a7_hard_neon-vfpv4/libm.so
./target/usr/lib/a7_soft/libm.so

The directory where the error was reported above is arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_ arm9_soft, so in the results we found, we found the corresponding directory file, and it should be ./target/usr/lib/armv5te_arm9_soft/libm.socopied to the directory where the error was reported above. But since this file is a soft link, we need to copy the actual link to the file libm.so.0.

lrwxrwxrwx  1 root root      36 Feb 24  2016 libm.so -> ../../../armv5te_arm9_soft/libm.so.0

In ../../../armv5te_arm9_soft/the directory, after the copy is complete, regenerate the soft link in the error directory.

sudo cp ./target/armv5te_arm9_soft/libm.so.0 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
cd /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo rm libm.so
sudo ln -s libm.so.0 libm.so

Successfully regenerated the soft link:

lrwxrwxrwx 1 root root       9 Jan  1 20:01 libm.so -> libm.so.0
-rwxr-xr-x 1 root root   69147 Jan  1 19:59 libm.so.0

Similarly, other dynamic library links linked to the directory are regenerated in the same way.

cd /opt/hisi-linux/x86-arm/arm-hisiv300-linux/
sudo cp target/armv5te_arm9_soft/libcrypt.so.0 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo cp target/armv5te_arm9_soft/libdl.so.0 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo cp target/armv5te_arm9_soft/libnsl.so.0 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo cp target/armv5te_arm9_soft/libresolv.so.0 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo cp target/armv5te_arm9_soft/librt.so.0 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo cp target/armv5te_arm9_soft/libthread_db.so.1 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo cp target/armv5te_arm9_soft/libutil.so.0 /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
cd /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft
sudo rm libcrypt.so 
sudo ln -s libcrypt.so.0 libcrypt.so
sudo rm libdl.so
sudo ln -s libdl.so.0 libdl.so
sudo rm libnsl.so
sudo ln -s libnsl.so.0 libnsl.so
sudo rm libresolv.so
sudo ln -s libresolv.so.0 libresolv.so
sudo rm librt.so
sudo ln -s librt.so.0 librt.so
sudo rm libthread_db.so
sudo ln -s libthread_db.so.1 libthread_db.so
sudo rm libutil.so
sudo ln -s libutil.so.0 libutil.so

After modification, all dynamic library links are normal, try to recompile again.

insert image description here

3.5 /opt/hisi-linux/x86-arm/arm-hisiv300-linux/bin/../lib/gcc/arm-hisiv300-linux-uclibcgnueabi/4.8.3/../../../../arm-hisiv300-linux-uclibcgnueabi/bin/ld: cannot find libc.so.0

Refer to the above solution, find the corresponding one in the toolchain directory libc.so.0, and copy it to the corresponding directory. target/armv5te_arm9_softIn order to prevent other libraries from being found, copy all the files under the toolchain directory directly .

sudo cp -d target/armv5te_arm9_soft/*  /media/data/hisi/buildroot-2022.02.8/output/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/armv5te_arm9_soft

3.6 fallocate.c:(.text.fallocate_main+0xa0): undefined reference to 'posix_fallocate'

Reference: https://blog.csdn.net/qq_44045338/article/details/109368225 .

Close the module in busybox.

sudo make busybox-menuconfig

insert image description here

Save and exit, then recompile.

3.7 Other errors

After printing the following content, the root file system has been compiled and the image file we need has been generated.

insert image description here

>>>   Generating filesystem image rootfs.jffs2
>>>   Generating filesystem image rootfs.squashfs
>>>   Generating filesystem image rootfs.tar

Mirror file path output/images:

duapple@92fa1c7e1a00:/media/data/hisi/buildroot-2022.02.8/output/images$ ls -lh 
total 3.9M
-rw-r--r-- 1 root root 995K Jan  1 20:30 rootfs.jffs2
-rw-r--r-- 1 root root 632K Jan  1 20:30 rootfs.squashfs
-rw-r--r-- 1 root root 2.3M Jan  1 20:31 rootfs.tar

Note that there are still some errors that will not be exposed during compilation, but after burning the root file system, it will cause a startup error. Because I have solved it before, I can modify it directly.

First unzip to see if our rootfs folder and files are normal:

sudo mkdir rootfs 
sudo tar -xvf rootfs.tar -C rootfs

Mainly look at two places, because I use buildroot2020.2 to compile, copying the mk execution of the cross-compilation toolchain will report an error, because I can’t solve it, I ignore the error in mk, and finally the generated root file system will lack the system Dynamic library, startup script is missing S10mdev. Then manually copy the dynamic library of the cross-compilation toolchain to output/targetthe directory, the operation is the same as the previous copy of the dynamic library, and then copy package/busybox/S10mdevthe script to the directory output/target/etc/init.d/.

Since the final packaged root file system directory is output/target, the files we need to add to the root file system can be directly placed in the corresponding position of this directory.

etc/init.d/S10mdevCheck the , lib, and dynamic library paths in the rootfs directory to see usr/libif there are necessary dynamic libraries. If not, copy all the dynamic libraries of the corresponding architecture version of the toolchain to lib.

But I buildroot-2022.02.8don't have this problem in the current version ( ).

4. Burn test

Build tftp server

Configure the tftp server. Copy rootfs.jffs2and rootfs.squashfsto the tftp server directory.

cp rootfs.jffs2 rootfs.squashfs /media/data/tftp/

Configure uboot network

Start the hisi development board, and enter any key to enter uboot during the startup process. Configure the uboot network and the virtual machine to be on the same network segment.

setenv serverip 192.168.10.100
setenv ipaddr 192.168.10.101
setenv ethaddr 12:23:34:45:56:67
setenv netmask 255.255.255.0
setenv gatewayip 192.168.10.1
ping 192.168.10.100

Burn jffs2 root file system

mw.b 82000000 ff C00000; tftp 0x82000000 rootfs.jffs2; sf probe 0; sf erase 400000 C00000; sf write 82000000 400000 C00000

insert image description here

Set startup parameters

You need to set the startup parameters of the jffs2 root file system and save:

setenv bootargs 'mem=64M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 mtdparts=hi_sfc:1M(boot),3M(kernel),12M(rootfs)'
setenv bootcmd 'sf probe 0;sf read 0x82000000 0x100000 0x300000;bootm 0x82000000'
sa

restart the system

hisilicon # reset

Sure enough, it was still an error.

TCP: cubic registered
Initializing XFRM netlink socket
NET: Registered protocol family 17
NET: Registered protocol family 15
lib80211: common routines for IEEE802.11 drivers
Registering the dns_resolver key type
VFS: Mounted root (jffs2 filesystem) on device 31:2.
Freeing init memory: 140K
usb 1-1: new high-speed USB device number 2 using hiusb-ehci
/sbin/init: can't load library 'libc.so.0'
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00001000

Missing libc.so.o, indicating that the root file system still lacks some necessary dynamic libraries. Here, according to the method mentioned above, copy the dynamic library to output/target/libgo. Here, since my target/usr/libdirectory is empty, I still put all the libraries in this directory to output/target/lib/distinguish it from the existing directories in . If it is init , linuxrcrelated kernel startup errors may also be caused by the lack of necessary dynamic libraries.

duapple@92fa1c7e1a00:/opt/hisi-linux/x86-arm/arm-hisiv300-linux$ sudo cp -d target/armv5te_arm9_soft/* /media/data/hisi/buildroot-2022.02.8/output/target/usr/lib/

duapple@92fa1c7e1a00:/opt/hisi-linux/x86-arm/arm-hisiv300-linux$ sudo cp -d arm-hisiv300-linux-uclibcgnueabi/lib/armv5te_arm9_soft/* /media/data/hisi/buildroot-2022.02.8/output/target/usr/lib

Recompile and reprogram.

Start successfully ✿✿ヽ(°▽°)ノ✿

insert image description here

Burn squashfs root file system

The operation steps are consistent with burning jffs2 root file system. But you need to modify bootargs to correspond to squashfs.

mw.b 82000000 ff C00000; tftp 0x82000000 rootfs.squashfs; sf probe 0; sf erase 400000 C00000; sf write 82000000 400000 C00000
setenv bootargs 'mem=64M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=squashfs mtdparts=hi_sfc:1M(boot),3M(kernel),12M(rootfs)'
setenv bootcmd 'sf probe 0;sf read 0x82000000 0x100000 0x300000;bootm 0x82000000'
sa

Restart the system:

reset

Error:

devpts: called with bogus options
can't open /dev/null: No such file or directory
can't open /dev/null: No such file or directory
can't open /dev/null: No such file or directory
can't open /dev/null: No such file or directory
Starting syslogd: OK
Starting klogd: OK
Running sysctl: /etc/init.d/S02sysctl: line 37: can't create /dev/null: Read-only file system
usb 1-1.2: new high-speed USB device number 3 using hiusb-ehci
OK
Starting mdev... OK
mmc1: error -84 whilst initialising SD card
mmc1: new high speed SDHC card at address 5048
mmcblk0: mmc1:5048 SD32G 29.7 GiB
 mmcblk0: p1 p2
modprobe: can't change directory to '/lib/modules': No such file or directory
Starting network: OK
can't open /dev/console: No such file or directory
can't open /dev/console: No such file or directory
can't open /dev/console: No such file or directory
can't open /dev/console: No such file or directory
can't open /dev/console: No such file or directory

Since squashfs is a read-only file system, mdev cannot create these devices, so create them manually.

cd output/target/dev
sudo mknod console c 5 1 
sudo mknod ttyAMA0 c 204 64
sudo mknod null c 1 3
sudo chmod 666 console ttyAMA0 null 

Recompile and package the file system, and then burn it, and the startup is successful:

insert image description here

Guess you like

Origin blog.csdn.net/duapple/article/details/128516133