Skip to content

Bash On Windows

Sean Cross edited this page Jan 23, 2018 · 23 revisions

Using Windows to develop Litex

Linux runs pretty well on Windows. Well enough to build and use Litex.

Pre-work

You can build Litex on Windows, using the Linux subsystem. To start with, Install Linux on Windows.

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 install Xilinx, install an X server. The preferred server is MobaXTerm.

You will need a terminal client. We use Tera Term.

You will also need a tftp server. Chocolatey has tftpd64.exe.

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.

  1. Open MobaXTerm
  2. Open bash
  3. run "export DISPLAY=:0"
  4. 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.

Install Litex

Download & setup the LiteX Build Environment

$ git clone https://github.com/timvideos/litex-buildenv.git
$ cd litex-buildenv
$ export CPU=or1k 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=or1k) $

You should have "(LX P=arty C=or1k)" 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=or1k PLATFORM=arty TARGET=net
$ source ./scripts/enter-env.sh
(LX P=arty C=or1k) $

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/tftp
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
Clone this wiki locally