Networking - timvideos/litex-buildenv GitHub Wiki

TFTP Firmware Loading

If your board has networking, you can TFTP boot your firmware.

Dependencies

Ubuntu / Debian

You need atftpd server to net boot firmware;

$ sudo apt-get install atftpd

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 server to net boot firmware;

$ sudo dnf install tftp-server

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.

TFTP Server control

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

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.

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.

Getting Ethernet to bare metal firmware working

Due to the Ethernet link being reset multiple times during the FPGA programming and booting sequence, your network needs to be manually configured to remain up rather than using automated management with network manager or systemd.

You have been provided a USB Hub with an inbuilt Ethernet controller for connecting to the Arty. This should mean you don't need to break or affect your normal networking set up.

Debian Network Setup

Debian uses /etc/network/interfaces to control static configurations.

Add the following to your /etc/network/interfaces file.

Note: Your interface name is unique to each USB hub. Make sure you are using your own value.

iface enx00e04c680b24 inet static
	address 192.168.100.100
	netmask 255.255.255.0

After changing this file, restart Network Manager with;

$ sudo service network-manager restart

You should then check that network manager is not managing the enx00e04c680b24 interface using the following and look for a status of "unmanaged"; if you see a status of "connected" or "unavailable" that means that Network Manager is trying to manage that interface (and it either has ethernet carrier or does not have carrier respectively).

$ nmcli dev status
DEVICE           TYPE      STATE         CONNECTION
docker0          bridge    connected     docker0
wlp4s0           wifi      disconnected  --
enp0s31f6        ethernet  unavailable   --
enx00e04c680b24  ethernet  unmanaged     --
lo               loopback  unmanaged     --
tap0             tun       unmanaged     --

Delete the tap interface (or reboot)

$ sudo ip link delete dev tap0

Bring up the Ethernet device with ifup;

$ sudo ifup enx00e04c680b24

RedHat / Fedora Setup

Redhat / Fedora uses /etc/sysconfig/network-scripts/ifcfg-INTERFACE script files to control static network interface configurations.

Create an /etc/sysconfig/network-scripts/ifcfg-enx00e04c680b24 file.

Note: Your interface name is unique to each USB hub. Make sure you are using your own value in the name of the file, and below.

`DEVICE=enx00e04c680b24`


```
NM_CONTROLLED=no
ONBOOT=no
BOOTPROTO=static
IPADDR=192.168.100.100
NETMASK=255.255.255.0
```

After creating (or changing) this file, restart Network Manager with:

$ sudo systemctl restart NetworkManager

You should then check that network manager is not managing the enx00e04c680b24 interface using the following and look for a status of "unmanaged"; if you see a status of "connected" or "unavailable" that means that Network Manager is trying to manage that interface (and it either has ethernet carrier or does not have carrier respectively).

$ nmcli dev status
DEVICE           TYPE      STATE         CONNECTION
docker0          bridge    connected     docker0
wlp4s0           wifi      disconnected  --
enp0s31f6        ethernet  unavailable   --
enx00e04c680b24  ethernet  unmanaged     --
lo               loopback  unmanaged     --
tap0             tun       unmanaged     --

Delete the tap interface (or reboot)

$ sudo ip link delete dev tap0

Bring up the Ethernet device with ifup;

$ sudo ifup enx00e04c680b24

Manual Network Configuration

If you don't have network manager installed, you can just manually configure the network interface using ifconfig or ip. Note: Your interface name (shown in red) is unique to each USB hub. Make sure you are using your own value.

Using ifconfig

$ sudo ifconfig enx00e04c680b24 inet 192.168.100.100 up

Using IP

$ sudo ip addr add 192.168.100.100/24 dev enx00e04c680b24
$ sudo ip link set enx00e04c680b24 up

Advanced Networking Setup

If can be useful to have the 192.168.100.100 on both your ethernet interface and inside QEmu so you can quickly switch back and forth between them. You can do this by using the Linux bridge interface.

Create a bridge

$ sudo brctl addbr br0

Add interfaces to the bridge

$ sudo brctl addif br0 tap0
$ sudo brctl addif br0 enx00e04c680b24

Configure the bridge to be 192.168.100.100

$ sudo ifconfig br0 192.168.100.100 netmask 255.255.255.0
⚠️ **GitHub.com Fallback** ⚠️