ファームウェア 1.21 に telnetd(5)busybox のコンパイル

LS-CHL

結局自前でコンパイルする。

ソースの入手

http://opensource.buffalo.jp/ls-xhl-120.htmlから busybox-1.7.0.tar.bz2 をダウンロード

ソースの展開

yasunari@brick:~$ cd /usr/local/src/
yasunari@brick:/usr/local/src$ ls -al
total 0
drwxrwsr-x  2 root staff   6 Nov 21  2008 .
drwxrwsr-x 10 root staff 105 Nov 21  2008 ..
yasunari@brick:/usr/local/src$ id
uid=1001(yasunari) gid=1001(yamasita) groups=50(staff),1001(yamasita)
yasunari@brick:/usr/local/src$ mkdir busybox
yasunari@brick:/usr/local/src$ mv /mnt/share/busybox-1.7.0.tar.bz2 .
yasunari@brick:/usr/local/src$ cd busybox/
yasunari@brick:/usr/local/src/busybox$ mv /mnt/share/busybox-1.7.0.tar.bz2 .
yasunari@brick:/usr/local/src/busybox$ ls -l
total 1688
-rw-rw---- 1 yasunari yamasita 1726650 Sep 28 18:46 busybox-1.7.0.tar.bz2
yasunari@brick:/usr/local/src/busybox$ tar jxvf busybox-1.7.0.tar.bz2
tar: bzip2: Cannot exec: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
yasunari@brick:/usr/local/src/busybox$
bzip2 がない。

bzip2 のインストール

yasunari@brick:/usr/local/src/busybox$ su - root
Password:
brick:~# apt-get update
Get:1 http://security.debian.org lenny/updates Release.gpg [835B]
Get:2 http://security.debian.org lenny/updates Release [40.8kB]
Hit http://ftp.jp.debian.org lenny Release.gpg
Ign http://security.debian.org lenny/updates/main Packages/DiffIndex
Hit http://ftp.jp.debian.org lenny Release
Ign http://ftp.jp.debian.org lenny/main Packages/DiffIndex
Ign http://ftp.jp.debian.org lenny/main Sources/DiffIndex
Hit http://ftp.jp.debian.org lenny/main Packages
Hit http://ftp.jp.debian.org lenny/main Sources
Ign http://security.debian.org lenny/updates/main Sources/DiffIndex
Get:3 http://security.debian.org lenny/updates/main Packages [265kB]
Get:4 http://security.debian.org lenny/updates/main Sources [68.2kB]
Fetched 375kB in 4s (77.8kB/s)
Reading package lists... Done
brick:~# apt-get install bzip2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  bzip2-doc
The following NEW packages will be installed:
  bzip2
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 47.7kB of archives.
After this operation, 156kB of additional disk space will be used.
Get:1 http://ftp.jp.debian.org lenny/main bzip2 1.0.5-1 [47.7kB]
Fetched 47.7kB in 0s (226kB/s)
Selecting previously deselected package bzip2.
(Reading database ... 10188 files and directories currently installed.)
Unpacking bzip2 (from .../bzip2_1.0.5-1_armel.deb) ...
Processing triggers for man-db ...
Setting up bzip2 (1.0.5-1) ...
brick:~# exit
logout
yasunari@brick:/usr/local/src/busybox$

ソースの展開(続き)

yasunari@brick:/usr/local/src/busybox$ tar jxvf busybox-1.7.0.tar.bz2
busybox-1.7.0/
busybox-1.7.0/networking/
busybox-1.7.0/networking/libiproute/
busybox-1.7.0/networking/libiproute/iptunnel.c
	:
	:
busybox-1.7.0/Makefile
busybox-1.7.0/LICENSE
busybox-1.7.0/README
busybox-1.7.0/Makefile.help
busybox-1.7.0/TODO
busybox-1.7.0/TODO_config_nommu
busybox-1.7.0/Makefile.flags
busybox-1.7.0/Config.in
yasunari@brick:/usr/local/src/busybox$

README を読む

どうやってコンパイルするんだ?
昔なら、
% make configure
% make
(% make install)
だったが。

README を読む

yasunari@brick:/usr/local/src/busybox$ cd busybox-1.7.0
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ less README
作り方は書いてない。

INSTALL を読む

書いてあった。
% make menuconfig
% make
で良いらしい。
カスタマイズしないなら
% make defconfig
% make
でも。

make defconfig

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make defconfig
-bash: make: command not found
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
開発環境もないんかい

開発環境のインストール

開発環境をインストールする。
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ su - root
Password:
brick:~# apt-get install make gcc libc6-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  cpp cpp-4.3 gcc-4.3 libgmp3c2 libgomp1 libmpfr1ldbl linux-libc-dev
Suggested packages:
  cpp-doc gcc-4.3-locales gcc-multilib manpages-dev autoconf automake1.9
  libtool flex bison gdb gcc-doc libmudflap0-4.3-dev gcc-4.3-doc libgcc1-dbg
  libgomp1-dbg libmudflap0-dbg glibc-doc make-doc
The following NEW packages will be installed:
  cpp cpp-4.3 gcc gcc-4.3 libc6-dev libgmp3c2 libgomp1 libmpfr1ldbl
  linux-libc-dev make
0 upgraded, 10 newly installed, 0 to remove and 2 not upgraded.
Need to get 7600kB of archives.
After this operation, 24.2MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.jp.debian.org lenny/main libgmp3c2 2:4.2.2+dfsg-3 [182kB]
Get:2 http://ftp.jp.debian.org lenny/main libmpfr1ldbl 2.3.1.dfsg.1-2 [340kB]
Get:3 http://ftp.jp.debian.org lenny/main cpp-4.3 4.3.2-1.1 [3026kB]
Get:4 http://ftp.jp.debian.org lenny/main cpp 4:4.3.2-2 [13.9kB]
Get:5 http://ftp.jp.debian.org lenny/main libgomp1 4.3.2-1.1 [13.9kB]
Get:6 http://ftp.jp.debian.org lenny/main gcc-4.3 4.3.2-1.1 [458kB]
Get:7 http://ftp.jp.debian.org lenny/main gcc 4:4.3.2-2 [5024B]
Get:8 http://ftp.jp.debian.org lenny/main linux-libc-dev 2.6.26-19 [747kB]
Get:9 http://ftp.jp.debian.org lenny/main libc6-dev 2.7-18 [2429kB]
Get:10 http://ftp.jp.debian.org lenny/main make 3.81-5 [385kB]
Fetched 7600kB in 6s (1228kB/s)
Selecting previously deselected package libgmp3c2.
(Reading database ... 10216 files and directories currently installed.)
Unpacking libgmp3c2 (from .../libgmp3c2_2%3a4.2.2+dfsg-3_armel.deb) ...
Selecting previously deselected package libmpfr1ldbl.
Unpacking libmpfr1ldbl (from .../libmpfr1ldbl_2.3.1.dfsg.1-2_armel.deb) ...
Selecting previously deselected package cpp-4.3.
Unpacking cpp-4.3 (from .../cpp-4.3_4.3.2-1.1_armel.deb) ...
Selecting previously deselected package cpp.
Unpacking cpp (from .../cpp_4%3a4.3.2-2_armel.deb) ...
Selecting previously deselected package libgomp1.
Unpacking libgomp1 (from .../libgomp1_4.3.2-1.1_armel.deb) ...
Selecting previously deselected package gcc-4.3.
Unpacking gcc-4.3 (from .../gcc-4.3_4.3.2-1.1_armel.deb) ...
Selecting previously deselected package gcc.
Unpacking gcc (from .../gcc_4%3a4.3.2-2_armel.deb) ...
Selecting previously deselected package linux-libc-dev.
Unpacking linux-libc-dev (from .../linux-libc-dev_2.6.26-19_armel.deb) ...
Selecting previously deselected package libc6-dev.
Unpacking libc6-dev (from .../libc6-dev_2.7-18_armel.deb) ...
Selecting previously deselected package make.
Unpacking make (from .../archives/make_3.81-5_armel.deb) ...
Processing triggers for man-db ...
Setting up libgmp3c2 (2:4.2.2+dfsg-3) ...
Setting up libmpfr1ldbl (2.3.1.dfsg.1-2) ...
Setting up cpp-4.3 (4.3.2-1.1) ...
Setting up cpp (4:4.3.2-2) ...
Setting up libgomp1 (4.3.2-1.1) ...
Setting up gcc-4.3 (4.3.2-1.1) ...
Setting up gcc (4:4.3.2-2) ...
Setting up linux-libc-dev (2.6.26-19) ...
Setting up libc6-dev (2.7-18) ...
Setting up make (3.81-5) ...
brick:~# exit
logout
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$

make defconfig 再

asunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/split-include
  HOSTCC  scripts/basic/docproc
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/kxgettext.o
  HOSTCC  scripts/kconfig/mconf.o
  SHIPPED scripts/kconfig/zconf.tab.c
	:
	:
envdir (ENVDIR) [Y/n/?] y
softlimit (SOFTLIMIT) [Y/n/?] y
*
* ipsvd utilities
*
tcpsvd (TCPSVD) [Y/n/?] y
udpsvd (UDPSVD) [Y/n/?] y
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$

make

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make
  SPLIT   include/autoconf.h -> include/config/*
  GEN     include/bbconfigopts.h
  HOSTCC  applets/usage
  GEN     include/usage_compressed.h
  CC      applets/applets.o
  LD      applets/built-in.o
  LD      archival/built-in.o
  CC      archival/ar.o
  CC      archival/bbunzip.o
  CC      archival/cpio.o
	:
	:
  AR      init/lib.a
  LD      ipsvd/built-in.o
  CC      ipsvd/ipsvd_perhost.o
  CC      ipsvd/tcpudp.o
In file included from /usr/include/linux/netfilter_ipv4.h:8,
                 from ipsvd/tcpudp.c:33:
/usr/include/linux/netfilter.h:44: error: field 'in' has incomplete type
/usr/include/linux/netfilter.h:45: error: field 'in6' has incomplete type
ipsvd/tcpudp.c: In function 'tcpudpsvd_main':
ipsvd/tcpudp.c:314: warning: ignoring return value of 'write', declared with attribute warn_unused_result
make[1]: *** [ipsvd/tcpudp.o] Error 1
make: *** [ipsvd] Error 2
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$

netfilter.h を見る。
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ less /usr/include/linux/netfilter.h
#ifndef __LINUX_NETFILTER_H
#define __LINUX_NETFILTER_H

#include 
	:
	:
union nf_inet_addr {
        __u32           all[4];
        __be32          ip;
        __be32          ip6[4];
        struct in_addr  in;
        struct in6_addr in6;
};

#endif /*__LINUX_NETFILTER_H*/
(END)
ないのは、in_addr と in6_addr

こんなの、in.h じゃないの?

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ less /usr/include/netinet/in.h
	:
	:
typedef uint32_t in_addr_t;
struct in_addr
  {
    in_addr_t s_addr;
  };
	:
	:
struct in6_addr
  {
    union
      {
        uint8_t u6_addr8[16];
        uint16_t u6_addr16[8];
        uint32_t u6_addr32[4];
      } in6_u;
#define s6_addr                 in6_u.u6_addr8
#define s6_addr16               in6_u.u6_addr16
#define s6_addr32               in6_u.u6_addr32
  };
	:
	:

パッチをあてる

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ cd ipsvd/
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/ipsvd$ mv tcpudp.c{,.orig}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/ipsvd$ cp tcpudp.c{.orig,}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/ipsvd$ vi tcpudp.c
	:
	:
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/ipsvd$ !cp:s/cp/diff -c/
diff -c tcpudp.c{.orig,}
*** tcpudp.c.orig       Fri Aug 24 19:49:55 2007
--- tcpudp.c    Mon Sep 28 20:29:17 2009
***************
*** 30,35 ****
--- 30,36 ----
   */

  #include 
+ #include        /* yasunari @ yamasita.jp */
  #include  /* wants  */

  #include "libbb.h"
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/ipsvd$

再コンパイル

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/ipsvd$ cd ..
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make
  CC      ipsvd/tcpudp.o
ipsvd/tcpudp.c: In function 'tcpudpsvd_main':
ipsvd/tcpudp.c:315: warning: ignoring return value of 'write', declared with attribute warn_unused_result
  AR      ipsvd/lib.a
  LD      libbb/built-in.o
  CC      libbb/ask_confirmation.o
	:
	:
  AR      util-linux/lib.a
  LINK    busybox_unstripped
Trying libraries: crypt m
Library crypt is needed
Library m is needed
Final link with: crypt m
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
できたみたい。

確認

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ ldd busybox
        libcrypt.so.1 => /lib/libcrypt.so.1 (0x40026000)
        libm.so.6 => /lib/libm.so.6 (0x4005f000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4010c000)
        libc.so.6 => /lib/libc.so.6 (0x40120000)
        /lib/ld-linux.so.3 (0x40000000)
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
あかん。

static 版を作る

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ mv .config{,.orig}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ cp .config{.orig,}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ vi .config
	:
	:
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ !cp:s/cp/diff -c/
diff -c .config{.orig,}
*** .config.orig        Mon Sep 28 19:04:10 2009
--- .config     Mon Sep 28 20:40:54 2009
***************
*** 38,44 ****
  #
  # Build Options
  #
! # CONFIG_STATIC is not set
  # CONFIG_BUILD_LIBBUSYBOX is not set
  # CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
  # CONFIG_FEATURE_SHARED_BUSYBOX is not set
--- 38,44 ----
  #
  # Build Options
  #
! CONFIG_STATIC=y
  # CONFIG_BUILD_LIBBUSYBOX is not set
  # CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
  # CONFIG_FEATURE_SHARED_BUSYBOX is not set
良い子は真似をしてはいけません(笑

再 build

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make clean
  CLEAN   applets
  CLEAN   .tmp_versions
  CLEAN   busybox busybox_ld.err busybox_ld.out busybox_unstripped busybox_unstripped.map .kernelrelease
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make menuconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/split-include
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make
  CC      applets/applets.o
applets/applets.c:20:2: warning: #warning Static linking against glibc produces buggy executables
applets/applets.c:21:2: warning: #warning (glibc does not cope well with ld --gc-sections).
applets/applets.c:22:2: warning: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
applets/applets.c:23:2: warning: #warning Note that glibc is unsuitable for static linking anyway.
applets/applets.c:24:2: warning: #warning If you still want to do it, remove -Wl,--gc-sections
applets/applets.c:25:2: warning: #warning from top-level Makefile and remove this warning.
applets/applets.c:26:2: error: #error Aborting compilation.
make[1]: *** [applets/applets.o] Error 1
make: *** [applets] Error 2
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
あかんか。

applets/applets.c の確認

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ less applets/applets.c
	:
	:
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
#warning Static linking against glibc produces buggy executables
#warning (glibc does not cope well with ld --gc-sections).
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from top-level Makefile and remove this warning.
#error Aborting compilation.
#endif

-Wl,--gc-sections を Makefile から削除すれば良い?

Makefile の修正

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ mv Makefile{,.orig}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ cp Makefile{.orig,}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ vi Makefile
	:
	:
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ !cp:s/cp/diff -u/
diff -u Makefile{.orig,}
--- Makefile.orig       2007-08-24 19:50:32.000000000 +0900
+++ Makefile    2009-09-28 20:49:08.599021653 +0900
@@ -570,7 +570,7 @@
 quiet_cmd_busybox__ ?= LINK    $@
       cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
       -o $@ -Wl,-Map -Wl,$@.map \
-      -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
+      -Wl,--warn-common -Wl,--sort-common \
       -Wl,--start-group $(busybox-all) -Wl,--end-group \
       $(LDLIBS)

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$

make

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make
  CC      applets/applets.o
applets/applets.c:20:2: warning: #warning Static linking against glibc produces buggy executables
applets/applets.c:21:2: warning: #warning (glibc does not cope well with ld --gc-sections).
applets/applets.c:22:2: warning: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
applets/applets.c:23:2: warning: #warning Note that glibc is unsuitable for static linking anyway.
applets/applets.c:24:2: warning: #warning If you still want to do it, remove -Wl,--gc-sections
applets/applets.c:25:2: warning: #warning from top-level Makefile and remove this warning.
applets/applets.c:26:2: error: #error Aborting compilation.
make[1]: *** [applets/applets.o] Error 1
make: *** [applets] Error 2
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
あかんかぁ。。。

LS-CHL
バッファローダイレクト
楽天市場
Amazon


ファームウェア 1.21 に telnetd(4)
ハックの記録
LinkStation/玄箱 をハックしよう

ファームウェア 1.21 に telnetd(6)busybox のコンパイルのやり直し

Copyright (C) 2003-2009 Yasunari Yamashita. All Rights Reserved.
yasunari @ yamasita.jp 山下康成@京都府向日市