2

Run and Debug DD-WRT with VirtualBox

 2 years ago
source link: https://e3pem.github.io/2020/03/20/IoT/DD-WRT-VirtualBox/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Run and Debug DD-WRT with VirtualBox

发表于 2020-03-20

| 分类于 IoT

最近有运行并调试DD-WRT中程序的需求,最开始想的是从源码编译一个x86 or x86_64下的待调试程序出来直接在本地调,可是DD-WRT的官方文档写的不怎么好,而且光是下载好源码和交叉编译工具就占用了超过55G的空间。后来发现官方其实已经基于最新版源码编译好了适应各种架构/型号的固件,再结合VirtualBox就能将这个最新版的固件跑起来,简直完美!

运行环境搭建

相关工具准备

下载安装virtualbox:

https://download.virtualbox.org/virtualbox/6.1.4/VirtualBox-6.1.4-136177-Win.exe

下载VirtualBox Extension Pack:
https://download.virtualbox.org/virtualbox/6.1.4/Oracle_VM_VirtualBox_Extension_Pack-6.1.4.vbox-extpack

我这里准备在64位下运行固件,所以下载dd-wrt x86_64 image(可以在官网找到最新编译好的image):

https://download1.dd-wrt.com/dd-wrtv2/downloads/betas/2020/03-18-2020-r42729/x86_64/dd-wrt_x64_public_vga.image

首先将dd-wrt x64 image 转换为VDI形式,进入到VirtualBox安装的目录,执行如下代码(需根据自己的情况将其中的路径进行替换):

vboxmanage.exe convertdd "D:\tmp\rm\dd-wrt\dd-wrt_x64_public_vga.image" "D:\tmp\rm\dd-wrt\dd-wrt-64.vdi"

设置VDI文件的大小:

vboxmanage.exe modifyhd --resize 512 "D:\tmp\rm\dd-wrt\dd-wrt-64.vdi"

接着启动VirtualBox,创建新的VM:

  • 类型选择Linux
  • 版本选择Other Linux
  • 不添加虚拟硬盘

然后将设置过大小后的VDI文件拷贝到新建的VM目录下。并设置VM的存储,选择刚刚复制的VDI文件:

在设置界面点击网络,选择桥接:

启动vm,在界面的内容不再滚动时,按下回车,并使用root/admin登录,使用如下命令设置dd-wrt的网络(要和当前主机在同一个网段):

ifconfig br0 192.168.1.144

接着就可以通过浏览器访问该地址,进入dd-wrt后台了

要调试dd-wrt里面的程序,需要有对应的静态编译的gdbserver(64位),下载源码:https://ftp.gnu.org/gnu/gdb/

进入到./gdb/gdbserver目录下,执行下列命令(执行./configure之后还需要手动修改Makefile文件以生成静态的gdbserver)

./configure --host=x86_64-linux --target=x86_64-linux
// modify CC-LD=${CC} to CC-LD=gcc -static
make

编译之前需要下载libinproctrace.so,并把它放到gdbserver目录下。

将编译好的gdbserver上传至DD-WRT中,附加待调试进程即可:

tftp -g -r gdbserver ip_addr
chmod +x gdbserver
./gdbserver 0.0.0.0:12345 --attach pid

https://www.youtube.com/watch?v=BRLukj4dZxk


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK