Combine uClinux and Asterisk on a Card

David Rowe

Issue #155, March 2007

Embedding Asterisk on a Digikey Blackfin STAMP card.

This article describes how to build an embedded Asterisk IP-PBX with four analog (FXO or FXS) ports. Total parts cost is about $500 US, which is competitive with PC/PCI-card based Asterisk solutions. Embedded solutions have the advantage of small size, low power and no moving parts. Figure 1 is a photo of the PBX hardware in action.

Figure 1. Digi-Key Blackfin STAMP Development Card

The PBX is built around a Blackfin STAMP development card, available off the shelf from Digi-Key for around $225 US. The Blackfin is a powerful DSP chip that runs uClinux. Sitting on top of the Blackfin STAMP card is a daughterboard, which contains interface hardware and the SD card socket. Into the daughterboard plugs FXO or FXS modules, one for each port. In this example, there are two FXS modules on the left and two FXO modules on the right. The color of each LED indicates the type of module inserted.

Here's a brief review of telephony jargon:

  • FXO ports connect to telephone lines and the exchange.

  • FXS ports connect to analog telephone handsets.

Figure 2 is a block diagram of the PBX hardware and software components. SIP phones or analog phones can be used for handsets (extensions), which are connected via a LAN to the IP PBX. External calls can be routed over the Internet or through the analog FXO ports. Internal calls between IP phones are routed over the LAN.

Figure 2. Sample PBX Configuration

The PBX supports most of the features of Asterisk running on an x86 PC. As there is no hard disk, an SD card is used for voice-mail storage.

Why Port Asterisk to uClinux/Blackfin?

I have a history of developing computer telephony hardware and have always wanted to build a small embedded box that combines a host processor, DSP, line interface hardware and software. It's an itch I've needed to scratch!

There are some very cool things about the Blackfin processor chip:

  1. The problem with most embedded processors is that they are not very powerful. The Blackfin is a powerful host processor and a DSP—that is, it can run uClinux, Asterisk and codecs like G729 on the same processor at the same time. A standard 500MHz Blackfin runs at around 1,000 DSP-MIPs, which is plenty for codecs, echo cancellation and so forth.

  2. A lot of effort and hardware cost is usually required to interface telephony hardware to the host processor (typically a PC), such as PCI bridge chips. The Blackfin makes it easy, as it has a lot of nice interfaces built in, such as serial ports, SPI and DMA controllers, which are all tightly integrated with the core processor.

  3. The Blackfin chips are good value for the money, ranging from $4.95 US each (BF531 in 10k volume), which makes low-cost embedded telephony hardware a real possibility. This makes it possible to build an IP PBX including analog or E1/T1 line interfaces for far less than comparable PC-PCI card solutions.

  4. Best of all there is an Open Source community that has developed GPL hardware (the family of STAMP boards).

Open-Source Hardware

The hardware designs for this project are open—the schematics and PCB layouts are freely available for anyone to download, copy and modify.

The hardware designs have been released under the GPL. Although there is some debate over how defensible the GPL is when applied to hardware, the key ideas are similar to open-source software—the hardware designs are free as in speech, and a community exists that is working together on extending and enhancing the designs. Intellectual Property (IP) is shared for the mutual benefit of all.

The community is loosely organised under the Free Telephony Project, and it consists of private hackers, researchers and several companies who are donating time and other resources to the project. A series of hardware designs are being developed, for example, analog and ISDN interface hardware, and DSP motherboard designs. Significant software development work is also occurring, for example, open echo cancellation software and drivers for the hardware.

The outputs of the project are high-quality, professionally designed telephony hardware, freely available for all. Hardware development is a little different from software—hardware design/test cycles are much longer (for example, a bug might mean a new board needs to be manufactured), and of course, it costs money to make a “copy” of a hardware design. However, the benefits of open hardware are similar to open software:

  • Peer review is a wonderful way to trap bugs early, leading to big savings in development time.

  • Re-use of open designs enables innovative products to be developed quickly and with a very small number of bugs.

  • Discussion and contributions from people all over the world lead to a much higher-quality product than a product developed by one company in its own lab.

  • Using open hardware, an individual or small company can build sophisticated telephony products without needing large company resources.

  • The part I like best—you get to work with a community of talented hardware and software people! Some of the best and brightest minds out there seem to migrate naturally to open projects.

Business models are being developed that function within the open-hardware environment. For example, one company sponsoring our efforts has a service model based around low-cost telephony hardware—maintaining ownership of the hardware IP is not a critical part of its business plan.

Open hardware is also great for small, localised businesses and allows developing countries to build their own products locally—overcoming tariff barriers and building a local high-technology industry.

A Really Open Hardware/Software Project

This PBX runs open-source software (Asterisk), on an open-source operating system (uClinux). The operating system, drivers and applications are built using a GNU gcc toolchain.

The hardware designs are open and were designed using open-source tools. Schematic entry was performed using gschem, and the PCB layouts were developed using a program called PCB—both included in the gEDA package of open electronic design tools.

Verilog was used to implement some programmable logic on the daughterboard. Verilog is a language used to describe logic in electronic circuits. The Verilog code was developed with Icarus Verilog, also part of the gEDA package.

Figure 3 shows the high-level work flow for the project. As you can see, hardware, software and even the tool used to design the hardware are all open.

Figure 3. The Work Flow Used to Create the Project

Assembling the Hardware

Let's start putting it all together.

The first step is to plug your desired combination of modules in to the daughter card. For example, for a home PBX, you might simply want one FXO and two FXS modules; for an office you might want four FXO modules. In Figure 1, two FXO and two FXS modules are loaded.

The next step is to plug the daughter card/module assembly in to the Blackfin STAMP card. That's pretty much it for the hardware assembly. As a quick test, try applying power to the STAMP, and it should boot without any problems. Not much else will happen yet, as we need to compile and download the software.

Building the Software

The software is built on a Linux host PC, then downloaded to the Blackfin STAMP board using FTP (driven by some shell and Expect scripts). Here are the steps:

Download and install the Blackfin gcc toolchain. Detailed instructions for this step are on the blackfin.uclinux.org Web site.

You need a compiled version of the latest Blackfin STAMP uClinux distribution (uClinux-dist RPM or tarball). Before building it, set up the following configuration using make menuconfig:

  • Kernel hacking: boot param— root=/dev/mtdblock0 rw. This makes the root filesystem read-write, which allows us to add the many files Asterisk requires to the root filesystem.

  • Blackfin options: write back cache—this improves the speed of the DSP-intensive operations, such as the Speex codec, by about 10% per codec instance.

  • Customize vendor/user settings: Flash tools—MTD Utils is switched off, as it breaks the uClinux-dist compilation (at least on my machine).

  • I modified the file: uClinux-dist/vendors/AnalogDevices/BF537-STAMP/rc to set the hostname and enable dhcpcd.

Generic instructions for building uClinux are included in the Blackfin uClinux-dist documentation. Read these and build uClinux. If your build was successful, a uClinux-dist/images directory will be created containing the uClinux images.

Download the uCasterisk tarball, then:

$ tar xvzf uCasterisk-0.1.6.tar.gz
$ cd uCasterisk-0.1.6

In the file .config, check that:

BR2_TOOLCHAIN_DIR="/opt/uClinux/bfin-uclinux/bin"
BR2_KERNEL_SOURCE="/opt/uClinux-dist/linux-2.6.x"

point to your toolchain and target kernel sources.

Then, typing:

$ make

downloads, patches and makes all the different packages you need. See the top-level Makefile for other useful options.

Downloading and Testing

Now, download Asterisk and all the support files to the Blackfin STAMP:

$ ./scripts/install_all stamp

where stamp is the hostname of your STAMP card. There will be a few pauses as the drivers are installed, and the LEDs on the daughterboard should light indicating that the FXS/FXO modules have been auto-detected.

The next step is to configure Asterisk for your combination of FXO and FXS modules. Asterisk configuration is a big subject and can be daunting for the beginner. To help get started, some basic configuration files have been developed.

Let's assume for now that you have loaded two FXS modules and two FXO modules. In that case, run:

$ ./scripts/config_2fxo2fxs stamp

Now, you are ready to start Asterisk. Use Telnet to open a console to the Blackfin STAMP:

$ /var/tmp/asterisk -vc

A lot of text will flash by as Asterisk boots, but eventually, you should be greeted by the Asterisk CLI prompt:

Asterisk Event Logger restarted
Asterisk Ready.
*CLI>

Plug a regular analog telephone in to one of the FXS ports (the FXS ports will have green LEDs). Pick up the phone, and you will hear a dial tone. Try dialing 2000, and you should hear the “Congratulations, you have...” welcome message. You then can try dialing a few of the demo options and make some calls between extensions.

The above procedure needs to be performed every time you power down or reset the STAMP card. For regular use, the PBX can boot Asterisk from the SD card; however, while experimenting, it is often more convenient to download from the host PC.

The configuration files for Asterisk are the same as for x86 Asterisk. Some useful files are:

  • /etc/zaptel.conf: Zaptel driver configuration

  • /etc/asterisk/zapata.conf: more Zaptel configuration.

  • /etc/asterisk/extensions.conf: sets up dial plan for PBX.

  • /etc/asterisk/sip.conf: SIP phone configuration.

These files can be edited with vi on the Blackfin, but remember that any configurations will be lost when the board is powered down or reset. Permanent changes can be stored on the SD card.

Further Work

So, there you have the basic steps for building your own embedded Asterisk PBX. Kits containing the daughterboards and modules are available from the author. We are working on further development—for example, custom Blackfin hardware designed specifically for telephony work and other line interface cards, such as BRI-ISDN. It's an exciting project, with the novel feature of open hardware development.

David Rowe has 20 years of experience in the development of DSP-based telephony and sat-com hardware/software. David has a wide mix of skills including software, hardware and project management, and a PhD in DSP theory. He has held executive-level positions in the sat-com industry ( www.dspace.com.au) and has built and successfully exited a small business ( www.voicetronix.com). However, he has decided he is better at debugging machines than people, so he currently chooses to hack telephony hardware and software full time.