QEMU runs armv8 platform

Posted by q1234ask on Mon, 06 Sep 2021 04:52:57 +0200

Running armv8 platform with qumu

Because the work involves the bsp part of the mobile phone, we will systematically learn the contents of uboot and kernel in the future.
This chapter refers to the linux kernel of running bar

Bloggers use virtual machines for learning. The system is Ubuntu 16.04

Tools and code download

  1. Install the following tools
    sudo apt-get install qemu libncurses5-dev gcc-aarch64-linux-gnu build-essential
  2. Code download
    • git download kernel 4.14 kernel code
      I use the code cloud to download, which will be very fast. The kernel mainline code address is: https://gitee.com/mirrors/linux
      git clone git@gitee.com:mirrors/linux.git
      Because you are downloading the mainline code, you need to switch to the corresponding version
      git tag / / view tag
      git checkout v4.14 / / switch to the corresponding version
    • Download busybox Toolkit
      wget https://busybox.net/downloads/busybox-1.24.0.tar.bz2

Compile minimum file system

  1. Execute the command to compile

    cd busybox
    export ARCH=arm64
    export CROSS_COMPILE=aarch64-linux-gnu-
    make menuconfig  #The configuration interface settings are as follows:
    make install 

    Configure busybox as static compilation in the configuration interface:

    Busybox Settings ---> 
    		Build options --->
    			[*]Build BusyBox as a static binary (no shared libs) 

    Put the compiled busybox /_ Copy the install directory to kernel4.14 /.

  2. Adding directories and files

    • Add the etc/ dev / and mnt / directories
      mkdir etc
      mkdir dev
      mkdir mnt
      mkdir -p etc/init.d/	
    • Create a new rcS file under etc/init.d / and add executable permissions. Write the following:
      mkdir -p /proc
      mkdir -p /tmp
      mkdir -p /sys
      mkdir -p /mnt
      /bin/mount -a
      mkdir -p /dev/pts
      mount -t devpts devpts /dev/pts
      echo /sbin/mdev > /proc/sys/kernel/hotplug
      mdev -s
    • Create a new fstab file under etc / and write the following contents:
      proc /proc proc defaults 0 0
      tmpfs /tmp tmpfs defaults 0 0
      sysfs /sys sysfs defaults 0 0
      tmpfs /dev tmpfs defaults 0 0
      debugfs /sys/kernel/debug debugfs defaults 0 0
    • Create a new inittab file under etc / and write the following contents:
      ::ctrlaltdel:/bin/umount -a -r
    • Create a new device node under dev /
      sudo mknod console c 5 1
      sudo mknod null c 1 3

Compiling kernel 4.14

Execute the following command:

export ARHC=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make menuconfig #Refer to the following for compiling configuration
make -j4

In the pop-up configuration interface, you need to configure the following:

General setup --->
	[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support !!Select this item to modify
		(_install) Initramfs source file(s)   !!!(_install)Directory is the directory of the files we added earlier
Boot options --->
	() Default kernel command string
Kernel Features -->
	Page size (4KB) --->
		Virtual address space size (48-bit) --->

QEMU running armv8

Execute command:

qemu-systme-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -m 2048 -smp 2 -kernel arch/arm64/boot/Image --append "rdinit=/linuxrc console=ttyAMA0"

Problem summary

  1. The error "$'\ r': command not found"? Occurred while compiling kernel4.14??
    The reason is that the kernel 4.14 code is copied from the windows system, and the file format needs to be converted from dos to unix.
    To do this, download the tool dos2unix and execute the following command:
    for x in $(find .);do dos2unix $x $x;done
  2. Slow speed and error report when downloading kernel code???
    First of all, downloading kernel code using git will be very slow. Here, I'm Amway Code cloud . You can first create a warehouse on the code cloud and import the original git warehouse into the code cloud. Then download the code cloud through git, and the speed will take off. The operation is shown in the figure:

    After synchronizing the git warehouse to the code cloud, when I use the git clone command to download, I will prompt fatal: index pack failed
    Baidu explained that the reason is that the ubuntu memory partition is insufficient. Downloading the linux kernel requires more than 3G memory. The hard disk space I allocated for the virtual machine is too small, so I need to modify the ubuntu virtual machine partition. Refer to [ubuntu] expansion of image sda1 partition of ubuntu virtual machine (Gparted)
  3. How to switch the kernel mainline code downloaded by git to the specified version??
    After downloading the kernel mainline code, we can switch to the specified version through the following command:
    git tag #Check whether you have the version you need
    git checkout <tag_id> #Switch the code to the branch corresponding to tag

Topics: kernel