(end) transplant Ubuntu 16 on Hi3559 04-base

Posted by mattm1712 on Tue, 21 Dec 2021 04:06:27 +0100

Porting ubuntu 16.04 base to arm64

Hardware: hi3559av100 Official development board(emmc)
Software: Original uboot + Original factory kernel  + ubuntu Official website base

Step0: introduction to Ubuntu base

Ubuntu Base is the smallest rootfs for creating custom images for specific needs. Ubuntu Base is committed to creating an appropriate minimum environment for applications in board level support package (BSP), restricted or integrated environment as the basis for application or Linux container (such as LXC or Docker) demonstration image.

Step 1: Download ubuntu base

ubuntu base official address

nameexplain
ubuntu-base-16.04.6-base-arm64.tar.gzarm64 bit minimum system
ubuntu-base-16.04.6-base-armhf.tar.gzarm32 bit minimum system

At present, the author's development version is arm64, so download the first file. Execute the following commands in the ubuntu environment on your PC:

#mkdir ubuntu-rootfs
#tar -zxvf ubuntu-base-16.04.6-base-arm64.tar.gz -C ubuntu-rootfs

Step 2: copy external resources (optional)

  • Copy host DNS configuration

    #cp -b /etc/resolv.conf ubuntu-rootfs/etc/
    

    Open and add the following:

    nameserver 8.8.8.8
    nameserver 8.8.4.4 
    
  • Copy compiled kernel ko modules

    #cp -r xxx/ ~/ubuntu-rootfs/lib/modules
    

Step 3: install arm hardware simulation

ubuntu base is a simplified ubuntu system. There are many things in it. You need to install some necessary software packages on your PC (different from person to person). Therefore, it is necessary to simulate the arm64 environment on the PC to support the arm instruction set. Generally, qemu is installed:

#sudo apt-get install qemu-user-static
#cp /usr/bin/qemu-aarch64-static  ubuntu-rootfs/usr/bin

Because arm64 processor is used, QEMU aarch64 static is copied; If it is arm32, copy QEMU arm static.

Step 4: enter the arm simulation environment

The chroot command is used to change the root directory. The chroot(change root) command replaces the root directory with the specified destination directory. The chroot command is mainly used to change the current root directory to Ubuntu rootfs, and then install the necessary software packages. The commands used below are encapsulated as script mount sh:

#!/bin/bash 
mnt () 
{ 
	echo "MOUNTING" 
	sudo mount -t proc /proc ${2}proc 
	sudo mount -t sysfs /sys ${2}sys 
	sudo mount -o bind /dev ${2}dev 
	sudo mount -o bind /dev/pts ${2}dev/pts 
	sudo chroot ${2}  
}
umnt () 
{ 
	echo "UNMOUNTING" 
	sudo umount ${2}proc 
	sudo umount ${2}sys 
	sudo umount ${2}dev/pts 
	sudo umount ${2}dev 
} 

if [ "$1" = "-m" ] && [ -n "$2" ]; 
then 
	mnt $1 $2 
	echo "mnt -m pwd" 
elif [ "$1" = "-u" ] && [ -n "$2" ]; 
then 
	umnt $1 $2 
	echo "mnt -u pwd" 
else 
	echo "" 
	echo "Either 1'st, 2'nd or bothparameters were missing" 
	echo "" 
	echo "1'st parameter can be one ofthese: -m(mount) OR -u(umount)" 
	echo "2'nd parameter is the full pathof rootfs directory(with trailing '/')" 
	echo "" 
	echo "For example: ch-mount -m/media/sdcard/" 
	echo "" 
	echo 1st parameter : ${1} 
	echo 2nd parameter : ${2} 
fi

The command to enter Ubuntu FS is as follows:

./mount -m ubuntu-rootfs

After entering, execute uname -a to see that it is now in the simulated arm environment.

root@work:/# uname -a
Linux work 4.15.0-45-generic #48~16.04.1-Ubuntu SMP Tue Jan 29 18:03:48 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux

In Ubuntu rootfs, you can also execute the following command to exit:

root@work:/# exit
exit
mnt -m pwd
work@work:~$ ./mount.sh -u ubuntu-fs/
UNMOUNTING
mnt -u pwd

Step 5: modify the necessary configuration

  • Modify the update source of the official Ubuntu base arm version to the domestic source

    Modify / etc / apt / sources The contents of the list are as follows:

    deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
    deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
    deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
    deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
    deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
    deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
    deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
    deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
    deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
    deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
    

    After setting, execute the following command,

    root@work:/#apt-get update
    
  • /The etc/fstab is used to specify the device mount. It needs to be set according to the specific situation of the development board. The configuration of hi3559av100 is as follows:

    # stock fstab - you probably want to override this with a machine specific one
    /dev/mmcblk0p3       /                    ext4       defaults  			   0  0
    proc                 /proc                proc       defaults              0  0
    devpts               /dev/pts             devpts     mode=0620,gid=5       0  0
    tmpfs                /run                 tmpfs      mode=0755,nodev,nosuid,strictatime 0  0
    tmpfs                /var/volatile        tmpfs      defaults              0  0
    
    # uncomment this if your device has a SD/MMC/Transflash slot
    

At the same time, if the swap partition needs to be enabled, it is also set here. If the fstab setting is wrong, the ubuntu startup will have an error check of 1 minute and 30 seconds.

step6: general configuration (optional)

  • Set user and password

    root@work:/#useradd -s '/bin/bash' -m -G adm,sudo xxx
    root@work:/#passwd xxx
    root@work:/#passwd root
    
  • Set up automatic DNS update

    root@work:/#apt-get install resolvconf
    root@work:/#dpkg-reconfigure resolvconf
    
  • Install common packages

    apt-get install \
      language-pack-en-base \
      sudo \
      ssh \
      net-tools \
      network-manager \
      iputils-ping \
      rsyslog \
      bash-completion \
      htop \
    

step7: modify uboot parameter (optional)

  • Set ubuntu partition size

    Because the partition of Ubuntu rootfs needs to be large, if the uboot parameters provided by the original factory are not enough, they need to be modified manually

  • File system device

    /The configuration in etc/fstab must be consistent with the uboot bootargs parameter

  • Set swap partition (optional)

8GBemmc is posted on hi3519av100, and 4GB internal control is allocated to it. The final uboot parameter is:

setenv bootargs 'mem=512M console=ttyAMA0,115200 clk_ignore_unused rw rootwait root=/dev/mmcblk0p3 rootfstype=ext4 blkdevparts=mmcblk0:1M(uboot.bin),10M(kernel),4096M(rootfs.ext4)'
saveenv

step8: modify kernel configuration (optional)

Because the Ubuntu base file system is much more powerful than busybox, it needs the support of many linux kernel features. If you use less SDK package kernel configuration, you may not be able to enter the console. Here, you need to open the corresponding kernel options through error messages.

hi3519av100 encountered the following problems:

  • Failed to insert module 'autofs4': No such file or directory

    Select file systems -- > kernel automounter version 4 support (also supports V3)

  • Failed to mount tmpfs at /sys/fs/cgroup: No such file or directory

    Select General setup - > control group support

  • mount can't find /dev

    Select Device Drivers – > generic driver options – > automount devtmpfs at / dev

Step 9: make ubuntu image

After all configurations are completed, the image of ext4 needs to be made. At present, there are two methods:

#Build a 2GB ext4 file system first
sudo dd if=/dev/zero of=ubuntu-rootfs.img bs=1M count=2048
sudo mkfs.ext4  ubuntu-rootfs.img

#Copy Ubuntu rootfs content to it
mkdir ubuntu-mount
sudo mount -o loop ubuntu-rootfs.img ubuntu-mount/
sudo cp -rfp ubuntu-rootfs/*  ubuntu-mount/
sudo umount ubuntu-mount/
sudo e2fsck -p -f ubuntu-rootfs.img

#It must be reduced, otherwise the firmware burned is 2G, and it is only 100M after reduction
sudo resize2fs -M ubuntu-rootfs.img

Now you can burn ubuntu rootfs IMG, then ubuntu runs!!!