QEMU - timvideos/litex-buildenv GitHub Wiki

Running test firmware inside QEMU

You are able to run the firmware using QEMU for emulation.

Dependencies

Ubuntu / Debian

You need atftpd net boot images inside QEMU

$ sudo apt-get install atftpd

You also need some build dependencies;

$ sudo apt-get install libpixman-1-dev pkg-config libglib2.0-dev python-minimal libftdi-dev uml-utilities openvpn net-tools
$ sudo apt install bison flex
$ sudo apt build-dep qemu # maybe?

You may also need to add an app exclusion for ufw, to allow inbound tftp connections:

$ sudo ufw allow tftp
$ sudo ufw allow 6069

Fedora

You need tftpd to net boot images inside QEMU

$ sudo dnf install tftp-server

You also need some build dependencies;

$ sudo dnf install glib2-devel pixman-devel libftdi-devel uml_utilities openvpn bison flex

On Fedora you may need to configure your firewall with;

$ sudo firewall-cmd --zone=FedoraWorkstation --add-service tftp
$ sudo firewall-cmd --zone=FedoraWorkstation --add-port 6069/udp

Note about tftp setup

If you already have a tftpd installed and configured, you're going to have problems here. This can include things started by inetd. You'll know this is the case if you get a "cannot bind to 192.168.100.100 port 69 udp" error from the below steps.

If you get this error, check out the contents of your /etc/inetd.conf and comment out the line (by prepending it with '#') which might look similar to this:

    tftp          dgram   udp4    wait    nobody /usr/sbin/tcpd /usr/sbin/in.tftpd --tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 --mcast-addr 239.239.239.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /srv/tftp

If you needed to edit /etc/inetd.conf (or similar) then you will also need to reload the inetd configuration, eg, "service inetutils-inetd reload" to cause it to re-read the changed configuration.

NOTE: A Litex BIOS change around 2018-01-18 allowed it to support both TFTP boot from a high-numbered port (UDP/6069 was chosen in timvideos/litex-buildenv) and also to fall back to the well known UDP/69. If you installed/updated your litex-buildenv on/after 2018-01-18 try checking for tftpd running on UDP/6069 instead (which will hopefully reduce the conflicts with tftpd running as a system daemon).

FIXME: We need better detection and set up of tftpd. See this github issue.

Net booting firmware in QEmu

Enter the LiteX Build Environment and then type

(LX P=arty C=mor1kx) $ ./scripts/build-qemu.sh

This will build QEmu, and create the tap interface (shared between the host and QEmu) the first time, and then start the tftp server on that interface.

If you need to manually stop or start the tftp server (e.g. after a reboot), then you can use

(LX P=arty C=mor1kx) $ make tftpd_stop          # Stop any previously run tftp server
(LX P=arty C=mor1kx) $ make tftpd_start         # Start the tftp server again

After running ./scripts/build-qemu.sh, If you see something like this:

    Reading value 00000000 fr MDIO PHY 00000000 REG 0000001f
    reg 31: 0000
    Datasync
    Reading value 0000bc00 fr MDIO PHY 00000000 REG 00000011
    MDIO mode: 1000Mbps / link: up
    uIP init done with ip 192.168.100.50
    Etherbone listening on port 1234
    Telnet listening on port 23
    H2U 00:00:00>

Then you're good to go. Now you should check that you can telnet to the firmware:

    $ telnet 192.168.100.50 23
    Trying 192.168.100.50...
    Connected to 192.168.100.50.
    Escape character is '^]'.

    <hit enter a couple of times>
    H2U 00:00:42>

Exit telnet by typing "ctrl-] q" in the telnet session to exit telnet, and "ctrl-c" in the build-qemu session to exit qemu.

⚠️ **GitHub.com Fallback** ⚠️