My first experience with the ZedBoard SoC board.

I recently registered my masters with the Central Peninsula University of Technology in Cape Town, and part of my research with include the use of a FPGA for real-time network communications between smart grids. So I am faced with 2 things – learning a new environment as well as a different field(Power Systems) coming from an Electronics and Computer engineering background.

I am the type of person that is always eager to learn new things, so being thrown into the deep end is nothing foreign to me, sounds like something I took from my resume.

After I registered for the MEng, I was given this board – and I needed to familiarise myself with it.

This blog will detail my experiences and hacks.

zedboard-2zedboard box

Getting started with the ZedBoard SoC

Firstly, we will need to download Xilinx Vivado suite, in order to do this we go to the Xilinx Downloads page to obtain the installer.
Select version 2017.2 or later on the left sidebar. I used the “Single File Download” option and chose “Vivado HLx 2017.2: All OS installer Single-File Download”. It is a tarball that is 22Gigs, yes there was no typo – 22Gigs large.
Note: You have to be a registered user to download it.

Once the download is completed, untar the tarball, cd into the extracted directory, and execute the GUI installer.

# Confirm the file is valid by checking the md5 hash
# MD5 SUM Value: 958f190a089ad3f39d327d972c7dcf35
$ md5sum Xilinx_Vivado_SDK_2017.2_0616_1.tar.gz
# Once that is confirmed untar and install
$ tar -zxvf Xilinx_Vivado_SDK_2017.2_0616_1.tar.gz
$ cd Xilinx_Vivado_SDK_2017.2_0616_1
$ sudo ./xsetup

Agree to the terms of use and select “Vivado HL WebPACK Edition”. Next, tick also Xilinx Software Development Kit (SDK) on the next page, since it’s free and very useful.

Note: by default, Vivado is installed into the /opt/Xilinx/Vivado/2017.2 directory.

At the end of the installation, the license manager will ask for a license. The “Obtain a license” button in the license manager if that does not work, just go to Xilinx Licensing site directly and get a WebPACK license and install it.

Once done with the installation, we need to install the JTAG cable drivers that are needed for many purposes e.g. programming the hardware.

cd
 /opt/Xilinx/Vivado/2017.2/data/xicom/cable_drivers/lin64/install_script/install_drivers
sudo ./install_drivers

Now, change the ownership of the ~/.Xilinx directory so that you may use Vivado without superuser privilege:
sudo chown -hR $USER:$USER $HOME/.Xilinx/

Every time you want to fire up Vivado, remember to source the “settings” scripts to have the right environment variables:

source /opt/Xilinx/Vivado/2017.2/settings64.sh
source /opt/Xilinx/SDK/2017.2/settings64.sh

Lazy people like myself prefer to uncomplicate the complicated, to avoid executing the above commands each and everytime one needs to start Vivado – do the following.

echo "source /opt/Xilinx/Vivado/2017.2/settings64.sh" >> ~/.bashrc
echo "source /opt/Xilinx/SDK/2017.2/settings64.sh" >> ~/.bashrc
source ~/.bashrc		

When done, start-up Vivado from the command line:
vivado
or SDK:
xsdk

Quoting Raymond Hettinger, While hitting the podium and “There must be a better way!”

Create a new file called vivado.desktop

sudo vim /usr/share/applications/vivado.desktop
# Copy the contents to the file

[Desktop Entry]
Type=Application
Version=1.0
GenericName=Vivado
Name=Vivado
Comment=Vivado
TryExec=/opt/Xilinx/Vivado/2017.2/bin/vivado
Exec=/opt/Xilinx/Vivado/2017.2/bin/vivado
Icon=
Terminal=false
Categories=Education;System
StartupNotify=false
X-GNOME-Autostart-Delay=5

When done, log out-in in order to refresh the systems settings.

Vivado should be available from start-menu and can be copied to the desktop for future executions.

Advertisements

How to stop Jenkins CI build by extract a value from a JSON endpoint in bash using Curl

Curl the URL to get the JSON response and pipe it to the python tool. The python code will extract the value mapped to the given key (number in this case).

machine='dbelab04'
machineport=8080
jobname='mkat_fpga_tests_4k'
buildnumber=$(curl --silent -X POST http://$machine:$machineport/job/$jobname/lastBuild/api/json?tree=number | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["'number'"]';)
curl -X POST http://$machine:$machineport/job/$jobname/$number/stop

Note: the above command actually works

System V init script(start-stop-daemon)

I’ve been looking for efficient ways to start at boot my NodeJS dependent applications, with inspiration from https://gist.github.com/alobato/1968852, I modified it to my own needs.

Link might interest you as well:
http://big-elephants.com/2013-01/writing-your-own-init-scripts/
https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

Copy template to /etc/init.d and rename it to something meaningful. Then edit the script and enter that name after Provides:(between ### BEGIN INIT INFO and ### END INIT INFO).

#!/bin/bash
# Inspired by https://gist.github.com/alobato/1968852
# Needs Provides, Descriptions

### BEGIN INIT INFO
# Provides:
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description:
# Description:
### END INIT INFO

set -e
NAME=""
PIDFILE="/run/$NAME/$NAME.pid"
# Application one wants to upstart
DAEMON=""
DAEMON_OPTS=""
# Run as user
RUN_USER=""
RUN_GROUP=""
function daemon_run {
	mkdir -p /run/$NAME
	chown $RUN_USER:$RUN_GROUP /run/$NAME
	start-stop-daemon --start --background --quiet --chuid $RUN_USER:$RUN_GROUP --chdir /run/$NAME --pidfile $PIDFILE --make-pidfile --exec $DAEMON $DAEMON_OPTS
}
exec > /var/log/$NAME.log 2>&1

case "$1" in
start)
	echo -n "Starting $NAME ... "
	daemon_run
	echo "done."
;;

silent)
	echo -n "Starting $NAME in silent mode ... "
	daemon_run
	echo "done."
;;

stop)
	echo -n "Stopping $NAME ... "
	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --remove-pidfile
	echo "done."
;;
restart|force-reload)
	echo -n "Restarting $NAME ... "
	start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE --remove-pidfile
	alexa_run
	echo "done."
;;
*)
	echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

When done,

sudo systemctl enable 'name_of_filename'
reboot

Mpho

Move files by date into different directory using CLI

A while back I was unfortunate in such a way that my HDD that I primarily use as photo archive started having mechanical issues, and before It died on my arms I had the opportunity to backup most of my pictures, however most of them were truncated and had to be discarded and the ones I could recover their filenames where overwritten with random filenames and ascii codes.

For over a while I have neglected my pictures and they just piled up in a single and nameless directory, until I took it against myself to clean them up.

And one of the benefits of using Linux OS is the scripting features.

for i in *; 
do d=$(exiftool $i | grep 'Date/Time Original' | cut -f 17 -d ' '); 
newd=`echo ${d//:/-}`; 
echo $i ${newd} ;
mkdir -p ${newd}; 
mv -- ${i} ${newd}; 
done
  1. write this script to a file named mvByDate.sh in your old directory.
  2. replace the /your/new/directory with your new directory’s path
  3. make this file executable with chmod +x mvByDate.sh
  4. then execute this file by ./mvByDate.sh
  5. voila