【问题标题】:How to write Hello World for OpenWRT and/or dd-wrt如何为 OpenWRT 和/或 dd-wrt ​​编写 Hello World
【发布时间】:2012-09-06 18:25:35
【问题描述】:

我正致力于在运行 dd-wrt ​​或 OpenWRT 的 Linksys WRT54G-V4 上运行 Hello World 程序。

现在这个路由器正在运行 dd-wrt,原因我将在下面解释。我想将此路由器切换到 OpenWRT,因为我无法构建 dd-wrt ​​或其工具链。我“假设”OpenWRT 工具链应该生成可以在 dd-wrt ​​上运行的可执行二进制文件。

OpenWRT 的构建非常简单,因为它有一个很好的菜单驱动的制作系统。使用这个方便的工具,我构建了一个工具链,可以从我的 x86 Ubuntu 机器交叉编译到 MIPS 目标。

按照说明,我已经能够构建 OpenWRT 并为 brcm47xx 和 brcm63xx 生成图像。

例如,这是我的 Hello World 小程序的成功编译:

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$

遗憾的是,当我尝试在运行 dd-wrt ​​的 WRT54G-V4 上运行 HelloWorld 时,我遇到了 seg 错误。

查看维基百科,我看到这款路由器使用的是 Broadcom BCM5352。

当我在 OpenWRT/trunk 目录中运行 make menuconfig 时,我没有看到 BCM5352 的选项,这就是为什么我不愿意用我在 brcm47xx 或 brcm63xx 中创建的映像之一来刷新我的路由器目录。我不想猜错并把路由器变砖。

问题 1 - 我应该使用 make menuconfig 选择哪种 Broadcom 配置来针对我的 WRT54G-V4 及其 BCM5352 芯片组?

问题 2 - 我上面生成的“HelloWorld”可执行文件应该直接从 54G 上的命令行运行,还是必须按照http://www.gargoyle-router.com/wiki/doku.php?id=openwrt_coding 将其作为一个包?

TIA

【问题讨论】:

  • 我完全不确定你是否在 Ubuntu 上正确设置了你的工具链 :( 看这里:wiki.openwrt.org/doc/devel/crosscompile
  • 我能够让它工作,我没有正确版本的 open-wrt。我会回来回答我的问题,关于我后来做了什么。
  • 酷 - 感谢您的跟进 :)

标签: openwrt broadcom dd-wrt


【解决方案1】:

您可以按照官方howto(来自: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.

使用 Ubuntu 6.06.1 LTS 测试。

【讨论】:

    猜你喜欢
    • 2014-06-22
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 2023-02-07
    相关资源
    最近更新 更多