xilinx qemu

本文描述如何在 QEMU 中启动 xilinx 设备,并启动 xilinx 官方提供的系统镜像

1. xilinx 是什么

2. xilinx QEMU 编译部署

从 github 下载 Xilinx qemu 源码:

1
2
$ git clone git://github.com/Xilinx/qemu.git
$ cd qemu

安装依赖:

1
$ sudo apt install libglib2.0-dev libgcrypt20-dev zlib1g-dev autoconf automake libtool bison flex libpixman-1-dev libsd1.2-dev

创建compile/buildcompile/install目录,在compile/build下创建 build.sh 编译脚本:

../../configure --prefix="/qemu/compile/install" --target-list="aarch64-softmmu,microblazeel-softmmu" --enable-fdt --disable-kvm --disable-xen

make -j4 install

运行脚本,若出现报错:

warning: cannot parse SRV response: Message too long

则可能是 submodule 获取路径错误,修改./git/config或.gitsubmodules 如下:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = https://github.com/Xilinx/qemu.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "branch/xilinx-v2019.1"]
        remote = origin
        merge = refs/heads/branch/xilinx-v2019.1
[submodule "dtc"]
        url = https://github.com/qemu/dtc.git
[submodule "capstone"]
        url = https://github.com/qemu/capstone.git
[submodule "ui/keycodemapdb"]
        url = https://github.com/qemu/keycodemapdb.git

再次运行编译脚本。更多 git submodule 的信息可参考Git-工具 - 子模块

使用 help 命令查看 machine 支持

1
2
3
4
$ ./qemu-system-aarch64 -M help | grep arm-generic-fdt-plnx
arm-generic-fdt-plnx Deprecated ARM device tree driven machine for the Zynq-7000
$ ./qemu-system-microblazeel -M help | grep microblaze-fdt-plnx
microblaze-fdt-plnx  Microblaze device tree driven machine model for PetaLinux

3. 运行官方提供的镜像

1
2
3
4
$ ./aarch64-softmmu/qemu-system-aarch64 \
    -M arm-generic-fdt-7series -machine linux=on \
    -serial /dev/null -serial mon:stdio -display none \
    -kernel <path>/uImage -dtb <path>/devicetree.dtb --initrd <path>/uramdisk.image.gz
1
2
3
4
5

$ ./aarch64-softmmu/qemu-system-aarch64 \
    -M arm-generic-fdt-7series -machine linux=on \
    -serial /dev/null -serial mon:stdio -display none \
    -kernel <path>/image.elf -dtb <path>/system.dtb

示例中的镜像可在http://www.wiki.xilinx.com/Zynq+Releases找到。

4.文件传输

  1. 使用 dd 创建一个文件,作为虚拟机和宿主机之间传输桥梁 dd if=/dev/zero of=/opt/share.img bs=1M count=200
  2. 格式化 share.img 文件 mkfs.ext4 /opt/share.img
  3. 在宿主机上创建一个文件夹, mkdir /tmp/share mount -o loop /opt/share.img /tmp/share 这样,在宿主机上把需要传输给虚拟机的文件放到/tmp/share 下即可。
  4. 启动 qemu-kvm 虚拟机,添加上/opt/share.img 文件。
  5. 在虚拟机中 mount 上添加的一块硬盘。即可以获得宿主机上放在/tmp/share 文件夹下的文件