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

LS-CHL

最小限のオプションでコンパイルする。

make menuconfig

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ make menuconfig
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:31:20: error: curses.h: No such file or directory
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:128: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'use_colors'
scripts/kconfig/lxdialog/dialog.h:129: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'use_shadow'
scripts/kconfig/lxdialog/dialog.h:131: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'attributes'
scripts/kconfig/lxdialog/dialog.h:143: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:146: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:147: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:148: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:149: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:151: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:31: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:59: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:95: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c: In function 'dialog_checklist':
scripts/kconfig/lxdialog/checklist.c:117: error: 'WINDOW' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:117: error: (Each undeclared identifier is reported only once
scripts/kconfig/lxdialog/checklist.c:117: error: for each function it appears in.)
scripts/kconfig/lxdialog/checklist.c:117: error: 'dialog' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:117: error: 'list' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:117: warning: left-hand operand of comma expression has no effect
scripts/kconfig/lxdialog/checklist.c:121: warning: implicit declaration of function 'endwin'
scripts/kconfig/lxdialog/checklist.c:122: warning: implicit declaration of function 'fprintf'
scripts/kconfig/lxdialog/checklist.c:122: warning: incompatible implicit declaration of built-in function 'fprintf'
scripts/kconfig/lxdialog/checklist.c:122: error: 'stderr' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:140: error: 'COLS' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:141: error: 'LINES' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:143: warning: implicit declaration of function 'draw_shadow'
scripts/kconfig/lxdialog/checklist.c:143: error: 'stdscr' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:145: warning: implicit declaration of function 'newwin'
scripts/kconfig/lxdialog/checklist.c:146: warning: implicit declaration of function 'keypad'
scripts/kconfig/lxdialog/checklist.c:146: error: 'TRUE' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:148: warning: implicit declaration of function 'draw_box'
scripts/kconfig/lxdialog/checklist.c:148: error: 'attributes' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:149: warning: implicit declaration of function 'wattrset'
scripts/kconfig/lxdialog/checklist.c:150: warning: implicit declaration of function 'mvwaddch'
scripts/kconfig/lxdialog/checklist.c:152: warning: implicit declaration of function 'waddch'
scripts/kconfig/lxdialog/checklist.c:156: warning: implicit declaration of function 'print_title'
scripts/kconfig/lxdialog/checklist.c:159: warning: implicit declaration of function 'print_autowrap'
scripts/kconfig/lxdialog/checklist.c:166: warning: implicit declaration of function 'subwin'
scripts/kconfig/lxdialog/checklist.c:190: warning: implicit declaration of function 'print_item'
scripts/kconfig/lxdialog/checklist.c:194: warning: implicit declaration of function 'print_arrows'
scripts/kconfig/lxdialog/checklist.c:197: warning: implicit declaration of function 'print_buttons'
scripts/kconfig/lxdialog/checklist.c:199: warning: implicit declaration of function 'wnoutrefresh'
scripts/kconfig/lxdialog/checklist.c:201: warning: implicit declaration of function 'doupdate'
scripts/kconfig/lxdialog/checklist.c:204: warning: implicit declaration of function 'wgetch'
scripts/kconfig/lxdialog/checklist.c:211: error: 'KEY_UP' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:211: error: 'KEY_DOWN' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:221: error: 'FALSE' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:222: warning: implicit declaration of function 'scrollok'
scripts/kconfig/lxdialog/checklist.c:223: warning: implicit declaration of function 'wscrl'
scripts/kconfig/lxdialog/checklist.c:232: warning: implicit declaration of function 'wrefresh'
scripts/kconfig/lxdialog/checklist.c:282: warning: incompatible implicit declaration of built-in function 'fprintf'
scripts/kconfig/lxdialog/checklist.c:283: warning: implicit declaration of function 'delwin'
scripts/kconfig/lxdialog/checklist.c:287: error: 'KEY_LEFT' undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:288: error: 'KEY_RIGHT' undeclared (first use in this function)
make[2]: *** [scripts/kconfig/lxdialog/checklist.o] Error 1
make[1]: *** [menuconfig] Error 2
make: *** [menuconfig] Error 2
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
今度は curses か。

curses のインストール

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ apt-cache search ncurses
abook - text-based ncurses address book application
audtty - ncurses based frontend to audacious
aumix - Simple text-based mixer control program
aumix-gtk - Simple mixer control program with GUI and text interfaces
avida-viewer - ncurses viewer for avida
aylet - ncurses-based player for Spectrum '.ay' music files
bochs-term - Terminal (ncurses-based) plugin for Bochs
btscanner - ncurses-based scanner for Bluetooth devices
cabber - Easy and basic jabber console client
cdw - Tool for burning CD's - console version
centerim-utf8 - A text-mode multi-protocol instant messenger client
clex - command line file manager which uses the ncurses library
cmus - lightweight ncurses audio player
cwcp - Ncurses frontend to unixcw
dares - rescue files from damaged CDs and DVDs (ncurses-interface)
dav-text - A minimalist ncurses-based text editor
ekg - console Gadu Gadu client for UNIX systems
ettercap-gtk - Multipurpose sniffer/interceptor/logger for switched LAN
fbb - Packet radio mailbox and utilities
gom - Command line and interactive ncurses-based OSS audio mixer
gopher - Distributed Hypertext Client, Gopher protocol
gtypist - A simple ncurses touch typing tutor
herrie - Minimalistic audio player built upon Ncurses
hexcurse - A ncurses-based hex editor with many features
hnb - hierarchical notebook
imediff2 - interactive full screen 2-way merge tool
iptraf - Interactive Colorful IP LAN Monitor
irmp3-ncurses - irmp3 control frontend
juke - A curses-based jukebox program
libcunit1-ncurses - Unit Testing Library for C (ncurses)
libcunit1-ncurses-dev - Unit Testing Library for C (ncurses) -- development files
libcurses-ocaml - OCaml bindings for the ncurses library
libcurses-ocaml-dev - OCaml bindings for the ncurses library
libcurses-perl - Curses interface for Perl
libcurses-widgets-perl - Curses widget interface for Perl
libggi-target-terminfo - General Graphics Interface TermInfo display target
libkaya-ncurses-dev - Ncurses binding for kaya
libkaya-ncursesw-dev - Ncurses binding for kaya
libncurses-gst - Ncurses bindings for GNU Smalltalk
libncurses-ruby - ruby Extension for the ncurses C library
libncurses-ruby1.8 - ruby Extension for the ncurses C library
libncurses-ruby1.9 - ruby Extension for the ncurses C library
libncurses5 - shared libraries for terminal handling
libncurses5-dbg - debugging/profiling libraries for ncurses
libncurses5-dev - developer's libraries and docs for ncurses
libncursesw5 - shared libraries for terminal handling (wide character support)
libncursesw5-dbg - debugging/profiling libraries for ncurses
libncursesw5-dev - developer's libraries for ncursesw
libruby-extras - a bundle of additional libraries for Ruby
libruby1.8-extras - a bundle of additional libraries for Ruby 1.8
moc - ncurses based console audio player
moc-ffmpeg-plugin - ncurses based console audio player - ffmpeg plugin
mtr - Full screen ncurses and X11 traceroute tool
mtr-tiny - Full screen ncurses traceroute tool
multitail - view multiple logfiles windowed on console
mybashburn - Burn data and create songs with interactive dialog box
nast - packet sniffer and lan analyzer
ncdu - ncurses disk usage viewer
ncftp - A user-friendly and well-featured FTP client
ncurses-base - basic terminal type definitions
ncurses-bin - terminal-related programs and man pages
ncurses-hexedit - Edit files/disks in hex, ASCII and EBCDIC
ncurses-term - additional terminal type definitions
ninvaders - A space invaders-like game using ncurses
nrss - A ncurses-based RSS reader
pacman4console - a console based pacman game
php5-cli - command-line interpreter for the php5 scripting language
pinfo - An alternative info-file viewer
pork - Console-based AOL Instant Messenger & IRC client
procps - /proc file system utilities
psk31lx - Soundcard-based ncurses program for operating PSK31
radio - ncurses-based radio application
rexima - a simple ncurses/command-line mixer
rolo - text-based (vCard) contact management software
rtorrent - ncurses BitTorrent client based on LibTorrent
siggen - Waveform generation tools
signing-party - Various OpenPGP related tools
squidview - monitors and analyses squid access.log files
tack - terminfo action checker
tack-dbg - terminfo action checker (debug)
tcd - Portable CD player with an ncurses interface
tig - ncurses-based Git repository browser
tlf - Console mode purpose CW keyer, logging- and contest program
tpp - text presentation program
tudu - Command line hierarchical ToDo list
vdr-plugin-examples - Plugins for vdr to show some possible features
vfu - A versatile text-based filemanager
vifm - a ncurses based file manager with vi like keybindings
whowatch - Real-time user logins monitoring tool
worklog - Keep Track of Time worked on Projects
wyrd - text-based calendar application
whiptail - Displays user-friendly dialog boxes from shell scripts
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
libncurses5-dev あたりか?
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ su - root
Password:
brick:~# apt-get install libncurses5-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  libncurses5-dev
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 1546kB of archives.
After this operation, 6631kB of additional disk space will be used.
Get:1 http://ftp.jp.debian.org lenny/main libncurses5-dev 5.7+20081213-1 [1546kB]
Fetched 1546kB in 2s (646kB/s)
Selecting previously deselected package libncurses5-dev.
(Reading database ... 11412 files and directories currently installed.)
Unpacking libncurses5-dev (from .../libncurses5-dev_5.7+20081213-1_armel.deb) ...
Processing triggers for man-db ...
Setting up libncurses5-dev (5.7+20081213-1) ...
brick:~# exit
logout
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$

もう一回 manuconfig

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ !make
make menuconfig
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/lxdialog.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
	:
	:
無事 Busybox Configuration が起動してきた。
telnetd 以外は徹底的に OFF にする。
*** End of busybox configuration.
*** Execute 'make' to build busybox or try 'make help'.

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
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$
やっぱり static link できない???

もう一度 make menuconfig

static link でなくする

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
  AR      archival/lib.a
  LD      archival/libunarchive/built-in.o
	:
	:
  LD      util-linux/built-in.o
  AR      util-linux/lib.a
  LINK    busybox_unstripped
Trying libraries: crypt m
Library crypt is not needed
Library m is needed
Library m is needed
Final link with: m
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$

必要なライブラリ

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ ldd ./busybox
        libm.so.6 => /lib/libm.so.6 (0x40026000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x400d3000)
        libc.so.6 => /lib/libc.so.6 (0x400e7000)
        /lib/ld-linux.so.3 (0x40000000)
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ 
標準ファームにあるか確認する。
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ su - root
Password:
brick:~# mkdir /tmp/root
mkdir: cannot create directory `/tmp/root': File exists
brick:~# mount /dev/sdb2  /tmp/root
brick:~# ls /tmp/root/lib/libm.*
/tmp/root/lib/libm.so.6
brick:~# ls /tmp/root/lib/libgcc*
ls: cannot access /tmp/root/lib/libgcc*: No such file or directory
brick:~# ls /tmp/root/lib/libc.so*
/tmp/root/lib/libc.so.6
brick:~# ls /tmp/root/lib/ld-linux*
/tmp/root/lib/ld-linux.so.3
brick:~# exit
logout
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
libgcc がない。

無理やり static link

もういい加減いや。無理やり static link にする。

applets/applets.c の変更

yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ cd applets/
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/applets$ mv applets.c{,.orig}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/applets$ cp applets.c{.orig,}
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/applets$ vi applets.c
	:
	:
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0/applets$ !cp:s/cp/diff -c/
diff -c applets.c{.orig,}
*** applets.c.orig      Fri Aug 24 19:50:02 2007
--- applets.c   Tue Sep 29 20:21:59 2009
***************
*** 23,29 ****
  #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


--- 23,29 ----
  #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


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

make menuconfig

static link にする
    [*] Build BusyBox as a static binary (no shared libs)

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
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.
  LD      applets/built-in.o
  LINK    busybox_unstripped
Trying libraries: crypt m
Library crypt is not needed
Library m is needed
Library m is needed
Final link with: m
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ ldd busybox
        not a dynamic executable
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$
できた。

テスト

inetd を終了
yasunari@brick:/usr/local/src/busybox/busybox-1.7.0$ su - root
Password:
brick:~# kill `cat /var/run/inetd.pid `
brick:~# /usr/local/src/busybox/busybox-1.7.0/busybox telnetd
brick:~# ps -aux
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2   1968   716 ?        Ss   18:45   0:04 init [2]
root         2  0.0  0.0      0     0 ?        S<   18:45   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        SN   18:45   0:00 [ksoftirqd/0]
	:
	:
root      4736  0.1  0.4   2644  1076 pts/0    S    20:27   0:00 su - root
root      4737  0.3  0.6   2948  1572 pts/0    S    20:27   0:00 -su
root      4743  0.0  0.0    868    84 ?        Ss   20:27   0:00 /usr/local/src/busybox/busybox-1.7.0/busybox telnetd
root      4744  0.0  0.3   2476   948 pts/0    R+   20:27   0:00 ps -aux
brick:~#
別マシンから telnet する
yasunari@sil:~$ telnet brick
Trying 192.168.2.49...
Connected to brick.
Escape character is '^]'.

Debian GNU/Linux 5.0
brick:/#
これはやりすぎ(驚
ログイン名もパスワードも聞いてこない。

標準ファームに納める

brick:~# cp /usr/local/src/busybox/busybox-1.7.0/busybox /tmp/root/usr/local/sbin
brick:~# ln -s /usr/local/sbin/busybox /tmp/root/usr/local/sbin/telnetd
brick:~# vi /tmp/root/etc/init.d/rcS
	:
	:
brick:~# tail !$
tail /tmp/root/etc/init.d/rcS
exec_sh bootcomplete.sh

echo "** step final(after bootcomplete) **"
for cmd in hdd_late_check.sh check_initialization.sh usb_late_check.sh
do
        exec_sh ${cmd}
done

/usr/local/bin/share_delete.sh &
/usr/local/sbin/telnetd
brick:~# ls -l /tmp/root/usr/local/sbin/telnetd
lrwxrwxrwx 1 root root 23 Sep 29 20:31 /tmp/root/usr/local/sbin/telnetd -> /usr/local/sbin/busybox
brick:~# ls -l /tmp/root/usr/local/sbin/busybox
-rwxr-xr-x 1 root root 646596 Sep 29 20:31 /tmp/root/usr/local/sbin/busybox
brick:~#

標準ファームで起動

コンパイルマシンの LS-XHL をシャットダウン、コンセントも抜く。
標準ファームの HDD を LS-CHL に戻して、起動

telnet する

yasunari@sil:~$ telnet chl
Trying 192.168.2.52...
Connected to chl.
Escape character is '^]'.


うんともすんとも
でも connection refused といわれないだけましか。

ログを見る

LS-CHL をシャットダウン、コンセントも抜く。
標準ファームの HDD を LS-XHL に USB で接続
brick:~# mkdir /tmp/root/
mkdir: cannot create directory `/tmp/root/': File exists
brick:~# mount /dev/sdb2 /tmp/root
brick:~# cd /tmp/root/var/log/
brick:/tmp/root/var/log# ls
apache           cron.3.gz                  linkstation.log.4.gz  messages.5.gz
backup.log       cron.4.gz                  linkstation.log.5.gz  messages.6.gz
backup.log.1.gz  file.smb                   linkstation.log.6.gz  samba
backup.log.2.gz  hotplug                    log.nmbd              wtmp
backup.log.3.gz  lighttpd.webui.access.log  log.smbd              wtmp.1.gz
backup.log.4.gz  lighttpd.webui.error.log   messages              wtmp.2.gz
cores            linkstation.log            messages.1.gz         wtmp.3.gz
cron             linkstation.log.1.gz       messages.2.gz
cron.1.gz        linkstation.log.2.gz       messages.3.gz
cron.2.gz        linkstation.log.3.gz       messages.4.gz
brick:/tmp/root/var/log# less messages
何も手がかりなし

もういい加減、別ファームの telnetd に手を出そうかなぁ.。。



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


ファームウェア 1.21 に telnetd(5)busybox のコンパイル
ハックの記録
LinkStation/玄箱 をハックしよう

ファームウェア 1.21 に telnetd(7)何で動かないの?

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