仙石浩明の日記

2007年12月17日

La Fonera+ へ ssh でログインする (1) flash への書込み hatena_b

FON ソーシャル・ルータ La Fonera+ へログインするのは、 La Fonera のときほど容易ではない。 La Fonera はシリアル・コンソールでシェル (/bin/ash) を使えたので、 dropbear (ssh サーバ) を立ち上げるだけで、 ssh でログインできるようになる。 しかし La Fonera+ はシリアル・コンソールをつなげても シェルが動いていないので、 Linux 起動後はコンソール出力を眺めることくらいしかできない。

ログインできないようにしてあると、 余計にログインしたくなるのは人の常であるようで、 すでに多くの方が挑戦し 成功しているようだ。 基本的には、 ファームウェアを書き換えてシリアル・コンソールを 有効にしてしまえばいいだけのことであるが、 いかに La Fonera+ の機能そのままに、 シリアル・コンソールだけ有効にするかが肝であろう。

というわけで、 先人が作ったファームウェアをそのまま使うのでは面白くないので、 FON が公開しているソース を元に、 改変ファームウェアを作ってみた。 作り方を書いていると長くなるので、 次回以降で説明するとして、 まずは作った改変ファームウェアを La Fonera+ に書込むところから。

RedBoot> load -r -b 0x80040400 image
Using default protocol (TFTP)
Raw file loaded 0x80040400-0x8028062f, assumed entry at 0x80040400
RedBoot> fis create image
... Erase from 0xa8040000-0xa8280230: .....................................
... Program from 0x80040400-0x80280630 at 0xa8040000: .....................................
... Erase from 0xa87e0000-0xa87f0000: .
... Program from 0x80ff0000-0x81000000 at 0xa87e0000: .

ここで TFTP サーバから読み込んでフラッシュへ書込んだ image というファイルが、 今回作成した改変ファームウェア。 これは、 kernel と root イメージをつなげて、 先頭にヘッダをつけた、 次のようなフォーマットのファイル。

┌───────┬───────┬───────┬───<<───┬───<<───┐
│rootイメージの│チェック・サム│rootイメージの│lzma 圧縮した │root イメージ │
│サイズ   4byte│(CRC32)  4byte│位置     4byte│カーネル      │squashfs      │
└───────┴───────┴───────┴───>>───┴───>>───┘

FON のソース に含まれる (fon/target/linux/fonera-2.6/image/fonimage.pl)、 fonimage.pl コマンドを 以下のように実行すると、 この image ファイルを作成できる。

fonimage.pl  image 《lzma圧縮したカーネルイメージ》 《squashfsなrootイメージ》

前回書いたように、 La Fonera+ は起動すると「loader」を起動する。 この loader プログラムが、 上記 image ファイルを読み込んで、 カーネルと root イメージに分解し、 カーネルを lzma 展開した上で起動する。

試しに起動してみる。 printk サポートを有効にしてある (CONFIG_PRINTK=y) ので、 Linux 起動ログを見ることができる。

RedBoot> fis load loader
RedBoot> go
Failsafe loader v0.2

Looking for board config data... found at offset 0xa87f0000
Reset button GPIO: 6
Reading flash from 0xa8040000 to 0xa8280224... done.
Verifying CRC... OK - 0x9ffc079a
Uncompressing Linux... Ok, booting the kernel.
Linux version 2.6.19.2 (sengoku@senri.gcd.org) (gcc version 4.1.2) #8 Sun Dec 16 16:52:31 JST 2007
CPU revision is: 00019064
Determined physical RAM map:
 memory: 01000000 @ 00000000 (usable)
Initrd not found or empty - disabling initrd
Built 1 zonelists.  Total pages: 4064
Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2 init=/etc/preinit
        ... 中略 ...
switching to jffs2
mini_fo: using base directory: /
mini_fo: using storage directory: /jffs
init started:  BusyBox v1.4.1 (2007-12-13 15:41:27 JST) multi-call binary

Please press Enter to activate this console. 
eth0.0: dev_set_promiscuity(master, 1)
device eth0 entered promiscuous mode
device eth0.0 entered promiscuous mode
: udhcpc (v1.4.1) started

        ... 中略 ...

: 21 2 * * * /bin/thinclient cron

: 13 5 * * * ntpclient -s -h ntp-1.cso.uiuc.edu

: fonsmcd successfully started

La Fonera と同様に mini_fo を使って、 squashfs の上に jffs2 を 重ねることによって、 / (root ファイル・システム) を書込み可能にしている。

La Fonera と同様、 cron から /bin/thinclient を実行しているが、 実はこれは機能していない。 つまり、 /bin/thinclient cron を実行してみると、 以下のように Usage が表示されてしまう。

root@OpenWrt:/# /bin/thinclient cron
Usage /bin/thinclient (dummy|start|config|upgrade) [voucher_file]

La Fonera の thinclient が果たしていた役割は、 La Fonera+ では /usr/sbin/fonsmcd が担っているようだ。 しかしながら fonsmcd のソースは公開されていない (少なくとも前述したソースには含まれていない) ので、 詳細は不明。

シリアル・コンソールで「Enter」を入力すれば、 シェルを使うことができるようにしてある。 さらに、ネットワーク経由で ssh ログインすることもできる:

% rsh -l root 172.16.191.252


BusyBox v1.4.1 (2007-12-13 15:41:27 JST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

  ______                                           __      
 /\  ___\                                         /\ \     
 \ \ \__/  __     ___      __   _ __    __        \_\ \___ 
  \ \  _\/ __`\ /' _ `\  /'__`\/\`'__\/'__`\     /\___  __\
   \ \ \/\ \L\ \/\ \/\ \/\  __/\ \ \//\ \L\.\_   \/__/\ \_/
    \ \_\ \____/\ \_\ \_\ \____\\ \_\\ \__/.\_\      \ \_\ 
     \/_/\/___/  \/_/\/_/\/____/ \/_/ \/__/\/_/       \/_/ 

--------------  Fonera 1.5 Firmware (v1.1.0.2) -----------------

               * Based on OpenWrt - http://openwrt.org
             * Powered by FON - http://www.fon.com
      -----------------------------------------------------
root@OpenWrt:/# df
Filesystem           1k-blocks      Used Available Use% Mounted on
tmpfs                      512         0       512   0% /dev
/dev/mtdblock4            3840       284      3556   7% /jffs
/jffs                     1664      1664         0 100% /
root@OpenWrt:/# free
              total         used         free       shared      buffers
  Mem:        13612        12680          932            0         1064
 Swap:            0            0            0
Total:        13612        12680          932
root@OpenWrt:/# ifconfig eth0.1
eth0.1    Link encap:Ethernet  HWaddr 00:18:84:XX:XX:XX
          inet addr:172.16.191.252  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1480  Metric:1
          RX packets:1367 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1212 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:129328 (126.2 KiB)  TX bytes:184394 (180.0 KiB)

root@OpenWrt:/# 

La Fonera+ には ether ケーブルのソケットが二つついているが、 カーネルから見ると WAN 側ソケットは eth0.1 つまり VLAN デバイスとして見える。 LAN 側ソケットは eth0.0 である。

(つづく)

Filed under: La Fonera — hiroaki_sengoku @ 07:59

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment