OpenWrtのクロス開発環境をFedora上に作成

Fonera関連のブログを漁っていたら,ちょうどDebian上にクロスコンパイル環境を作ってる方(http://d.hatena.ne.jp/sdkt4a/20080814/1218655463)をみつけたので、参考にしながらやってみました。
クロス開発環境構築自体初体験!なので、殆ど、何が行われているのか?不明なんですが、まずは実践あるのみで・・・。


使用した環境はFedora9。詳細は以下。

$ uname -a
Linux fedora9 2.6.25.10-86.fc9.i686 #1 SMP Mon Jul 7 20:46:03 EDT 2008 i686 i686 i386 GNU/Linux

適当なディレクトリを作成して、OpenWrtのソースコードを落としてくる。
ソースコードを落とす作業が、自動的に進みますが、結構長い。。。

[irishin@fedora9 ~]$ mkdir openwrt
[irishin@fedora9 ~]$ cd openwrt/
[irishin@fedora9 openwrt]$ svn checkout https://svn.openwrt.org/openwrt/tags/kamikaze_7.09 kamikaze

A kamikaze/rules.mk
A kamikaze/toolchain
A kamikaze/toolchain/uClibc
A kamikaze/toolchain/uClibc/config
A kamikaze/toolchain/uClibc/config/arm
A kamikaze/toolchain/uClibc/config/powerpc
A kamikaze/toolchain/uClibc/config/cris
A kamikaze/toolchain/uClibc/config/armeb
A kamikaze/toolchain/uClibc/config/mips
A kamikaze/toolchain/uClibc/config/i386
A kamikaze/toolchain/uClibc/config/mipsel
A kamikaze/toolchain/uClibc/config/avr32
A kamikaze/toolchain/uClibc/config/x86_64

 (大量に中略)

A kamikaze/package/nozomi/files
A kamikaze/package/nozomi/files/Makefile
A kamikaze/package/nozomi/patches
A kamikaze/package/nozomi/patches/001-devfs.patch
A kamikaze/package/nozomi/patches/002-nozomi_vf_01.patch
A kamikaze/package/nozomi/Makefile
A kamikaze/package/ifenslave
A kamikaze/package/ifenslave/Makefile
A kamikaze/Makefile
A kamikaze/README
U kamikaze
リビジョン 13952 をチェックアウトしました。
[irishin@fedora9 openwrt]$

作成されたディレクトリに移動して、READMEを読むと、"make menuconfig"してねと書いてあるので、それに従う。

[irishin@fedora9 openwrt]$ ls
kamikaze
[irishin@fedora9 openwrt]$ cd kamikaze/
[irishin@fedora9 kamikaze]$ ls
BSDmakefile LICENSE README include rules.mk target tools
Config.in Makefile docs package scripts toolchain
[irishin@fedora9 kamikaze]$ cat README
This is the buildsystem for the OpenWrt Linux distribution

Please use "make menuconfig" to configure your appreciated
configuration for the toolchain and firmware.

You need to have installed gcc, binutils, patch, bzip2, flex, bison,
make, gettext, pkg-config, unzip, libz-dev and libc headers.

Simply running 'make' will build your firmware.
It will download all sources, build the cross-compile toolchain,
the kernel and all choosen applications.

You can use scripts/flash.sh for remotely updating your embedded system
via tftp.

The OpenWrt system is documented in docs/. You will need a LaTeX distribution
and the tex4ht package to build the documentation. Type make -C docs/ to build it.

Building your own firmware you need to have access to a Linux, BSD or MacOSX system.
Cygwin will not be supported because of the lack of case sensitiveness.

Sunshine!
Your OpenWrt Project
http://openwrt.org


[irishin@fedora9 kamikaze]$

「make menuconfig」すると、なにやらチェックが行われて、そのうちメニューが現れます。

[irishin@fedora9 kamikaze]$ make menuconfig
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'working-gcc'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'zlib'... ok.
Checking 'gawk'... ok.
Checking 'bison'... ok.
Checking 'flex'... ok.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'patch'... ok.
Checking 'perl'... ok.
Checking 'wget'... ok.
Checking 'gnutar'... ok.
Checking 'autoconf'... ok.
Checking 'non-root'... ok.
Collecting target info: done
Collecting package info: done

僕は、FedoraPCにsshで繋いでいるので、テキストベースなメニュー画面。(でもわかり易い。)
まずはTarget Systemの選択。Target Systemを選んでEnterを押します。

出てきた中から,アセロラじゃなかった、"Atheros [2.6]"を選択する。

正しく選択されてますね。
その後「Build the OpenWrt SDK」にチェックを入れて、Exitします。

*** End of OpenWrt configuration.
*** Execute 'make' to build the OpenWrt or try 'make help'.

といわれるので,ここまでこれば、makeでビルド開始。

[irishin@fedora9 kamikaze]$ make
make[2] tools/install
make[3] -C tools install
make[4] -C tools/sed prepare
make[4] -C tools/sed compile
make[4] -C tools/sed install
make[4] -C tools/sstrip prepare
make[4] -C tools/sstrip compile
make[4] -C tools/sstrip install

 (大量に中略)

make[4] -C toolchain/uClibc install
make[4] -C toolchain/gcc install
make[2] target/compile
make[3] -C target compile
make[4] -C target/linux compile
make[5] -C target/linux/atheros-2.6 compile
Build failed. Please re-run make with V=99 to see what's going on
make: *** [world] エラー 1
[irishin@fedora9 kamikaze]$

と、ほっておいたら、エラーになってしまいました。
V=99オプションをつけて実行し、エラー箇所を探ります。

[irishin@fedora9 kamikaze]$ make V=99
make[1]: Entering directory `/home/irishin/openwrt/kamikaze'
make -C tools install
make[2]: Entering directory `/home/irishin/openwrt/kamikaze/tools'
make[2]: `install' is up to date.
make[2]: Leaving directory `/home/irishin/openwrt/kamikaze/tools'
make[1]: Leaving directory `/home/irishin/openwrt/kamikaze'
make[1]: Entering directory `/home/irishin/openwrt/kamikaze'
make -C toolchain install
make[2]: Entering directory `/home/irishin/openwrt/kamikaze/toolchain'
make[2]: `install' is up to date.
make[2]: Leaving directory `/home/irishin/openwrt/kamikaze/toolchain'
make[1]: Leaving directory `/home/irishin/openwrt/kamikaze'
make[1]: Entering directory `/home/irishin/openwrt/kamikaze'
make -C target compile
make[2]: Entering directory `/home/irishin/openwrt/kamikaze/target'
make -C linux compile
make[3]: Entering directory `/home/irishin/openwrt/kamikaze/target/linux'
make -C atheros-2.6 compile
make[4]: Entering directory `/home/irishin/openwrt/kamikaze/target/linux/atheros-2.6'
rm -f /home/irishin/openwrt/kamikaze/build_mips/linux-2.6-atheros/linux-2.6.21.5/vmlinux /home/irishin/openwrt/kamikaze/build_mips/linux-2.6-atheros/linux-2.6.21.5/System.map
make -j1 -C /home/irishin/openwrt/kamikaze/build_mips/linux-2.6-atheros/linux-2.6.21.5 CROSS_COMPILE="mips-linux-uclibc-" ARCH="mips" CONFIG_SHELL="/bin/bash" CC="mips-linux-uclibc-gcc" modules
make[5]: Entering directory `/home/irishin/openwrt/kamikaze/build_mips/linux-2.6-atheros/linux-2.6.21.5'
CHK include/linux/version.h
CHK include/linux/utsrelease.h
HOSTCC scripts/mod/sumversion.o
scripts/mod/sumversion.c: In function 'get_src_version':
scripts/mod/sumversion.c:387: error: 'PATH_MAX' undeclared (first use in this function)
scripts/mod/sumversion.c:387: error: (Each undeclared identifier is reported only once
scripts/mod/sumversion.c:387: error: for each function it appears in.)
scripts/mod/sumversion.c:387: warning: unused variable 'filelist'
make[7]: *** [scripts/mod/sumversion.o] Error 1
make[6]: *** [scripts/mod] Error 2
make[5]: *** [scripts] Error 2
make[5]: Leaving directory `/home/irishin/openwrt/kamikaze/build_mips/linux-2.6-atheros/linux-2.6.21.5'
make[4]: *** [/home/irishin/openwrt/kamikaze/build_mips/linux-2.6-atheros/linux-2.6.21.5/.modules] Error 2
make[4]: Leaving directory `/home/irishin/openwrt/kamikaze/target/linux/atheros-2.6'
make[3]: *** [compile] Error 2
make[3]: Leaving directory `/home/irishin/openwrt/kamikaze/target/linux'
make[2]: *** [linux-compile] Error 2
make[2]: Leaving directory `/home/irishin/openwrt/kamikaze/target'
make[1]: *** [target/compile] Error 2
make[1]: Leaving directory `/home/irishin/openwrt/kamikaze'
make: *** [world] エラー 2
[irishin@fedora9 kamikaze]$

どうやら、sumversion.c内で'PATH_MAX'が未定義であるらしい。
ググッてみると、こちらに解決方法がありました。先人の切り開いた道に感謝。

In sumversion.c add this line at the top of the file:

#include

I had the same problem some weeks ago!

をインクルードしろといってます。

$vi /home/irishin/openwrt/kamikaze/build_mips/linux-2.6-atheros/linux-2.6.21.5/scripts/mod/sumversion.c
で修正して保存。再度、make V=99で走らせると、かなり時間がかかりましたが、今度はエラーなく終了。

これでクロス開発環境が出来てるのか…?