Differences
This shows you the differences between the selected revision and the current version of the page.
howto:crosscompile 2008/09/13 22:27 | howto:crosscompile 2017/09/06 18:38 current | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Cross Compile Environment for DNS-323 ====== | ====== Cross Compile Environment for DNS-323 ====== | ||
+ | ===== Pre-compiled Binaries ===== | ||
+ | |||
+ | If, for whatever reason, you cannot compile the source code below, pre-compiled binaries are available from the uClibc website [[http://uclibc.org/downloads/binaries/0.9.30.1/cross-compiler-armv5l.tar.bz2|here]] as of May 17th. You can also download a native compiler, to compile programs for the device, on the device [[http://uclibc.org/downloads/binaries/0.9.30.1/mini-native-armv5l.tar.bz2|here]]. The cross-compiler is around 55MB when unpacked, and the native compiler around 35MB. | ||
+ | |||
+ | To set up the build environment, you simply need to un-tar the files and add the necessary folders to the PATH: | ||
+ | |||
+ | For the cross-compiler ('user' is an example username): | ||
+ | <code bash>cd /home/user | ||
+ | tar xjf cross-compiler-armv5l.tar.bz2 | ||
+ | rm cross-compiler-armv5l.tar.bz2 | ||
+ | export PATH=/home/user/cross-compiler-armv5l/bin:$PATH</code> | ||
+ | Then you would compile programs with armv5l-tool, e.g. armv5l-gcc | ||
+ | |||
+ | If you are using configure/make programs, you will need to follow the documentation for cross-compilation. You will also want the programs to be installed in a different directory from /usr/local so you can copy them later. For GNU and compatible programs, it is usually this: | ||
+ | <code bash>export CC=armv5l-gcc | ||
+ | ./configure --host=arm-unknown-linux --prefix=/home/user/arm # example directory | ||
+ | make | ||
+ | make install</code> | ||
+ | |||
+ | For the native compiler: | ||
+ | <code bash>cd /mnt/HD_a2 | ||
+ | tar xjf mini-native-armv5l.tar.bz2 | ||
+ | rm mini-native-armv5l.tar.bz2 | ||
+ | export PATH=/mnt/HD_a2/mini-native-armv5l/usr/bin:$PATH</code> | ||
+ | Then you would compile programs simply with the normal tool name e.g. gcc | ||
+ | |||
+ | Oh, I might point out, these images actually use newer versions of the source components than D-Link used. | ||
+ | |||
+ | ==== __cxa_atexit error ==== | ||
+ | |||
+ | You might get this error when using make with the native compiler. You can either download a patched version here: {{:download:make.gz}} or recompile make, adding the following line to main.c after the includes: | ||
+ | <code c>int __cxa_atexit(void (*func) (void *), void * arg, void * dso_handle){}</code> | ||
+ | |||
+ | ==== Cross vs Native compile ==== | ||
+ | |||
+ | Since the DNS-323 has only a 400MHz processor, configuring and compiling programs can be a slow process, usually slow enough that you won't be able to just sit there while it processes, but not so slow you have to do something else entirely or leave it on overnight. Native compiling has the advantage of building programs that exactly match the specifications of the device, only linking to libraries that are present, and warning of any errors properly. | ||
+ | |||
+ | A cross-compiler takes advantage of your PC's CPU, meaning that it will work a lot faster, however the end result might not work 100% on the device. You also need to ensure that the program you are compiling is properly configured for cross-compilation to ARM devices. | ||
+ | |||
+ | An ideal solution would be to emulate the DNS-323 architecture and kernel, but at much faster speeds. I haven't managed to do this with qemu, it is just as slow as the device itself. | ||
+ | |||
+ | Usually the best solution, if you are compiling large programs, is to construct your own configuration file, check all the dependencies manually, ensure libraries are linked dynamically, then cross-compile it. | ||
+ | |||
+ | ===== Firmware 1.05 ===== | ||
+ | This was done with http://tsd.dlink.com.tw/temp/download/3034/dns323_GPL_v1.05_05052008.tgz . | ||
+ | Untar this tarball. You should find another one inside which holds the actual source. Untar that one as well. | ||
+ | <code>wget http://tsd.dlink.com.tw/temp/download/3034/dns323_GPL_v1.05_05052008.tgz | ||
+ | tar zxvf dns323_GPL_v1.05_05052008.tgz | ||
+ | cd dns323_GPL | ||
+ | tar zxvf dns323_GPL.tgz | ||
+ | cd dns323_GPL</code> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Host build environment ==== | ||
+ | This was done with | ||
+ | * gcc (GCC) 3.4 (Ubuntu 3.4.6-6unbuntu2) | ||
+ | * bison (GNU Bison) 2.3 | ||
+ | * flex 2.5.34 | ||
+ | * gettext (GNU gettext-runtime) 0.17 (0.16.1 also works) | ||
+ | * and some small utilities like: make, bzip2, libncurses5-dev, patch | ||
+ | To install these using apt do something like | ||
+ | <code bash>sudo apt-get install gcc-3.4 bison flex gettext make bzip2 libncurses5-dev patch </code> | ||
+ | |||
+ | If you are using ubuntu 9.04 you should set an symbolic link, since the build of the toolchain will be done using ''/usr/bin/gcc''. If this is the default ubuntu gcc (for ubuntu 9.04 it is 4.3) then the build fails. | ||
+ | |||
+ | <code> | ||
+ | sudo rm /usr/bin/gcc | ||
+ | sudo ln -s /usr/bin/gcc-3.4 /usr/bin/gcc | ||
+ | </code> | ||
+ | |||
+ | Now you are ready to build the toolchain, but dont forget to set a symbolic link back to ''/usr/bin/gcc-4.3'' when it's finished. | ||
+ | |||
+ | |||
+ | |||
+ | ==== Toolchain ==== | ||
+ | The toolchain didn't quite compile out-of-the-box… | ||
+ | note (2009-10-24) Somebody should note where to get the tarball for uclibc described below? | ||
+ | -> As for me, the tarball was found inside the downloaded file (dns323_GPL.tgz). | ||
+ | <code bash> | ||
+ | # untar everything | ||
+ | tar xzf uclibc-toolchain-src-20040609.tgz | ||
+ | cd uclibc-toolchain-src-20040609/gcc-3.3.x | ||
+ | |||
+ | # fix broken link | ||
+ | #sed -i.old -e 's%ftp://ftp.gnu.org/gnu/gcc/releases/gcc-%ftp://ftp.gnu.org/gnu/gcc/gcc-%' -e 's/gdb //' | ||
+ | # | ||
+ | # above link to ftp-site refuses to connect, http-site would answer | ||
+ | sed -i.old -e 's%ftp://ftp.gnu.org/gnu/gcc/releases/gcc-%http://ftp.gnu.org/gnu/gcc/gcc-%' -e 's/gdb //' make/gcc-uclibc-3.3.mk | ||
+ | |||
+ | # fix linux headers versioning | ||
+ | sed -i.old -e 's/UTS_RELEASE \\"2\.4\.21\\"/UTS_RELEASE \\"2.6.12.6-arm1\\"/' -e 's/LINUX_VERSION_CODE 132117/LINUX_VERSION_CODE 132620/' make/kernel-headers.mk | ||
+ | |||
+ | # do not build gdb. | ||
+ | # building gdb did not work for me. you might want give it a shot, if you really need the debugger.. | ||
+ | # to do so just leave out these steps. if it fails, just retry from this point | ||
+ | sed -i.old 's/gdb #ccache$/# gdb #ccache/' Makefile | ||
+ | mv make/gdb-uclibc.mk make/gdb-uclibc.mk.dontinclude | ||
+ | |||
+ | # build a clean toolchain | ||
+ | # if some error occurs, try to fix it, drop a note somewhere and redo these two steps | ||
+ | make dirclean | ||
+ | yes "" | make | ||
+ | </code> | ||
+ | Voila, you just have built your cross-compiler. | ||
+ | Note: this does not compile with gcc-4.2, but works with gcc-3.4 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Setting up build environment for cross-compiling ==== | ||
+ | Use crosstools-env.sh, which is in [http://www.inreto.de/dns323/source/fw103-scripts-0.3-2007-07-29.tar.bz2], and fix the CWD variable to suit your needs. | ||
+ | |||
+ | Now you should be able to compile whatever you need. | ||
+ | |||
+ | For example: | ||
+ | <code># create a directory for this and copy all the files that you need there | ||
+ | mkdir ~/arm | ||
+ | cd ~/arm | ||
+ | |||
+ | # copy the toolchain_arm directory here. The directory is something like: dns323_GPL/dns323_GPL/uclibc-toolchain-src-20040609/gcc-3.3.x/toolchain_arm | ||
+ | cp -R $PATH_TO_DNS323_toolchain_arm . | ||
+ | |||
+ | # get the crossentools-env.sh with bunch of other stuff. We only need crosstools-env.sh | ||
+ | wget http://www.inreto.de/dns323/source/fw103-scripts-0.3-2007-07-29.tar.bz2 | ||
+ | tar xvjf fw103-scripts-0.3-2007-07-29.tar.bz2 | ||
+ | cp fw103-0.3/crosstools-env.sh .</code> | ||
+ | |||
+ | This is what crosstools-env.sh looks like | ||
+ | <code>#!/bin/sh | ||
+ | |||
+ | #CWD=$(pwd) | ||
+ | #CWD=/opt/dns323/fw103-0.3 | ||
+ | CWD=/home/dns323_GPL/dns323_GPL/uclibc-toolchain-src-20040609/gcc-3.3.x | ||
+ | |||
+ | # I've changed this line: | ||
+ | #export CROSSTOOLS=$CWD/crosstools/gcc-3.3.x/toolchain_arm | ||
+ | # to: | ||
+ | export CROSSTOOLS=~/arm/toolchain_arm | ||
+ | |||
+ | # compile-time | ||
+ | |||
+ | export PATH=$CROSSTOOLS/bin:$PATH | ||
+ | |||
+ | export BUILD="-Os -mtune=arm9e -march=armv5te" | ||
+ | |||
+ | export CROSS_TARGET=arm-linux-uclibc | ||
+ | |||
+ | export CC="${CROSS_TARGET}-gcc" | ||
+ | export CXX="${CROSS_TARGET}-g++" | ||
+ | export AR="${CROSS_TARGET}-ar" | ||
+ | export AS="${CROSS_TARGET}-as" | ||
+ | export LD="${CROSS_TARGET}-ld" | ||
+ | export RANLIB="${CROSS_TARGET}-ranlib" | ||
+ | export READELF="${CROSS_TARGET}-readelf" | ||
+ | export STRIP="${CROSS_TARGET}-strip" | ||
+ | </code> | ||
+ | |||
+ | Now, to compile your own program, do: | ||
+ | <code># bring the environment variables from crosstools-env.sh into our current shell | ||
+ | source crosstools-env.sh | ||
+ | |||
+ | # check the CC environment variable has been set | ||
+ | echo $CC | ||
+ | |||
+ | # output should be: arm-linux-uclibc-gc | ||
+ | |||
+ | # create a sample hello-world program: | ||
+ | echo '#include<stdio.h> | ||
+ | int main() | ||
+ | { | ||
+ | printf("Hello, World\n"); | ||
+ | return 0; | ||
+ | }' > hello.C | ||
+ | |||
+ | # now compile it | ||
+ | $CC -O2 hello.C -o hello | ||
+ | |||
+ | #or | ||
+ | arm-linux-cc -O2 hello.C -o hello | ||
+ | |||
+ | # now copy the hello executable to your DNS-323, and try it there</code> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Firmware 1.06 ===== | ||
+ | |||
+ | For firmware 1.06 all you have to do is get another tarball from ftp://ftp.dlink.com/GPL/DNS-323/106/dns323_GPL_v1.06_12032008.tgz | ||
+ | |||
+ | <code> | ||
+ | # get and unpack toolchain files | ||
+ | wget ftp://ftp.dlink.com/GPL/DNS-323/106/dns323_GPL_v1.06_12032008.tgz | ||
+ | tar zxvf dns323_GPL_v1.06_12032008.tgz | ||
+ | cd dns323_GPL | ||
+ | tar zxvf dns323_GPL.tgz | ||
+ | cd dns323_GPL | ||
+ | </code> | ||
+ | |||
+ | then continue with instructions for firmware 1.05 above. | ||
+ | |||
+ | - didn't work for me, it generated "32-bit, no machine" executables, which of course, can't be executed on i686. | ||
+ | <code> | ||
+ | # workaround (just remove --build= and --host= from ./configure options): | ||
+ | sed -i.old 's/--build=$(GNU_HOST_NAME) \//g' make/gcc-uclibc-3.3.mk | ||
+ | sed -i.old 's/--host=$(GNU_HOST_NAME) \//g' make/gcc-uclibc-3.3.mk | ||
+ | |||
+ | # for binutils too | ||
+ | sed -i.old 's/--build=$(GNU_HOST_NAME) \//g' make/binutils-uclibc.mk | ||
+ | sed -i.old 's/--host=$(GNU_HOST_NAME) \//g' make/binutils-uclibc.mk | ||
+ | </code> | ||
+ | |||
+ | __Note:__ to compile (optware-)packages for the DNS323, the correct **./configure** parameter is **-- --host=arm-linux-uclibc**. at least that worked for me... | ||
+ | |||
+ | __Another note:__ i set this up with ubuntu 9.04 in a virtual machine (vmware, any other flavour should do too) and did a snapshot of the working environment. gives me a fully operational and (in a certain way) portable solution for cross compiling. | ||
+ | |||
+ | __And yet another note:__ For 1.6, you need also to comment out or remove the 'gdb' target in gcc-uclibc-3.3.mk, i.e. before making, run: | ||
+ | <code> | ||
+ | sed -i.old 's/gdb//' make/gcc-uclibc-3.3.mk | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== Firmware ?.?? ===== | ||
**Please feel free to update, cleanup or correct this page** | **Please feel free to update, cleanup or correct this page** | ||
+ | |||
+ | **Note**: The **wget-gpl** script now no longer works: instead the GPL directory has a readme file redirecting you [[http://www.dlink.com/support/gpl/|here]]. The actual GPL files are found [[ftp://gpl.dlink.com/|here]], with the DNS-323 specific file [[ftp://gpl.dlink.com/DNS-323/dns323_GPL_v1.08_12182009.tgz|here]] as of May 10th. Simply copy this file into GPL/zips and continue. | ||
What is this? | What is this? | ||
Line 9: | Line 239: | ||
**Things you will need first** | **Things you will need first** | ||
- | * Development System x86 based Debian based "Ubuntu Dapper" | + | * Development System x86-based Debian-based [[http://releases.ubuntu.com/6.06/|Ubuntu Linux "Dapper Drake" (6.06)]] |
* You will need the following tools: **bison flex gcc-3.4 byacc g++-3.4 gettext patch** | * You will need the following tools: **bison flex gcc-3.4 byacc g++-3.4 gettext patch** | ||
* Check your active compiler version with **gcc -v** | * Check your active compiler version with **gcc -v** | ||
Line 51: | Line 281: | ||
\\ | \\ | ||
\\ GCC_SITE:=ftp://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VERSION) | \\ GCC_SITE:=ftp://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VERSION) | ||
+ | \\ - note: I could not access the ftp server, but http://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VERSION) worked fine. -- badwolf April 09 | ||
\\ | \\ | ||
\\ Now, since we have already uncompressed the tar file, we comment out lines 23 and 24 of build_uclibc by adding a # to that start of each line. | \\ Now, since we have already uncompressed the tar file, we comment out lines 23 and 24 of build_uclibc by adding a # to that start of each line. |