4

I'm working on running a Hello World program on the Linksys WRT54G-V4 running either dd-wrt or OpenWRT.

Right now this router is running dd-wrt for reasons I'll explain below. I'd like to switch this router to OpenWRT, because I've not been able to build dd-wrt or its toolchain. I 'assume' that the OpenWRT toolchain should produce executable binaries that will run on dd-wrt also.

OpenWRT was pretty straightforward to build, since it has a nice menu driven make system. Using this handy tool I built a toolchain that will cross compile from my x86 Ubuntu box to a MIPS target.

Following the instructions I've been able to build OpenWRT and produce images for brcm47xx and brcm63xx.

For example, here is a successful compile of my little Hello World program:

jim@ubuntu:~/Desktop/tests$ cat helloC.c
#include <stdio.h>
int main (int argc, char **argv)
{
  printf("Hello World\n");
  return 0;
}
jim@ubuntu:~/Desktop/tests$
jim@ubuntu:~/Desktop/tests$ mipsel-openwrt-linux-gcc -o HelloWorld helloC.c
jim@ubuntu:~/Desktop/tests$
jim@ubuntu:~/Desktop/tests$ file HelloWorld
HelloWorld: ELF 32-bit LSB executable, MIPS, MIPS32 version 1, dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, not stripped
jim@ubuntu:~/Desktop/tests$

Sadly, when I try to run HelloWorld on my WRT54G-V4 running dd-wrt I get a seg fault.

Looking at Wikipedia, I see that this router uses the Broadcom BCM5352.

When I run make menuconfig in by OpenWRT/trunk directory I don't see an option for the BCM5352, which is why I'm reluctant to flash my router with one of the images I've created in the brcm47xx or brcm63xx directories. I don't want to guess wrong and brick the router.

Question 1 - Which Broadcom configuration should I select using make menuconfig to target my WRT54G-V4 with its BCM5352 chipset?

Question 2 - Should my 'HelloWorld' executable file I generated above run directly from the command line on the 54G, or must I make it a package per http://www.gargoyle-router.com/wiki/doku.php?id=openwrt_coding ?

TIA

Jim In Texas
  • 1,524
  • 4
  • 20
  • 31
  • I'm not at all sure you've got your toolchain set up correctly on Ubuntu :( Look here: http://wiki.openwrt.org/doc/devel/crosscompile – paulsm4 Sep 06 '12 at 18:44
  • 3
    I was able to get it working, I didn't have the correct version of open-wrt. I'll come back and answer my question as to exactly what I did latter. – Jim In Texas Sep 07 '12 at 20:27

1 Answers1

1

You can follow the official howto (from: http://www.dd-wrt.com/forum/viewtopic.php?p=21499&sid=de90601a8d51747d1c8ccec29284127d)

1. The helloworld.c source
Code:   
#include <stdio.h>

int main ( void ) {
        printf( "Hello world!\n" );
}   

2. Get and unpack the toolchain in your homedir
Code:   
cd ~
wget ftp://ftp.dd-wrt.com/sourcecode/toolchains.x86.debian.sp1.tar.bz2
tar -jxf toolchains.x86.debian.sp1.tar.bz2  

3. Add the path to your cross-compiler executable to your path environment variable and compile helloworld.c
Code:   
PATH=~/toolchains/4.1.0-uclibc-0.9.28/bin:$PATH mipsel-linux-uclibc-gcc helloworld.c -o helloworld  

4. Check if its correctly compiled with the cross-compiler
Code:   
file helloworld
helloworld: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped  

5. Finally, transfer the helloworld binary file to your router, set the executable bit and run it.

Tested with Ubuntu 6.06.1 LTS.

Pol Hallen
  • 1,852
  • 6
  • 32
  • 44