Wednesday, December 28, 2016

Installing Python3, NumPy, SciPy and MatPlotLib under Cygwin on Windows 7

I had a working Cygwin environment with Python 2.7 installed, but I needed to install Python3, NumPy, SciPy, and MatPlotLib, which brought about a whole slew of issues.  I had to scour the web for the following solutions, but I was not able to find a single

I'm a command line junky, so I had already installed apt-cyg.  The following will outline the steps I had to do to get the packages identified above installed.

Install Python3

Installing Python3 is easy enough.
$ apt-cyg install python3
Now, before we attempt to install NumPy, SciPy, and MatPlotLib, we need to install a bunch of other dependencies, if they aren't already installed.  These include python3-setuptools, liblapack-devel, libopenblas, gcc-fortran, gcc-g++, python-gtk2, and libfreetype-devel.
$ apt-cyg install python3-setuptools liblapack-devel libopenblas gcc-fortran gcc-g++ python-gtk2 libfreetype-devel
Next, we need to create a symbolic link of /usr/include/locale.h to /usr/include/xlocale.h:
$ ln -s /usr/include/locale.h /usr/include/xlocale.h
Finally, we need to install pip and upgrade it.  Note, if you haven't updated your PATH environment variable the following command may not work until you do that or open a new Cygwin terminal.
$ python3 -m pip install --upgrade pip
Now we should be ready to install NumPy, SciPy, and MatPlotLib using pip.

Install NumPy, SciPy, and MatPlotLib

$ pip install numpy$ pip install scipy$ pip install matplotlib
 That should be it.


Wednesday, July 24, 2013

Automating ModelSim/QuestaSim Regressions

Implementing a makefile driven regression setup to automate the execution of testcases of varying length requires some method of gracefully ending the simulation. Verilog supports the use of $finish to signal the end of the simulation. VHDL 2008 introduces the 'env' package to the 'std' library that includes a method similar to Verilog:
library std;use std.env.all;.......stop(0);--orfinish(0);-- For both STOP and FINISH the STATUS values are those used-- in the Verilog $finish task-- 0 prints nothing-- 1 prints simulation time and location-- 2 prints simulation time, location, and statistics about-- the memory and CPU times used in simulation-- Other STATUS values are interpreted as 0.
If the project requires VHDL 93, then the following method can be used instead.
  1. Add a signal to the testbench top level that can be asserted by the testcase to indicate the end of the simulation.
  2. Add the following to the do-file used to execute the simulation:
## Initialize broken variable to 0set broken 0set finished 0## assert statments with a severity of failure cause breakpoints## when a breakpoint is encountered the following routine runs## which sets the broken variable.onbreak {  if {$finished} {    resume  } else {    set broken 1    resume  }}when -label end_of_simulation {sim_done_s == '1'} {echo "simulation finished"; set finished 1; stop;}## run until breakrun -all## if the sim was brokenif {$broken } {puts "Test Failed to Complete"} else {puts "Test Successfully Completed"}quit -f
In this example, I added a signal to my testbench called "sim_done_s" which is initialized to '0'. At the end of the testcase, sim_done_s is assigned to '1'.

Alternatively, the more common approach is to simply apply an assertion of the appropriate level to cause the simulator to break.  This is set in the modelsim.ini file and defaults to a level of Failure.  I personally don't like this method because I don't want to see the word Failure in my transcript if there isn't actually a failure.  This way I can automate the regressions and run a grep on the logs for the word Failure or Error.

Command Line Fu

I had an SVN Add crash on me and now the entire folder is locked such that any attempt to perform anything on that folder errors out. The Adds that did complete appear to be only locally and not pushed to the server, so I'm going to try to blow away all of the .svn folders locally and try adding again..... but that's a lot of manual deleting in Winblows, so here's some command-line-fu in Cygwin.
$ find . -iname *.svn | xargs -r -n 20 rm -rf
The 'find' stuff is obvious. The rest pipes the output from find into xargs which creates a list of 20 and executes 'rm -rf' on that list.  The list size would obviously need to be adjusted to the expected number of hits.  Sweet.

On another note, I recently had to resurrect an old project originally developed on Solaris.  This particular project environment used several layers of Makefiles that called several different Perl scripts.  The Perl scripts all pointed at the wrong path for the Perl executable in my Linux environment, so I had two options: 1) create a symbolic link in the directory the scripts pointed to (hack!) or 2) modify each of the scripts to point to the correct directory.  The first is a hack, but the second takes quite a bit more time and when it comes to monotonous tasks like that, I'm fairly lazy and prefer an automated method.  Hence the following:
$ grep –rl ‘/usr/local/bin/perl’ *.pl | xargs sed -i  ‘s/\/usr\/local\/bin\/perl/\/usr\/bin\/perl/g’
The '-r' option tells grep to operate recursively through subdirectories and the '-l' option tells grep to return only the filename of the files containing matches.  The output is piped to xargs and a simple sed switch is executed on each of the files.  Brilliant!  

Monday, July 22, 2013

Installing Old Libraries on Ubuntu

As a Design Services company, we quite often will have to support an old project for a customer that was implemented in an old version of the tools.  This typically requires us to install older versions of the tools when the customer doesn't want to update the design to the new tools for some reason.

I recently had to support a project that was originally implemented in Xilinx ISE v9.1.  Installing this on Ubuntu Server 11.04 64-bit required some extra effort.

When attempting to install Xilinx ISE v9.1 tools on the Builder box (Ubuntu Server 11.04), I received the following error when attempting to run the installer.
/home/builder/ISE_DVD_J.30.5.0/bin/lin64/setup: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
So what’s installed?
$ dpkg --get-selections | grep libstdc++
libstdc++6
Ah. Okay, so we need to install libstdc++5.
$ sudo apt-get install libstdc++5
...
$ dpkg --get-selections | grep libstdc++
libstdc++5 install
libstdc++6 install

$ dpkg -L libstdc++5
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libstdc++5
/usr/share/doc/libstdc++5/TODO.Debian
/usr/share/doc/libstdc++5/copyright
/usr/share/doc/libstdc++5/changelog.Debian.gz
/usr/share/doc/libstdc++5/README.Debian
/usr/lib
/usr/lib/libstdc++.so.5.0.7
/usr/lib/libstdc++.so.5

$ ll /usr/lib/libstdc++*
lrwxrwxrwx 1 root root 18 2013-03-26 14:03 /usr/lib/libstdc++.so.5 -> libstdc++.so.5.0.7
-rw-r--r-- 1 root root 829320 2011-02-19 11:01 /usr/lib/libstdc++.so.5.0.7
Works!

One thing to make note of – if the applications are old enough to have this problem, they will likely have problems with other libraries such as libXm from the libmotif package. In this case, the compxlib tool required libXm.so.3 from libmotif3, but later versions of Ubuntu have libmotif4 in the repos. The easiest workaround is to install libmotif4 and sym link the library:
$ sudo apt-get install libmotif4
$ ln -s /usr/lib/libXm.so.4 /usr/lib/libXm.so.3

Friday, July 19, 2013

Automating Timestamp Updates at Build Time

In the past, I've used a simple makefile to update the revision register value to the current system time using a simple sed command as follows:
buildStamp=$(shell date +%m%d%y%H)
sed 's/ABCDEF01/$(buildStamp)/' ../ip/common/buildver_pkg.vhd > $(localTemp)/buildver_pkg.vhd
This works well when we're using a strictly command line build flow. I typically have the make file copy all of the source to a timestamped sub-directory and make this update at the time of the copy. This preserves the pedigree of the build and allows me to rerun builds from that directory without updating the revision register every time.

However, a problem arises when the Quartus II GUI is used because the revision register won't be updated. The following is one method for making the GUI update the revision register.
Add a script like this:
##############################################################################################
#
# This script copies the buildver_pkg.vhd file to the local build directory, and updates the
# placeholder string to the current system time.
#
##############################################################################################

proc copyfile { args } {
set timestamp [clock format [clock seconds] -format {%y%m%d%H}]
# Year 0-99, 7 bits
# Month 1-12, 4 bits
# Day 1-31, 5 bits
# Hour 0-23, 5 bits

set ifp [open "../ip/common/buildver_pkg.vhd" r]
set ofp [open "buildver_pkg.vhd" w]

while { [gets $ifp line] >= 0 } {
regsub -all "ABCDEF01" $line $timestamp line
puts $ofp $line
}

close $ifp
close $ofp
}

copyfile
Now, add the following line to the QSF file:
## Run script to copy buildver_pkg.vhd file and update revision register
set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:update_build_stamp.tcl"
Now when the design is built using the build flows in the GUI, this script will be executed first and will update the revision register with the current system time.

This does not allow for subsequent builds from the makefile-generated-subdirectory area without modifying the revision register, though. I suppose we could implement an additional, less automated major revision register that is not automagically updated by a script in the GUI... but now we're circling back.

Cygwin and File Permissions

I was running into a problem while setting up command line scripting of the Altera tools. Some files generated by SOPC Builder would have permissions of 000 in Cygwin so quartus_map would fail because it couldn't open those files in read mode. 

Apparently Cygwin defaults to using POSIX permissions. Some files generated by Windows apps set ACLs that are then interpreted incorrectly by Cygwin. 

The only work-around I have found is to change the way Cygwin mounts to the filesystem to ignore ACLs. I modified the /etc/fstab in the Cygwin root to uncomment the following line and add 'noacl': 
 none /cygdrive cygdrive binary,noacl,posix=0,user 0 0 
 I had to close down all of my Cygwin processes and relaunch them to fix the problem.

Installing Altera Quartus II on Ubuntu Server 11.04 64-bit

IT received a couple of sweet new servers the other day and have been gracious enough to allow me to do some benchmarking tests of our Altera builds on one of them.  They installed Ubuntu Server 11.04 64-bit and gave me the user account.  The following are some of the "extra" steps required for installing and running the Altera tools on a Linux server.

Set the Shell

Ubuntu defaults the shell to Dash to speed up boot times.  We need to set that to Bash.
sudo rm /bin/sh
sudo ln -s /bin/bash /bin/sh

Install 32-bit Libs

Before installing the tools, we need to install the 32-bit libraries for the installers to run properly.
sudo apt-get install ia32-libs

Set the Locale

sudo locale-gen en_US

Install Tools

Download the install scripts and run them in the proper sequence.
sudo ./11.1_173_quartus_linux.sh
sudo ./11.1_173_devices_stratix_hardcopy_linux.sh
sudo ./11.1sp2_259_quartus_linux.sh
Note:  You may have to chmod the files to be executable to use the format above.  Otherwise you could replace the "./" with "bash ".

chown The Default .altera.quarus Folder

Since I installed the tools using sudo, the default .altera.quartus folder at the user's root directory will be owned by root.  This is where the tools store tool configuration settings, such as the ip search path.... which will not be writable if the tools are launched by the user without sudo.  We need to chown this folder and all subsequent folders.
sudo chown -R <user>:<user> .altera.quartus

Add Environment Variables

Finally, you need to add some environment variables to run the tools.  Here is what I have in my default .bashrc file:
ALTERA_VERSION="11.1"
QUARTUS="/opt/altera/$ALTERA_VERSION/quartus/bin"
QUARTUS_ROOTDIR= "/opt/altera/$ALTERA_VERSION/quartus"
SOPC_BUILDER="/opt/altera/$ALTERA_VERSION/quartus/sopc_builder/bin"
SOPC_KIT_NIOS2=" /opt/altera/$ALTERA_VERSION/nios2eds"
SOPC_BUILDER_PATH_100=/ opt/altera/$ALTERA_VERSION/nios2eds"
QUARTUS_64BIT=1

export QUARTUS
export QUARTUS_ROOTDIR
export QUARTUS_64BIT
export SOPC_BUILDER
export SOPC_BUILDER_PATH_100
export SOPC_KIT_NIOS2

LPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
LPATH=$LPATH:$QUARTUS:$QUARTUS_ROOTDIR:\
$QUARTUS_64BIT:$SOPC_BUILDER:$SOPC_BUILDER_PATH_100:\
$SOPC_KIT_NIOS2/bin:$SOPC_KIT_NIOS2/sdk2/bin:\
$SOPC_KIT_NIOS2/bin/nios2-gnutools/H-i686-pc-linux-gnu/bin:\
$SOPC_KIT_NIOS2/bin/fs2/bin

export PATH=$LPATH
export LM_LICENSE_FILE="1717@flexlm"
alias n2sdk="bash --rcfile $QUARTUS_ROOTDIR/sopc_builder/bin/nios_bash"

That should do it.