2017年1月22日 星期日

在 MIPS 平台上 Build OpenWRT user space program

最近手上有一塊板子, 想要把裡面的檔案拿出來, 但是板子只支援 telnet login, 所以想乾脆
build 一個簡單的 http server 放進去來下載檔案
板子是用 mips 的架構, 上面的 libc 是 uclibc, 原本想找有沒有像 arm-linux-gcc 之類的
prebuilt compiler 可以直接用, 但找了很久都沒甚麼收穫, 後來發現板子上是跑 OpenWRT, 就
往 OpenWRT build system 搜尋

一開始把 OpenWRT source code 抓下來直接 build, build 出來是 musl 的 C library, 說已經用
musl 取代 uclibc, 後來發現 branch Chaos Calmer 還在用 uclibc, 切到 Chaos Calmer 後卻
build fail.

後來轉換方向, 發現有 OpenWRT SDK 可以用, 官網的描述

"The SDK is a relocatable, precompiled OpenWrt toolchain suitable to cross compile single userspace packages for a specific target without compiling the whole system from scratch."

看起來正是我需要的, 我的板子是用 mt7620 的平台, 在官網就可以找到 mt7620 SDK 的下
載連結

OpenWrt-SDK-15.05.1-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2

應該就是這一包了, 下載後解開, 裡面的內容像這樣



在 staging_dir 裡面就有 cross-compiler



但是在 build 的時候會出現 STAGING_DIR not defined error, 所以還需要 define 這個環境
變數, 經過實驗似乎 STAGING_DIR 的值是甚麼無所謂, 只要有就可以

網路上找了用 C 寫的簡單的 http server, build 出了執行檔, 之後成功在板子上跑起來並可
用 http 下載檔案


沒有留言:

張貼留言