Around a week ago I started experimenting with running Asterisk on my FRITZ!Box 7270 to replace my DECT phone, which has been getting a bit long in the tooth, with a SIP client running on my new Motorola Milestone HTC Desire cell phone so that when I am at home and my cell phone is signed in to my WLAN I can use it as a mobile handset for calls arriving on my landline.
As it turned out it is a little bit tricky to get Asterisk to compile for the FRITZ!Box, so this posting is supposed to summarize the steps I had to take and also comes with a neat helper script, which should automate most of the required preparation and compilation steps.
Prerequisites
This guide assumes that you are running some Linux derivate that comes with a complete gcc toolchain for your host platform. You will also need a current Freetz version (I used 1.1.x as well as trunk as of revision 5752) to build the cross-compilation toolchain, which we will use to build the Asterisk binaries for the FRITZ!Box. If you have not yet done so, grab a copy of Freetz from its Subversion repository using:
svn co http://svn.freetz.org/branches/freetz-stable-1.1
By default, Freetz uses a pre-compiled toolchain, which we do not want to use. Instead, we will build our own toolchain. To enable this feature of the Freetz build, change to the freetz-stable-1.1 directory and type:
make menuconfig
Make sure the general configuration fits your needs (especially the box type needs to be correct). Further details are available on the Freetz Wiki (in German).
Also make sure you have the “bash” package (listed under “Package selection” -> “Testing”) is selected. Under “Advanced options” -> “Compiler options” -> “Toolchains” select “Build toolchain (requires 4GB diskspace)”.
Next, enable the compilation of libresolv by selecting the respective checkbox at “Advanced options” -> “Shared libraries” -> “uClibc” -> “libresolv-0.9.2x.so”. Update: You will also need to select “Advanced options” -> “Shared libraries” -> “ncurses” -> “ncurses (libncurses.so)” and [Update2:] “Advanced options” -> “Shared libraries” -> “CAPI 2.0 (libcapi20.so)”.
Build a new Freetz image and toolchain by issuing
make
on the command line.
Update: If some of the options mentioned above were not selected when you last built and flashed Freetz to your FRITZ!Box you will have to do so before starting Asterisk later as it will otherwise not find some of its dependencies.
You will also need an USB memory stick attached to your FRITZ!Box, which has been formatted with the ext3 file system (so file attributes and symlinks are correctly preserved). I have not tried whether a FAT32-formatted stick works. If so, please leave a comment.
The build script itself needs the fakeroot package in addition to the usual development packages.
Cross-compiling Asterisk
Now that the cross-compilation toolchain has been built we can start looking into actually building Asterisk for the FRITZ!Box. This tutorial will focus on building Asterisk 1.6.0.19 1.6.2.9 with chan_capi 1.1.4 1.1.5, but can be easily adapted to newer versions.
First, you will need to download the Asterisk-Freetz compilation helper, which is available for download at:
http://github.com/ginkel/asterisk-freetz-build/tarball/v0.5
Extract the file into a directory of your choice:
tar xvzf ginkel-asterisk-freetz-build-v0.5-0-gdc9f7c2.tar.gz
Next, edit the build-asterisk.sh script and point the FREETZ_TOOLCHAIN variable to the directory hosting your Freetz cross-compiler toolchain. Usually, this is the “toolchain/target” directory below the main Freetz directory. Save your changes.
Finally, start the build by issuing the following command:
./build-asterisk.sh
Installation
If everything works out correctly you will end up with a file named “asterisk-1.6.2.11+chan_capi-1.1.5-freetz.tar.bz2″ after the completion of the build. It contains the complete runtime environment for Asterisk (except for the Asterisk configuration files). Copy the file to the USB memory stick attached to the FRITZ!Box, log on to your FRITZ!Box and extract it to a directory of your choice.
For my Freetz installation the USB memory stick is mounted as /var/media/uStor01, so I have to issue the following commands to perform the installation (assuming that asterisk-1.6.2.11+chan_capi-1.1.5-freetz.tar.bz2 is located in the USB memory stick’s root directory):
ssh root@fritz.box
cd /var/media/uStor01
tar xjf asterisk-1.6.2.11+chan_capi-1.1.5-freetz.tar.bz2
Before starting Asterisk for the first time you will want to populate the “etc/asterisk” directory with some sensible configuration files.
Starting Asterisk
After doing that it is time to start Asterisk. Let’s assume you extracted the distribution .tar.gz file into the root directory of your USB memory stick (/var/media/uStor01). Then, you would be able to start it using the following command while logged in to the FRITZ!Box shell:
/var/media/uStor01/asterisk/bin/start-asterisk.sh
This will start Asterisk through the safe_asterisk script, which will make sure that Asterisk is re-spawned in case it terminates irregularly. This is probably not what you want while still debugging your Asterisk configuration, so if you prefer a non-respawning invocation with debug messages sent to the console, use
/var/media/uStor01/asterisk/bin/start-asterisk.sh --debug
instead.
Surviving Reboots
Once you are comfortable with your Asterisk configuration it is time to configure Freetz so that it will automatically start when the FRITZ!Box reboots. To do so, sign in to the Freetz configuration web UI (usually located at http://fritz.box:81/) and add the start-asterisk command to rc.custom.
Voilà
Now you have Asterisk running on your FRITZ!Box. Enjoy!
Hi, I am trying to do the same as in this howto.
I have Freetz-1.1.2 and compiled the toolchain. Everything went fine, I got the firmware.
But for compiling Asterisk I get a lot of errors in the form of
chan_capi.c:5507: error: ‘struct capi_pvt’ has no member named ‘PLCI’
Do I have to install asterisk-chan-capi on my compiling ubuntu (9.10)?
I am having the same problem as the previous commenter.
How can we solve this error?
I’ll try to look into this as soon as I find some time…
I have sipdroid working with the default PBX of fritzbox. Dont know what the real advantage it gives to compile asterisk on it. (Ofcource it gives some more freedom with the dial plan)
Well, when I originally tried it was basically impossible to get the native FRITZ!Box SIP registrar and Sipdroid to talk to each other – mainly because the FRITZ!Box SIP implementation incorrectly sets some headers to 127.0.0.1. I also remember having struggled with some issues regarding TCP/UDP connections.
Maybe Sipdroid is now working around this issue or the most recent FRITZ!Box firmware solved them.
Hi,
thank you for the post and the scripts. Unfortunately I cannot compile chan_capi as well. See below
~/asterisk-freetz-build-0.1/build/chan_capi-1.1.4 ~/asterisk-freetz-build-0.1/build ~/asterisk-freetz-build-0.1
[LD] chan_capi.so (chan_capi.o chan_capi_utils.o chan_capi_rtp.o chan_capi_command.o xlaw.o dlist.o chan_capi_qsig_core.o chan_capi_qsig_ecma.o chan_capi_qsig_asn197ade.o chan_capi_qsig_asn197no.o chan_capi_supplementary.o chan_capi_chat.o)
/home/freetz/freetz-stable-1.1/toolchain/build/gcc-4.2.1-uClibc-0.9.29/mipsel-linux-uclibc/bin-ccache/../lib/gcc/mipsel-linux-uclibc/4.2.1/../../../../mipsel-linux-uclibc/bin/ld: cannot find -lcapi20
collect2: ld returned 1 exit status
make: *** [chan_capi.so] Fehler 1
I tried a few things but I could’t make it find the lib. You patched the make file to use a precompiled lib. What lib are you using and where does it come from?
Danke
For my Freetz build environment libcapi20 resides in toolchain/build/gcc-4.2.1-uClibc-0.9.29/mipsel-linux-uclibc/lib/.
It is marked as selected at “Advanced options” -> “Shared libraries” -> “CAPI 2.0 (libcapi20.so)” for my Freetz configuration.
Could you please check whether this is also the case for your Freetz build environment?
Thanks for the fast reply. No CAPI 2.0 wasn’t selected. But then again you didn’t told me to select it and I looked over it. Without further funny remarks, yes it compiles and builds the package without (visible) errors. Tomorrow I’ll have a look at actually installing the firmware and asterisk.
Hi, I posted the first comment.
For me the compilation works now with the [Update2:] and Freetz 1.1.2.
Thank you very much for your post and build script! Running it from a ext2 usb-stick.
Hy,
is it possible, that uClibc-0.9.29.tar.bz2 isn’t longer valid?
I changed the file ./config
from:
” FREETZ_TARGET_COMPILER_GCC_4_2_1_UCLIBC_0_9_29=y”
to
” FREETZ_TARGET_COMPILER_GCC_4_2_1_UCLIBC_0_9_30=y”
It’s still compiling – lets see what happens..
…
“mkdir -p /mnt/nfs/ubuntu/fritz/freetz-stable-1.1/source/toolchain/target
tar -C /mnt/nfs/ubuntu/fritz/freetz-stable-1.1/source/toolchain/target -xjf dl/uClibc-0.9.30.tar.bz2
for i in toolchain/make/target/uclibc/0.9.30/*.patch; do \
tools/freetz_patch /mnt/nfs/ubuntu/fritz/freetz-stable-1.1/source/toolchain/target/uClibc-0.9.30 $i; \
done
tools/freetz_patch: line 67: toolchain/make/target/uclibc/0.9.30/*.patch: Datei oder Verzeichnis nicht gefunden
ERROR: modpatch: Error in patch-file toolchain/make/target/uclibc/0.9.30/*.patch
make: *** [/mnt/nfs/ubuntu/fritz/freetz-stable-1.1/source/toolchain/target/uClibc-0.9.30/.unpacked] Fehler 2
”
Change the Lines:
#
# Download site #4 – default: empty (reserved for later use)
#
FREETZ_MOD_DL_SITE_4=”ftp://ftp.slackware.org.uk/armedslack/armedslack-devtools/uclibc/sources”
seems to work better
Still compiling more than 3h – I go to bed now!
(Running on an old eeePC with 700MHz)
Greetz
Hi,
i’ve compiled the new Fritz_Freetz image right now. Runs.
But the link to the asterisk-freetz-build-0.1.tar.gz is broken.
how can i get this?
thx
The download should be working again (once the DNS change has propagated – should take ~ 30 minutes).
Hi great tutorial!
\Before starting Asterisk for the first time you will want to populate the “etc/asterisk” directory with some sensible configuration files\
Could you please add more information regarding this?? I just want to verify that asterisk starts running before making my own configuration
Hi,
I have compiled it succesfully. I need sccp/skinny support.
The ready compiled asterisk includes only chan_skinny and it seem to be bugy, because asterisk crash very often, if i use the skinny phones (C7960).
At another PC-Installation i use chan_sccp-b with good results.
How can i add chan_sccp-b compilation for the fritzbox 7170 ?
[...] has been a while since I published my guide to cross-compile Asterisk for the FRITZ!Box 7270. This guide and build script was based on Asterisk [...]
Checked, if i can compile with 1.6.2.9 and freetz-1.1.3
Stuck with errormsg:
ginkel-asterisk-freetz-build-7f77135/build/asterisk-1.6.2.9/main/dns.c:292: undefined reference to `__res_close’
collect2: ld returned 1 exit status
make[1]: *** [asterisk] Fehler 1
make: *** [main] Fehler 2
Any idear to solve this ?
@Erwin:
Actually the patch at http://github.com/ginkel/asterisk-freetz-build/blob/master/patches/asterisk-res_close.patch should take care of this issue.
Could you please verify whether this patch is present in your distribution and check in build/asterisk-1.6.2.9/main/dns.c whether line 292 reads:
– 8< –
#if !defined(__APPLE__) && !(defined(__UCLIBC__) && !defined(__UCLIBC_HAS_BSD_RES_CLOSE__))
– 8< –
Hi,
Patch is there, also the line 292 in dns.c is there at line 291, but this shoud make no difference.
Before i tested your compilation i have tested another one.
Maybe there is left some information.
I have changed there this values:
make uclibc-menuconfig
enable this options:
* Networking Support -> Support res_close()
* Big and Tall -> Support gnu glob() interface
(see at http://www.voipfan.de/showthread.php?p=1565663)
I have revert this changes, but your compilation did not run anyway. Do i have to delete something before ?
Ok,
fixed. Started from the scratch with new freetz installation and now compilation works as before. So do not test with other “distributions” in the same freetz framework.
It will be nice to find a way to implement asterisk with asterisk-gui in fritzbox with freetz. If you find a way please let us know.
* no new union subclass in ast_frame structure
* no new ast_channel_release function
* found new ast_devstate2str function
* no requestor in ast_request
* no format_t in ast_request
* no const char in ast_register_application
* no linkedid in ast_channel_alloc
* no rtp_engine.h
config.h complete.
[CC] chan_capi.c -> chan_capi.o
/bin/sh: mipsel-linux-gcc: not found
make: *** [chan_capi.o] Fehler 127
iget this eerror if i follow this tutor (i use vmware freetz and work fine, latest svn), but ast. compiling end with this err – pls help, many thanx.
@mario: Did you set the FREETZ_TOOLCHAIN variable in build-asterisk.sh to a sensible (non-empty) value?
[...] trunk my existing Asterisk build suddenly stopped working. This was a good reason to bring my asterisk-freetz-build script in sync with the current Asterisk 1.6.2 version as well with Freetz trunk, which I have been using [...]
[...] This post tells you what this is all [...]
I followed your instruction with Freetz 1.1.4 and ginkel-asterisk-freetz-build-v0.5-0-gdc9f7c2.zip. It starts compiling but ends up with:
file.o: In function `ast_readaudio_callback’:
/home/freetz/asterisk_0.5/build/asterisk-1.6.2.11/main/file.c:766: undefined reference to `roundf’
collect2: ld returned 1 exit status
make[1]: *** [asterisk] Fehler 1
make: *** [main] Fehler 2
Why do you run the asterisk on FB? Cannot you connect your HTC Desire to the FB with wifi directly? Then you can register a SIP client of your mobile as a voip phone very simply at the F!B naturally. I do it at my F!B 7170. In F!B, you “Configure a new device” -> Telephone -> LAN/WLAN (IP phone). You get an user name, registrar is the “fritz.box”. These values you need for your mobile SIP client. Done.
Well, I am aware of the FRITZ!Box’s built-in registrar. Unfortunately, it is only available via WiFi, but not via the WAN interface (on the Internet), which originally prompted me to cross-compile Asterisk.
Hi,
I’m also trying to install Asterisk on my FB7390 by using your script. I’m using freetz trunk because it seems that the 7390 is not supported in any stable version of freetz.
When running the script everything works fine until the make of chan capi. There I get an error in /asterisk/include/asterisk/lock.h:55:22 fatal error execinfo.h no such file or directory.
Do you know what is going wrong here?
Regards,
Oliver
Everything ist running fine on FAT32 formated media as well:
You’ll get an error while unpacking that symlink rasterisk on asterisk could not be created. Just place a copy of asterisk binary at asterisk/bin/rasterisk.
Anyway. I guess I’ll migrate the stick to ext3 as it’s a far better filesystem
Everything goes fine except that I cannot understand where asterisk-1.6.2.11+chan_capi-1.1.5-freetz.tar.bz2 is saved. I’ve searched most of the folders but didn’t find it in any of them.
Thanks in advance!
Additionally, when I compile it, it says “Zeile 162 : Fakeroot : Kommando nicht gefunden”.
I can fully understand german, but I can’t get why fakeroot command doesn’t exist.
unfortunately your howto doesn’t seem to work with the
more recent versions of freetz that use
uClibc and do NOT have a libresolv anymore
maybe with a newer version of asterisk?
or does anyone know how to modify asterisk’s Build process to link uClibc rather than libresolv?
.. so close for my FBF 7390 @ 84.05.50