OpenWrt Forum Archive

Topic: Compiling on a router

The content of this topic has been archived on 19 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have a newly acquired 512MB USB flashdrive that I'd like to dedicate to my WGT634U and was wondering how I can turn it into a full OpenWrt development platform (ie. compiling for MIPS right on the router).

Any idea how this would be accomplished?  I can't figure out how to create new packages from source with the buildroot-ng package builder.

Sorry if there's a post like this already.  I coudn't find it.

(Last edited by KillaB on 21 Dec 2006, 02:48)

Bah, this idea is so stupid. Cross-compilation is the way to go.

I've written a guide to build OpenWrt with the VMware player. Can be used for Kamikaze too.

I already know how to build images/packages with buildroot-ng....
what I'm trying to figure out how to do is compile a new package from source.

you need to cross compile the toolchain itself. buildroot (the non-openwrt one) has an option for this, if you can match the versions, otherwise there's plenty of other docs and utilities around on making cross compiling toolchains.  from personal experience I think I should tell you that performance will be terrible on most openwrt supported devices, believe it or not your 2ghz dualcore desktop with 1gb ram will compile faster smile  perhaps you could set up distcc to make it worth it?

why would you cross compile from vmware? native is faster, and should work on most architectures.. that's the point of the "cross", after all. if your using windows it would be more efficient to use cygwin or mingw, which despite popular opinion is not an emulator.  or install linux, of course smile

export PATH=/path/to/toolchain/target/bin:$PATH
export PATH=/path/to/toolchain/kernel/bin:$PATH

after that type mips- 2 times tab key.
should, when found looks like:

mii-diag                            mipsel-linux-uclibc-gcc
mii-tool                            mipsel-linux-uclibc-gcc-4.1.0
min12xxw                            mipsel-linux-uclibc-gccbug
minicom                             mipsel-linux-uclibc-gcov
mipsel-linux-addr2line              mipsel-linux-uclibc-ld
mipsel-linux-ar                     mipsel-linux-uclibc-nm
mipsel-linux-as                     mipsel-linux-uclibc-objcopy
mipsel-linux-c++                    mipsel-linux-uclibc-objdump
mipsel-linux-cc                     mipsel-linux-uclibc-ranlib
mipsel-linux-c++filt                mipsel-linux-uclibc-readelf
mipsel-linux-cpp                    mipsel-linux-uclibc-size
mipsel-linux-g++                    mipsel-linux-uclibc-strings
mipsel-linux-gcc                    mipsel-linux-uclibc-strip
mipsel-linux-gcc-4.1.0              mipsel-unknown-linux-gnu-addr2line
mipsel-linux-gccbug                 mipsel-unknown-linux-gnu-ar
mipsel-linux-gcov                   mipsel-unknown-linux-gnu-as
mipsel-linux-ld                     mipsel-unknown-linux-gnu-c++filt
mipsel-linux-nm                     mipsel-unknown-linux-gnu-cpp
mipsel-linux-objcopy                mipsel-unknown-linux-gnu-gcc
mipsel-linux-objdump                mipsel-unknown-linux-gnu-gcc-3.4.5
mipsel-linux-ranlib                 mipsel-unknown-linux-gnu-gccbug
mipsel-linux-readelf                mipsel-unknown-linux-gnu-gcov
mipsel-linux-size                   mipsel-unknown-linux-gnu-gprof
mipsel-linux-strings                mipsel-unknown-linux-gnu-ld
mipsel-linux-strip                  mipsel-unknown-linux-gnu-nm
mipsel-linux-uclibc-addr2line       mipsel-unknown-linux-gnu-objcopy
mipsel-linux-uclibc-ar              mipsel-unknown-linux-gnu-objdump
mipsel-linux-uclibc-as              mipsel-unknown-linux-gnu-ranlib
mipsel-linux-uclibc-c++             mipsel-unknown-linux-gnu-readelf
mipsel-linux-uclibc-cc              mipsel-unknown-linux-gnu-size
mipsel-linux-uclibc-c++filt         mipsel-unknown-linux-gnu-strings
mipsel-linux-uclibc-cpp             mipsel-unknown-linux-gnu-strip
mipsel-linux-uclibc-g++

then in source tree:

./configure --build=i386-linux-gnu --target=mipsel-linux --host=mipsel-linux

or edit Makefile.in

(edit) this is take from avm toolchain. near simular to openwrt one. build some own binary's with it for my hardware.

(Last edited by heini on 21 Dec 2006, 09:45)

Kevin wrote:

why would you cross compile from vmware? native is faster, and should work on most architectures..

I think there's a misunderstanding.

"Cross compiling" means using an i386 host to compile for MIPS. This is what OpenWrt's buildroot does when run under i386 Linux (whether that be a "real" i386 machine or a virtual machine)

"Native" means using a MIPS host to compile for MIPS. That's what the OP wanted to do. It will be much slower building packages on a 266MHz MIPS CPU than on a 2GHz i386 (or even a Linux VM running under Windows on a 2GHz i386)

The OP will end up with a lot more work getting native compilation to work, since there's no existing MIPS toolchain to work with. So he/she will first have to cross-compile the toolchain to MIPS, before copying it to the box, before being able to start compiling.

In other words - you have a lot less work to do if you just use a Linux i386 machine (or VM) in the first place.

I can't figure out how to create new packages from source with the buildroot-ng package builder.

If you want to build a real package (a .ipkg) then it will be the same whether or not you perform the compilation under i386 or on the router itself. But you don't need buildroot for this - all you need is the SDK

If you want an example of how to build a package from scratch, try this example - you just unpack it under the SDK and type 'make'

If you want to build a single binary and copy it onto your target, without using ipkg at all, then you can use the toolchain which the SDK is supplied with, or which the buildroot builds from scratch.

candlerb@candlerb-desktop:~/svn/openwrt/trunk$ cat >hello.c
#include <stdio.h>
int main(void)
{
    printf("Hello, world!\n");
    return 0;
}
^D
candlerb@candlerb-desktop:~/svn/openwrt/trunk$ staging_dir_mips/bin/mips-linux-gcc -Wall -o hello hello.c
candlerb@candlerb-desktop:~/svn/openwrt/trunk$ file hello
hello: ELF 32-bit MSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
candlerb@candlerb-desktop:~/svn/openwrt/trunk$

The discussion might have continued from here.