将openwrt移植到P720

来源:互联网 发布:java培训班包住 编辑:程序博客网 时间:2024/05/18 02:29

将openwrt移植到P720

早年写的笔记,压箱底了,翻出来晒晒


目          录

将openwrt移植到P720.1

实验环境...1

配置,编译openwrt支持普通IXP路由器...2

烧录oepnwrt到普通路由器...3

配置,编译openwrt支持P720.4

修改内核串口支持...4

修改以太网驱动...5

修改root文件系统...6

烧录oepnwrt到P720.7

配置P720上的openwrt7

启动P720以太网...8

启动无线网卡...8

升级xwrt9

移植的摸索过程...11

解压squashfs12

重新制作suqashfs12

检查启动文件...17

分析修改preinit18

检查inittab和rcS.19

管道的问题...20

jeffs的问题...20

试验wrv54g.21

redboot的支持问题...22

配置以太网...22

多出的配置分区...23

 

实验环境

u  P720,使用串口1.

u  FC6

u  kamikaze_8.09.1_source.tar.bz2

u  redboot2.04

       当Linksys 释放 WRT54G/GS 的源码后,网上出现了很多不同版本的 Firmware 去增强原有的功能。OpenWrt 的历史OpenWrt 项目由 2004 年 1 月开始, 第一个版本是基于 Linksys 提供的 GPL 源码及 uclibc 中的 buildroot 项目。到了2005年初释出了第一个 “experimental” 版本, 这版本差不多完全舍弃了 Linksys 的 GPL 源码, 使用了 buildroot2 作为核心技术, 将 OpenWrt 完全模块化。

       openwrt的网站上有许多编译好的firmware,需要对照着要更新的路由器的信号选择对应的信号。

目前最新版本的openwrt代码是kamikaze_8.09.1_source.tar.bz2,可以在http://openwrt.org/下载。因为openwrt目前并不支持P720,所以需要重新编译,做一些简单的修改。

 

配置,编译openwrt支持普通IXP路由器

       这里的一般IXP路由器指的是openwrt网站上列出的已经经过测试能支持的使用IXP系列CPU的路由器。

下载的kamikaze_8.09.1_source.tar.bz2原始文件只有大约6.2M,这个显然不是全部的代码,不过剩余的东西并不需要人工再去慢慢准备,编译的过程openwrt会自动下载需要的文件。解压到kamikaze_8.09.1_source.tar.bz2 到/home/linuxuser/openwrt/kamikaze_8.09

执行如下命令:

#cd/home/linuxuser/openwrt/kamikaze_8.09

#make menuconfig

 

 

注意选择一下几样:

1.     Target System选择Intel IXP4xx [2.6]

2.     Target Images选择squashfs,这也是默认的选择。如果选择熟悉的ramdisk,openwrt并不能编译出zImage和ramdisk,而是编译出一个大的zImage。这样就无法修改一些关键的配置文件导致无法成功移植。而且就算是支持一般的路由器日常使用,也是使用squashfs支持更好。

3.     下面4个选项:

Advanced configuration options (for developers)

Build the OpenWrt Image Builder

Build the OpenWrt SDK

Image configuration

       如果需要进行深入分析配置,那么点上就可以,这对移植没有影响。

配置完成以后,执行。

#make V=99

系统将会自动下载各种文件,在/home/linuxuser/openwrt/kamikaze_8.09/bin下生成openwrt-ixp4xx-zImage和openwrt-ixp4xx-squashfs.img。这个两个文件已经足够支持openwrt网站上列出的已经经过测试能支持的路由器。

烧录oepnwrt到普通路由器

烧录openwrt到路由器的方法。在这里,假设P720的redboot已经烧录好了。在此注意,1.94版本的redboot是不能正常启动openwrt的,必须是2.04版本。

       在fc6下面执行

cp bin/openwrt-ixp4xx-zImage /tftpboot/zImage

cp bin/openwrt-ixp4xx-squashfs.img /tftpboot/rootfs

注意启动FC6上的tftp服务。在这里,假设FC6的IP地址是192.168.1.99, P720的redboot配置IP在同一网段。

用串口连接上P720,在redboot操作符下执行如下命令:

fis init

load -r -b 0x1800000 -h 192.168.1.99 zImage

fis create zImage

load -r -b 0x1800000 -h 192.168.1.99 rootfs

fis create rootfs

fis load zImage

exec

这样P720就能够正常启动openwrt了。需要每次都自动启动openwrt的话,需要在redboot里执行fconfig,编译及启动脚本为

fis load zImage

exec

就可以了。样例如下:

 

RedBoot> fconfig

Run script at boot: true

Boot script:

Enter script, terminate with empty line

>> fis load zImage

>> exec

>>

Boot script timeout (1000ms resolution): 1

Use BOOTP for network configuration: false

Gateway IP address: 10.0.0.1

Local IP address: 10.0.0.204

Local IP address mask: 255.255.255.0

Default server IP address: 10.0.0.110

Console baud rate: 115200

GDB connection port: 9000

Force console for special debug messages: false

Network debug at boot time: false

Default network device: npe_eth0

Update RedBoot non-volatile configuration - continue(y/n)? y

 

配置,编译openwrt支持P720

       P720和普通的路由器有两个地方不同:

1.     普通的IXP路由器使用的是串口0,而P720使用的是串口1

2.     普通的IXP路由器以太网卡使用的PHY芯片的PHY id一般从0开始,而P720使用的是从1开始

 

在编译完普通路由器的基础上做一些简单修改就可以支持P720。现在假设已经执行完普通路由器的编译工作,还需要进行下面两个步骤。

修改内核串口支持

执行下面两条命令

#cd /home/linuxuser/openwrt/kamikaze_8.09

# make kernel_menuconfig

       在Boot options里修改启动命令

将console=ttyS0修改为console=ttyS1,然后保存设置。

 

修改以太网驱动

打开kamikaze_8.09/build_dir/linux-ixp4xx_generic\linux-2.6.26.8\drivers\net\arm\Ixp4xx_eth.c,找到下面几句,添加红色部分

    switch (port->id) {

    case IXP4XX_ETH_NPEA:

        port->regs = (struct eth_regs __iomem*)IXP4XX_EthA_BASE_VIRT;

        regs_phys  = IXP4XX_EthA_BASE_PHYS;

        break;

    case IXP4XX_ETH_NPEB:

        port->regs = (struct eth_regs __iomem*)IXP4XX_EthB_BASE_VIRT;

        regs_phys  = IXP4XX_EthB_BASE_PHYS;

    /*this is for P720 phy*/

        plat->phy = 1;

    printk(KERN_INFO "change npe-b phy to 1for P720");

        break;

    case IXP4XX_ETH_NPEC:

        port->regs = (struct eth_regs __iomem*)IXP4XX_EthC_BASE_VIRT;

        regs_phys  = IXP4XX_EthC_BASE_PHYS;

    plat->phy = 2;

    printk(KERN_INFO "change npe-c phy to 2for P720");

        break;

    default:

        err = -ENOSYS;

        goto err_free;

    }

 

 

修改root文件系统

修改完成以后,执行编译,得到openwrt-ixp4xx-zImage和openwrt-ixp4xx-squashfs.img。其中openwrt-ixp4xx-squashfs.img就是root文件系统,是采用lzma算法压缩成的squashfs格式。修改前需要先进行解压。

在kamikaze_8.09/build_dir/host/squashfs3.0/squashfs-tools下找到mksquashfs-lzma和unsquashfs-lzma两个文件,复制到/home/linuxuser/squashfs/squash10下。

将openwrt-ixp4xx-squashfs.img也复制到/home/linuxuser/squashfs/squash10下。执行如下操作解压:

#cd /home/linuxuser/squashfs/squash10

#./unsquashfs-lzmaopenwrt-ixp4xx-squashfs

 

解压后,得到squashfs-root文件夹,里面就是root文件系统的内容。打开squashfs-root/etc/inittab文件,原始内容如下:

::sysinit:/etc/init.d/rcSS boot

::shutdown:/etc/init.d/rcSK stop

tts/0::askfirst:/bin/ash--login

ttyS0::askfirst:/bin/ash--login

tty1::askfirst:/bin/ash–login

 

将tts/0和ttyS0修改为tts/1和ttyS1,修改完如下:

::sysinit:/etc/init.d/rcSS boot

::shutdown:/etc/init.d/rcSK stop

tts/1::askfirst:/bin/ash--login

ttyS1::askfirst:/bin/ash--login

tty1::askfirst:/bin/ash–login

 

修改完之后,执行如下操作:

./mksquashfs-lzma./squashfs-root root.squashfs -nopad -noappend -root-owned -be

ddif=root.squashfs of=tmpfile.1 bs=64k conv=sync

echo -ne'\xde\xad\xc0\xde' >> tmpfile.1

ddof=root.squashfs if=tmpfile.1 bs=64k conv=sync

echo -ne'\xde\xad\xc0\xde' >> root.squashfs

ddif=root.squashfs of=openwrt-ixp4xx-squashfs.img bs=131072 conv=sync

cp -rfopenwrt-ixp4xx-squashfs.img /tftpboot/rootfs

这样在/tftpboot文件夹下有了rootfs文件。

 

烧录oepnwrt到P720

复制openwrt-ixp4xx-zImage到/tftpboot,通过串口在P720的的redboot提示符下执行如下命令:

fis init

load -r -v -b 0x00800000 rootfs

fis create -b 0x00800000 -l 0x300000 -f 0x50180000 -e0x00800000 -r 0x00800000 rootfs

load -r -v -b 0x01600000 openwrt-ixp4xx-zImage

fis create -b 0x01600000 -l 0x100000 -f 0x50080000 -e0x01600000 -r 0x01600000 zImage

 

配置P720上的openwrt

第一次启动openwrt会很慢,因为openwrt要对flash进行一些操作。启动之后,因为openwrt的原始配置里面并没有支持P720,所以网卡和atheros无线网卡都不能正常启动,需要进行一些修改。

正常启动之后,显示如下:

BusyBox v1.11.2(2009-09-13 01:01:39 CST) 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

 KAMIKAZE (8.09.1,unknown) ----------------------------

  * 10 oz Vodka       Shake well with ice and strain

  * 10 oz Triple sec  mixture into 10 shot glasses.

  * 10 oz lime juice  Salute!

 ---------------------------------------------------

root@(none):/#

 

启动P720以太网

在提示符下执行

vi/etc/config/network

将内容修改为如下:

 

 

config'interface' 'loopback'

        option 'ifname' 'lo'

        option 'proto' 'static'

        option 'ipaddr' '127.0.0.1'

        option 'netmask' '255.0.0.0'

 

config'interface' 'lan'

        option 'ifname' 'eth0'

        option 'macaddr' '00:00:AA:BB:CC:D1'

        option 'proto' 'static'

        option 'netmask' '255.255.255.0'

        option 'dns' '202.106.46.151'

        option 'gateway' '10.0.0.1'

        option 'ipaddr' '10.0.0.204'

 

执行/etc/init.d/networkrestart,试试以太网,应该已经通了。

 

启动无线网卡

在提示符下执行vi /etc/config/wireless,将option disabled 1:这句话屏蔽,修改完内容如下:

 

config wifi-device wifi0

        optiontype     atheros

        optionchannel  auto

 

        #REMOVE THIS LINE TO ENABLE WIFI:

        #option disabled 1

 

config wifi-iface

        optiondevice   wifi0

        optionnetwork  lan

        optionmode     ap

        optionssid     OpenWrt

        optionencryption none

 

保存。执行/etc/init.d/network restart重启网络,这个时候应该就可以通过笔记本的无线网卡找到叫做“OpenWrt”的无线网络,这时候就可以进行无线连接了。

       更详细复杂的配置请参看其他设置文档。

在openwrt中也支持wlanconfig和iwconfig,也可以用下面的命令启动无线网卡;

wlanconfig athcreate wlandev wifi0 wlanmode ap

iwconfig ath0channel 6

iwconfig ath0essid "wrv54gopen"

ifconfig ath0 10.0.0.205up

 

升级xwrt

       xwrt是openwrt的web界面,但是目前有许多东西是不能正确设置的,用处不是太大。在此简单介绍加入xwrt的方法。

在串口的openwrt提示符下执行如下命令:

echo "srcX-Wrt http://downloads.x-wrt.org/xwrt/kamikaze/8.09/ixp4xx/packages/">> /etc/opkg.conf

opkg update

opkgremove -recursive luci-*

opkgupdate

opkg installwebif

 

如果发现Could not obtain administrative lock错误并且不能升级,则等等jffs刷写完成再说。这个需要的时间比较长。

 

升级时候的打印信息如下:

root@OpenWrt:/#opkg update

Downloadinghttp://downloads.openwrt.org/kamikaze/8.09.1/ixp4xx/packages/Packages.gz

Connecting todownloads.openwrt.org (78.24.191.177:80)

Packages.gz          100%|*******************************|   142k00:00:00 ETA

Inflatinghttp://downloads.openwrt.org/kamikaze/8.09.1/ixp4xx/packages/Packages.gz

Updated list ofavailable packages in /var/opkg-lists/snapshots

Downloadinghttp://downloads.x-wrt.org/xwrt/kamikaze/8.09/ixp4xx/packages//Packages

Connecting todownloads.x-wrt.org (88.198.39.176:80)

Packages             100%|*******************************| 63377 00:00:00 ETA

Updated list ofavailable packages in /var/opkg-lists/X-Wrt

 

root@OpenWrt:/#opkg install webif

Installing webif(0.3-4709) to root...

Downloadinghttp://downloads.x-wrt.org/xwrt/kamikaze/8.09/ixp4xx/packages//./webif_0.3-4709_armeb.ipk

Connecting todownloads.x-wrt.org (88.198.39.176:80)

webif_0.3-4709_armeb100% |*******************************|  165k 00:00:00 ETA

Installinghaserl (0.9.24-1) to root...

Downloadinghttp://downloads.x-wrt.org/xwrt/kamikaze/8.09/ixp4xx/packages//./haserl_0.9.24-1_armeb.ipk

Connecting todownloads.x-wrt.org (88.198.39.176:80)

haserl_0.9.24-1_arme100% |*******************************| 10147 00:00:00 ETA

 

Configuringhaserl

Configuringwebif

Collectederrors:

 * Could not obtain administrative lock

Committing newfirmware id ...

Device: Generic

Committing newdevice id ...

SUCCESS! Webif^2installation appears OK. Welcome to X-Wrt!

You may need todo a hard REFRESH to clear old CSS style from your browser.

Reinitializinghttpd ...

root@OpenWrt:/#

 

执行完之后系统会自动安装上webif。这时在浏览器输入10.0.0.204,就可以看到xwrt。首先是设置密码:

 

 

移植的摸索过程

       一开始按照说明比较容易的就编译好了openwrt,配置target image是ramdisk,因为不想破坏目前flash的状态。结果很容易openwrt就在wrv54g上跑起来。而wrv54g就是openwrt支持的硬件列表上有的路由器。

解压squashfs

       然后使用make kernel_menuconfig将console=ttyS0修改为console=ttyS1,这样已经可以启动P720,但是不能够进入控制台,进入到命令行下。没有办法之后将targetimage该为squashfs以方便再次修改。开始安装squashfs-tools-3.0-4.i386.rpm,安装完成之后解压openwrt-ixp4xx-squashfs.img,但是报错,无法解压。

       查找官方网站http://www.squashfs-lzma.org/,上面所需要linux kernel 2.6.27or higher才能支持squashfs,似乎FC6不能解决这个问题。但是目前并不是要挂载squashfs,而是希望解压。FC6有squashfs-tools,就算内核无法支持,无法mount,但是没理由不能作为应用程序解压文件内容。另外网站上提到一种lzma的东西。

目前的错误信息是

FATAL ERROR aborting:uncompress_inode_table: failed to read block

zlib::uncompress failed, unknown error -3

FATAL ERROR aborting:uncompress_inode_table: failed to read block

zlib::uncompress failed, unknown error -3

FATAL ERROR aborting:uncompress_inode_table: failed to read block

zlib::uncompress failed, unknown error -3

根据下载的http://www.squashfs-lzma.org/上的squashfs3.4.tar.gz,解压之后在squashfs3.4/squashfs-tools执行make,编译得到unsquashfs和mksquashfs,这个似乎是比较新的版本。但是也不能正常解压,出的错误信息是:

zlib::uncompressfailed, unknown error -3

       干脆测试openwrt下载下来的工具。编译完后也是不行。难道做了修改?尝试了一下用mksquashfs可以做出squashfs文件,unsquashfs也可以解压。看来是lzma的问题,也许openwrt使用的是lzma算法而不是普通的zlib包含的算法。

       既然openwrt能做出这种squashfs,肯定在某个地方有编译好的工具,  既然openwrt里面有打包的工具,也应该有解压的工具。使用find命令在整个openwrt编译文件夹查找,找到有几个地方有

 

[root@localhost kamikaze_8.09]# find ./ |grepunsquashfs

./build_dir/armeb/OpenWrt-SDK-ixp4xx-for-Linux-i686/staging_dir/host/bin/unsquashfs-lzma

./build_dir/armeb/OpenWrt-ImageBuilder-ixp4xx-for-Linux-i686/staging_dir/host/bin/unsquashfs-lzma

./build_dir/host/squashfs3.0/squashfs-tools/unsquashfs.c

./build_dir/host/squashfs3.0/squashfs-tools/unsquashfs-lzma

./build_dir/host/squashfs3.0/squashfs-tools/unsquashfs.o

./staging_dir/host/bin/unsquashfs-lzma

 

重新制作suqashfs

       使用编译好的工具直接解压openwrt-ixp4xx-squashfs.img果然没有问题。而且在同一个文件夹下面找到了mksquashfs-lzma,这个就是制作工具。解压完了之后尝试利用mksquashfs压缩,没有问题,但是无法下载到板子上,板子报unknow error。这个就比较奇怪,因为根本什么都没有修改。以为是网络坏了,尝试别的文件,可以下载。说明还是文件制作的原因,重新制作还是不行,只能查看openwrt在编译的时候是如何制作squashfs的。结果在编译的信息里面找到如下内容:

/home/linuxuser/openwrt/kamikaze_8.09/staging_dir/host/bin/mksquashfs-lzma/home/linuxuser/openwrt/kamikaze_8.09/build_dir/armeb/root-ixp4xx/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/root.squashfs-nopad -noappend -root-owned -be

Creating big endian 3.0 filesystem on/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/root.squashfs,block size 65536.

 

Big endian filesystem, data block size 65536,compressed data, compressed metadata, compressed fragments

Filesystem size 1345.67 Kbytes (1.31 Mbytes)

        36.50%of uncompressed filesystem size (3686.41 Kbytes)

Inode table size 3583 bytes (3.50 Kbytes)

        24.88%of uncompressed inode table size (14404 bytes)

Directory table size 3969 bytes (3.88 Kbytes)

        60.99%of uncompressed directory table size (6508 bytes)

Number of duplicate files found 0

Number of inodes 454

Number of files 231

Number of fragments 18

Number of symbolic links  175

Number of device nodes 0

Number of fifo nodes 0

Number of socket nodes 0

Number of directories 48

Number of uids 1

        root(0)

Number of gids 0

 

ddif=/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/root.squashfsof=/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/tmpfile.1bs=64k conv=sync

21+1 records in

22+0 records out

1441792 bytes (1.4 MB) copied, 0.00356398 seconds,405 MB/s

echo -ne'\xde\xad\xc0\xde' >>/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/tmpfile.1

ddof=/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/root.squashfsif=/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/tmpfile.1bs=64k conv=sync

22+1 records in

23+0 records out

1507328 bytes (1.5 MB) copied, 0.00413698 seconds,364 MB/s

echo -ne'\xde\xad\xc0\xde' >>/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/root.squashfs

ddif=/home/linuxuser/openwrt/kamikaze_8.09/build_dir/linux-ixp4xx_generic/root.squashfsof=/home/linuxuser/openwrt/kamikaze_8.09/bin/openwrt-ixp4xx-squashfs.imgbs=131072 conv=sync

11+1 records in

12+0 records out

1572864 bytes (1.6 MB) copied, 0.00388263 seconds,405 MB/s

 

去掉太多的路径,摘录命令如下:

 

./mksquashfs-lzma./squashfs-root root.squashfs -nopad -noappend -root-owned -be

ddif=root.squashfs of=tmpfile.1 bs=64k conv=sync

echo -ne'\xde\xad\xc0\xde' >> tmpfile.1

ddof=root.squashfs if=tmpfile.1 bs=64k conv=sync

echo -ne'\xde\xad\xc0\xde' >> root.squashfs

ddif=root.squashfs of=openwrt-ixp4xx-squashfs.img bs=131072 conv=sync

 

       很明显,openwrt在制作完成之后,有对文件进行了一些操作。

在上面的步骤中一共生成了6个文件,依次对比如下

 

openwrt-ixp4xx-squashfs_ori.img是openwrt编译出来的原始文件,其他的按照文件名的最后一个数字表示各次生成的结果。

 

tmpfile.12仅仅比root.squashfs1补充了0,补全为64K的整倍数。

 

tmpfile.13 仅仅比tmpfile.12后面多了echo进去的4bytes

root.squashfs4也是在tmpfile.13后面补充0. 补全为64K的整倍数。

 

 

 

root.squashfs5比root.squashfs4多了echo进去的4bytes。

 

openwrt-ixp4xx-squashfs.img6比root.squashfs5后面补充0,补全为64K的整倍数

 

       经过研究,不管文件内容对错,文件大小是64K的整倍数才可以下载。使用下面的命令对squashfs重新制作了一篇,果然是好的。squashfs的问题终于解决了。

 

./mksquashfs-lzma./squashfs-root root.squashfs -nopad -noappend -root-owned -be

ddif=root.squashfs of=tmpfile.1 bs=64k conv=sync

echo -ne'\xde\xad\xc0\xde' >> tmpfile.1

ddof=root.squashfs if=tmpfile.1 bs=64k conv=sync

echo -ne'\xde\xad\xc0\xde' >> root.squashfs

ddif=root.squashfs of=openwrt-ixp4xx-squashfs.img bs=131072 conv=sync

 

检查启动文件

       不管是ramdisk还是squash,都是启动到一定阶段就没有信息了,无法进入控制台。

wifi0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps24Mbps 36Mbps 48Mbps 54Mbps

wifi0: 11brates: 1Mbps 2Mbps 5.5Mbps 11Mbps

wifi0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps

wifi0: turboArates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps

wifi0: turboGrates: 6Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps

wifi0: H/Wencryption support: WEP AES AES_CCM TKIP

ath_pci: wifi0:Atheros 5212: mem=0x48000000, irq=27

       这个时候在串口敲击键盘,可以有回显,但是命令不会执行。

猜测是启动脚本在某个地方出现了错误,而控制台是在启动脚本执行之后才出现的,所以先检查openwrt的启动脚本。

 

分析修改preinit

根据资料,preinit是openwrt的第一个启动文件

echo "-preinit -"

echo "PressCTRL-C for failsafe"

trap'FAILSAFE=true' INT

trap'FAILSAFE=true' USR1

[ -e /etc/preinit.arch] && . /etc/preinit.arch

set_statepreinit

echo"$HOTPLUG" > /proc/sys/kernel/hotplug

export FAILSAFE

eval${FAILSAFE:+failsafe}

lock -w/tmp/.failsafe

 

if [ -z"$INITRAMFS" ]; then

    mount_root

    [ -f /sysupgrade.tgz ] && {

        echo "- config restore -"

        cd /

        mv sysupgrade.tgz /tmp

        tar xzf /tmp/sysupgrade.tgz

        rm -f /tmp/sysupgrade.tgz

        sync

    }

 

    echo "- init -"

   

    exec /sbin/init

fi

       既然不能正常启动,就按照failsafe启动。但是按了CTRL-C根本没作用,干脆修改preinit。

       其中trap的含义有这么一段解释:

INT 就是中断信号(linux中是ctrl-CSCO unix中是"del")

trap 就是捕捉信号,与所提供的arg联系起来,就是当捕捉到某个信号时执行arg规定的动作。

如文件a

#!/bin/bash

trap "echo-e \"\nreceive int\n\";exit" INT

while :

do

((i++))

done

 

由于是死循环,不会退出,按下ctrl-c键后,程序会显示

 

将preinit相关内容修改如下:

echo "-preinit -"

echo "PressCTRL-C for failsafe"

#trap'FAILSAFE=true' INT

#trap'FAILSAFE=true' USR1

FAILSAFE=true

[ -e/etc/preinit.arch ] && . /etc/preinit.arch

 

重新烧录squashfs,可以正常启动进入控制台。说明系统本身没有问题。

 

检查inittab和rcS

经过加入echo,发现preinit实际上是exec /sbin/init执行的。而init一般是通过inittab来执行任务的。inittab的内容如下:

::sysinit:/etc/init.d/rcSS boot

::shutdown:/etc/init.d/rcSK stop

tts/0::askfirst:/bin/ash--login

ttyS0::askfirst:/bin/ash--login

tty1::askfirst:/bin/ash–login

 

查找OPENWRT的网站资料,有如下说明

exec /sbin/init启动文件系统,在OpenWrt上也就是busyboxinit程序。它会自动分析/etc/inittab这个文件,其内容解释详见busybox网站的cmd help。如果找不到该文件,默认按照如下内容执行:

 

::sysinit:/etc/init.d/rcS

::askfirst:/bin/sh

::ctrlaltdel:/sbin/reboot

::shutdown:/sbin/swapoff-a

::shutdown:/bin/umount-a -r

::restart:/sbin/init

 

既然目前编译好的openwrt有inittab,那么肯定是按照inittab来执行。找到/etc/init.d/rcS,内容如下:

#!/bin/sh

# Copyright (C)2006 OpenWrt.org

 

run_scripts() {

    for i in /etc/rc.d/$1*; do

        [ -x $i ] && $i $2 2>&1

    done | $LOGGER

}

 

LOGGER="cat"

[ -x/usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"

 

if ["$1" = "S" ]; then

    run_scripts "$1" "$2"&

else

    run_scripts "$1" "$2"

fi

 

这个脚本就是轮循执行/rc.d/下的脚本,因为inittab执行参数为rcS S boot,所以在此执行命令为run_scripts boot &。

管道的问题

在rcS中有done |$LOGGER,这句话会把所有的打印都定向到$LOGGER,妨碍调试,必须去掉| $LOGGER。

 

在/rc.d/下的脚本的start或者boot里都加上echo语句,发现这些脚本执行的其实没有问题。在failsafe模式下手动执行这些脚本,执行也都没有问题,那看起来就不是这些脚本的问题。

 

猜测也许是inittab启动控制台命令导致的?对比以前uclinux启动控制台的命令:::askfirst:/bin/sh,在检查inittab,发现多了tts/0, ttyS0,tty1:等内容。ttyS0显然是错误的,查资料发现tts/0也是串口0的意思,估计就是这个错误了。将其全部修改成1,重新烧录启动,果然能够看到控制台了。当然第一次启动的时候比较长,需要耐心多等待,不然会当作启动失败。

 

jeffs的问题

       修改inittab串口的过程中,走了一段弯路。

在没有正确修改串口的时候,启动的过程中,使用echo之后,可以看到如果等待的时间长一点,实际上会出现如下的信息:

ath_pci: wifi0:Atheros 5212: mem=0x48000000, irq=27

jffs2_scan_eraseblock():End of filesystem marker found at 0x0

jffs2_build_filesystem():unlocking the mtd device... done.

jffs2_build_filesystem():erasing all blocks after the end marker...

过了好长一段时间,又打印出几句话,

mini_fo: usingbase directory: /

mini_fo: usingstorage directory: /jffs

然后就彻底没响应了。当时猜测既然flash上没有jffs分区,又没有usb。这个可能是造成问题的原因。google得到如下信息:

Changingmini_fo's storage directory (/jffs on external media)

1. Introduction
This guide describes how to use your USB stick or your MMC/SD card for storingpakages and files instead of
using the JFFS2 partion on your flash chip. / in this case is the SquashFSpartition on the flash chip and the
writable EXT2 partion is on your external media. With little modifications youcan use this guide also for MMC/SD
card. Tested with Kamikaze pre1 on a Asus WL-500GD and a 512MB Sundisk CruzerMini USB 2.0 stick. With little
modifications it will also work with WhiteRussian 0.9.
With this guide you do not have to mess around with PATH, LD_LIBRARY_PATH orcreate symlinks anymore.

 

另外在jffs信息之前是ath_pci: wifi0: Atheros 5212: mem=0x48000000, irq=27,而ath_pci信息是S10boot里面的。所以猜测是s10boot之后启动的一些操作。在rc.d的启动脚本里检查相关内容, S10boot看起来[ -f /proc/jffs2_bbc ] &&echo "S" > /proc/jffs2_bbc可能是导致无法启动的原因。去掉再说。当时尝试了几个都不行,而且在failsafe模式下执行各个启动脚本也没有问题。仔细检查启动信息,根据在执行rcs之前就有一些jffs错误,ath_pci后面的也许是后续操作,猜测是preinit就已经执行了让系统无法运行的操作。

加入echo,打印信息如下

- preinit -

Press CTRL-C forfailsafe

preinit 20

preinit 30

preinit 35

preinit 40

preinit 50

jffs2not ready yet; using ramdisk

mini_fo:using base directory: /

mini_fo:using storage directory: /tmp/root

- init -

br-lan: DroppingNETIF_F_UFO since no NETIF_F_HW_CSUM feature.

ath5k: Unknownsymbol __bad_udelay

PPP generic driverversion 2.4.2

 

看起来是是preinit里面的mount_root的问题,屏蔽再说。但是还是没有出现控制台,这些试验都表明,初始化脚本里没有造成致命错误的地方。最后还是检查inittab的问题。终于最后找到了是串口的问题。

 

试验wrv54g

       为了测试initab的影响,特意试了一下wrv54g。wrv54g使用的串口0,将inittab里的tts/0和ttys0都改成1,看看能不能启动。现象果然是可以输入信息由回显,但是控制台就是无法启动。

 

redboot的支持问题

       同样的zImage在另外一个P720盒子上无法启动。但是唯一的区别就是redboot而已。能启动的盒子redboot是2.04的,不能启动的是原始的1.94的。重新刷了盒子,结果好了。

 

配置以太网

       openwrt启动以后,输入ifconfig eth0 up报错。

ifconfig:SIOCSIFFLAGS: Cannot assign requested address

       查找资料得知,这个是因为因为mac地址错误的原因而不是IP地址错误。所以执行ifconfig eth0 hw ether00:00:AA:BB:CC:DD,然后就可以执行ifconfigeth0 up。但是还是会报错。

eth0: MII readfailed

eth0: MII readfailed

 

用eth1没有问题,但是这个明明是NPEB,openwrt的配置和其他的不同?

无法ping通,因为P720的phy的配置是不同的,eth0使用的是phy1。也许是openwrt使用eth0配phy0,eth1配phy1,所以eth0的MII读取总是错误的,而eth1读取phy1是正确的,但是因为实际上用的是eth0,所以网络还是不通。在启动语句里找到下面的话

eth0: MII PHY 0on NPE-B

eth0: MII readfailed

eth0: MII readfailed

eth0: MII readfailed

eth0: MII readfailed

eth1: MII PHY 1on NPE-C

这更明显的提示了错误的所在。menuconfig没有phy的设置,只能自己看以太网驱动了。搜索源代码中“: MII PHY”的打印语句,就应该是设定phy的语句。一共有好几个文件都有打印这句话:

Ixp4xx_eth.c (linux-ixp4xx_generic\linux-2.6.26.8\.pc\platform\202-npe_driver_switch_support.patch\drivers\net\arm):       printk(KERN_INFO "%s: MII PHY %i on%s\n", dev->name, plat->phy,

Ixp4xx_eth.c (linux-ixp4xx_generic\linux-2.6.26.8\.pc\platform\203-npe_driver_phy_reset_autoneg.patch\drivers\net\arm):       printk(KERN_INFO "%s: MII PHY %i on%s\n", dev->name, phy_id,

Ixp4xx_eth.c (linux-ixp4xx_generic\linux-2.6.26.8\.pc\platform\204-npe_driver_ixp43x_support.patch\drivers\net\arm):       printk(KERN_INFO "%s: MII PHY %i on%s\n", dev->name, phy_id,

Ixp4xx_eth.c (linux-ixp4xx_generic\linux-2.6.26.8\.pc\platform\303-avila_gw23x7_phy_quirk.patch\drivers\net\arm):       printk(KERN_INFO "%s: MII PHY %i on%s\n", dev->name, phy_id,

Ixp4xx_eth.c (linux-ixp4xx_generic\linux-2.6.26.8\drivers\net\arm):    printk(KERN_INFO "%s: MII PHY %i on%s\n", dev->name, phy_id,

只有linux-ixp4xx_generic\linux-2.6.26.8\drivers\net\arm的Ixp4xx_eth.c有编译的迹象,应该就是这个。强行在eth_init_one()修改phy id

 

    switch (port->id) {

    case IXP4XX_ETH_NPEA:

        port->regs = (struct eth_regs __iomem*)IXP4XX_EthA_BASE_VIRT;

        regs_phys  = IXP4XX_EthA_BASE_PHYS;

        break;

    case IXP4XX_ETH_NPEB:

        port->regs = (struct eth_regs __iomem*)IXP4XX_EthB_BASE_VIRT;

        regs_phys  = IXP4XX_EthB_BASE_PHYS;

    /*this is for P720 phy*/

        plat->phy = 1;

    printk(KERN_INFO "change npe-b phy to 1for P720");

        break;

    case IXP4XX_ETH_NPEC:

        port->regs = (struct eth_regs __iomem*)IXP4XX_EthC_BASE_VIRT;

        regs_phys  = IXP4XX_EthC_BASE_PHYS;

    plat->phy = 2;

    printk(KERN_INFO "change npe-c phy to 2for P720");

        break;

    default:

        err = -ENOSYS;

        goto err_free;

    }

 

这样就能正确启动以太网了。

 

多出的配置分区

通过xwrt配置完成以后,多了一个rootfs_data分区,应该是存储配置的。

Creating 5 MTDpartitions on "IXP4XX-Flash.0":

0x00000000-0x00080000: "RedBoot"

0x00080000-0x00180000: "zImage"

0x00180000-0x00fe0000: "rootfs"

mtd: partition"rootfs" set to be root filesystem

mtd: partition"rootfs_data" created automatically, ofs=300000, len=CE0000

0x00300000-0x00fe0000: "rootfs_data"

0x00fe0000-0x00fff000: "FIS directory"

0x00fff000-0x01000000: "RedBoot config"