Exploring Shakti E Processors — Part 1 Compiling and Programming the Core
While I was randomly perusing through my LinkedIn feed(we’ve all done it) I’ve recently discovered the Swadeshi Microprocessor Challenge and was extremely curious as to what the Shakti platform offered.
This article is Part-1 of the steps I did to get started with the platform. Part-2 will cover the software development ecosystem and my thoughts on it.
So, what is Shakti?
An excerpt from the Shakti website
Shakti is an Open Source processor development program based on RISC-V ISA. There are many classes of processors in the Shakti ecosystem with varying compute capabilities.
There are a couple of different classes of processors available for evaluation, the E-Class and the C-Class processors.
E-Class
- An Embedded class processor, built around a 3-stage in-order core. It is aimed at low-power and low compute applications.
- It is capable of running basic RTOS like FreeRTOS, Zephyr and eChronos.
C-Class
- A controller class of processor, aimed at mid-range application workloads.
- The core is highly optimized, 6-stage in-order design with MMU support and capability to run operating systems Linux and Sel4.
Since I’m most familiar with embedded designs for Cortex M class processors, I decided to experiment with the E-Class. Also, there’s something intensely satisfying in getting a blinky LED project to work in bare-metal C right?? Right?? Just me eh…
Hardware and Software Platform
The E-Class is available as a open source soft-core and must be first loaded onto a FPGA to evaluate. The Digilent Arty A7 is the board supported for this class, a moderately priced kit at 129$ so I put in the order.
Now, from a software development environment perspective I was happy to see PlatformIO integration which helps me as I’m a VSCode fan for a while.
Everything seemed to be going smoothly except…
Linux…why god why
I get it, you aren’t a real developer until you run Linux. But I’m just not in the mood to make a VM to get this working.
I already have WSL installed, so my hope was that I can get to the point where I will compile the E-Class core bit file onto the FPGA and then continue working in Windows as usual for the actual code compilation/debug in VSCode/PlatformIO.
So going way off the beaten path here
Getting the tooling ready on WSL
Getting Ubuntu on windows
Ubuntu on Windows 10 is actually fairly easy, just go ahead to the Windows store and download ‘Ubuntu’; it shows up as an App which you can run. Make sure you run this as Administrator to avoid any snafus
Note that you need to have WSL enabled, just follow the instructions here.
Special Note, I ran into weird connectivity issues when trying to install the required packages using apt-get, to get around this I had to do 2 things,
- Follow instructions here from Windows Power Shell https://github.com/microsoft/WSL/issues/3438#issuecomment-519625580
2. Do a ‘sudo apt-get update’ from the Ubuntu Shell
Installing all the pre-requisite packages
All of these are from the User Guide here, http://shakti.org.in/docs/user_manual.pdf
However, there are a few places which are not quite straight forward, so I’m adding notes
Tooling:
Run the below in your Ubuntu Shell(same as User guide)
sudo apt install ghc libghc-regex-compat-dev libghc-syb-dev iverilog
sudo apt install libghc-old-time-dev libfontconfig1-dev libx11-dev
sudo apt install libghc-split-dev libxft-dev flex bison libxft-dev
sudo apt install tcl-dev tk-dev libfontconfig1-dev libx11-dev gperf
sudo apt install itcl3-dev itk3-dev autoconf git
Blue Spec Compiler:
git clone --recursive https://github.com/B-Lang-org/bsc
cd bsc
Now, the user guide mentions that you can compile this by running,
make PREFIX=/path/to/installation/folder
The /path/to/installation/folder must be replaced with where you git cloned your bsc repository; for example I created a shakti folder before I did the git clone so my path is
make PREFIX=/home/sreh/shakti/bsc
The above takes quite a while so go grab a cup of tea,
Afterwards, you need to add the compiled binary to your PATH variable; while the user guide asks you to export the /home/sreh/shakti/bsc/bin to the $PATH, this means it’s temporary until you restart the shell. I just added it to the bash_profile file by,
sudo vi ~/.bash_profile
Check if bsc is accessible by restarting shell and typing
bsc -help
Installing DTC:
The User guide calls for running these from home, so I moved back to the root
cd ~sudo wget https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/dtc-1.4.7.tar.gzsudo tar -xvzf dtc-1.4.7.tar.gz
cd dtc-1.4.7/
sudo make NO_PYTHON=1 PREFIX=/usr/
sudo make install NO_PYTHON=1 PREFIX=/usr/
Installing Vivado:
Ok, here’s the first real fork from the user guide.
First off, ensure you register for a Xilinx account, there’s no wget way of getting Vivado easily so you will have to manually copy over files into the Linux install location for this to work.
After your Xilinx account registration, get the Vivado HLx 2018.3: WebPACK and Editions — Linux Self Extracting Web Installer file.
Copy over using the ‘cp’ command within Ubuntu, otherwise you will have issues with seeing the file. You can access your Windows 10 file structure by going to the /mnt/c/ path within Ubuntu
cp /mnt/c/Users/sreh/Downloads/Xilinx_Vivado_SDK_Web_2018.3_1207_2324_Lin64.bin ~/shakti/vivado/
Now, here’s the annoying part. Simply running the above file throws an error as WSL doesn’t support GUI’s
Fortunately, there was a workaround documented here,
Just follow those steps(I downloaded XMing) until you hit the export DISPLAY command. From that point onwards, you can install Vivado
export DISPLAY=:0
sudo ./Xilinx_Vivado_SDK_Web_2018.3_1207_2324_Lin64.bin
Click through all the prompts and wait a while.
Now, just for the final steps
cd /tools/Xilinx/Vivado/2018.3/data/xicom/cable_drivers/lin64/install_script/install_drivers/sudo ./install_driverscd
cd .Xilinx/Vivado
sudo chown -R $USER *
sudo chmod -R 777 *
sudo chgrp -R $USER *
Again, a path variable addition which I do to my bash_profile file
sudo vi ~/.bash_profile
Finally, we see Vivado shows up fine after a shell restart
Ok, now to get the board support stuff all lined up
cd shakti/vivado
git clone https://github.com/Digilent/vivado-boards.git
cd vivado-boards/new/board_files
cd vivado-boards/new/board_files sudo cp -r ./* /tools/Xilinx/Vivado/2018.3/data/boards/board_files
Installing MiniTerm, OpenOCD
Fairly easy, but install guide had missing dependencies like libtool and libusb
sudo apt-get install python-serial
sudo apt-get install -y libtoolgit clone https://github.com/riscv/riscv-openocd.git
cd riscv-openocd
sudo ./bootstrap
sudo apt-get install libusb-1.0-0-devcd ..
mkdir riscv-openocd-tool
cd riscv-opencd
export RISCV=~/shakti/riscv-openocd-tool/OpenOCD
sudo ./configure --prefix=$RISCV --enable-remote-bitbang --enable-ftdi --enable-jlink --enable-jtag_vpi --disable-werrorsudo make
sudo make install
And one final path variable
Are we there yet? Compiling the E-Core
Finally, lets clone the Shakti e-core repository
git clone https://gitlab.com/shaktiproject/cores/shakti-soc.git
cd shakti-soc/fpga/boards/artya7-35t/e-class
sudo make quick_build_xilinx
Aand…. we get an error. Dammit.
Looks like there’s a BSC_DIR variable which needs to be set. Taking a guess here and assuming it’s the Blue Spec Compiler.
Now here’s the awkward thing, when you look at the Makefile the line clearly says,
BSC_DIR:=$(shell which bsc)
So it technically should have queried the bsc, which we added in our .bash_profile and returned the path. But for some reason the shell environment which is called from the Makefile doesn’t seem to share the PATH variables we set already. I haven’t seen this happen in the past and got stuck here for a few hours.
After googling for a few hours turns out ‘sudo’ has a much more limited scope of environment variables being passed, so I just added permissions to all of the git files before running the make(without sudo of course). Which is why I needed sudo in the first place… you live and learn eh?
sudo chmod -r sreh ~/shakti/shakti-soc/
make quick_build_xilinx
And make again and another error…
So far, we never installed the GCC tooling for RISCV so that is to be expected, documentation error from the looks of it.
Further down in the user guide looks like you can download the shakti-tools git repository which has the riscv-gcc libraries and added it to the PATH.
cd ~/shakti/
git clone --recursive https://gitlab.com/shaktiproject/software/shakti-tools.git
export PATH=$PATH:/home/sreh/shakti/shakti-tools/riscv32/bin
And try another make… Fails again. I think I’m dying slowly inside
Well looks like the shared library of “libmpfr.so.4” no longer exists in Ubuntu 18.04 and was replaced with “libmpfr.so.6” and one way is probably to recompile the riscv library(here), but there maybe a quick and dirty approach by adding the exact file to renamed to “.so.4”; LOL.
At this point I’m willing to try anything so
sudo ln -s /usr/lib/x86_64-linux-gnu/libmpfr.so.6 /usr/lib/x86_64-linux-gnu/libmpfr.so.4
And do a make again and….it’s definitely doing something. Takes a while, wait a few minutes for the synthesis to complete.
Looks like the last piece of the puzzle is seeing the board in WSL. TBH I was fairly certain I would hit this issue, but atleast it looks like the compile went through fine.
Programming the E-Core via Windows 10
Now, since we technically have all the files compiled and all I need to do is invoke the program_mcs_spansion in the Makefile, I switched over to Windows, and installed Vivado over on Windows10 again.
After installation, add the C:\Xilinx\Vivado\2018.3\bin into your Environment variables,
Make a copy of your build shakti-soc files into a local Windows folder, then simply run the below from regular windows command-line in the “\shakti-soc\fpga\boards\artya7–35t\e-class” folder
vivado -nojournal -nolog -mode tcl -source tcl/program_mcs_arty_a7_spansion.tcl
Finally, success!
And sure enough, if you fire up a terminal program with baud rate 19200
Never been happier to see this!
Next Steps
Alright, so for all of you guys who don’t need to go through the horrors of Windows and Shakti, I’m going to upload the compiled MCS file so you can just use Vivado and Windows to directly upload it. Files available here,
https://github.com/sreeharshaangara/shakti-e-class-pre-built-mcs
Now, if someone from the Shakti team has pre-built versions they maintain(and it apparently did exist a while back from the User Guide), I’ll be happy to update this article with the latest info.
Now, onto the fun stuff, can we use PlatformIO, VSCode and the OpenOCD to make a simple blinky LED? Stay tuned for Part-2.