NSLU2的嵌入式linux实验(一):基于OpenWrt的Linksys的NSLU2

上一篇 / 下一篇  2008-07-26 23:52:34 / 个人分类:linux

  NSLU2是Linksys在2004年出的一款家用NAS(网络存储),由于该设备基于Linux,因此Linksys公开了该设备的源代码。因此嵌入式linux的hacker们启动了www.nslu2-linux.org的开源项目。OpenWrt的开源项目也支持该设备。下图是该设备的外观:

  该设备的硬件基于Intel IXP420 266Mhz的CPU,Flash为8M,SDRAM为32M。因此说这个资源还是比较富裕的。该设备在taobao上有卖,基本都是二手的,价格稍有点贵,大都在600元以上。不过比IXP的开发板来说要便宜多了。
  该设备没有用螺丝,用塑料卡扣固定。它的塑料卡扣在银色和深灰色之间,因此只要用力把银色和深灰色的塑料拉开就可以了。
  打开后需要连接出设备的串口,串口J2从左至右依次为 3.3V RXD TXD GND
 
  需要注意的是,串口的电平为TTL电平,不是RS232的,因此还需要TTL和RS232转换的设备,该设备taobao上有卖,也可以自己做,详见我的blog上的《用br104h制作eCos实验板》
  NSLU2的串口波特率为115200,数据位8,停止位1。上电后,需要输入ctrl-c,让设备停在boot阶段。下面是输入ctrl-c后,串口的打印。
 

  NSLU2的boot是Redboot,Redboot的命令可以参《RedBoot User's Guide》 (http://ecos.sourceware.org/docs-latest/redboot/redboot-guide.html)。

  接下来的工作就是如何编译OpenWrt了。开发环境建立在ubuntu上,如果下面的编译出现问题,基本都是ubuntu缺一些软件包,可以google一把(关键字: ubuntu 加上 错误信息),然后安装之。最近一直在用ubuntu,感觉越来越贴心,除了网上银行必须用windows外,其他的都在ubuntu上解决了。
  1. 下载OpenWrt
     svn co https://svn.openwrt.org/openwrt/tags/kamikaze_7.09
  2. 配置OpenWrt
     cd kamikaze_7.09
     make menuconfig


     由于缺省配置是Linksys的Wrt54g,因此需要修改配置:
     a. Target System 需要选择 "Intel Xscale IXP4xx [2.6]"
     b. Target Porfile 需要选择 "Linksys NSLU2"
     c. 进入Target Images 子菜单
     因为不想破坏原来的Flash,因此采用ramfs的方式


 
     d. 退出保存。

  3. 编译之
     make
     这个阶段很长,会从网上下载各种linux源代码包,然后完成toolchain,工具软件,ucLibc,linux kernel,各种应用软件的解压,打补丁,编译,安装,这个阶段是完全自动化的,很方便。

  4. 配置linux内核
     make kernel_menuconfig
     在General Setup里面,选择"Initial RAM filesystem and RAM disk (initramfs/initrd) support",原因同上面讲的,不破坏flash,让app以ramfs的方式运行在内存中。
    
  5. 再编译之
     make

  6. 将编译的文件放到tftp server的目录下
     cp bin/openwrt-nslu2-2.6-zImage /tftpboot/zImage

  7. 回到串口,在redboot下载
     RedBoot> load -r -b 0x1000000 -h 192.168.0.99 zImage
     Using default protocol (TFTP)
     Raw file loaded 0x01000000-0x011fb1a7, assumed entry at 0x01000000

  8. 运行之
     RedBoot> go 0x1000000

 



  9. 启动网口
     root@OpenWrt:/# ifconfig eth0 up
     eth0: NPE-B not running
     ifconfig: SIOCSIFFLAGS: Input/output error
     这时出现问题,网口无法使能,google一下,发现是IXP420的网口微码没有加载

  10.修改文件,让IXP420的微码文件生成到ramfs里面
     在package/Makefile的第72行添加一行,将微码文件NPE-B拷贝到文件系统中。
     这个方法虽然快捷,但不太好,以后再改进吧。

install:
    rm -rf $(BUILD_DIR)/root
    $(MAKE) install-targets
    $(MAKE) preconfig
    @if [ -d $(TOPDIR)/files ]; then \
        $(CP) $(TOPDIR)/files/. $(BUILD_DIR)/root; \
    fi
    @mkdir -p $(BUILD_DIR)/root/etc/rc.d
    @( \
        cd $(BUILD_DIR)/root; \
        for scrīpt in ./etc/init.d/*; do \
            grep '#!/bin/sh /etc/rc.common' $$scrīpt >/dev/null || continue; \
            IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$scrīpt enable; \
        done || true \
    )
    @-find $(BUILD_DIR)/root -name CVS   | $(XARGS) rm -rf
    @-find $(BUILD_DIR)/root -name .svn  | $(XARGS) rm -rf
    @-find $(BUILD_DIR)/root -name '.#*' | $(XARGS) rm -f
    cp /home/ning/OpenWrt/kamikaze_7.09/build_armeb/linux-2.6-ixp4xx/NPE-B /home/ning/OpenWrt/kamikaze_7.09/build_armeb/root/lib/firmware

  11. 再编译之
      make

  12. 将编译的文件放到tftp server的目录下
      cp bin/openwrt-nslu2-2.6-zImage /tftpboot/zImage

  13. 重启设备,按下ctrl-c,进入redboot

  14. 在redboot下载
      RedBoot> load -r -b 0x1000000 -h 192.168.0.99 zImage
      Using default protocol (TFTP)
      Raw file loaded 0x01000000-0x011fb1a7, assumed entry at 0x01000000

  15. 运行之
      RedBoot> go 0x1000000

  16. 启动完成后,在shell下敲入下面的命令
      root@OpenWrt:/# cat /lib/firmware/NPE-B > /dev/ixp4xx_ucode

      Image loaded to NPE-B Func:0, Rel: 2:1, Status: 82400000
      root@OpenWrt:/# ifconfig eth0 192.168.0.200 up
      eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
      root@OpenWrt:/# ping 192.168.0.99
      PING 192.168.0.99 (192.168.0.99): 56 data bytes
      64 bytes from 192.168.0.99: icmp_seq=0 ttl=64 time=4.5 ms
      64 bytes from 192.168.0.99: icmp_seq=1 ttl=64 time=0.9 ms
      64 bytes from 192.168.0.99: icmp_seq=2 ttl=64 time=0.8 ms
      64 bytes from 192.168.0.99: icmp_seq=3 ttl=64 time=0.9 ms

      --- 192.168.0.99 ping statistics ---
      4 packets transmitted, 4 packets received, 0% packet loss
      round-trip min/avg/max = 0.8/1.7/4.5 ms

  17. linux的基本环境到此大功告成,telnet,http(但没有网页)的服务都已经开启。


TAG: Linux OpenWrt NSLU2 linux

引用 删除 Guest   /   2008-11-10 08:11:05
5
引用 删除 Guest   /   2008-10-15 10:12:14
5
引用 删除 Guest   /   2008-10-13 16:42:53
5
引用 删除 zx   /   2008-10-13 16:42:48
太厉害了
引用 删除 rwhitby   /   2008-07-28 14:28:16
Welcome to the NSLU2-Linux community.

-- Rod Whitby
-- NSLU2-Linux Project Lead
Imcomplete 引用 删除 zhull1052   /   2008-07-28 13:52:16
看上去很不错......
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar