Centos7 build qemu simulator to simulate arm-vexpress-a9 development board

Centos7 build qemu simulator to simulate arm-vexpress-a9 development board

1. Download and installation of cross compiler

2. Installation of qemu

  • reference:

  • Official website: https://download.qemu.org/

  • step:

    # 下载源代码
    wget https://download.qemu.org/qemu-3.1.0.tar.xz
    tar xvf qemu-3.1.0.tar.xz
    # 新建编译目标路径
    mkdir build
    # 编译
    cd qemu-3.1.0
    ./configure --target-list=arm-softmmu --audio-drv-list= --prefix=/root/qemu/build  # 配置qemu,支持模拟arm架构下的全部单板
    # ./configure --prefix=/root/xxx/build
    make -j8
    make install
    
    # 说明:
    $./configure --enable-kvm --enable-debug --enable-vnc --enable-werror  --target-list=arm-softmmu --audio-drv-list=
    # configure脚本用于生成Makefile,其选项可以用./configure --help查看。这里使用到的选项含义如下:
    # --enable-kvm:编译KVM模块,使QEMU可以利用KVM来访问硬件提供的虚拟化服务。
    # --enable-vnc:启用VNC。
    # --enalbe-werror:编译时,将所有的警告当作错误处理。
    # --target-list:选择目标机器的架构。默认是将所有的架构都编译,但为了更快的完成编译,指定需要的架构即可。
    

3. uboot installation

Reference: http://blog.csdn.net/aggresss/article/details/54945726

  • 1), source file download: http://ftp.denx.de/pub/u-boot/

    wget http://ftp.denx.de/pub/u-boot/u-boot-2018.09.tar.bz2
    
  • 2), unzip the source file

    tar jvxf u-boot-2018.01.tar.bz2 -C xxxx  (xxx为需要解压的目录)
    
  • 3). Enter the U-Boot source file directory, and then execute:

    # export CROSS_COMPILE=arm-none-eabi-
    export ARCH=arm
    export CROSS_COMPILE=arm-linux-gnueabi-
    # 要求bison等
    yum install bison flex
    # 编译
    make vexpress_ca9x4_defconfig
    make
    # 或执行如下2个步骤
    # make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_ca9x4_defconfig
    # make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm
    

    After the compilation is complete, if the u-boot file is generated in the directory, the compilation is successful.

  • 4) Write the script run.sh in the U-Boot source code directory

    qemu-system-arm -M vexpress-a9 -nographic -m 512M -kernel u-boot
    

    Then chmod +x run.sh increases file execution permissions.

  • 5), finally execute ./run.sh, you can see that the bootloader is started, but there is no image file

    smc911x: MAC 52:54:00:12:34:56
    Wrong Image Format for bootm command
    ERROR: can't get kernel image!
    => 
    

    Press Ctrl+a, X to exit

4. Compile the kernel

  • Reference blog post: http://blog.csdn.net/aggresss/article/details/54946438

  • Official download address: https://www.kernel.org/pub/linux/kernel/

  • Tsinghua University Mirror: https://mirrors.tuna.tsinghua.edu.cn/kernel

  • Git clone

    git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    
  • Download

    wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v3.x/linux-3.18.135.tar.xz
    
  • 1), find the configuration file vexpress_defconfig that needs to compile the kernel from arch/arm/configs and copy it to the root directory of the source code

  • 2), execute the command

    # export CROSS_COMPILE=arm-none-eabi-
    # export ARCH=arm
    make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm  vexpress_defconfig  # 生成vexpress开发板的config文件
    make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm  zImage
    make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm  modules
    make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm  dtbs
    
  • 3). Generate zImage file in arch/arm/boot directory after compiling, it means compiling successfully.

    • test
      qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -nographic -append "console=ttyAMA0"
      
    • Which tty should be filled in the console= parameter in the kernel startup parameters?
      • Reference: https://blog.csdn.net/qingtian12138/article/details/53609526
      • Solution: Because the serial port driver types of different boards are different, the names of the created tty devices are of course also different. What is the tty device name of the vexpress board? In fact, this value can be found from the generated .config file CONFIG_CONSOLE macro.
  • 4), about the kernel version

    • Reference: https://www.cnblogs.com/mfmdaoyou/p/6934098.html
    • Explanation: It is found that the code of the 3.18 version number and later version number on the main line cannot be executed using this construction method. The root cause of the problem has not yet been identified. Suppose the reader wants to build successfully at high speed. It is recommended to use the kernel of version 3.16 to build.
  • 5) When I compile the 3.1.16 kernel with arm-none-eabi- version 5.4, the following error is reported

    include/linux/compiler-gcc.h:106:30: fatal error: linux/compiler-gcc6.h: No such file or directory
    #include gcc_header(__GNUC__)
    
    • You can download the corresponding version of the cross-compilation tool on Linaro's official website (https://releases.linaro.org/components/toolchain/binaries/) to solve this problem.
      # 原因是因为我使用的交叉编译工具链版本太高(6.2.1版本)导致,先在内核代码根目录下搜索compiler-gcc*
      ./include/linux/compiler-gcc3.h 
      ./include/linux/compiler-gcc5.h 
      ./include/linux/compiler-gcc.h 
      ./include/linux/compiler-gcc4.h
      # 支持的版本有3、4、5,在Linaro官网上下载5版本的交叉编译工具链即可解决问题。
      
    • The author also reported the above problems when compiling 3.1.16 with gcc-linaro-6.3.1 version of arm-linux-gnueabi, and compiling version 3.18.135 did not report the above problems.

5. Compile busybox

  • 1), download busybox from https://busybox.net/downloads/

  • 2), enter the Busybox source file directory and execute make menuconfig, if an error is reported, yum list ncurses , and then install the listed things

    Busybox Setting -> Build options 
      -> Build Busybox as a static binary (no shared libs)    # 选中 静态编译。
      -> Cross Compiler prefix                                # 交叉编译器配置(arm-linux-gnueabi-,可make命令带入)
      -> Installation options -> BusyBox installation prefix  # 默认目标位置(若不指定,需手动移到rootfs;若已有rootfs,可指定rootfs位置<推荐,自动完成>)
    

    Note : If you do not select "Build Busybox as a static binary (no shared libs)", when you start qemu, it will report a "kernel panic" error!

  • 3), compile

    make distclean   # 清除原有配置
    make menuconfig  # 配置命令选项
    make CROSS_COMPILE=arm-linux-gnueabi-
    make CROSS_COMPILE=arm-linux-gnueabi- install   # 在_install 目录下生成编译文件: bin sbin linuxrc usr 等
    
  • 4), the problem

    • When compiling busybox with arm-none-eabi-, an error of curses.h not found is reported
    # make menuconfig
    HOSTCC  scripts/basic/fixdep
    HOSTCC  scripts/basic/split-include
    HOSTCC  scripts/basic/docproc
    HOSTCC  scripts/kconfig/conf.o
    HOSTCC  scripts/kconfig/kxgettext.o
    HOSTCC  scripts/kconfig/mconf.o
    HOSTCC  scripts/kconfig/zconf.tab.o
    HOSTLD  scripts/kconfig/mconf
    HOSTCC  scripts/kconfig/lxdialog/checklist.o
      In file included from scripts/kconfig/lxdialog/checklist.c:24:0:
      scripts/kconfig/lxdialog/dialog.h:31:20: 致命错误:curses.h:没有那个文件或目录
      #include CURSES_LOC
    

6. Make the root file system

  • Reference: Use Qemu to simulate vexpress-a9 (1) — Build a Linux kernel debugging environment (https://blog.csdn.net/qingtian12138/article/details/53609526)

  • 1), create a blank file, 32M

    dd if=/dev/zero of=a9rootfs.ext3  bs=1M  count=32
    
  • 2), format

    mkfs.ext3 a9rootfs.ext3
    
  • 3), create a root file system directory

    mkdir rootfs
    
  • 4) Copy the files under busybox

    cp busybox/busybox-1.26.2/_install/* -r rootfs/
    
  • 5), copy the lib of the cross compiler

    mkdir rootfs/lib/
    cp -P /xxx/arm-linux-gnueabi/lib/* rootfs/lib/
    
  • 6), create terminal equipment

    mkdir rootfs/dev/
    mknod rootfs/dev/tty1    c 4 1
    mknod rootfs/dev/tty2    c 4 2
    mknod rootfs/dev/tty3    c 4 3
    mknod rootfs/dev/tty4    c 4 4
    mknod rootfs/dev/console c 5 1
    mknod rootfs/dev/null    c 1 3
    
  • 7), create the necessary directories

    mkdir -p rootfs/proc/
    mkdir -p rootfs/sys/
    mkdir -p rootfs/tmp/
    mkdir -p rootfs/root/
    mkdir -p rootfs/var/
    mkdir -p rootfs/mnt/
    
  • 8), create a temporary directory and map with blank files, the purpose is to copy the root file system into it

    mkdir tmpfs
    mount -t ext3  a9rootfs.ext3  tmpfs/ -o  loop 
    cp -r rootfs/* tmpfs/
    umount tmpfs
    
  • 0), the script of the above steps,
    create a directory, copy the zImage, vexpress-v2p-ca9.dtb, _install directories under one directory

    # 打开脚本文件
    vim mkrootfs.sh
    # 粘贴如下内容
    rm -rf rootfs
    rm -rf tmpfs
    rm -f  a9rootfs.ext3
    
    mkdir rootfs
    cp ../busybox/busybox-1.26.2/_install/* rootfs/ -raf  # 与你的busybox的目录有关
    mkdir -p rootfs/proc/
    mkdir -p rootfs/sys/
    mkdir -p rootfs/tmp/
    mkdir -p rootfs/root/
    mkdir -p rootfs/var/
    mkdir -p rootfs/mnt/
    
    cp -arf ~/xxx/arm-linux-gnueabi-6/lib/lib rootfs/     # 与你的arm-linux-gnueabi-的目录有关 
    rm rootfs/lib/*.a
    arm-linux-gnueabi-strip rootfs/lib/*
    
    mkdir -p rootfs/dev/
    mknod rootfs/dev/tty1    c 4  1
    mknod rootfs/dev/tty2    c 4  2
    mknod rootfs/dev/tty3    c 4 3
    mknod rootfs/dev/tty4    c 4 4
    mknod rootfs/dev/console c 5 1
    mknod rootfs/dev/null    c 1 3
    
    dd if=/dev/zero of=a9rootfs.ext3  bs=1M  count=32
    mkfs.ext3 a9rootfs.ext3
    
    mkdir -p tmpfs
    mount -t ext3  a9rootfs.ext3  tmpfs/ -o  loop
    cp -r rootfs/*  tmpfs/
    umount tmpfs
    

7, start

# 拷贝kernel文件到a9rootfs.ext3所在目录,以便执行
cp -r ../kernel/linux-3.18.135/arch/arm/boot/ .
# 执行
qemu-system-arm  -nographic -sd a9rootfs.ext3 -M vexpress-a9 -m 512M -kernel zImage -dtb ./dts/vexpress-v2p-ca9.dtb -append "init=/linuxrc root=/dev/mmcblk0 rw rootwait earlyprintk console=ttyAMA0"  
qemu-system-arm  -serial stdio -sd a9rootfs.ext3 -M vexpress-a9 -m 512M -kernel zImage -dtb ./dts/vexpress-v2p-ca9.dtb -append "init=/linuxrc root=/dev/mmcblk0 rw rootwait earlyprintk console=ttyAMA0"  

8. Attention

  • 1). Before compiling the above, please make sure export ARCH=arm; export CROSS_COMPILE=arm-linux-gnueabi-
  • 2). If an error is reported, it is generally not included in some libraries, Baidu or Google

9. Problem

Guess you like

Origin blog.csdn.net/hylaking/article/details/88423941