PLANEX MZK-W300NH2

2013年6月 8日 (土)

◆ OpenWrt の trunk 版(r36853) を Planex MZK-W300NH2 用にビルドしてみました(対策編)

前回の記事の続きです。

※ 本記事の対象は、OpenWrt のリビジョン r36853 のソースコードです。 BARRIER BREAKER リリースに向けた 開発途上である trunk ブランチなのでこれからどんどん変わって適用できなくなる可能性があります。

※ trunk 版は開発途中です。何がおきるかわかりません。MZK-W300NH2 にシリアル接続ができることは必須と考えたほうがよいでしょう。前回も今回もシリアル接続できることを前提として書いています。シリアル接続については以前書いた記事「PLANEX MZK-W300NH2 とのシリアル接続とブートログ」などを参考にしてください。

※ビルド環境の構築、ファームの入れ替え方などは、カテゴリ「openwrt」の過去記事を参考にしてください。

 

firmware パーティションから自動で kernel と rootfs を切り出してくれる処理が mtdpart.c にあるのですが、kernel の認識に失敗しています。これが、OpenWrt のブートでカーネルパニックを起こしている理由です。
認識できない理由は、れ@さんがコメントしてくれたように、MZK-W300NH2 では Edimax ヘッダを追加しているのに、そのことへの考慮がされていないことです。
そこで、Edimax ヘッダ分をずらして読み出す処理を追加します。
以下に、mtdpart.c へのパッチファイルを用意しました。
http://ranosgrant.cocolog-nifty.com/openwrt-trunk-r36853/0212-mtd_fix_edimax_header.patch

*** a/drivers/mtd/mtdpart.c	2013-06-06 05:26:55.646489841 +0900
--- b/drivers/mtd/mtdpart.c	2013-06-06 06:02:18.427481167 +0900
***************
*** 899,904 ****
--- 899,912 ----
  	};
  
  	split_partitions[0].size = find_uimage_size(mtd, part->offset);
+         if (!split_partitions[0].size) {
+         	unsigned long uimage_size;
+ 
+ 		uimage_size = find_uimage_size(mtd, part->offset + 0x14);
+ 		if (uimage_size) {
+ 			split_partitions[0].size = uimage_size + 0x14;
+ 		}
+         }
  	if (!split_partitions[0].size) {
  		split_partitions[0].size = find_squashfs_offset(mtd, part->offset);
  		if (!split_partitions[0].size) {

■ビルド方法
以下、作業ディレクトリが ~/openwrt/trunk と仮定して書いています。
ビルドに必要なパッケージのインストールなど OS 側の準備が出来ているという前提です。

1) 今回の対策パッチファイルを置きます。
cd ~/openwrt/trunk/target/linux/ramips/patches-3.8
wget http://ranosgrant.cocolog-nifty.com/openwrt-trunk-r36853/0212-mtd_fix_edimax_header.patch

2) すでにビルドをしている場合は、コンパイル済のオブジェクトを削除します
cd ~/openwrt/trunk
make clean

3) ビルドしてください
cd ~/openwrt/trunk

make menuconfig (未実施の場合)
  以下を指定します:
  [Target System]:  Ralink RT288x/RT3xxx
  [Subtarget]:      RT3x5x/RT5350 based boards

make            (「make V=99 2>&1 | tee build.log」がオススメ)

ファームウェアは、~/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin にできます。

■ブート

ファーム入れ替え後の一度目のログインで以下のコマンドを実施してゴミ掃除しておきます。
  mtd -r erase rootfs_data

オプション -r を付けているのでコマンドの終了時に自動でリブートされます。
以下、リブート時のブートログです。(OpenWrt のバナーが出る前にリターンキーを押しています)
赤字のところで kernel と rootfs が認識できているメッセージが出ています。バウンダリがどうこうといわれていますが readonly で使うところなので問題ありません。

U-Boot 1.1.3 (Nov 25 2008 - 16:46:30)

Board: Ralink APSoC DRAM:  16 MB
relocate_code Pointer at: 80fa8000
****************************
Init GPIO Pin****************************
flash_protect ON: from 0xBFC00000 to 0xBFC26213
protect on 0
protect on 1
protect on 2
protect on 3
protect on 4
protect on 5
protect on 6
protect on 7
protect on 8
protect on 9
flash_protect ON: from 0xBFC30000 to 0xBFC3FFFF
protect on 10
============================================
Ralink UBoot Version: 3.1
--------------------------------------------
ASIC 3052_MP1 (MAC to GigaMAC Mode)
DRAM COMPONENT: 64Mbits
DRAM BUS: 32BIT
Total memory: 16 MBytes
Flash: 4 MBytes
Date:Nov 25 2008  Time:16:46:30
============================================
icache: sets:256, ways:4, linesz:32 ,total:32768
dcache: sets:128, ways:4, linesz:32 ,total:16384

 ##### The CPU freq = 384 MHZ ####

 SDRAM bus set to 32 bit
 SDRAM size =16 Mbytes

Please choose the operation:
   0: Load ucos code to SDRAM via TFTP Client.
   1: Load system code to SDRAM via TFTP.
   2: Load system code then write to Flash via TFTP.
   3: Boot system code via Flash (default).
   4: Entr boot command line interface.
   9: Load Boot Loader code then write to Flash via TFTP.
 0

3: System Boot system code via Flash.
## Booting image at bfc50000 ...
Bad Magic Number,43535953
   Image Name:   MIPS OpenWrt Linux-3.8.13
   Created:      2013-06-07  14:29:37 UTC

 System Control Status = 0x01040000
   Image Type:   MIPS Linux Kernel Image (lzma compressed)
   Data Size:    954429 Bytes = 932.1 kB
   Load Address: 80000000
   Entry Point:  80000000
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 80000000) ...
## Giving linux memsize in MB, 16

Starting kernel ...

[    0.000000] Linux version 3.8.13 (lubun@lubun) (gcc version 4.6.4 (OpenWrt/Linaro GCC 4.6-2012.12 r36852) ) #1 Fri Jun 7 23:27:40 JST 2013
[    0.000000] SoC Type: Ralink RT3052 id:1 rev:3
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU revision is: 0001964c (MIPS 24KEc)
[    0.000000] MIPS: machine is Planex MZK-W300NH2
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 01000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x00000000-0x00ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x00000000-0x00ffffff]
[    0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 16kB, 4-way, VIPT, no aliases, linesize 32 bytes
[    0.000000] Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 4064
[    0.000000] Kernel command line: console=ttyS0,57600 rootfstype=squashfs,jffs2
[    0.000000] PID hash table entries: 64 (order: -4, 256 bytes)
[    0.000000] Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.000000] __ex_table already sorted, skipping sort
[    0.000000] Writing ErrCtl register=00071960
[    0.000000] Readback ErrCtl register=00071960
[    0.000000] Memory: 13184k/16384k available (2084k kernel code, 3200k reserved, 509k data, 220k init, 0k highmem)
[    0.000000] SLUB: Genslabs=9, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:128
[    0.000000] CPU Clock: 384MHz
[    0.000000] Calibrating delay loop... 255.59 BogoMIPS (lpj=1277952)
[    0.070000] pid_max: default: 32768 minimum: 301
[    0.080000] Mount-cache hash table entries: 512
[    0.090000] NET: Registered protocol family 16
[    0.120000] bio: create slab <bio-0> at 0
[    0.130000] rt2880_gpio 10000600.gpio: registering 24 gpios
[    0.140000] Switching to clocksource MIPS
[    0.150000] NET: Registered protocol family 2
[    0.160000] TCP established hash table entries: 512 (order: 0, 4096 bytes)
[    0.170000] TCP bind hash table entries: 512 (order: -1, 2048 bytes)
[    0.190000] TCP: Hash tables configured (established 512 bind 512)
[    0.200000] TCP: reno registered
[    0.210000] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.220000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.230000] NET: Registered protocol family 1
[    0.240000] rt-timer 10000100.timer: maximum frequncy is 7812Hz
[    0.280000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.290000] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.310000] msgmni has been set to 25
[    0.320000] io scheduler noop registered
[    0.330000] io scheduler deadline registered (default)
[    0.340000] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
[    0.350000] 10000c00.uartlite: ttyS0 at MMIO 0x10000c00 (irq = 20) is a 16550A
[    0.370000] console [ttyS0] enabled, bootconsole disabled
[    0.370000] console [ttyS0] enabled, bootconsole disabled
[    0.390000] 1f000000.cfi: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x0000c2 Chip ID 0x0022a8
[    0.410000] Amd/Fujitsu Extended Query Table at 0x0040
[    0.420000]   Amd/Fujitsu Extended Query version 1.1.
[    0.430000] number of CFI chips: 1
[    0.440000] 5 ofpart partitions found on MTD device 1f000000.cfi
[    0.450000] Creating 5 MTD partitions on "1f000000.cfi":
[    0.460000] 0x000000000000-0x000000030000 : "u-boot"
[    0.480000] 0x000000030000-0x000000040000 : "u-boot-env"
[    0.490000] 0x000000040000-0x000000050000 : "factory"
[    0.500000] 0x0000003e0000-0x000000400000 : "cimage"
[    0.520000] 0x000000050000-0x0000003e0000 : "firmware"
[    0.530000] found squashfs behind kernel
[    0.540000] Creating 2 MTD partitions on "1f000000.cfi":
[    0.550000] 0x000000050000-0x000000139091 : "kernel"
[    0.560000] mtd: partition "kernel" must either start or end on erase block boundary or be smaller than an erase block -- forcing read-only
[    0.590000] 0x000000139091-0x0000003e0000 : "rootfs"
[    0.600000] mtd: partition "rootfs" must either start or end on erase block boundary or be smaller than an erase block -- forcing read-only
[    0.620000] mtd: partition "rootfs" set to be root filesystem
[    0.640000] mtd: partition "rootfs_data" created automatically, ofs=2E0000, len=100000
[    0.650000] 0x0000002e0000-0x0000003e0000 : "rootfs_data"
[    0.670000] rt305x-esw 10110000.esw: link changed 0x08
[    0.680000] eth0: done loading
[    0.690000] TCP: cubic registered
[    0.700000] NET: Registered protocol family 17
[    0.710000] 8021q: 802.1Q VLAN Support v1.8
[    0.720000] VFS: Mounted root (squashfs filesystem) readonly on device 31:6.
[    0.740000] Freeing unused kernel memory: 220k freed
[    3.000000] input: gpio-keys-polled.2 as /devices/gpio-keys-polled.2/input/input0
[    3.080000] Button Hotplug driver version 0.4.1
- preinit -
Press the [f] key and hit [enter] to enter failsafe mode
- regular preinit -
[    6.490000] jffs2: notice: (406) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
switching to jffs2
- init -

Please press Enter to activate this console. [    7.910000] compat-drivers backport release: compat-drivers-2013-03-28-5
[    7.930000] Backport based on wireless-testing.git master-2013-04-16
[    7.940000] compat.git: wireless-testing.git
[    8.100000] cfg80211: Calling CRDA to update world regulatory domain
[    8.110000] cfg80211: World regulatory domain updated:
[    8.120000] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
[    8.130000] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[    8.150000] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[    8.170000] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[    8.180000] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[    8.200000] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[    8.810000] NET: Registered protocol family 10
[    9.180000] usbcore: registered new interface driver usbfs
[    9.200000] usbcore: registered new interface driver hub
[    9.210000] usbcore: registered new device driver usb
[    9.580000] rt2800_wmac 10180000.wmac: failed to load eeprom property
[    9.590000] phy0 -> rt2x00lib_request_eeprom_file: Info - Loading EEPROM data from 'soc_wmac.eeprom'.
[   17.900000] phy0 -> rt2x00_set_rt: Info - RT chipset 2872, rev 0200 detected
[   17.920000] phy0 -> rt2x00_set_rf: Info - RF chipset 0008 detected
[   18.070000] PPP generic driver version 2.4.2
[   18.230000] ip_tables: (C) 2000-2006 Netfilter Core Team
[   18.490000] xt_time: kernel timezone is -0000
[   18.540000] NET: Registered protocol family 24
[   18.570000] nf_conntrack version 0.5.0 (209 buckets, 836 max)
[   18.880000] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   19.080000] dwc_otg: version 2.72a 24-JUN-2008
[   26.150000] device eth0.1 entered promiscuous mode
[   26.160000] device eth0 entered promiscuous mode
[   26.170000] br-lan: port 1(eth0.1) entered forwarding state
[   26.180000] br-lan: port 1(eth0.1) entered forwarding state
[   27.400000] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.1: link becomes ready
[   28.180000] br-lan: port 1(eth0.1) entered forwarding state
[   28.440000] ralink-wdt: timeout value 60 must be 0 < timeout <= 33, using 30



BusyBox v1.19.4 (2013-06-07 23:07:54 JST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Bleeding Edge, r36852)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------
root@OpenWrt:/#

リブート後に /etc/config/network を見ると以下があり、lan 側ポート、つまり「1」~「4」のポートに接続すればIP アドレス 192.168.1.1 で telnet でつながります。

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '0 1 2 3 6t'

config interface 'lan'
        option ifname 'eth0.1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

2013年6月 7日 (金)

◆ OpenWrt の trunk 版(r36853) を Planex MZK-W300NH2 用にビルドしてみました

以前、OpenWrt の trunk のブランチにMZK-W300NH2 用のコードが追加されたという情報をいただきビルドしたという記事を書きました(「OpenWrt (trunk 版 r36041)を MZK-W300NH2 用にビルドしてみました」)。
その記事に対して最近いただいたコメントから、今の trunk では大幅な変更が入っていて以前作成したパッチが使い物にならないことがわかりました。
(れ@さん、情報ありがとうございます。m(_ _)m)

どう変わったのか確認するため、手を加えずにそのままビルドしてみました。

■ビルド手順での変更点
make menuconfig で指定する値が変わっています。
以下を指定します:
[Target System]:  Ralink RT288x/RT3xxx
[Subtarget]:      RT3x5x/RT5350 based boards

20130605195033_660x414_scrot_2


その後のビルドは、make コマンドを実行するだけなのは変わりません。
~/openwrt/trunk ディレクトリが作業ディレクトリとした場合、ファームウェアは、~/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin にできます。
以前の記事のような問題はなく、ファームウェアのファイルは作成されました。

■ビルドログにて

致命傷ではないですが make V=99 として詳細を出すと MZK-W300NH2 のファームのイメージを作ろうとしているところで以下の変なメッセージが記録されます。
  bash: line 0: [: xxxx: unary operator expected
 (xxxx のところはファイルサイズの数値が入ります)

具体的には以下:

if [ `stat -c%s "/home/lubun/openwrt/trunk/build_dir/target-mipsel_dsp_uClibc-0.9.33.2/linux-ramips_rt305x/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-sysupgrade.bin"` -gt  ]; then echo "Warning: /home/lubun/openwrt/trunk/build_dir/target-mipsel_dsp_uClibc-0.9.33.2/linux-ramips_rt305x/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-sysupgrade.bin is too big" >&2; else cp -fpR /home/lubun/openwrt/trunk/build_dir/target-mipsel_dsp_uClibc-0.9.33.2/linux-ramips_rt305x/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-sysupgrade.bin /home/lubun/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-sysupgrade.bin; fi
bash: line 0: [: 2883588: unary operator expected

これは、~/openwrt/trunk/target/linux/ramips/image/Makefile にて mzkw300nh2_mtd_size が定義されていないためでした。
そのため、Makefile中の以下の箇所の実行でエラーが出ています。

Image/Build/Profile/MZKW300NH2=$(call BuildFirmware/Edimax/$(1),$(1),mzk-w300nh2,MZK-W300NH2,$(mzkw300nh2_mtd_size),CSYS,RN52,0x50000,0xc0000)

展開されたコードから判断すると影響はファイルサイズの上限チェックがされないだけなので、良くはないですがとりあえず無視できます。

■ファーム入れ替え後のブート
何も手を加えずにビルドしてできたファームウェアを MZK-W300NH2 に入れ替え、シリアル接続してブートログを採取してみました。
れ@さんにいただいたコメント通りで、カーネルパニックを起こして起動しません。

ポイントは、赤字にしたところ。kenel と rootfs は自動で認識する仕掛けに変更されているはずなのですが認識できていません。

U-Boot 1.1.3 (Nov 25 2008 - 16:46:30)

Board: Ralink APSoC DRAM:  16 MB
relocate_code Pointer at: 80fa8000
****************************
Init GPIO Pin****************************
flash_protect ON: from 0xBFC00000 to 0xBFC26213
protect on 0
protect on 1
protect on 2
protect on 3
protect on 4
protect on 5
protect on 6
protect on 7
protect on 8
protect on 9
flash_protect ON: from 0xBFC30000 to 0xBFC3FFFF
protect on 10
============================================
Ralink UBoot Version: 3.1
--------------------------------------------
ASIC 3052_MP1 (MAC to GigaMAC Mode)
DRAM COMPONENT: 64Mbits
DRAM BUS: 32BIT
Total memory: 16 MBytes
Flash: 4 MBytes
Date:Nov 25 2008  Time:16:46:30
============================================
icache: sets:256, ways:4, linesz:32 ,total:32768
dcache: sets:128, ways:4, linesz:32 ,total:16384

 ##### The CPU freq = 384 MHZ ####

 SDRAM bus set to 32 bit
 SDRAM size =16 Mbytes

Please choose the operation:
   0: Load ucos code to SDRAM via TFTP Client.
   1: Load system code to SDRAM via TFTP.
   2: Load system code then write to Flash via TFTP.
   3: Boot system code via Flash (default).
   4: Entr boot command line interface.
   9: Load Boot Loader code then write to Flash via TFTP.
 0

3: System Boot system code via Flash.
## Booting image at bfc50000 ...
Bad Magic Number,43535953
   Image Name:   MIPS OpenWrt Linux-3.8.13
   Created:      2013-06-05  14:10:42 UTC

 System Control Status = 0x01040000
   Image Type:   MIPS Linux Kernel Image (lzma compressed)
   Data Size:    954399 Bytes = 932 kB
   Load Address: 80000000
   Entry Point:  80000000
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 80000000) ...
## Giving linux memsize in MB, 16

Starting kernel ...

[    0.000000] Linux version 3.8.13 (lubun@lubun) (gcc version 4.6.4 (OpenWrt/Linaro GCC 4.6-2012.12 r36852) ) #1 Wed Jun 5 23:08:46 JST 2013
[    0.000000] SoC Type: Ralink RT3052 id:1 rev:3
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU revision is: 0001964c (MIPS 24KEc)
[    0.000000] MIPS: machine is Planex MZK-W300NH2
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 01000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x00000000-0x00ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x00000000-0x00ffffff]
[    0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 16kB, 4-way, VIPT, no aliases, linesize 32 bytes
[    0.000000] Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 4064
[    0.000000] Kernel command line: console=ttyS0,57600 rootfstype=squashfs,jffs2
[    0.000000] PID hash table entries: 64 (order: -4, 256 bytes)
[    0.000000] Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.000000] __ex_table already sorted, skipping sort
[    0.000000] Writing ErrCtl register=000718a9
[    0.000000] Readback ErrCtl register=000718a9
[    0.000000] Memory: 13184k/16384k available (2084k kernel code, 3200k reserved, 509k data, 220k init, 0k highmem)
[    0.000000] SLUB: Genslabs=9, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:128
[    0.000000] CPU Clock: 384MHz
[    0.000000] Calibrating delay loop... 255.59 BogoMIPS (lpj=1277952)
[    0.070000] pid_max: default: 32768 minimum: 301
[    0.080000] Mount-cache hash table entries: 512
[    0.090000] NET: Registered protocol family 16
[    0.120000] bio: create slab <bio-0> at 0
[    0.130000] rt2880_gpio 10000600.gpio: registering 24 gpios
[    0.140000] Switching to clocksource MIPS
[    0.150000] NET: Registered protocol family 2
[    0.160000] TCP established hash table entries: 512 (order: 0, 4096 bytes)
[    0.170000] TCP bind hash table entries: 512 (order: -1, 2048 bytes)
[    0.190000] TCP: Hash tables configured (established 512 bind 512)
[    0.200000] TCP: reno registered
[    0.210000] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.220000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.230000] NET: Registered protocol family 1
[    0.240000] rt-timer 10000100.timer: maximum frequncy is 7812Hz
[    0.280000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.290000] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.310000] msgmni has been set to 25
[    0.320000] io scheduler noop registered
[    0.330000] io scheduler deadline registered (default)
[    0.340000] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
[    0.350000] 10000c00.uartlite: ttyS0 at MMIO 0x10000c00 (irq = 20) is a 16550A
[    0.370000] console [ttyS0] enabled, bootconsole disabled
[    0.370000] console [ttyS0] enabled, bootconsole disabled
[    0.390000] 1f000000.cfi: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x0000c2 Chip ID 0x0022a8
[    0.410000] Amd/Fujitsu Extended Query Table at 0x0040
[    0.420000]   Amd/Fujitsu Extended Query version 1.1.
[    0.430000] number of CFI chips: 1
[    0.440000] 5 ofpart partitions found on MTD device 1f000000.cfi
[    0.450000] Creating 5 MTD partitions on "1f000000.cfi":
[    0.460000] 0x000000000000-0x000000030000 : "u-boot"
[    0.480000] 0x000000030000-0x000000040000 : "u-boot-env"
[    0.490000] 0x000000040000-0x000000050000 : "factory"
[    0.500000] 0x0000003e0000-0x000000400000 : "cimage"
[    0.520000] 0x000000050000-0x0000003e0000 : "firmware"
[    0.530000] failed to split firmware partition
[    0.540000] Can't split firmware partition
[    0.550000] rt305x-esw 10110000.esw: link changed 0x08
[    0.560000] eth0: done loading
[    0.570000] TCP: cubic registered
[    0.580000] NET: Registered protocol family 17
[    0.590000] 8021q: 802.1Q VLAN Support v1.8
[    0.600000] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
[    0.610000] Please append a correct "root=" boot option; here are the available partitions:
[    0.630000] 1f00             192 mtdblock0  (driver?)
[    0.640000] 1f01              64 mtdblock1  (driver?)
[    0.650000] 1f02              64 mtdblock2  (driver?)
[    0.660000] 1f03             128 mtdblock3  (driver?)
[    0.670000] 1f04            3648 mtdblock4  (driver?)
[    0.680000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

(つづく...)

2013年3月24日 (日)

PLANEX MZK-WNH および MZK-W300NH2 で動く OpenWrt with OpenFlow 1.0 のイメージをアップロードしました(Ver.2)」

前回書いた記事「MZK-WNH/MZK-W300NH2 用 OpenWrt を OpenFlow 1.0 スイッチにカスタマイズする」で作成したファームウェアのイメージをアップロードしておきます。

おことわり: ここで公開したファームを入れようとしたことで二度と起動しなくなる可能性があります。リスクを承知の上でお使いください。

■ OpeFlow スイッチ化した OpenWrt のイメージファイル

このブログで使っている ココログでは1ファイルのサイズ上限が 1Mバイトとのことで、面倒ですが3つに分割して置いてあります:
  concat.bat     image1.bin    image2.bin    image3.bin

3つの image*.bin ファイルを結合して1つのファイルにしてください。 Windows 用にバッチファイル concat.bat を用意しました。このバッチファイルを実行すると  openwrt-ramips-rt305x-mzk-wnh-squashfs-factory.bin というファイルができます。
  UNIX/Linux なら、cat image1.bin image2.bin image3.bin > openwrt-ramips-rt305x-mzk-wnh-squashfs-factory.bin でできあがり。
もし、ファイルが壊れていたらファームの入替え時にファイルのフォーマット不正か、チェックサムのエラーではじかれます。

■ファームの入れ替え方

先日書いた記事「PLANEX MZK-WNH と MZK-W300NH2 用 OpenWrt 12.09 ファームウェア(Attitude Adjustment, r35864)をアップロードしました」の「■ファームの入れ替え方」を参考にしてください。

あるいは、以前の記事 「MZK-WNH を純正ファームに戻す方法(シリアル接続不要)」の方法で純正ファームのイメージファイルの代わりに今回のイメージファイルを用いることで入れ替えることもできます。

■入れ替えたあと

先日書いた記事「MZK-WNH/MZK-W300NH2 用 OpenWrt を OpenFlow 1.0 スイッチにカスタマイズする」の「■ファームウェア入れ替え後の構成」以降を参考にしてください。

■前回公開版との違い

去年の10月に「MZK-WNH で動かす OpenFlow 1.0 のイメージをアップロードしました」で公開したものとの違いを以下にあげておきます。

1) Datapath ID の初期値(/etc/config/openflow ファイルの dpid)は MAC アドレスになるようにしてあります。 (OpenFlow 1.0 準拠にした)
2) Pantou: OpenFlow 1.0 の ofprotocol プロセスの起動時オプション --fail と --inactivity-probe を /etc/config/openflow ファイルで指定できるようにした。
3) --fail オプションをデフォルトの open から closed にして、OpenFlow コントローラとの接続失敗が続いてもブリッジとして動くことがないようにした。
4) LED(WPS, Wireless, Power) や ボタン(WPS, Reset)が扱える。
5) 使用している OpenWrt が新しい。
  「PLANEX MZK-WNH と MZK-W300NH2 用 OpenWrt 12.09 ファームウェア(Attitude Adjustment, r35864)をアップロードしました」がベースになっています。

2013年3月22日 (金)

MZK-WNH/MZK-W300NH2 用 OpenWrt を OpenFlow 1.0 スイッチにカスタマイズする

PLANEX MZK-WNH および MZK-W300NH2 用に先日公開した OpenWrt を OpenFlow スイッチ化したのでその手順を書いておきます。

OpenWrt 用の OpenFlow 1.0 の実装には以下の Pantou を利用しました:
http://www.openflow.org/wk/index.php/Pantou_:_OpenFlow_1.0_for_OpenWRT

Pantou がサポート対象としている機種には、当たり前ですが MZK-WNH および MZK-W300NH2 は含まれていません。また、対象としている OpenWrt も BackFire と古いバージョンです。
簡単な動作確認はしていますが、MZK-WNH/MZK-W300NH2 用の OpenWrt Attitude Adjustment で動作する保証があるものではないことをあらかじめご了承ください。

■今回用いたビルド環境
  ビルド環境は、先日書いた OpenWrt の Attitude Adjustment ブランチのビルド環境です。
なので、
  OSは、Lubuntu 12.04 Desktop(i386) を使用。
 OpenWrt があるディレクトリは、 ~/openwrt/attitude_adjustment を想定。

OpenWrt のファームウェアのファイルが作成でき、入れ替えて起動できるものがすでに作成できていることが前提です。

■どういう OpenFlow スイッチができるのか?

今回作成したファームウェアにより MZK-WNH、MZK-W300NH2 が、4ポートの OpenFlow 1.0 のスイッチとして動作します。

あまり期待はしすぎないでください。
Pantou OpenFlow 1.0 がどれだけ標準に準拠しているのかは分かりません。
また、MZK-WNH/MZK-W300NH2 では、ハードウェア構成上 VLAN タグの入ったパケットが扱えないことがわかっています。
ポート単位のリンクアップ/ダウンも扱えません。
他にもまだまだあると思います。

■手順1) Pantou のソース入手

以下のようにコマンドを実行します:

cd ~/openwrt
git clone git://gitosis.stanford.edu/openflow-openwrt

するとカレントディレクトリに openflow-openwrt というディレクトリができます。

■手順2) 省略→ ブランチ作成 

公式HPにはありますが、不要なので省略します。
ブランチを作ってみたい人は以下のような感じでやるとよいと思います。

cd ~/openwrt/openflow-openwrt
git branch origin/openflow-1.0/mzkwnh
git checkout -b openflow-1.0/mzkwnh

ブランチ origin/openflow-1.0/mzkwnh は、オリジナルの状態のソース参照用。
ブランチ openflow-1.0/mzkwnh は、MZK-WNH/MZK-W300NH2 用のソース。

■手順3) Pantou を OpenWrt のビルド環境に組み込む

cd ~/openwrt/attitude_adjustment/package
ln -s ../../openflow-openwrt/openflow-1.0 .

※ 個人的な好みの理由で、公式HPでは絶対パスでシンボリックリンクしているところを相対パスにしています。

■手順4) 省略→ 設定ファイルの OpenWRT への追加

公式HPにはありますが、不要なので省略します。
公式HPの「Add basic configuration files for OpenWRT」という手順に該当します。

この手順では、OpenWrt のルートファイルシステムを作るときに、追加でコピーするファイルを指定できる仕掛けを利用して OpenFlow の各ファイルのコピーをするようにしています。
しかし、パッケージのインストール処理でそれらのファイルをコピーするようにしてあるので、この仕掛けを利用する必要がありません。
~/openwrt/attitude_adjustment/openflow-openwrt/openflow-1.0/Makefile の中の "define Package/openflow/install" の箇所がパッケージのインストール処理の箇所です。

■手順5) make menuconfig によるビルド項目カスタマイズ

cd ~/openwrt/attitude_adjustment
make menuconfig

make menuconfigを使って、openflow 自体、および前提として必要な tc のパッケージを有効にします。
また、公式HPには記載がないですが、完全に OpenFlow スイッチとして動かすことを考えると Firewall などの処理は不要なので削除します。

対象項目にカーソルを移動したらスペースキーで種別を切り替えます。各項目名の先頭に表示される「< >」のところが種別を表しています。<*> を選ぶとファームウェアに組込まれます。削除は < > の状態。<M> はコンパイルしてパッケージ形式にしますがファームウェアのイメージには含まれません。

以下の3つの項目を <*> にします:
・ [Network] → [OpenFlow]
・ [Network] → [tc]
・ [Kernel modules] → [Network Support] → [kmod-tun]

以下の2つの項目を < > にします:
・ [Base system]→[dnsmasq]
・ [Base system]→[firewall]

■手順6) make kernel_menuconfig によるカーネルオプション変更

cd ~/openwrt/attitude_adjustment
make kernel_menuconfig

以下の項目を <*> にします:
・ [Networking support]→[Networking options]→[QoS and/or fair queueing]→[Hierarchical Token Bucket (HTB)]

■手順7) Patnou へのパッチの適用

Pantou 公式 HP にはない手順です。
openflow 用定義ファイル /etc/config/openflow ファイルで指定できる起動時オプションを追加したいので修正をしました。
修正パッチは以下においておきます:
http://ranosgrant.cocolog-nifty.com/PantouOpenFlow_1_0/pantou.diff

以下の手順でパッチをあててください:

cd ~/openwrt/openflow-openwrt
wget http://ranosgrant.cocolog-nifty.com/PantouOpenFlow_1_0/pantou.diff
patch -p0 < pantou.diff

実行時出力

$ patch -p0 < pantou.diff
patching file openflow-1.0/files/lib/openflow/ofprotocol.sh

パッチの中身

diff --git openflow-1.0/files/lib/openflow/ofprotocol.sh openflow-

1.0/files/lib/openflow/ofprotocol.sh
index 745ef3c..25b6543 100755
--- openflow-1.0/files/lib/openflow/ofprotocol.sh
+++ openflow-1.0/files/lib/openflow/ofprotocol.sh
@@ -5,11 +5,15 @@ setup_ofprotocol() {
 	local config="$1"
 	local ofctl
 	local dp
+	local fail
+	local inactivity_probe
 
 	[ -x "/usr/bin/ofprotocol" ] || ( echo "ofprotocol not executable" && return 0 )
 	config_get ofctl "$config" ofctl
 	config_get dp "$config" dp
 	config_get mode "$config" mode
+	config_get fail "$config" fail "open"
+	config_get inactivity_probe "$config" inactivity_probe "15"
 
 
 	pidfile="/var/run/ofprotocol.pid"
@@ -25,9 +29,9 @@ setup_ofprotocol() {
 		[ -z "$dp" -o -z "$ofctl" ] && echo "no controller specified" && return 1
 		if [[ "$mode" == "inband" ]]			
 		then
-			ofprotocol unix:/var/run/dp0.sock "$ofctl" --fail=open "-D" "--

pidfile=$pidfile" --listen=ptcp: --log-file="/var/log/ofprotocol.log" &
+			ofprotocol unix:/var/run/dp0.sock "$ofctl" --fail="$fail" "-D" 

"--pidfile=$pidfile" --listen=ptcp: --log-file="/var/log/ofprotocol.log" --inactivity-

probe="$inactivity_probe" &
 		else
-			ofprotocol unix:/var/run/dp0.sock "$ofctl" --fail=open "-D" "--

pidfile=$pidfile" --out-of-band --listen=ptcp: --log-file="/var/log/ofprotocol.log" &
+			ofprotocol unix:/var/run/dp0.sock "$ofctl" --fail="$fail" "-D" 

"--pidfile=$pidfile" --out-of-band --listen=ptcp: --log-file="/var/log/ofprotocol.log" 

--inactivity-probe="$inactivity_probe" &
 		fi
 		lock -u "/var/lock/ofprotocol"
 	fi

このパッチは以下のコマンドで出力しました:

cd ~/openwrt/openflow-openwrt
git diff --no-prefix

■手順8) 定義ファイルの OpenWrt への追加

こちらも Pantou 公式HPにはない手順です。
MZK-WNH/MZK-W300NH2 を OpenFlow スイッチとして動作させるためのカスタマイズをした定義ファイルを用意します。

カスタマイズ済のファイルは tar でアーカイブして、http://ranosgrant.cocolog-nifty.com/PantouOpenFlow_1_0/files.tar においておきました。

以下の手順でビルド環境に取り込んでください:

cd ~/openwrt/attitude_adjustment
wget http://ranosgrant.cocolog-nifty.com/PantouOpenFlow_1_0/files.tar
tar xvf files.tar

これで2つのファイルが生成されます。

1) files/etc/config/openflow

openflow 用の定義ファイル /etc/config/openflow に対して少し手を加えたもので置き換えます。
OpenFlow の Datapath ID を OpenFlow 1.0 の規格に従って MAC アドレスを指定しやすくするため少し手を加えてあります。
openflow の中身は以下です:

config ofswitch 'ofswitch0'
	option dp 'dp0'
	option ofports 'eth0.1 eth0.2 eth0.3 eth0.4'
	option ofctl 'tcp:192.168.1.10:6633'
	option mode  'outofband'

2) files/etc/uci-defaults/network

OpenWrt では、初期ブート時に /etc/config/network ファイルを作成するために /etc/uci-defaults/network というファイルが起動します。
このファイルを、OpenFlow スイッチ用の定義を作成するファイルにおきかえます。置き換え後の network ファイルは、MKZ-WNH/MZK-W300NH2 固有の定義内容です。

/etc/config/openflow ファイルの dpid (Datapath ID)の値の設定処理も入れてあります。

network の内容は、以下です:

#!/bin/sh

. /etc/functions.sh
. /lib/ramips.sh
. /lib/functions/uci-defaults.sh


[ -e /etc/config/network ] && exit 0
if [ ! -x /usr/sbin/maccalc ]; then
	echo "$0: maccalc not found!"
	exit 1
fi

lan_mac=$(ramips_get_mac_binary factory 4)
wan_mac=`/usr/sbin/maccalc add "$lan_mac" 1`

dpid=`echo "$wan_mac" | sed -e 's/://g'`
uci set openflow.ofswitch0.dpid=$dpid
uci commit openflow

touch /etc/config/network
ucidef_set_interface_loopback

ucidef_add_switch "switch0" 1 1
ucidef_add_switch_vlan "switch0" 1 "0 6t"
ucidef_add_switch_vlan "switch0" 2 "1 6t"
ucidef_add_switch_vlan "switch0" 3 "2 6t"
ucidef_add_switch_vlan "switch0" 4 "3 6t"
ucidef_add_switch_vlan "switch0" 5 "4 6t"


uci batch << EOF
set network.eth0='interface'
set network.eth0.ifname='eth0'
set network.eth0.proto='static'
set network.eth0.macaddr='$lan_mac'
EOF

ucidef_set_interface_raw "eth0_1" "eth0.1"
ucidef_set_interface_raw "eth0_2" "eth0.2"
ucidef_set_interface_raw "eth0_3" "eth0.3"
ucidef_set_interface_raw "eth0_4" "eth0.4"

uci batch << EOF
set network.eth0_5='interface'
set network.eth0_5.ifname='eth0.5'
set network.eth0_5.proto='static'
set network.eth0_5.ipaddr='192.168.1.1'
set network.eth0_5.netmask='255.255.255.0'
set network.eth0_5.macaddr='$wan_mac'
EOF

uci commit network

exit 0

■手順9) イメージのビルド

準備は以上です。あとは make するだけです。

cd ~/openwrt/attitude_adjustment
make

エラーが出るようだったら make V=99 として詳細なログを出力して確認してください。

■手順10) ファームウェアの入替え

イメージファイルのありか、ファームウェアの入替え方法などは変わりないので説明は省きます。

■ファームウェア入れ替え後の構成

接続するポートに注意してください!。今回作成したファームウェアがログイン用に受け付けるのは「Internet」というラベルのついたポートです。

1)「Internet」と書いてあるポート
  IP アドレス 192.168.1.1
  OpenFlow コントローラとの接続用です。
  ログインして設定を変更するにも使います。パスワード設定前なら telnet でパスワードなしで入れます。

  IPアドレスは、/etc/config/network ファイルで変更可能です。

2)「1」~「4」と書いてあるポート
 OpenFlow 専用ポート

3) OpenFlowコントローラ
  192.168.1.10 の TCP ポート 6633 にめがけて接続しにいきます。

  IPアドレスは、/etc/config/openflow ファイルで変更可能です。後述する OpenFlow フレームワーク Trema と接続する場合、この設定のままで大丈夫です。

4) ログファイル
 /var/log/ofprotocol.log ファイルにログが出力されます。
OpenFlowコントローラとの接続状況などが出力されています。

■簡単な動作確認

dpctl コマンドで OpenFlow のプロセスを制御できます。まずは、showサブコマンドを使ってみましょう。

root@OpenWrt:/# dpctl show unix:/var/run/dp0.sock
features_reply (xid=0xdd8a589b): ver:0x1, dpid:22cf212a29
n_tables:2, n_buffers:256
features: capabilities:0xc7, actions:0xeff
 1(eth0.1): addr:00:22:cf:21:2a:28, config: 0, state:0
 2(eth0.2): addr:00:22:cf:21:2a:28, config: 0, state:0
 3(eth0.3): addr:00:22:cf:21:2a:28, config: 0, state:0
 4(eth0.4): addr:00:22:cf:21:2a:28, config: 0, state:0
get_config_reply (xid=0xba967ffb): miss_send_len=128

ポートが4つ eth0.1 ~ eth0.4 が表示されるはずです。
また、dpid には、MZK-WNH/MZK-W300NH2 の底部に貼ってあるシールの「Node ID WAN」の箇所の MAC アドレスと一致しているはずです(先頭の 00 は表示上省略されているのは気にしなくて構いません)。
OpenFlow 1.0 の規格に従って MAC アドレスを datapath id (dpid) としています。

記載箇所:
http://www.openflow.org/documents/openflow-spec-v1.0.0.pdf
"OpenFlow Switch Specification Version 1.0.0"(p.25) "5.3.1 Handshake" より:

The datapath_id field uniquely identifies a datapath. The lower 48 bits are
intended for the switch MAC address, while the top 16 bits are up to the implementer.

直訳:
datapath_id フィールドは、データパスを一意に識別します。下位48ビットはスイッチの MAC アドレスを用いることを意図しているが、上位16ビットは実装者にまかせる。

■簡単なフローエントリの確認

OpenFlow コントローラを用意しなくてもコマンドラインでフローエントリの登録ができるので以下でポート1 と 2 だけを接続してみてください。

dpctl add-flow unix:/var/run/dp0.sock idle_timeout=0,hard_timeout=0,in_port=1,actions=output:2
dpctl add-flow unix:/var/run/dp0.sock idle_timeout=0,hard_timeout=0,in_port=2,actions=output:1

フローエントリをダンプして登録されていることを確認してみます:

# dpctl dump-flows unix:/var/run/dp0.sock
stats_reply (xid=0x811a0216): flags=none type=1(flow)
  cookie=0, duration_sec=24s, duration_nsec=633000000s, table_id=1, priority=32768, n_packets=0, n_bytes=0, idle_timeout=0,hard_timeout=0,in_port=2,actions=output:1
  cookie=0, duration_sec=24s, duration_nsec=653000000s, table_id=1, priority=32768, n_packets=0, n_bytes=0, idle_timeout=0,hard_timeout=0,in_port=1,actions=output:2

これで、「1」「2」の印があるポート同士だけが通信できる状態になっています。
ケーブルを差し替えて例えば「1」と「3」にすると通信できなくなります。

dpctl コマンドの詳細は、以下のようにしてソース中の man ページを見てください:

nroff -man ~/openwrt/attitude_adjustment/build_dir/target-mipsel_r2_uClibc-0.9.33.2/openflow-1.0.0/utilities/dpctl.8 | more

■ OpenFlow コントローラとの接続確認

ここまで動いたらOpenFlow コントローラとの接続確認に挑戦してみてください。
私は、OpenFlow フレームワーク Trema を使って接続確認をしました。
Tremaについては、書籍「OpenFlow実践入門」を読んでください。

まずは ping で OpenFlow スイッチと OpenFlow コントローラの通信確認をしておいてください。

それができたら、OpenFlow フレームワーク Trema に付属するサンプルの repeater-hub あたりでまずは試してみるとよいと思います。

OpenFlow コントローラを起動したら、OpenFlow スイッチ側で tail -f /var/log/ofprotocol.log でログを監視して以下のように OpenFlow コントローラの IPアドレスで "connected" のメッセージが出たら接続完了です。

Jan 01 00:59:27|00588|rconn|INFO|tcp:192.168.1.10:6633: connected

もし、接続がなかなかできないとかすぐに切断してしまうような場合は以下のようにして openflow を再起動してみてください。

/etc/init.d/openflow restart

■ Pantou OpenFlow 1.0 のデフォルト動作の変更点について

/etc/config/openflow にて起動オプションのパラメタを変更しています。

1) option inactivity_probe '90'

デフォルトは15秒です。
Trema との接続するためには --inactivity-probe オプションを 90 秒にするように以下のブログで報告があるので採用しました。
http://trema.hatenablog.jp/entry/20120312/1331548450

2) option fail 'closed'

デフォルト値は、'open' です。
デフォルト動作は、OpenFlow コントローラとの接続失敗を繰り返したときにブリッジとして動きだす設定です。
'closed' に変更して、そのような動作をしないようにしています。

上記起動オプションの詳細は、以下のようにしてソース中の man ページを見てください:

nroff -man ~/openwrt/attitude_adjustment/build_dir/target-mipsel_r2_uClibc-0.9.33.2/openflow-1.0.0/secchan/ofprotocol.8 | more

■おまけ: Pantou に関して

ダウンロードしたソースを見てみると非常に少なくてどこにも OpenFlow のコードがないのが不思議でした。が、OpenFlow のソースは別のところからビルド時にダウンロードする仕掛けでした。

以下がソースツリーです:

$ cd ~/openwrt
$ tree openflow-1.0
openflow-1.0/
├── Makefile
├── files
│   ├── etc
│   │   ├── config
│   │   │   └── openflow
│   │   ├── hotplug.d
│   │   │   └── ofiface
│   │   │       └── 00-netstate
│   │   └── init.d
│   │       └── openflow
│   ├── lib
│   │   └── openflow
│   │       ├── ofinterfaces.sh
│   │       ├── ofprotocol.sh
│   │       └── ofswitch.sh
│   └── sbin
│       ├── ofdown
│       └── ofup
└── patches
    ├── 001-secchan-Fix-port-status-detection.patch
    ├── 002-BSD_cross_compile_fix.patch
    ├── 003_FLOW_ENTIES_limit.patch
    ├── 004-lib-use-bitwise-AND-when-checking-for-ARP.patch
    └── 005-Remove-hardcoded-path-for-tc.patch

10 directories, 14 files

Pantou のホームページに書いてあるように、OpenFlow部分は Standford reference の実装を使っています。

The OpenFlow module is based on the Stanford reference implementation (userspace).

files ディレクトリにはそのままインストールするファイル群、patches の下には元となるソースに対するパッチファイル群がおいてあります。

もともと OpenWrt のパッケージのビルドの仕掛けには、他からソースを持ってきてパッチをあててビルドするという仕掛けがあります。
OpenWrt のパッケージの仕掛けの詳細は以下を参照ください(英語です):
http://wiki.openwrt.org/doc/devel/packages

~/openwrt/attitude_adjustment/openflow-1.0/Makefile の以下の箇所がソースの入手元:

PKG_NAME_SHORT:=openflow
PKG_NAME:=kmod-$(PKG_NAME_SHORT)
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME_SHORT)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:= http://openflowswitch.org/downloads/

今回の場合、実際にコンパイルに使っているソースや生成したオブジェクトがあるディレクトリは以下でした:
~/openwrt/attitude_adjustment/build_dir/target-mipsel_r2_uClibc-0.9.33.2/openflow-1.0.0/

ちなみに、パッケージだけコンパイルしたい場合は以下の手順です:

cd ~openwrt/attitude_adjustment
make package/openflow-1.0/compile

(情報源: http://wiki.openwrt.org/doc/howtobuild/single.package)

p.s.
以前、公開した OpenFlow 対応のファームウェアは Attitude Adjustment が trunk (開発用ブランチ) だった古いものです。
当時は、試行錯誤でつくったので手順を公開できませんでしたが、今回はできるだけ最小限の手間でビルドできる手順としました...したつもりです。

2013年3月17日 (日)

OpenWrt (trunk 版 r36041)を MZK-W300NH2 用にビルドしてみました

 [2013/6/8 追記: trunk 版のコードに大幅な変更が入っており本記事の方法は使えなくなっています。本記事のコメント欄、および新しい記事「◆ OpenWrt の trunk 版(r36853) を Planex MZK-W300NH2 用にビルドしてみました」を参照ください]

OpenWrt の trunk 版だと PLANEX MZK-W300NH2 対応がすでにされているというコメントをいただいたのでビルドに挑戦してみました。しかし、そのままだとファームウェアイメージのファイルができず少し修正が必要でした。

開発中ブランチである trunk 版なので今後どういう修正が入ってくるか分かりませんが、現時点についての参考として書いておきます。

■使用したソース

ソースの入手方法の本家情報はココ:
https://dev.openwrt.org/wiki/GetSource
このページにて「Development branch」の箇所が最新の開発ブランチ(trunk)です。

以下の手順でソースを入手しました:

$ mkdir -p ~/openwrt
$ cd ~/openwrt
$ svn co svn://svn.openwrt.org/openwrt/trunk/

確認に用いたソースのバージョンですが、svn info で確認すると以下のものです。
Revision: 36041

■ビルド結果

ほとんど Attitude Adjustment のビルド方法と変わらないのでビルドの仕方の詳細ははぶきます。

make menuconfig にて、MZK-W300NH2 が含まれるはずの rt305x を指定してビルドすればよいはずですが、make の完了後にファームウェアのファイルを確認してみると作成されていません。

$ ls ~/openwrt/trunk/bin/ramips/*mzk*
ls: /home/lubun/openwrt/trunk/bin/ramips/*mzk* にアクセスできません: そのようなファイルやディレクトリはありません

■ファームウェアのイメージファイルが作成されない原因

ビルドするときの make コマンドの引数に V=99 をつけて出力させたログを確認すると、カーネルのファイルサイズの上限チェックでひっかかっていました。
以下、ビルド時のログから MZK-W300NH2 のファームウェアイメージを作ろうとしている箇所の抜粋です。
赤字のところが上限チェックで出たメッセージ:

cp /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2
/home/lubun/openwrt/trunk/staging_dir/host/bin/patch-cmdline /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2 'board=MZK-W300NH2 console=ttyS1,57600 mtdparts=physmap-flash.0:192k(u-boot)ro,64k(u-boot-env)ro,64k(factory)ro,832k(kernel),2816k(rootfs),128k@0x3e0000(cimage)ro,3648k@0x50000(firmware)'
/home/lubun/openwrt/trunk/staging_dir/host/bin/lzma e /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2 -lc1 -lp2 -pb2 /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.bin.lzma

LZMA 4.65 : Igor Pavlov : Public domain : 2009-02-03
mkimage -A mips -O linux -T kernel -C lzma -a 0x80000000 -e 0x80000000 -n "MIPS OpenWrt Linux-3.7.10" -d /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.bin.lzma /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage
Image Name:   MIPS OpenWrt Linux-3.7.10
Created:      Fri Mar 15 10:25:17 2013
Image Type:   MIPS Linux Kernel Image (lzma compressed)
Data Size:    915975 Bytes = 894.51 kB = 0.87 MB
Load Address: 80000000
Entry Point:  80000000
if [ `stat -c%s "/home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage"` -gt 851968 ]; then echo "Warning: /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage is too big" >&2; else if [ `stat -c%s /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/root.squashfs` -gt 2883584 ]; then echo "Warning: /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/root.squashfs is too big" >&2; else ( dd if=/home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage bs=851968 conv=sync; dd if=/home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/root.squashfs ) > /home/lubun/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-sysupgrade.bin; fi; fi
Warning: /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage is too big
if [ `stat -c%s "/home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage"` -gt `expr 851968 - 20` ]; then echo "Warning: /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage is too big" >&2; else if [ `stat -c%s /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/root.squashfs` -gt 2883584 ]; then echo "Warning: /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/root.squashfs is too big" >&2; else ( dd if=/home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage bs=`expr 851968 - 20` conv=sync; dd if=/home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/root.squashfs ) > /home/lubun/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin; fi; fi
Warning: /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage is too big
mkedimaximg -i /home/lubun/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin -o /home/lubun/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin -s CSYS -m RN52 -f 0x50000 -S 0xc0000;
stat failed on /home/lubun/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin
Usage: mkedimaximg [OPTIONS...]

Options:
  -s <sig>        set image signature to <sig>
  -m <model>      set model to <model>
  -i <file>       read input from file <file>
  -o <file>       write output to file <file>
  -f <flash>      set flash address to <flash>
  -S <start>      set start address to <start> make[5]: [install] Error 1 (ignored)

ファイルサイズを確認してみると

$ ls -l /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage
-rw-r--r-- 1 lubun lubun 916039  3月 15 10:25 /home/lubun/openwrt/trunk/build_dir/target-mipsel_uClibc-0.9.33.2/linux-ramips_rt305x/vmlinux-mzk-w300nh2.uImage

■対策

前回作成した Attitude Adjustment 用のパッチを元にイメージファイルの作成方法を変更しました。以下にパッチを置いておきます:
http://ranosgrant.cocolog-nifty.com/openwrt-BB-r36032/mzkw300nh2.patch

パッチの当て方はこんな感じです。

cd ~/openwrt/trunk
wget http://ranosgrant.cocolog-nifty.com/openwrt-BB-r36032/mzkw300nh2.patch
patch -p0 < mzkw300nh2.path

以下、パッチの内容です。

Index: target/linux/ramips/image/Makefile
===================================================================
--- target/linux/ramips/image/Makefile	(revision 36032)
+++ target/linux/ramips/image/Makefile	(working copy)
@@ -407,15 +407,10 @@
 	$(call BuildFirmware/Buffalo2,$(1),wli-tx4-ag300n,WLI-TX4-AG300N,$(call mkmtd/phys,$(mtdlayout_wlitx4ag300n)),917504,2883584)
 endef
 
-mtdlayout_mzkw300nh2=192k(u-boot)ro,64k(u-boot-env)ro,64k(factory)ro,832k(kernel),2816k(rootfs),128k@0x3e0000(cimage)ro,3648k@0x50000(firmware)
-kernel_size_mzkw300nh2=851968
-rootfs_size_mzkw300nh2=2883584
+mtdlayout_mzkw300nh2=192k(u-boot)ro,64k(u-boot-env)ro,64k(factory)ro,896k(kernel),2752k(rootfs),128k(cimage)ro,3648k@0x50000(firmware)
 define BuildFirmware/MZKW300NH2
-	$(call BuildFirmware/Generic,$(1),$(2),$(call mkcmdline,$(3),$(4),$(5)) $(call mkmtd/$(6),$(mtdlayout_mzkw300nh2)),$(kernel_size_mzkw300nh2),$(rootfs_size_mzkw300nh2))
-	$(call CatFiles,$(KDIR)/vmlinux-$(2).uImage,`expr $(kernel_size_mzkw300nh2) - 20`,$(KDIR)/root.$(1),$(rootfs_size_mzkw300nh2),$(call imgname,$(1),$(2))-factory.bin)
-	-mkedimaximg -i $(call imgname,$(1),$(2))-factory.bin \
-		-o $(call imgname,$(1),$(2))-factory.bin \
-		-s CSYS -m RN52 -f 0x50000 -S 0xc0000;
+	$(call BuildFirmware/Generic,$(1),$(2),$(call mkcmdline,$(3),$(4),$(5)) $(call mkmtd/$(6),$(mtdlayout_mzkw300nh2)),917484,2818048)
+	$(call BuildFirmware/Edimax,$(1),mzk-w300nh2,CSYS,RN52,0x50000,0xc0000)
 endef
 
 define BuildFirmware/MZKW300NH2/initramfs

■対策後

修正をして再度ビルドすると trunk/bin/ramips ディレクトリの下に以下のファイルができました。
openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin
openwrt-ramips-rt305x-mzk-w300nh2-squashfs-sysupgrade.bin

openwrt-ramips-rt305x-mzk-w300nh2-squashfs-factory.bin を用いて MZK-W300NH2 のファームを入れ替えたところ正常に起動できました。

以下の画像は、Windows 7 のコマンドプロンプトから telnet でログインした画面です:

Loginbannar_3

Attitude Adjustment の次にあたる BARRIER BREAKER の文字が見えます。

2013年3月10日 (日)

PLANEX MZK-WNH//MZK-W300NH2 用 OpenWrt にボタンの仕掛けを追加

先日公開した PLANEX MZK-WNH/MZK-W300NH2 用 OpenWrt において config ファイルからボタンを扱う仕掛けを用意しました。

http://wiki.openwrt.org/doc/howto/hardware.button を参考にしましたが定義ファイルには既存の /etc/config/system を使うのではなくて、新たに /etc/config/button という設定ファイルを用いています。

使い方はサンプルを見ていただければわかると思います。どのボタンで pressed(押す)、released(離す) のアクションが起きた時に何をするかを handler で指定します。
min, max は直前の状態がどれだけの秒数続いたかの条件です。例えば、released のアクションにおいて min が 8 だと最低でも8 秒は押しっぱなし(pressed)の状態が続いていたことが条件になります。これにより、ボタンを長押しした時は動作を変える、ということができます。

使えるボタンは、wps と reset です。

以下、ボタンを扱う仕掛けの設定手順です。

■手順1 /etc/hotplug2.rules の変更

/etc/hotplug2.rules ファイルの "^button" の箇所の "^" を削除します。

変更前:
SUBSYSTEM ~~ (^net$|^input$|^button$|^usb$|^ieee1394$|^block$|^atm$|^zaptel$|^tty$) {
変更後:
SUBSYSTEM ~~ (^net$|^input$|button$|^usb$|^ieee1394$|^block$|^atm$|^zaptel$|^tty$) {

■手順2 /etc/hotplug2.d/button の下に制御スクリプトを作成

まずディレクトリをつくります:

root@OpenWrt:/# mkdir -p /etc/hotplug2.d/button

以下のファイルを /etc/hotplug2.d/button/01-button として作成します。http://ranosgrant.cocolog-nifty.com/openwrt-aa-r35864/01-button

内容は以下:

#!/bin/sh
. /lib/functions.sh

chk_minmax() {
	[ -z "$min" -a -z "$max" ] || 
	[ -z "$min" -a -n "$max" -a "$max" -ge "$SEEN" ] ||
	[ -n "$min" -a -z "$max" -a "$min" -le "$SEEN" ] ||
	[ -n "$min" -a -n "$max" -a "$min" -le "$SEEN" -a "$max" -ge "$SEEN" ]
}

do_button () {
	config_get button "$1" button
	config_get action "$1" action
	config_get handler "$1" handler
	config_get min "$1" min
	config_get max "$1" max

	[ "$button" = "$BUTTON" -a "$action" = "$ACTION" ] &&
		chk_minmax && eval "$handler"
}

config_load button
config_foreach do_button button

ファイル転送する方法がない場合の技:
ファイルの内容をメモ帳やWebブラウザで開いてコピーしたのち、telnet 画面から以下を実行した状態で貼付けして、最後に Ctrl-D で終了します:
  # cat - > /etc/hotplug2.d/button/01-button

■手順3 /etc/config/button を作成

サンプルをここに用意しました。
http://ranosgrant.cocolog-nifty.com/openwrt-aa-r35864/button

内容は以下:

config button 'reset_pressed'
	option button reset
	option action pressed
	option handler 'logger reset_pressed'
	
config button 'reset_released'
	option button reset
	option action released
	option handler 'logger reset_released'
	
config button 'wps_pressed'
	option button wps
	option action pressed
	option handler 'logger wps_pressed'
	
config button 'wps_released'
	option button wps
	option action released
	option handler 'logger wps_released'
	
config button 'wps_long_holding'
	option button wps
	option action released
	option handler 'logger wps_long_holding'
	option min 8
	
config button 'wps_short_holding'
	option button wps
	option action released
	option handler 'logger wps_short_holding'
	option max 1
	
config button 'wps_middle_holding'
	option button wps
	option action released
	option handler 'logger wps_middle_holding'
	option min 2
	option max 7

動作確認だけは上記でして、後は好きにいじってください。

■動作確認
logread -f コマンドを実行してボタンを押した時に、表示される文字列を確認してください。

サンプルで handler に指定している logger は引数で指定された文字列をログに書き込みをするコマンドです。このログの内容は、logread コマンドで確認できます。

logread に -f オプションを付けるとずっとログ監視し続け追加がされた行のみ表示していってくれます。

WPSボタンを押してすぐに離した場合の例:

root@OpenWrt:/# logread -f
Jan  1 01:59:06 OpenWrt user.notice root: wps_pressed
Jan  1 01:59:06 OpenWrt user.notice root: wps_released
Jan  1 01:59:06 OpenWrt user.notice root: wps_short_holding

WPSボタンを4秒押し続けて離した場合の例:

root@OpenWrt:/# logread -f
Jan  1 02:00:08 OpenWrt user.notice root: wps_pressed
Jan  1 02:00:12 OpenWrt user.notice root: wps_released
Jan  1 02:00:12 OpenWrt user.notice root: wps_middle_holding

上記の時刻の箇所を見てください。pressed から4秒後に released していることで wps_middle_holding が出力されています。

p.s.
WPSボタンを利用する場合は、押しやすいので間違えて押しても反応しないようにある程度押し続けた場合だけ処理するようにした方が良いと思います。

PLANEX MZK-WNH および MZK-W300NH2 用 OpenWrt のビルド方法

前回公開した PLANEX MZK-WNH および MZK-W300NH2 用 OpenWrt のビルド方法について書いておきます。
使用OSは、Lubuntu 12.04 Desktop (i386) です。

OpenWrt のビルドについての本家の情報は英語ですが以下にあります。
・ソースのありかに関する情報
    https://dev.openwrt.org/wiki/GetSource
・ビルド手順に関する情報
    http://wiki.openwrt.org/doc/howto/buildroot.exigence

  必要なディスクサイズは 3 ~ 4GB と書いてありますが、5GB は確保しておいてください。実測値は以下の通りで約 4.4GB 必要でした。

ビルド作業前:

$ df -k /
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       11352304 2599928   8175712  25% /

ビルド作業後(パッケージ追加の増分も含む):

$ df -k /
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       11352304 7183516   3592124  67% /

■前提条件

(1)ビルド環境
OSは、Lubuntu 12.04 Desktop (i386) を使用します。Ubuntu 12.04 Desktop でも同じだと思います。

(2)作成する対象
前回公開した PLANEX MZK-WNH および MZK-W300NH2 用の OpenWrt Attitude Adjustment 12.09 です。

(3)作業ディレクトリ
~/openwrt ディレクトリ配下で作業するものとします。
(「~」 はホームディレクトリの意味)

■手順1)必要なパッケージのインストール

$ sudo apt-get install subversion build-essential git-core libncurses5-dev
$ sudo apt-get install zlib1g-dev gawk flex quilt libssl-dev xsltproc libxml-parser-perl

■手順2) ソースの入手

$ mkdir -p ~/openwrt
$ cd ~/openwrt
$ svn co svn://svn.openwrt.org/openwrt/branches/attitude_adjustment

 ソースツリーがカレントディレクトリの attitude_adjustment ディレクトリ配下にできます。

■手順3) MKZ-WNH/MZK-W300NH2 用のパッチ適用
  私が行った MKZ-WNH/MZK-W300NH2 用の修正の変更差分を以下にパッチファイルとして1つにまとめたのでダウンロードして適用します。
  http://ranosgrant.cocolog-nifty.com/openwrt-aa-r35864/new-mzk-wnh.diff

以下のようにしてパッチを適用します:

$ cd ~/openwrt/attitude_adjustment
$ wget http://ranosgrant.cocolog-nifty.com/openwrt-aa-r35864/new-mzk-wnh.diff
$ patch -p0 < new-mzk-wnh.diff

パッチ適用時の出力結果:

$ patch -p0 < new-mzk-wnh.diff
patching file target/linux/ramips/rt305x/config-3.3
patching file target/linux/ramips/base-files/lib/ramips.sh
patching file target/linux/ramips/base-files/lib/upgrade/platform.sh
patching file target/linux/ramips/base-files/lib/preinit/06_set_iface_mac
patching file target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
patching file target/linux/ramips/base-files/etc/uci-defaults/leds
patching file target/linux/ramips/base-files/etc/uci-defaults/network
patching file target/linux/ramips/base-files/etc/diag.sh
patching file target/linux/ramips/files/arch/mips/ralink/rt305x/Makefile
patching file target/linux/ramips/files/arch/mips/ralink/rt305x/mach-mzk-wnh.c
patching file target/linux/ramips/files/arch/mips/ralink/rt305x/Kconfig
patching file target/linux/ramips/files/arch/mips/include/asm/mach-ralink/machine.h
patching file target/linux/ramips/image/Makefile

 1つだけ新規ファイルがあるので以下のようにすると新規ファイルも svn の管理対象にできます

$ cd ~/openwrt/attitude_adjustment/target/linux/ramips/files/arch/mips/ralink/rt305x
$ svn add mach-mzk-wnh.c

■手順4) make menuconfig の実行

  MZK-WNH および MZK-W300NH2 用にビルド対象を指定します。

$ cd ~/openwrt/attitude_adjustment
$ make menuconfig

実行するとメニュー画面が表示されるはずですが、必要なパッケージのインストールがされていないとメニューは表示されずにコマンドが終了します。その時は、出力されたメッセージを参考にパッケージを追加してください。

メニューが表示されたら以下の2つの項目を設定します。
 1) "Target System" の項目に、"Ralink RT288x/RT3xxx" を設定します。
  2) 次に "Subtarget" の項目に、"RT305x based boards" を設定します。

 下図の赤い線で囲った箇所が設定後の状態です。

Menuconfig

■手順5) make の実行
 単に make と打つだけでも構いませんが、それだと概略しか表示されないのでエラーがおきるとさっぱり分かりません。
  以下の様にして、最大レベルのログ出力にしつつ結果をファイルに保存することをおすすめします。

$ cd ~/openwrt/attitude_adjustment
$ make V=99 2>&1 | tee build.log

  初回はクロスコンパイル環境のソース取得も行うので、インターネットへのネットワーク接続が必須です。
  時間も非常にかかります(私の環境では回線が貧弱で5~6時間くらいかかりました)。

■ファームウェアのファイルの生成先
  以下のディレクトリにファイルができます:
    ~/openwrt/attitude_adjustment/bin/ramips/

ファイルは2つできます。
 openwrt-ramips-rt305x-mzk-wnh-squashfs-factory.bin
 openwrt-ramips-rt305x-mzk-wnh-squashfs-sysupgrade.bin

*-factory.bin が通常のファームウェアのファイルです。
*-sysupgrade.bin は、OpenWrt 同梱の sysupgrade コマンド用のファームウェアのファイルです。
ヘッダ情報やチェックサムなどファイルのフォーマットに違いがあります。

■おまけ: 変更差分の出し方

  cd ~/openwrt/attitude_adjustment
 svn diff

■パッチファイルの中身
パッチは言語に依存しないように LANG=C svn diff にて取得しました。
なお、本パッチのライセンスの扱いは OpenWrt 自体と同様に GPL v2 とします。

ブログ上だと長い行の右端が切れてしまうようですので以下からダウンロードしたファイルを見てください:

http://ranosgrant.cocolog-nifty.com/openwrt-aa-r35864/new-mzk-wnh.diff

Index: target/linux/ramips/rt305x/config-3.3
===================================================================
--- target/linux/ramips/rt305x/config-3.3 (revision 35879)
+++ target/linux/ramips/rt305x/config-3.3 (working copy)
@@ -102,6 +102,7 @@
CONFIG_RT305X_MACH_FREESTATION5=y
CONFIG_RT305X_MACH_HW550_3G=y
CONFIG_RT305X_MACH_MOFI3500_3GN=y
+CONFIG_RT305X_MACH_MZK_WNH=y
CONFIG_RT305X_MACH_NBG_419N=y
CONFIG_RT305X_MACH_NW718=y
CONFIG_RT305X_MACH_OMNI_EMB=y
Index: target/linux/ramips/base-files/lib/ramips.sh
===================================================================
--- target/linux/ramips/base-files/lib/ramips.sh (revision 35879)
+++ target/linux/ramips/base-files/lib/ramips.sh (working copy)
@@ -128,6 +128,9 @@
  *"Omnima MiniEMBWiFi")
   name="omni-emb"
   ;;
+ *"PLANEX MZK-WNH")
+  name="mzk-wnh"
+  ;;
  *"Petatel PSR-680W"*)
   name="psr-680w"
   ;;
Index: target/linux/ramips/base-files/lib/upgrade/platform.sh
===================================================================
--- target/linux/ramips/base-files/lib/upgrade/platform.sh (revision 35879)
+++ target/linux/ramips/base-files/lib/upgrade/platform.sh (working copy)
@@ -32,6 +32,7 @@
  freestation5 | \
  hw550-3g | \
  mofi3500-3gn | \
+ mzk-wnh | \
  nbg-419n | \
  nw718 | \
  omni-emb | \
Index: target/linux/ramips/base-files/lib/preinit/06_set_iface_mac
===================================================================
--- target/linux/ramips/base-files/lib/preinit/06_set_iface_mac (revision 35879)
+++ target/linux/ramips/base-files/lib/preinit/06_set_iface_mac (working copy)
@@ -9,6 +9,7 @@

  case $(ramips_board_name) in
  3g-6200n |\
+ mzk-wnh |\
  wl-330n |\
  wl-330n3g)
   mac=$(ramips_get_mac_binary factory 4)
Index: target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
===================================================================
--- target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom (revision 35879)
+++ target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom (working copy)
@@ -67,6 +67,7 @@
  freestation5 | \
  hw550-3g | \
  mofi3500-3gn | \
+ mzk-wnh | \
  pwh2004 | \
  nbg-419n | \
  nw718 | \
Index: target/linux/ramips/base-files/etc/uci-defaults/leds
===================================================================
--- target/linux/ramips/base-files/etc/uci-defaults/leds (revision 35879)
+++ target/linux/ramips/base-files/etc/uci-defaults/leds (working copy)
@@ -61,6 +61,9 @@
  mofi3500-3gn)
   set_usb_led "mofi3500-3gn:green:usb"
   ;;
+ mzk-wnh)
+  set_wifi_led "mzk-wnh:amber:wlan"
+  ;;
  nw718)
   set_usb_led "nw718:amber:usb"
   ;;
Index: target/linux/ramips/base-files/etc/uci-defaults/network
===================================================================
--- target/linux/ramips/base-files/etc/uci-defaults/network (revision 35879)
+++ target/linux/ramips/base-files/etc/uci-defaults/network (working copy)
@@ -70,6 +70,13 @@
   ucidef_add_switch_vlan "switch0" "2" "0 6t"
   ;;

+ mzk-wnh)
+  ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
+  ucidef_add_switch "switch0" "1" "1"
+  ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
+  ucidef_add_switch_vlan "switch0" "2" "4 6t"
+  ;;
+
  f5d8235-v1 | \
  f5d8235-v2 | \
  ur-336un)
@@ -142,6 +149,7 @@
  argus-atp52b | \
  bc2 | \
  f5d8235-v1 | \
+ mzk-wnh | \
  nw718 | \
  psr-680w | \
  rt-n15 | \
Index: target/linux/ramips/base-files/etc/diag.sh
===================================================================
--- target/linux/ramips/base-files/etc/diag.sh (revision 35879)
+++ target/linux/ramips/base-files/etc/diag.sh (working copy)
@@ -61,6 +61,9 @@
  mofi3500-3gn)
   status_led="mofi3500-3gn:green:status"
   ;;
+ mzk-wnh)
+  status_led="mzk-wnh:green:power"
+  ;;
  nbg-419n)
   status_led="nbg-419n:green:power"
   ;;
Index: target/linux/ramips/files/arch/mips/ralink/rt305x/Makefile
===================================================================
--- target/linux/ramips/files/arch/mips/ralink/rt305x/Makefile (revision 35879)
+++ target/linux/ramips/files/arch/mips/ralink/rt305x/Makefile (working copy)
@@ -26,6 +26,7 @@
obj-$(CONFIG_RT305X_MACH_FREESTATION5)  += mach-freestation5.o
obj-$(CONFIG_RT305X_MACH_HW550_3G) += mach-hw550-3g.o
obj-$(CONFIG_RT305X_MACH_MOFI3500_3GN) += mach-mofi3500-3gn.o
+obj-$(CONFIG_RT305X_MACH_MZK_WNH) += mach-mzk-wnh.o
obj-$(CONFIG_RT305X_MACH_NBG_419N) += mach-nbg-419n.o
obj-$(CONFIG_RT305X_MACH_NW718)  += mach-nw718.o
obj-$(CONFIG_RT305X_MACH_OMNI_EMB) += mach-omni-emb.o
Index: target/linux/ramips/files/arch/mips/ralink/rt305x/mach-mzk-wnh.c
===================================================================
--- target/linux/ramips/files/arch/mips/ralink/rt305x/mach-mzk-wnh.c (revision 0)
+++ target/linux/ramips/files/arch/mips/ralink/rt305x/mach-mzk-wnh.c (revision 0)
@@ -0,0 +1,95 @@
+/*
+ *  PLANEX MZK-WNH board support
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/ethtool.h>
+
+#include <asm/mach-ralink/machine.h>
+#include <asm/mach-ralink/dev-gpio-buttons.h>
+#include <asm/mach-ralink/dev-gpio-leds.h>
+#include <asm/mach-ralink/rt305x.h>
+#include <asm/mach-ralink/rt305x_regs.h>
+#include <asm/mach-ralink/ramips_eth_platform.h>
+
+#include "devices.h"
+
+#define MZK_WNH_GPIO_LED_POWER  9
+#define MZK_WNH_GPIO_LED_WPS  11
+#define MZK_WNH_GPIO_LED_WLAN  14
+
+#define MZK_WNH_GPIO_BUTTON_RESET 0
+#define MZK_WNH_GPIO_BUTTON_WPS  12
+#define MZK_WNH_GPIO_SWITCH  13
+
+#define MZK_WNH_KEYS_POLL_INTERVAL 20
+#define MZK_WNH_KEYS_DEBOUNCE_INTERVAL (3 * MZK_WNH_KEYS_POLL_INTERVAL)
+
+static struct gpio_led mzk_wnh_leds_gpio[] __initdata = {
+ {
+  .name  = "mzk-wnh:green:power",
+  .gpio  = MZK_WNH_GPIO_LED_POWER,
+  .active_low = 1,
+ }, {
+  .name  = "mzk-wnh:amber:wps",
+  .gpio  = MZK_WNH_GPIO_LED_WPS,
+  .active_low = 1,
+ }, {
+  .name  = "mzk-wnh:amber:wlan",
+  .gpio  = MZK_WNH_GPIO_LED_WLAN,
+  .active_low = 1,
+ }
+};
+
+static struct gpio_keys_button mzk_wnh_gpio_buttons[] __initdata = {
+ {
+  .desc  = "reset",
+  .type  = EV_KEY,
+  .code  = KEY_RESTART,
+  .debounce_interval = MZK_WNH_KEYS_DEBOUNCE_INTERVAL,
+  .gpio  = MZK_WNH_GPIO_BUTTON_RESET,
+  .active_low = 1,
+ }, {
+  .desc  = "wps",
+  .type  = EV_KEY,
+  .code  = KEY_WPS_BUTTON,
+  .debounce_interval = MZK_WNH_KEYS_DEBOUNCE_INTERVAL,
+  .gpio  = MZK_WNH_GPIO_BUTTON_WPS,
+  .active_low = 1,
+#if 0
+ }, {
+  .desc  = "switch",
+  .type  = EV_KEY,
+  .code  = BTN_1,
+  .debounce_interval = MZK_WNH_KEYS_DEBOUNCE_INTERVAL,
+  .gpio  = MZK_WNH_GPIO_SWITCH,
+  .active_low = 1,
+#endif
+ }
+};
+
+static void __init mzk_wnh_init(void)
+{
+ rt305x_register_flash(0);
+
+ rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
+
+ rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
+ rt305x_register_ethernet();
+ ramips_register_gpio_leds(-1, ARRAY_SIZE(mzk_wnh_leds_gpio),
+      mzk_wnh_leds_gpio);
+ ramips_register_gpio_buttons(-1, MZK_WNH_KEYS_POLL_INTERVAL,
+         ARRAY_SIZE(mzk_wnh_gpio_buttons),
+         mzk_wnh_gpio_buttons);
+ rt305x_register_wifi();
+ rt305x_register_wdt();
+}
+
+MIPS_MACHINE(RAMIPS_MACH_MZK_WNH, "MZK-WNH", "PLANEX MZK-WNH",
+      mzk_wnh_init);
Index: target/linux/ramips/files/arch/mips/ralink/rt305x/Kconfig
===================================================================
--- target/linux/ramips/files/arch/mips/ralink/rt305x/Kconfig (revision 35879)
+++ target/linux/ramips/files/arch/mips/ralink/rt305x/Kconfig (working copy)
@@ -104,6 +104,11 @@
  select RALINK_DEV_GPIO_BUTTONS
  select RALINK_DEV_GPIO_LEDS

+config RT305X_MACH_MZK_WNH
+ bool "PLANEX MZK-WNH support"
+ select RALINK_DEV_GPIO_BUTTONS
+ select RALINK_DEV_GPIO_LEDS
+
config RT305X_MACH_WR512_3GN
  bool "SH-WR512NU/WS-WR512N1-like 3GN router"
  select RALINK_DEV_GPIO_BUTTONS
Index: target/linux/ramips/files/arch/mips/include/asm/mach-ralink/machine.h
===================================================================
--- target/linux/ramips/files/arch/mips/include/asm/mach-ralink/machine.h (revision 35879)
+++ target/linux/ramips/files/arch/mips/include/asm/mach-ralink/machine.h (working copy)
@@ -31,6 +31,7 @@
  RAMIPS_MACH_DIR_620_A1,  /* D-Link DIR-620 A1 */
  RAMIPS_MACH_RT_G32_B1,  /* Asus RT-G32 B1 */
  RAMIPS_MACH_RT_N10_PLUS, /* Asus RT-N10+ */
+ RAMIPS_MACH_MZK_WNH,  /* PLANEX MZK-WNH */
  RAMIPS_MACH_NW718,  /* Netcore NW718 */
  RAMIPS_MACH_WL_330N,  /* Asus WL-330N */
  RAMIPS_MACH_WL_330N3G,  /* Asus WL-330N3G */
Index: target/linux/ramips/image/Makefile
===================================================================
--- target/linux/ramips/image/Makefile (revision 35879)
+++ target/linux/ramips/image/Makefile (working copy)
@@ -327,6 +327,12 @@
  $(call BuildFirmware/Generic/initramfs,$(1),$(2),$(call mkcmdline,$(3),$(4),$(5)) $(call mkmtd/$(6),$(mtdlayout_dir645a1)))
endef

+mtdlayout_mzk_wnh=192k(u-boot)ro,64k(u-boot-env)ro,64k(factory)ro,896k(kernel),2752k(rootfs),128k(Cimage)ro,3648k@0x50000(firmware)
+define BuildFirmware/MZK_WNH
+ $(call BuildFirmware/Generic,$(1),$(2),$(call mkcmdline,$(3),$(4),$(5)) $(call mkmtd/$(6),$(mtdlayout_mzk_wnh)),917484,2818048)
+ $(call BuildFirmware/Edimax,$(1),mzk-wnh,CSYS,RN52,0x50000,0x01100000)
+endef
+
define BuildFirmware/UMedia
  $(call BuildFirmware/GENERIC_8M,$(1),$(2),$(3),ttyS1,57600,phys)
  if [ -e "$(call sysupname,$(1),$(2))" ]; then \
@@ -501,6 +507,10 @@
  $(call Image/Build/Template/$(fs_squash)/$(1),GENERIC_8M,mofi3500-3gn,MOFI3500-3GN,ttyS1,57600,phys)
endef

+define Image/Build/Profile/MZK_WNH
+ $(call Image/Build/Template/$(fs_squash)/$(1),MZK_WNH,mzk-wnh,MZK-WNH,ttyS1,57600,phys)
+endef
+
define Image/Build/Profile/NBG419N
  $(call Image/Build/Template/$(fs_squash)/$(1),GENERIC_4M,nbg-419n,NBG-419N,ttyS1,57600,phys)
endef
@@ -607,6 +617,7 @@
  $(call Image/Build/Profile/FREESTATION5,$(1))
  $(call Image/Build/Profile/HW5503G,$(1))
  $(call Image/Build/Profile/MOFI35003GN,$(1))
+ $(call Image/Build/Profile/MZK_WNH,$(1))
  $(call Image/Build/Profile/NBG419N,$(1))
  $(call Image/Build/Profile/NW718,$(1))
  $(call Image/Build/Profile/OMNIEMB,$(1))

2013年3月 9日 (土)

PLANEX MZK-WNH と MZK-W300NH2 用 OpenWrt 12.09 ファームウェア(Attitude Adjustment, r35864)をアップロードしました

[2015/05/10 追記: opkg コマンドの注意を追記しました]

PLANEX MZK-WNH と MZK-W300NH2 用に OpenWrt 12.09 のファームを作ったので公開しておきます。開発用の最新である trunk ブランチではなく attitude_adjustment のブランチのソースから作成しています。
/etc/banner によると以下のバージョンになります:
  ATTITUDE ADJUSTMENT (Attitude Adjustment, r35864)
ソースツリーで、svn info でみると
  Revision: 35879
  Last Changed Rev: 35864
でした。

Attitude Adjustment は、現時点で RC1(リリース候補1)であり正式リリースはされていないですが、OpenWrt のサイトにはコンパイル済のパッケージがおいてあり利用できます:
  http://downloads.openwrt.org/attitude_adjustment/12.09-rc1/ramips/rt305x/packages/
といっても、容量の少ないフラッシュメモリですからあれこれと入れるわけにはいきませんが。

今回は、OpenFlow 1.0 用のカスタマイズはしていません。
MZK-WNH/MZK-W300NH2 用のカスタマイズ以外はしていない純粋に OpenWrt のままのファームです。ただし、今回は、LED とボタンが扱えるようにしてあります。

ちなみに、数日前に秋葉原を歩き回ってみたら、Tsukumo12号店で MZK-W300NH2 が開封済という扱いとはいえ箱で売っていたり、あきばお~伍號店(5号店)で MZK-WNH のジャンクがまだ大量に積んであったりと、まだまだ入手可能な状態でした。

おことわり: ここで公開したファームを入れようとしたことで二度と起動しなくなる可能性があります。リスクを承知の上でお使いください。

■ MZK-WNH および MZK-W300Nh2 用の OpenWrt のイメージファイル

このブログで使っている ココログでは1ファイルのサイズ上限が 1Mバイトとのことで、面倒ですが3つに分割して置いてあります:
  concat.bat     image1.bin    image2.bin    image3.bin

3つの image*.bin ファイルを結合して1つのファイルにしてください。 Windows 用にバッチファイル concat.bat を用意しました。このバッチファイルを実行すると  openwrt-ramips-rt305x-mzk-wnh-squashfs-factory.bin というファイルができます。
  UNIX/Linux なら、cat image1.bin image2.bin image3.bin > openwrt-ramips-rt305x-mzk-wnh-squashfs-factory.bin でできあがり。
もし、ファイルが壊れていたらファームの入替え時にファイルのフォーマット不正か、チェックサムのエラーではじかれます。

■ファームの入れ替え方

通常の MZK-WNH および MZK-W300NH2 のファームの入替えの方法で入れ替えてください。

ファーム入替え手順は以下の通り(URLはプラネックス社のサイトへのリンクです)
(1) MZK-WNH の場合
手順1) 管理画面を開く
    スイッチをRouter側にしている場合, 「1」~「4」ポートにて192.168.1.1 でつながります。
      http://www.planex.co.jp/support/download/router/mzk-wnh/v31/html/menu-4-0.html
手順2) ファームを指定し入れ替える
       http://www.planex.co.jp/support/download/router/mzk-wnh/v31/html/menu-4-30.html

(2) MZK-W300NH2 の場合
手順1) 管理画面を開く
    スイッチをRouter側にしている場合, 「1」~「4」ポートにて192.168.111.1 でつながります。
  http://www.planex.co.jp/support/download/router/mzk-w300nh2/v2/html/menu-4-0.html
手順2) ファームを指定し入れ替える
    http://www.planex.co.jp/support/download/router/mzk-w300nh2/v2/html/menu-4-30.html

インジケータが100%に近くなると「Power」ランプが点滅し出すのですが、この点滅がとまったころに、OpenWrt が起動しています。
正常に起動できていれば、「1」~「4」のポートにつなげば IP アドレス 192.168.1.1 に telnet でパスワードなしで OpenWrt にログインできます。

もし、失敗して通常の起動もしなくなりどうしようもなくなったら、以前の記事 「MZK-WNH を純正ファームに戻す方法(シリアル接続不要)」を参考に純正ファームに戻してください。MZK-W300NH2 でも同じ方法が使えます。

純正ファームは以下から入手できます。
 MZK-WNH の純正ファーム:
  http://www.planex.co.jp/support/download/router/mzk-wnh.shtml
 MZK-W300NH2 の純正ファーム:
  http://www.planex.co.jp/support/download/router/mzk-w300nh2.shtml

■ファームの入れ替え方、つづき

ゴミが残って悪さすることがあるのでフラッシュメモリ内の rootfs_data 領域をクリアします。
OpenWrtへ ログイン後、以下を1回だけ実行してください:

 # mtd -r erase rootfs_data

実行すると以下のように「Rebooting...」が最後に出力されます。

 root@OpenWrt:/# mtd -r erase rootfs_data
 Unlocking rootfs_data ...
 Erasing rootfs_data ...
 Rebooting ...

この「Rebooting...」が表示されるとリブートが開始し「Power」ランプの点滅が始まります。点滅が終わり点灯状態になったら再度、telnet でログインして接続できることを確認してください。

以上で、ファームの入替え完了です。

■セキュリティについて

 最初はパスワードなしで root ユーザでログインできてしまいますが、passwd コマンドで root ユーザのパスワードを設定することができます。
  パスワード設定後は、telnet ではログインできなくなり、ssh を使う必要があります。
  Windows で SSH が使えるフリーソフトとしては TeraTerm が有名です。

■ OpenWrtについて

以下、OpenWrt の一般的なこと、今回のファーム固有のことなどを書いてます。

□ OpenWrt のドキュメント

公式サイト:
  http://wiki.openwrt.org/doc/start

右側の「Translations」という囲みに日の丸の国旗のアイコンがついたリンクがあれば翻訳版を読むことができますが、ほとんど翻訳はされていないと思った方が良いです。

□設定ファイル
  /etc/config ディレクトリ配下にあります。

  OpenWrt ではここの設定ファイルの書式を統一しています。
 uci というコマンドで読み書きできる仕掛けをもっています。
  詳しくは以下を読んでください(英語です):
   http://wiki.openwrt.org/doc/uci

□ネットワーク構成
  OpenWrt ではポートを、wan ポート、lan ポートと2種類に分けています。
  wan ポートには、ファイアウォールが設けらています。
  /etc/config/firewall ファイルや、コマンドで iptables --list を実行して確認してみてください。

 wan ポート
 物理的には、MZK-WNH および MZK-W300NH2 にて「Internet」の表示がしてあるポート。
  /etc/config/network ファイルにて config interface 'wan' と書いてあるところがこのポートの定義です。
 固定 IP は設定されておらず、dhcp で取得します。

 lan ポート
  物理的には、MZK-WNH および MZK-W300NH2 にて「1」~「4」の表示してあるポート。
  この4つはハブを構成していてつながっています。

 このポートからは DHCP で IP アドレスを取得できます。

  また、このハブを通して、OpenWrt にログインできます。
  IP アドレスは 192.168.1.1 です。
  IP アドレスを変更するには /etc/config/network ファイルを書き換えてください。
 書き換えを有効にするにはリブートするか、以下を実行します:
    # /etc/init.d/network restart

  /etc/config/network ファイルの詳細は以下を参照ください(英語です):
    http://wiki.openwrt.org/doc/uci/network

  /etc/config/firewall ファイルの詳細は以下を参照ください(英語です):
    http://wiki.openwrt.org/doc/uci/firewall

□LED

MZK-WNH, MZK-W300NH2 が持つ LED は以下の名前で点灯/消灯できます。

「Wireless」の表示がある LED
    mzk-wnh:amber:wlan
「WPS」の表示がある LED
    mzk-wnh:amber:wps
「Power」の表示がある LED
    mzk-wnh:green:power

使用例
点灯:

   # echo 255 > /sys/class/leds/mzk-wnh:amber:wlan/brightness

消灯:

   # echo 0 > /sys/class/leds/mzk-wnh:amber:wlan/brightness

□ボタン

MZK-WNH, MZK-W300NH2 が持つボタンは以下の名前のボタンとして押した(pressed)/離した(released)を検出できます。

「Reset」の表示があるボタン
    reset
「WPS」の表示があるボタン
    wps

使い方は以下を読んでください(英語です)。
  http://wiki.openwrt.org/doc/howto/hardware.button
  http://wiki.openwrt.org/doc/techref/hotplug

[2013/03/10 追記: ボタンを扱う仕掛けを用意しました。
記事「PLANEX MZK-WNH//MZK-W300NH2 用 OpenWrt にボタンの仕掛けを追加」 を参照ください。 ]

リセットボタンを押したら /etc/config 配下を正常時のバックアップから戻すとか、いっそのこと以下を実行してファームを入れた当初の状態に完全に戻すなどといった使い方ができます。
  mtd -r erase rootfs_data

□スイッチ

MZK-WNH および MZK-W300NH2 には、「Router」と「AP」を切り替えるスイッチがあります。
どちらになっているかは以下のようにして生で GPIO をアクセスしてください。

 # echo 13 > /sys/class/gpio/export
# echo in > /sys/class/gpio/gpio13/direction

/sys/class/gpio/export に使いたい GPIO の番号を書き込むと /sys/class/gpio/gpio番号 というディレクトリが作成される仕組みです。
  値は value ファイルを読み出すと取り出せます:

スイッチをRouter側にしている時:

    root@OpenWrt:/# cat /sys/class/gpio/gpio13/value
    0

スイッチをAP側にしている時:

    root@OpenWrt:/# cat /sys/class/gpio/gpio13/value
    1

リブートすると /sys/class/gpio/gpio13 が消えてしまうので /etc/rc.local ファイルの exit 0 の行の前に以下を書いておくとブート時に自動で実行してくれるので便利です。

  echo 13 > /sys/class/gpio/export
  echo in > /sys/class/gpio/gpio13/direction

  GPIO の扱いの詳細は、以下の中の「Paths in Sysfs」の箇所に書いてあります:
    https://www.kernel.org/doc/Documentation/gpio.txt

□パッケージ
  opkg コマンドで管理しています。

  インストール済一覧:
    opkg list
  インストール:
    opkg install パッケージのファイル名

  詳しくは以下を参照ください(英語です)
  http://wiki.openwrt.org/doc/techref/opkg

[2015/05/10追記:
注意: opkg install コマンドにはパッケージ名を指定する方法もありますがどんな環境でも使えるわけではないので、 パッケージの ipk ファイルを以下からダウンロードして /tmp あたりに置いておき ipkファイル名を指定する方法を用いてください:
http://downloads.openwrt.org/attitude_adjustment/12.09/ramips/rt305x/packages/

]

□ファイルシステム

ファームで書き込んだファイルシステムは読込専用のままで、overlayfs というファイルシステムによって /overlay というディレクトリ配下に変更点が書き込まれる仕掛けになっています。
LiveCD と似たような感じです。OpenWrt では /overlay はフラッシュメモリにあるのでリブート後でも変更点は残ります。

root@OpenWrt:~# mount
rootfs on / type rootfs (rw)
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,noatime)
sysfs on /sys type sysfs (rw,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,size=6876k)
tmpfs on /dev type tmpfs (rw,noatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,noatime,mode=600)
/dev/mtdblock5 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlayfs (rw,noatime,lowerdir=/,upperdir=/overlay)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
none on /proc/bus/usb type usbfs (rw,relatime)

では、/overlay とはなにかというとフラッシュメモリ上のパーティション5 になります。

root@OpenWrt:/proc# df /overlay
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mtdblock5            1344       392       952  29% /overlay

フラッシュメモリのパーティション構成は以下:

root@OpenWrt:/proc# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00030000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00010000 00010000 "factory"
mtd3: 000e0000 00010000 "kernel"
mtd4: 002b0000 00010000 "rootfs"
mtd5: 00150000 00010000 "rootfs_data"
mtd6: 00020000 00010000 "Cimage"
mtd7: 00390000 00010000 "firmware"

以下のコマンドを実行すると変更を綺麗さっぱり忘れてファームを入れた当初に戻ります:
mtd -r erase rootfs_data

■おまけ
□他のマシンとのデータ交換
 OpenWrt に標準で入ってるコマンドだけだと苦労します...。
[ 2013/3/11 追記: 標準で scp コマンドが入っていることに気がつきました。SSH Server を用意すれば SSH Server と簡単にファイル交換できるようになります。 lubuntu なら、sudo apt-get install openssh-server で SSH Server が入ります。 ]

1) ファイルを取得:
    wget コマンドぐらいしかなさそう。
    http か ftp 経由で取得する。

    ftp 経由の形式:
      wget ftp://ユーザ名:パスワード@IPアドレス/パス名

2) ファイルを他のマシンに持っていくには:
    トリッキーな感じですが nc コマンドが使えます。

  例: 192.168.1.2 の TCP ポート 50000 へファイルを送る
    受け取り側(nc コマンドが使えることを前提にしてます):
      nc -l 50000 > ファイル名
  OpenWrt側:
      nc 192.168.1.2 50000 < 送りたいファイル名

  OpenWrt に入っている nc は BusyBox により提供されていて機能が制限されおり -l が使えません。つまり、サーバ側にはなれません。

□インストール後の状態
(特に記載していないところは MZK-WNH で採取)

1) メモリ
top コマンドより
Mem: 12832K used, 916K free, 0K shrd, 1100K buff, 3044K cached

1MBも残ってません...。
あとで確認したように tmpfs を大きくとっているためで大丈夫そう。

root@OpenWrt:/# cat /proc/swaps
Filename         Type            Size    Used    Priority

スワップは、なし。

2) ディスク
残り 1M ぐらい。

root@OpenWrt:/# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
rootfs                    1344       224      1120  17% /
/dev/root                 1536      1536         0 100% /rom
tmpfs                     6876        56      6820   1% /tmp
tmpfs                      512         0       512   0% /dev
/dev/mtdblock5            1344       224      1120  17% /overlay
overlayfs:/overlay        1344       224      1120  17% /
root@OpenWrt:/lib/preinit# cat /etc/mtab
rootfs / rootfs rw 0 0
/dev/root /rom squashfs ro,relatime 0 0
proc /proc proc rw,noatime 0 0
sysfs /sys sysfs rw,noatime 0 0
tmpfs /tmp tmpfs rw,nosuid,nodev,noatime,size=6876k 0 0
tmpfs /dev tmpfs rw,noatime,size=512k,mode=755 0 0
devpts /dev/pts devpts rw,noatime,mode=600 0 0
/dev/mtdblock5 /overlay jffs2 rw,noatime 0 0
overlayfs:/overlay / overlayfs rw,noatime,lowerdir=/,upperdir=/overlay 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
none /proc/bus/usb usbfs rw,relatime 0 0

tmpfs で /tmp が 6876k もとっています。

3) CPU
BogoMIPS が 212 しかない...。 MZK-W300NH2 だと 255 で少し性能が良い。

MZK-WNHだと

root@OpenWrt:/# cat /proc/cpuinfo
system type             : Ralink RT3052 id:1 rev:2
machine                 : PLANEX MZK-WNH
processor               : 0
cpu model               : MIPS 24KEc V4.12
BogoMIPS                : 212.58
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0000, 0x0ff8, 0x0ff8, 0x0ff8]
ASEs implemented        : mips16 dsp
shadow register sets    : 1
kscratch registers      : 0
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available

MZK-W300NH2だと

root@OpenWrt:/# cat /proc/cpuinfo
system type             : Ralink RT3052 id:1 rev:3
machine                 : PLANEX MZK-WNH
processor               : 0
cpu model               : MIPS 24KEc V4.12
BogoMIPS                : 255.59
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0000, 0x0900, 0x0a20, 0x0eb0]
ASEs implemented        : mips16 dsp
shadow register sets    : 1
kscratch registers      : 0
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available

2012年11月 5日 (月)

【OpenWRT with OpenFlow 1.0 プログラミング】ブリッジを作る

【OpenWRT with OpenFlow 1.0 プログラミング】というタイトルほど大げさではないですが先日公開した MZK-WNH のファームで OpenFlow を使ったブリッジのプログラミングをしてみます。

OpenFlow コントローラなしでお手軽プログラミング。
■手順:
1) 対象の OpenWRT with OpenFlow 1.0 にtelnet でログイン。
2) 以下を実行

dpctl del-flows unix:/var/run/dp0.sock
dpctl add-flow unix:/var/run/dp0.sock idle_timeout=0, hard_timeout=0,actions=FLOOD

できあがりです。
■解説
1行目は全フローエントリを削除する del-flows を実行しています。電源投入後なら不要ですが念のため。
2行目は、どのようなパケットが入ってきても FLOOD 機能で転送するというものです。パケットが入ってきたポート以外のポートにパケットを出力するという便利な機能です。
「FLOOD」は、OpenFlow 1.0 の規格ではオプション扱いで必須機能ではないですが、先日公開したファームの OpenWRT with OpenFlow 1.0 ではサポートされています。
■注意
設定は OpenFlow のプロセスが生きている間のみ有効です。リブートしたり、電源切ったらやり直しです。
■参照
OpenFlow 1.0 の FLOOD の記載については
 P.6
にあります。
以下、抜粋
Optional Action: Forward. The switch may optionally support the following
virtual ports:
  略
  FLOOD: Flood the packet along the minimum spanning tree, not includ-
  ing the incoming interface.
■雑感
最近はどんなに安いものでもL2スイッチが当たり前になってしまい全ポートにパケットをばらまくことはしなくなり、パケットキャプチャをするためにはミラーポートの機能が必要になってきています。
ここで作ったブリッジであれば各ポートにパケットをばらまくのでどのポートからでもキャプチャできます(のはずです...)

2012年10月31日 (水)

OpenWRT with OpenFlow 1.0 性能比較

OpenWRT with OpenFlow 1.0 で2台の Linux を 100Mイーサでつなぎ iperf コマンドで速度を測定してみました。

UDP のテストでは -b 100000000 をつけて 100Mbps として送信しています。

比較として Baffalo WHR-G300N にも参戦していただきました。こちらは、 http://openflow.inthebox.info/ で公開されている OpenFlow 1.0 のイメージを使わせてもらいました。

結果:

  Planex MZK-WNH: 約 10Mbps

  Planex MZK-W300NH2: 約 20Mbps

  Baffalo WHR-G300N: 約40Mbps

top コマンドで CPU 使用率を見ていると 30% くらいなので何が悪いんでしょうね...。

■ MZK-WNH

UDP 

$ iperf -c 10.0.0.101 -u -b 100000000
------------------------------------------------------------
Client connecting to 10.0.0.101, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  160 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.100 port 45558 connected with 10.0.0.101 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   114 MBytes  95.8 Mbits/sec
[  3] Sent 81451 datagrams
[  3] Server Report:
[  3]  0.0-10.3 sec  13.7 MBytes 
11.2 Mbits/sec  14.903 ms 71681/81449 (88%)
[  3]  0.0-10.3 sec  1 datagrams received out-of-order

TCP

$ iperf -c 10.0.0.101 
------------------------------------------------------------
Client connecting to 10.0.0.101, TCP port 5001
TCP window size: 21.0 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.100 port 54097 connected with 10.0.0.101 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.1 sec  17.2 MBytes 
14.3 Mbits/sec

 

■ MZK-W300NH2

UDP

$ iperf -c 10.0.0.101 -u -b 100000000
------------------------------------------------------------
Client connecting to 10.0.0.101, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  160 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.100 port 58068 connected with 10.0.0.101 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   114 MBytes  95.7 Mbits/sec
[  3] Sent 81415 datagrams
[  3] Server Report:
[  3]  0.0-10.3 sec  24.8 MBytes 
20.3 Mbits/sec  15.116 ms 63720/81413 (78%)
[  3]  0.0-10.3 sec  3 datagrams received out-of-order

 TCP

$ iperf -c 10.0.0.101 
------------------------------------------------------------
Client connecting to 10.0.0.101, TCP port 5001
TCP window size: 21.0 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.100 port 54095 connected with 10.0.0.101 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.1 sec  26.9 MBytes 
22.4 Mbits/sec

■ WHR-G300N

UDP

$ iperf -c 10.0.0.101 -u -b 100000000
------------------------------------------------------------
Client connecting to 10.0.0.101, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  160 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.100 port 53927 connected with 10.0.0.101 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   115 MBytes  96.3 Mbits/sec
[  3] Sent 81917 datagrams
[  3] Server Report:
[  3]  0.0-10.0 sec  50.2 MBytes 
42.0 Mbits/sec   0.082 ms 46139/81915 (56%)
[  3]  0.0-10.0 sec  1 datagrams received out-of-order

TCP

$ iperf -c 10.0.0.101 
------------------------------------------------------------
Client connecting to 10.0.0.101, TCP port 5001
TCP window size: 21.0 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.100 port 54093 connected with 10.0.0.101 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  51.4 MBytes 
42.9 Mbits/sec

 

最近のトラックバック

無料ブログはココログ