Bash On Windows - timvideos/litex-buildenv GitHub Wiki
Using Bash On Windows to develop LiteX Build Environment
Linux runs pretty well on Windows, well enough to build and use LiteX Build Environment.
Pre-work
You can build Litex on Windows, using the Linux subsystem. To start with, Install Linux on Windows. (Requires an updated Win 10. original throws weird cryptic error messages.) Be sure to complete all three main steps.
- Enable the linux subsystem in an Administrator Level instance of Powershell
- Download and install a distro. The easiest way is via the Microsoft Store (requires login with any MS identity)
- The installer that comes from the store still needs to be run. It should be found at the top of the Recently Added column of the Start Menu.
sudo apt update && sudo apt upgrade
You can use Chocolatey as a package manager to install additional software, or you can manually install packages.
To use Bash, you can simply run "bash" from a command prompt, however it is recommended to use ConEmu.
To run the gui Xilinx installer, you will need to install an X server. Preferred: MobaXTerm.
You will need a terminal client. We use Tera Term.
You will also need a tftp server. Chocolatey has tftpd64.exe (the package name is tftpd32 but the appropriate version will be installed).
7-zip.exe to unzip openocd-nnn.7z.
openocd is not in Chocolatey, but is required. Download it from GNU Toolchains and manually extract it and set up your PATH variable to point to the bin directory. We will assume it has been installed to C:\Program Files\OpenOCD.
Finally, you will need a tool to modify the USB driver used. Download the Visual GDB USB Driver Tool.
Install Vivado
Litex uses Vivado. You can do a console-only install, but it's usually easier to use the GUI.
- Open MobaXTerm
- Open bash
sudo apt install libxrender1:amd64 libxtst6:amd64 libxi6:amd64
export DISPLAY=:0
- Follow the Linux instructions. Your Windows files are stored in /mnt/c/ in case you decide to download Vivado under Windows.
The Linux instructions are at Xilinx-Vivado. (Download Vivado for Linux. You can call the Windows Vivado from the Linux bash shell, but path resolution gets a bit weird if the path you're in isn't accessible from Windows.)
Install Litex
Download & setup the LiteX Build Environment
$ sudo apt install git bzip2 build-essential
$ git clone https://github.com/timvideos/litex-buildenv.git
$ cd litex-buildenv
$ export CPU=mor1kx PLATFORM=arty TARGET=net
$ ./scripts/download-env.sh
Currently, you need to download newer versions of the compiler that do not statically link glibc, due to Microsoft not implementing the deprecated vsyscall. Linux users will need to do this too if they're running a modern kernel that disables this syscall.
$ bash
$ export PATH=$PWD/build/conda/bin:$PATH
$ conda install http://hopper.mithis.com/~tim/gcc-or1k-elf-newlib-5.4.0_4334_g9310fdc97ee-20180119_141334.tar.bz2
$ conda install http://hopper.mithis.com/~tim/gcc-or1k-elf-nostdc-5.4.0_4334_g9310fdc97ee-20180119_140634.tar.bz2
$ conda install http://hopper.mithis.com/~tim/gcc-lm32-elf-newlib-5.4.0-20180119_142101.tar.bz2
$ conda install http://hopper.mithis.com/~tim/gcc-lm32-elf-nostdc-5.4.0-20180118_145621.tar.bz2
Now you can enter the environment:
$ source ./scripts/enter-env.sh
(LX P=arty C=mor1kx) $
You should have "(LX P=arty C=mor1kx)" in your bash prompt now. NOTE: if you see an error like “bash: lm32-elf-ld: command not found...” you probably forgot to do the exports above.
Resuming Development
So you walked away and now need to start a new session. Here’s how:
$ cd litex-buildenv
$ export CPU=mor1kx PLATFORM=arty TARGET=net
$ source ./scripts/enter-env.sh
(LX P=arty C=mor1kx) $
Setting up OpenOCD
We will replace the bundled copy of openocd with a Windows version, and create a shim. We will also copy the configuration scripts to our global install of openocd.
The Arty exposes two USB devices. The first is used for programming, and the second is used for serial communication.
Open up the VisualGDB USB Driver Tool. You should see two "Diligent USB Device" listings. One is listed as "Interface 00", and the other is "Interface 01".
Double-click on "Interface 00", and then double-click on "WinUSB". This will replace the default driver with the WinUSB libusb-compatible shim.
Double-click on "Interface 01", and then double-click on "FTDI". This will replace the default driver with the official FTDI driver.
Copy the scripts into the openocd directory:
$ sudo cp -a build/conda/share/openocd/scripts/* /mnt/c/Program\ Files/OpenOCD/share/openocd/scripts/
Create a shim for openocd to redirect it to the Windows version:
$ mv build/conda/bin/openocd build/conda/bin/openocd.orig
$ vi build/conda/bin/openocd
Create the following shell script:
#!/bin/bash
nargs=$#
args=
while [ $nargs -gt 0 ]
do
args="\"\$$nargs\" $args"
nargs=`expr \$nargs - 1`
done
eval exec "/mnt/c/Program\\ Files/OpenOCD/bin/openocd.exe" $args
Mark it as executable:
chmod a+x build/conda/bin/openocd
Setting up TFTP
The boards wants to boot from TFTP. Assign your interface a static address of 192.168.100.100.
Build the tftp image by running "make tftp", and run the tftp server:
make tftp
cd build/tftpd
tftpd64.exe
cd ../..
You can now rebuild the firmware by running "make tftp", and the server will automatically pick up changes.
You may want to disable the DHCP server, and modify tftpd64 to only listen on 192.168.100.100. This can be done in the Settings window.
Connecting via Serial
Tera Term can be used to talk to the board. Open Tera Term and connect to the COM port. It shows up as "USB Serial Port". Set the baudrate to 115200 by going to Setup -> Serial... and changing it to 115200. Correct the line endings by going Setup -> Terminal... and setting Receive to LF.
Running Qemu
By default, qemu wants to set up a TUN/TAP driver. It's much easier to just force it to use userspace. Before running build-qemu.sh, run:
$ export QEMU_NETWORK=user