Sunday, December 4, 2011

Setting up the Altera FPGA environment on a Mac

Here's a quick description of how I got everything set up on my Macbook Pro to be able to program my Altera FPGA board. Everything is reasonably well documented online, but since I still had to do some amount of debugging and searching I thought I'd document my, as far as I can tell, successful installation.

First off, all I wanted was to be able to do the FPGA development on my laptop with a minimum of fuss and money. Since Altera's Quartus software runs on just two platforms - Windows and Linux - it was pretty clear that I was going to run some virtualization software. At my old job we used VirtualBox and it seemed to work fine, so that's what I went with.

Between installing Windows or Linux there didn't seem to be much of a contest, but just to spell it out:

  • Convenience. Linux comes with all the tools that I'm used to, out of the box. With Windows I would have to go through at least some hassle to find and install shells, editors, revision control software, etc.
  • Performance. Occasionally I had to run Windows at my old work, on a Macbook comparable to the one I have now, and while Windows 7 worked flawlessly per se in VirtualBox, it had some clear performance problems. I never saw significant issues with the Linux image I ran.
  • Cost. As I have no other purpose for Windows, it would seem unnecessary to shell out money for it when Linux is supported by the Altera software and is often free.

So, Linux it was. According to Altera's OS requirements, I now had the choice between RHEL, SUSE, or CentOS. This time I really had little preference, but CentOS is free, and I remember using it some jobs ago with no particular problems. Only caveat is that the ModelSim version distributed by Altera is not officially supported on CentOS. I'm not sure what that is about as my understanding is that CentOS is RHEL without the trademarks, and ModelSim runs just fine in my setup. At least, the GUI starts fine and I'm getting no warnings or errors in the x/term. I guess I'll know better once I actually put a test bench through it.

As for the versions, I just picked the most recent releases, except for CentOS where I stuck with CentOS 5 as it was explicitly supported. At the end, I installed

  • VirtualBox 4.1.6
  • CentOS 5.7 i386
  • Quartus II 11.1 Web Edition
  • ModelSim-Altera Starter Edition 10.0c

After the initial VirtualBox installation, I thought I'd save some bandwidth by using the CentOS net installer, but for some reason it barfed in the middle of the process, so I decided to download the DVD release instead (fewer files than the CD release), and that did the trick - I asked for a Desktop setup with all the default settings and got exactly that without further complaints.

At this point, I had my system running at a paltry 800x600 resolution, and no way to extend it. Enter the  VirtualBox Guest Additions. Installing them from the menu mounts a CD in CentOS, switch to root and run the VBoxLinuxAdditions.run script. Voila. I bumped up the allocated Video Memory to 64MB in the VirtualBox settings for good measure and haven't had a resolution problem since.

Next, I downloaded the ACDS (Altera Complete Design Suite) installer and had it rip at installing the Quartus and ModelSim software - everything went smooth until the very end where it told me it had had some issues with a couple of steps and asked me to manually do them after the install. Trying to do so resulted in some mysterious

quartus: error while loading shared libraries: .../altera/11.1/linux/libccl_err.so: cannot restore segment prot after reloc: Permission denied

error message. As it turned out, the solution was either to turn off SELinux (against the recommendation of CentOS) or change the context of Quartus' shared libraries (probably also against the recommendation of CentOS). I chose the latter at it was at least just a local digression:
chcon -t textrel_shlib_t .../altera/11.1/linux/*.so
I could now run Quartus without incident, look at tutorials and all that. The only thing missing at this point was the ability to actually program the device. As the board is configured through a USB cable it meant that I first needed to get USB devices fully connected from the Mac to CentOS. To this end I first installed the VirtualBox Extension Pack. Next, I shut down CentOS and went to the Ports -> USB section of the VirtualBox settings, selected "Enable USB 2.0 (EHCI) Controller" and added the "Altera USB-Blaster" device to the filter. Back in CentOS, I switched to root and added
none /vbsusfs usbfs rw,devgid=500,devmode=664 0 0
to /etc/fstab. I simply hardcoded my personal group ID (500), I'm going to be the only user anyway.

After starting Quartus again, I was still unable to connect to the device, being told that I had "insufficient permissions on some ports". Again, the answer was to be found at Altera: As root, I created a new file, /etc/udev/rules.d/51-usbblaster.rules, with the following content:

BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6001", MODE="0666"
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6002", MODE="0666"
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6003", MODE="0666"
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6010", MODE="0666"
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6810", MODE="0666"
After that, I was able to successfully program the device.

1 comment: