Booting hvisor on NXP-IMX8MP
Date: 2024/2/25
Updated: 2025/3/7
Authors: Yang Junyi, Chen Xingyu, Li Guowei, Chen Linkun
1. Download the Linux source code provided by the manufacturer
https://pan.baidu.com/s/1XimrhPBQIG5edY4tPN9_pw?pwd=kdtk Extraction code: kdtk
Enter the Linux/sources/
directory, download the three compressed files OK8MP-linux-sdk.tar.bz2.0*
, and after downloading, execute:
cd Linux/sources
# Merge split compressed files
cat OK8MP-linux-sdk.tar.bz2.0* > OK8MP-linux-sdk.tar.bz2
# Unzip the merged compressed file
tar -xvjf OK8MP-linux-sdk.tar.bz2
After unzipping, the OK8MP-linux-kernel
directory is the Linux source code directory.
2. Compile Linux source code
Install cross-compilation tools
-
Download the cross-compilation toolchain:
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz
-
Unzip the toolchain:
tar xvf gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz
-
Add the path so that
aarch64-none-linux-gnu-*
can be used directly, modify the~/.bashrc
file:echo 'export PATH=$PWD/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin:$PATH' >> ~/.bashrc source ~/.bashrc
Compile Linux
-
Switch to the Linux kernel source code directory:
cd Linux/sources/OK8MP-linux-sdk
-
Execute the compilation command:
# Set Linux kernel configuration make OK8MP-C_defconfig ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- # Compile the Linux kernel make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- Image -j$(nproc) # Copy the compiled image to the tftp directory cp arch/arm64/boot/Image ~/tftp/
Create a tftp directory here for later image organization and for using tftp to transfer images as mentioned in the appendix.
3. Prepare the SD card
-
Insert the SD card into the card reader and connect it to the host.
-
Switch to the Linux/Images directory.
-
Execute the following commands for partitioning:
fdisk <$DRIVE> d # Delete all partitions n # Create a new partition p # Choose primary partition 1 # Partition number 1 16384 # Starting sector t # Change partition type 83 # Select Linux filesystem (ext4) w # Save and exit
-
Write the boot file to the SD card boot disk:
dd if=imx-boot_4G.bin of=<$DRIVE> bs=1K seek=32 conv=fsync
-
Format the first partition of the SD card boot disk as ext4:
mkfs.ext4 <$DRIVE>1
-
Remove the SD card reader and reconnect. Extract the root file system rootfs.tar to the first partition of the SD card. The rootfs.tar can be made by referring to qemu-aarch64 or using the image below.
tar -xvf rootfs.tar -C <path/to/mounted/SD/card/partition>
rootfs.tar download address:
https://disk.pku.edu.cn/link/AADFFFE8F568DE4E73BE24F5AED54B00EB
Filename: rootfs.tar
- After completion, eject the SD card.
4. Compile hvisor
- Organize the configuration files
Place the configuration files where they belong. Sample configuration files can be referred to here.
- Compile hvisor
Enter the hvisor directory, switch to the main branch or dev branch, and execute the compilation command:
make ARCH=aarch64 FEATURES=platform_imx8mp,gicv3 LOG=info all
# Put the compiled hvisor image into tftp
make cp
5. Boot hvisor and root linux
Before booting the NXP board, transfer the files from the tftp directory to the SD card, such as to the /home/arm64 directory on the SD card. The files in the tftp directory include:
- Image: root linux image, can also be used as non-root linux image
- linux1.dtb, linux2.dtb: device trees for root linux and non-root linux
- hvisor.bin: hvisor image
- OK8MP-C.dtb: This is used for some checks during uboot boot, essentially useless, can be obtained from here OK8MP-C.dts
Boot the NXP board:
- Adjust the dip switches to enable SD card boot mode: (1,2,3,4) = (ON,ON,OFF,OFF).
- Insert the SD card into the SD slot.
- Connect the development board to the host using a serial cable.
- Open the serial port with terminal software
After booting the NXP board, there should be output on the serial port. Restart the development board, immediately press and hold the spacebar to make uboot enter the command line terminal, and execute the following command:
setenv loadaddr 0x40400000; setenv fdt_addr 0x40000000; setenv zone0_kernel_addr 0xa0400000; setenv zone0_fdt_addr 0xa0000000; ext4load mmc 1:1 ${loadaddr} /home/arm64/hvisor.bin; ext4load mmc 1:1 ${fdt_addr} /home/arm64/OK8MP-C.dtb; ext4load mmc 1:1 ${zone0_kernel_addr} /home/arm64/Image; ext4load mmc 1:1 ${zone0_fdt_addr} /home/arm64/linux1.dtb; bootm ${loadaddr} - ${fdt_addr};
After execution, hvisor should boot and automatically enter root linux.
6. Boot non-root linux
Booting non-root linux requires hvisor-tool. For details, please refer to the README of hvisor-tool.
Appendix. Convenient image transfer using tftp
Tftp facilitates data transfer between the development board and the host without the need to plug and unplug the SD card each time. The specific steps are as follows:
For Ubuntu systems
If you are using Ubuntu, execute the following steps in sequence:
-
Install TFTP server software package
sudo apt-get update sudo apt-get install tftpd-hpa tftp-hpa
-
Configure TFTP server
Create TFTP root directory and set permissions:
mkdir -p ~/tftp sudo chown -R $USER:$USER ~/tftp sudo chmod -R 755 ~/tftp
Edit the tftpd-hpa configuration file:
sudo nano /etc/default/tftpd-hpa
Modify as follows:
# /etc/default/tftpd-hpa TFTP_USERNAME="tftp" TFTP_DIRECTORY="/home/<your-username>/tftp" TFTP_ADDRESS=":69" TFTP_OPTIONS="-l -c -s"
Replace
<your-username>
with your actual username. -
Start/restart TFTP service
sudo systemctl restart tftpd-hpa
-
Verify TFTP server
echo "TFTP Server Test" > ~/tftp/testfile.txt
tftp localhost tftp> get testfile.txt tftp> quit cat testfile.txt
If "TFTP Server Test" is displayed, the TFTP server is working properly.
-
Configure to start on boot:
sudo systemctl enable tftpd-hpa
-
Connect the development board's network port (there are two, please choose the one below) to the host using a network cable. And configure the host's wired network card, ip: 192.169.137.2, netmask: 255.255.255.0.
After booting the development board, enter the uboot command line, and the command becomes:
setenv serverip 192.169.137.2; setenv ipaddr 192.169.137.3; setenv loadaddr 0x40400000; setenv fdt_addr 0x40000000; setenv zone0_kernel_addr 0xa0400000; setenv zone0_fdt_addr 0xa0000000; tftp ${loadaddr} ${serverip}:hvisor.bin; tftp ${fdt_addr} ${serverip}:OK8MP-C.dtb; tftp ${zone0_kernel_addr} ${serverip}:Image; tftp ${zone0_fdt_addr} ${serverip}:linux1.dtb; bootm ${loadaddr} - ${fdt_addr};
Explanation:
setenv serverip 192.169.137.2
: Set the IP address of the tftp server.setenv ipaddr 192.169.137.3
: Set the IP address of the development board.setenv loadaddr 0x40400000
: Set the load address for the hvisor image.setenv fdt_addr 0x40000000
: Set the load address for the device tree file.setenv zone0_kernel_addr 0xa0400000
: Set the load address for the guest Linux image.setenv zone0_fdt_addr 0xa0000000
: Set the load address for the root Linux device tree file.tftp ${loadaddr} ${serverip}:hvisor.bin
: Download the hvisor image from the tftp server to the hvisor load address.tftp ${fdt_addr} ${serverip}:OK8MP-C.dtb
: Download the device tree file from the tftp server to the device tree file load address.tftp ${zone0_kernel_addr} ${serverip}:Image
: Download the guest Linux image from the tftp server to the guest Linux image load address.tftp ${zone0_fdt_addr} ${serverip}:linux1.dtb
: Download the root Linux device tree file from the tftp server to the root Linux device tree file load address.bootm ${loadaddr} - ${fdt_addr}
: Boot hvisor, load the hvisor image and device tree file.
For Windows systems
You can refer to this article: https://blog.csdn.net/qq_52192220/article/details/142693036