QEMU Basic - Xilinx€¦ · QEMU Basic In this simple Demo we shall be creating a simple Zynq HW...

8
XILINX INTERNAL QEMU Basic In this simple Demo we shall be creating a simple Zynq HW project in 2016.2, exporting to SDK to create the HDF file. This HDF file will be used as the base to create the Linux image in Petalinux. We can then use QEMU to test and explore its features. Create the Hardware System Create a project for ZC702 board Create a new BD based on the bellow image Generate output products Generate HDL Wrapper Export to SDK (This steps simply generate the HDF file used in the next steps)

Transcript of QEMU Basic - Xilinx€¦ · QEMU Basic In this simple Demo we shall be creating a simple Zynq HW...

  • XILINX INTERNAL

    QEMU Basic In this simple Demo we shall be creating a simple Zynq HW project in 2016.2, exporting to SDK to

    create the HDF file. This HDF file will be used as the base to create the Linux image in Petalinux. We

    can then use QEMU to test and explore its features.

    Create the Hardware System

    Create a project for ZC702 board

    Create a new BD based on the bellow image

    Generate output products

    Generate HDL Wrapper

    Export to SDK (This steps simply generate the HDF file used in the next steps)

  • XILINX INTERNAL

    Generate the Petalinux Image

    Change to the SDK folder of the Vivado project (where the HDF has been exported)

    Run the following commands

    petalinux-create --type project --template zynq --name sys_1

    petalinux-config --get-hw-description project_1/project_1.sdk -p sys_1

    petalinux-create --type apps --template c --name hello_world

    petalinux-config –c rootfs

    Configure the rootfs to include the following elements

    o Apps -> [*] hello_world

    o Filesystem Packages -> net -> netcat -> [*] netcat

    o Filesystem Package -> console/network -> dropbear -> [*]dropbear

    o Filesystem Package -> console/network -> dropbear -> [*]dropbear-openssh-sftp-server

    Modify the DTS to add the PHY node

    /dts-v1/;

    /include/ "system-conf.dtsi"

    / {

    };

    &gem0 {

    local-mac-address = [00 0a 35 00 c0 12];

    phy-handle = ;

    phy-mode = "rgmii-id";

    mdio {

    #address-cells = ;

    #size-cells = ;

    phy0: phy@7 {

    compatible = "marvell,88e1116r";

    device_type = "ethernet-phy";

    reg = ;

    };

    };

    };

    Petalinux-build

    Note To verify the DTB was created correctly (or expected), you can use the command below and check

    the output file.

    cd sys_1/images/linux

    ../../build/linux/kernel/xlnx-3.19/scripts/dtc/dtc -I dtb -O dts -o system.dts system.dtb

  • XILINX INTERNAL

    Run QEMU

    The QEMU is pre-compiled in Petalinux. Users can compile this themselves (See the Wiki for help

    here). For this demo, type the following command in the host machine in order to boot the built

    image.

    petalinux-boot --qemu –kernel

    This will boot. You should see the following on your console (towards the end, and before the login).

    To test the hello_world app, type hello_world on the console (after QEMU image login).

    To terminate QEMU use the Ctrl + A & X

    QEMU can be run manually instead of using petalinux commands. More information about the

    arguments can be found in the command help doc or in the QEMU wiki page or Xilinx wiki page. You

    can see in the bellow image the QEMU command used by petalinux when running the kernel image

    and a custom run of hello_world application.

    http://www.wiki.xilinx.com/QEMUhttps://qemu.weilnetz.de/qemu-doc.htmlhttp://www.wiki.xilinx.com/QEMU

  • XILINX INTERNAL

    QEMU Networking

    QEMU emulates a small sub-network (or LAN, kinda) containing a DHCP server, a gateway and a DNS

    server. Everything we need to access the internet. There are also some optional components that

    can be added to this emulated network. The DNS and gateway back onto the host machines internet

    connection. This means that the QEMU VM session has internet access.

    The Following diagram (Wiki) shows the networking architecture:

    We can check the acquired network parameters by the VM.

    Note

    If you don’t see the DNS and DCHP set up then you probably messed up your devicetree

    http://wiki.qemu.org/Documentation/Networking#User_Networking_.28SLIRP.29

  • XILINX INTERNAL

    The network connection can be used as normal, almost as if it were actually attached to the HOST

    network (If the machine running the QEMU has Xilinx network access).

    For example, we can use the wget command to download a files from the web.

    Download the crossroads homepage.

    wget web.xilinx.com

    We can also set up a proxy server to use the Xilinx proxy serverand download a released image from

    the Xilinx wiki page.

    export http_proxy=proxy.xilinx.com

    wget http://www.wiki.xilinx.com/file/view/2016.2-zc702-release.tar.xz/586243235/2016.2-zc702-release.tar.xz

    Note

    This link was correct as of writing this doc. To check the link go to the Wiki and under Download,

    verify the link address.

    Telnet

    Users can also connect to the QEMU via Telnet. For this purpose run the image with the following

    command, where value is anything between 2000 and 10000 (make sure it is unique and not

    used by other instance). Once opened, telnet from the host machine to have access to the target

    image.

    petalinux-boot --qemu --kernel --qemu-args "-redir tcp::10.0.2.15:23"

    http://www.wiki.xilinx.com/Zynq+Releases

  • XILINX INTERNAL

    SSH

    QEMU guest session can be accessed through ssh as done with telnet. In this case ssh port have to

    be redirected when launching the guest image.

    Launch the Guest:

    petalinux-boot --qemu --kernel --qemu-args "-redir tcp:1400:10.0.2.15:22"

    Launch the SSH session:

    ssh –c aes128-cbc –p 1400 root@localhost

    Note

    The RSA key of the booted linux is changed after reboot. So, beware of this. You can just do a vim

    .ssh/known_hosts and dd (delete the last key)

    TFTP

    QEMU also has a built in TFTP capability to allow for easy file transfer to/from guest machine to the

    host. To test this feature, create a directory with a new file on it and run the QEMU image sharing

    the folder with the TFTP server.

    mkdir public

    cd public

    echo "Hello There" > file.txt

    cd ..

    petalinux-boot –qemu –kernel –qemu-args “-tftp ./public”

  • XILINX INTERNAL

    SCP

    Other way to transfer files from the host machine to the target is using scp. To be able to use scp,

    QEMU have to been launched with the ssh tunnel redirected to the localhost (see SSH example). This

    way files can be send to the guest machine with the following command.

    Launch the Guest:

    petalinux-boot --qemu --kernel --qemu-args "-redir tcp:1400:10.0.2.15:22"

    Send the file with scp:

    scp –c aes128-cbc –p 1400 public/file.txt root@localhost:/home/root

  • XILINX INTERNAL

    Multiple session

    Users can also connect two QEMU sessions and using the –redir switch. Communication can be

    managed in a way that TX and RX between guest and host.

    petalinux-boot --qemu --kernel --qemu-args "-redir tcp:2500:10.0.2.15:1440"

    petalinux-boot --qemu --kernel --qemu-args "-redir tcp:2501:10.0.2.15:1550"

    Once both guest are running we can setup the scenario in two modes, Guest 1 as listener and Guest

    2 as sender or in the opposite direction.

    Guest 1 as listener:

    nc –l –p 1440

    Guest 2 as sender:

    nc 172.21.17.64 2500

    Here, you can see that if I type Hello in guest2, it is sent to guest1. Also, if I type on guest1, it will be

    sent to guest2.

    Guest 1

    1440

    Guest 2

    1500

    Host 2500 2501