fbpx

How to Build an Angstrom Linux Distribution for Intel (Altera) SoC FPGAs with OpenCV and Camera Driver Support

PathPartner_Logo

This article was originally published at PathPartner Technology's website. It is reprinted here with the permission of PathPartner Technology.

If your realtime image processing applications such as a driver monitoring system are dependent on OpenCV, you have to develop an OpenCV build environment on the target board. This article will guide you through the steps necessary to create a Linux OS build with OpenCV and camera driver support for Intel (Altera) SoC FPGAs.

In order to start building the Linux distribution for the Intel (Altera) platform, you must first install the necessary libraries and packages. Follow the Initialization steps for setting up the PC host.

The required packages to be installed for Ubuntu 12.04 are

$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install sed wget cvs subversion git-core coreutils unzip texi2html texinfo libsdl1.2-dev docbook-utils gawk python-pysqlite2 diffstat help2man make gcc build-essential g++ desktop-file-utils chrpath libgl1-mesa-dev libglu1-mesa-dev mercurial autoconf automake groff libtool xterm *

Important
Please note that * indicates that the command is one continuous line of text. Make sure that the command is in one line when you are pasting it.

If the host machine runs a 64-bit version of the OS, then you need to install the following additional packages:

$ sudo apt-get install ia32-libs

On Ubuntu 12.04 you will also need to make /bin/sh point to bash instead of dash. You can accomplish this by running the following and selecting "No".

sudo dpkg-reconfigure dash

Alternatively you can run:

sudo ln -sf bash /bin/sh

However, this is not recommended, as it may get undone by Ubuntu software updates.

Angstrom Buildsystem for Intel (Altera) SoC (Linux OS)

Download the scripts needed to start building the Linux OS. You can download the scripts for the angstrom build system from https://github.com/altera-opensource/angstrom-socfpga/tree/angstrom-v2014.12-socfpga

Unzip the files to the angstrom-socfpga folder:

$ unzip angstrom-socfpga-angstrom-v2014.12-socfpga.zip –d angstrom-socfpga $ cd angstrom-socfpga

These are the setup scripts for the Angstrom buildsystem. If you want to (re)build packages or images for Angstrom, this is what you should use.

The Angstrom buildsystem uses various components from the Yocto Project, most importantly the Openembedded buildsystem, the bitbake task executor, and various application and BSP layers.

Navigate to the source folder, and comment the following line in the layer.txt file

$ cd source $ gedit layers.txt & meta-kd4,https://github.com/Angstrom-distribution/metakde. git,master,f45abfd4dd87b0132a2565499392d49f465d847 * $ cd .. (Navigate back to the head folder)

To configure the scripts and download the build metadata:

$ MACHINE=socfpga_cyclone5 ./oebb.sh config socfpga_cyclone5

After the build metadata, you can download the meta-kde4 from the below link and place it in the sources folder, as this was earlier disabled in the layers.txt file http://layers.openembedded.org/layerindex/branch/master/layer/meta-kde4/

Source the environment file and use the below commands to start a build of the kernel/bootlaoder/rootfs:

$. /environment-angstrom $ MACHINE=cyclone5 bitbake virtual/kernel virtual/bootloader console-image

Depending on the type of machine used, this will take a few hours to build. After the build is completed the images can be found in:

Angstrom-socfpga/deploy/cyclone5/

After the build is completed, you will find the u-boot, dtb, rootfs and kernel image files in the above folder.

Adding the OpenCV Image to the rootfs

To add OpenCV to the console image (rootfs), you need to modify the local.conf file in the conf folder:

$ cd ~/angstrom-socfpga/conf $ gedit local.conf &

In the local.conf file navigate to the bottom of the file and add the following lines and save the file:

IMAGE_INSTALL += “ opencv opencv-samples opencv-dev opencv-apps opencv-samples-dev opencv-static-dev “

Then build the console image again using the following command:

$ cd .. $ MACHINE=cyclone5 bitbake console-image

After the image is built the rootfs will contain all necessary OpenCV libs for development and running opencv based applications.

Enabling Camera Drivers in the Kernel

Linux kernel v3.10 has a built-in UCV camera driver which supports a large number of USB cameras. In order to enable it, you need to configure the kernel using the menuconfig option:

$ MACHINE=cyclone5 bitbake virtual/kernel –c menuconfig

The above command opens a config menu window. From the menuconfig window enable the following to enable UVC:

Device Drivers Multimedia support Media USB Adapters [*] USB Video Class [*] UVC input events device support [*]

Save and exit the config menu then execute the following command:

$ MACHINE=cyclone5 bitbake virtual/kernel

The new kernel will be build with the UVC camera drivers enabled and will be available in the /deploy/cyclone5 folder.

For the camera to work, the coherent pool must be set to 4M, this can be done as follows:

U-Boot Environment Variables

Boot the board, pressing any key to stop at U-Boot console. The messages dispayed on the console will look similar to the following listing:

U-Boot SPL 2013.01.01 (Jan 31 2014 – 13:18:04) BOARD: Altera SOCFPGA Cyclone V Board SDRAM: Initializing MMR registers SDRAM: Calibrating PHY SEQ.C: Preparing to start memory calibration SEQ.C: CALIBRATION PASSED ALTERA DWMMC: 0   U-Boot 2013.01.01 (Nov 04 2013 – 23:53:26)   CPU : Altera SOCFPGA Platform BOARD: Altera SOCFPGA Cyclone V Board DRAM: 1 GiB MMC: ALTERA DWMMC: 0 In: serial Out: serial Err: serial Net: mii0 Warning: failed to set MAC address   Hit any key to stop autoboot: 0 SOCFPGA_CYCLONE5 #

Configuration of U-Boot Environment Variables

SOCFPGA_CYCLONE5 #setenv bootargs console=ttyS0,115200 vmalloc=16M coherent_pool=4M root=${mmcroot} rw rootwait;bootz ${loadaddr} – ${fdtaddr} *

Save of U-Boot Environment Variables

SOCFPGA_CYCLONE5 #saveenv

Boot Kernel

SOCFPGA_CYCLONE5 #boot

Following all the above guidelines, you should be able to build an Angstrom Linux distribution for Intel (Altera) SoC FPGAs with OpenCV and camera driver support. This build was successfully implemented on an Intel (Altera) Cyclone V SoC.

Here you’ll find a wealth of practical technical insights and expert advice to help you bring AI and visual intelligence into your products without flying blind.

Contact

Address

1646 N. California Blvd.,
Suite 360
Walnut Creek, CA 94596 USA

Phone
Phone: +1 (925) 954-1411
Scroll to Top