一半君的总结纸

听话只听一半君

编译带fchdir的<8mb的tomato-K26-1.28.RT-N5x-MIPSR2-131-Max

update:
本文内容已过时,至少在tomato shibby v138的max版本已经带有fchdir了,不用按照本文的办法乱搞了

插播,因为perp需要fchdir,而有他的libc的tomato又都大于8mb,这里自己来折腾一下,看能不能自定义一下tomato里哪些是我要的

lz准备先用tomato自带工具链试试,不行再用之前搞出来crosstools-ng的工具链(新一些)

  1. 重新clone一个repo (好大,有1.2g)
    # 后面发现似乎不该用v131,而要用tomato-shibby-RT-AC branch
    git clone https://github.com/tomatofirmware/tomato.git tomato_q3
    cd tomato_q3
    git checkout tags/v131
    
    # 所以请忽略上面三行,用下面这个
    git clone -b tomato-shibby-RT-AC https://github.com/tomatofirmware/tomato.git tomato_q3
    
    # 如果用错branch或者想重来可以
    git reset --hard && git clean -fdx
    
  2. 使用tomato的自带工具链
    export PATH=/opt/brcm/hndtools-mipsel-linux/bin:/opt/brcm/hndtools-mipsel-uclibc/bin:$PATH
    
    yum install 
    
    cd release/src-rt
    # 先试试看max版本能出来不,想法是把max里不用的功能去掉几个,
    # 加上那个能有fchdir的功能,最后还能在6mb左右
    # 在tomato源代码目录里搜fchdir,看到很多.h文件在samba3目录下,
    # 所以猜测是不是我加上samba,libc.so里就有fchdir了
    make V2="q3 ilmvfx" r2m 
    

    上面的尝试在编译max版本的tomato时遇到错误

    make[5]: Entering directory `/home/oglop/tomato/tomato_q3/release/src/router/openvpn'
    CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /home/oglop/tomato/tomato_q3/release/src/router/openvpn/missing aclocal-1.14 -I m4
    /home/oglop/tomato/tomato_q3/release/src/router/openvpn/missing: line 81: aclocal-1.14: command not found
    WARNING: 'aclocal-1.14' is missing on your system.
             You should only need it if you modified 'acinclude.m4' or
             'configure.ac' or m4 files included by 'configure.ac'.
             The 'aclocal' program is part of the GNU Automake package:
             <http://www.gnu.org/software/automake>
             It also requires GNU Autoconf, GNU m4 and Perl in order to run:
             <http://www.gnu.org/software/autoconf>
             <http://www.gnu.org/software/m4/>
             <http://www.perl.org/>
    make[5]: *** [aclocal.m4] Error 127
    make[5]: Leaving directory `/home/oglop/tomato/tomato_q3/release/src/router/openvpn'
    make[4]: *** [openvpn] Error 2
    make[4]: Leaving directory `/home/oglop/tomato/tomato_q3/release/src/router'
    make[3]: *** [all] Error 2
    make[3]: Leaving directory `/home/oglop/tomato/tomato_q3/release/src-rt'
    make[2]: *** [bin] Error 2
    make[2]: Leaving directory `/home/oglop/tomato/tomato_q3/release/src-rt'
    make[1]: *** [m] Error 2
    make[1]: Leaving directory `/home/oglop/tomato/tomato_q3/release/src-rt'
    make: *** [r2m] Error 2
    

    这是因为系统里的automake版本太低

    [oglop@localhost perp-2.07]$ automake --version
    automake (GNU automake) 1.13.4
    

    我来装个1.14,下载安装后,继续make,这次没问题了,编译出来的.trx固件文件会在 release/src-rt/image/里,在lz的中古thinkpad t410上耗时约25min(在make命令前加time记时)

    real    16m35.052s
    user    25m15.922s
    sys     4m40.121s
    

    此处插播一下,万一你不幸弄错固件,让q3变砖了,可以通过tftp或者miniweb页面救回,请看此文

    lz试用的是第三个Locale Emulator,使用后tftp智能刷机1.68可以正常运行,把电脑ip改成192.168.1.3,接好网线,重启(或者reset)路由器,然后立即点下更新固件按钮,lz先试着刷回了

    lz成功的变砖了几次,第一次尝试max版本增加samba3,build能成功,但是刷了以后变砖,build log在这里,此外其中有多行

    make[4]: Entering directory `/home/oglop/tomato/tomato/release/src/router/snmp/snmplib'
    /bin/sh ../libtool  --mode=compile mipsel-uclibc-gcc -I../include -I../include -I. -I.. -I. -I./..  -Os -Wall -DLINUX26 -DCONFIG_BCMWL5 -pipe -DBCMWPA2 -funit-at-a-time -Wno-pointer-sign -mtune=mips32 -mips32  -Dlinux  -c -o snmp_client.lo snmp_client.c
    ../libtool: line 85: -R: command not found
    

    这样的错误,lz去运行那行命令也是出错,看到85行的内容是

    # A symbol stripping program
    STRIP=mipsel-uclibc-strip -R .note -R .comment
    

    似乎右侧的命令直接运行了?改成下面这样就没事了,

    STRIP=“mipsel-uclibc-strip -R .note -R .comment“
    

    lz改了release/src/router/snmp/下的aclocal.m4.libtool和aclocal.m4,其实就是加了个引号

    之前用的是v131 tag,似乎用错? 后来尝试了tomato-shibby-RT-AC branch,因为我看他把tomato-shibby里的代码都merge进来了,而vxxx的tag都是在tomato-shibby branch里面的

    git branch --contains tag
    

    折腾过程中如果变砖了,都可以用tftp智能刷机刷nr235w原版救回,刷完后会自动重启,不要拔线,然后进webui刷tomato即可,可是后来不知为何,进webui刷tomato后不会自己重启,只是返回nr235w的首页而已,手动重启后还是nr235w,不知道什么原因,最后采取的方法lz也不记得了,总之似乎一阵乱刷,最后也没好,仿佛是刷过最新的235w 1.8固件导致的,lz这里只好祭出终极大招,从另一台q3上保存cfe,修改MAC再恢复到当前这台)

    1. 首先准备修改cfe文件,按照大神南浦月的说明,把备份的另一台q3的cfe里的mac换成了我的,下面截图借用论坛上的,我提供的文件里的mac换成02-9e-68-12-f5-b4(出于隐私),此外为了方便的转换,我用了这个网站string-hex来把mac地址字符转换成hex

      请在刷入前按照自己路由器标签上的mac进行相应修改,具体要修改的地方是:
      et0macaddr=04-8d-38-11-22-33
      macaddr=04-8d-38-11-22-33
      q3_cfe_mac1

      这里要进行运算:
      假设路由器标签上的mac为04-8d-38-11-22-33,
      wan_macaddr=04-8d-38-11-22-34:即标签上的mac加1
      wan2_macaddr=04-8d-38-11-22-35:再加1,即标签上的mac加2
      wl0_hwaddr=04-8d-38-11-22-33:标签上的mac
      wl0.1_hwaddr=04-8d-38-11-22-36:标签上的mac加3
      以上运算都是16进制的:
      如果最后一位是9,加1则为a,且不用进位
      如果最后一位为f,加1则为0,并进位
      9+1=a
      a+1=b
      f+1=10

      q3_cfe_mac2

      lz把比较旧的应该是能随便刷固件的cfe文件放在这里了

    2. 然后用tftp刷tomato的trx文件,刚刷完不等他重启就拔电线,这样再插上之后会进入miniweb
    3. 此时你电脑上的tftp server还开着,假设你电脑ip是192.168.1.3,你需要在浏览器地址栏贴上下面这行
      http://192.168.1.1/do.htm?cmd=flash+-noheader+192.168.1.3:cfe.bin+flash0.trx
      

      回车后

      cfe finish

      如果你运气好,cfe已经更新了,运气不好就彻底砖了(除非你拆机接jtag线或者焊掉芯片用编程器刷回)

    4. 总之最后cfe恢复后,lz刷了个netcore(NR235W)CN-V1.7.130315.bin,然后web页面里刷了tomato,复活….

  3. lz最终尝试编译Max版本使用的make命令是

    make V1=RT-N5x- V2=-131 v2m | tee ~/outputfile.txt
    

    tee的作用是在console里显示的同时,把log输出到文件里去,编译出来的trx文件在release/src-rt/images下
    显然这个肯定没有fchdir,因为和官网的一样嘛,但是官网的AIO和Mega版本都有,去到release/src-rt/Makefile里看了看,可以猜到如果想自定义,可以使用下面的命令,lz把mega版本后面的参数贴了几个过来,碰碰运气,看会不会有fchdir,同时看看出来的trx文件尺寸如何

    [oglop@localhost src-rt]$ make help
    n            Mini-USB - for oruter with 4MB flash and USB port - K24 only
    e            VPN - (standard plus VPN, extra utilities and NTFS support)
    c            BTgui-VPN - (Ext plus BT gui)
    d            Nocat-VPN - (BTgui plus VPN plus Nocat)
    g            Tor-VPN - (BTgui plus VPN plus TOR Project)
    t            BT-VPN - (BT plus VPN)
    b            Big-VPN - (Big plus VPN)
    o            Mega-VPN - (Mega plus VPN plus NOCAT minus NFS)
    z            MIPS Release 15F AIO (for routers +8MB flash)
    i            MiniIPv6 - (IPv6 with no USB support minus CIFS and RIPv1/2)
    j            MiniVPN - (VPN with no USB support minus CIFS and RIPv1/2)
    f            Mini - (no USB support minus CIFS and RIPv1/2)
    v            VPN (no usb) - (VPN with no USB support) / in K26 + IPv6 support
    m            Max (no usb) - (Max with no USB support) / in K26 + IPv6 support
    w            SD-VPN (no usb) - (VPN with SD-MOD and no USB support)
    r2e          MIPS Release 2 VPN
    r2c          MIPS Release 2 BTgui-VPN
    r2d          MIPS Release 2 Nocat-VPN
    r2g          MIPS Release 2 Tor-VPN
    r2t          MIPS Release 2 BT-VPN
    r2b          MIPS Release 2 Big-VPN
    r2o          MIPS Release 2 Mega-VPN (for routers +8MB flash)
    r2z          MIPS Release 2 AIO (for routers +8MB flash)
    r2v          MIPS Release 2 VPN (no usb)
    r2m          MIPS Release 2 Max (no usb)
    r2i          MIPS Release 2 MiniIPv6 (for 4MB flash)
    r2j          MIPS Release 2 MiniVPN (for 4MB flash)
    r2f          MIPS Release 2 Mini (for netgear)
           Linksys E-Series with 4MB Flash(E1000v2/v2.1/E1200v1)
    e1000v2f     Linksys E1000v2-v2.1/Cisco M10v2 Mini
    e1000v2i     Linksys E1000v2-v2.1/Cisco M10v2 MiniIPv6
    e1200v1f     Linksys E1200v1 Mini
    e1200v1i     Linksys E1200v1 MiniIPv6
           Linksys E-Series with 60k Nvram
    n60e         Linksys E-series build VPN
    n60c         Linksys E-series build BTGui-VPN
    n60d         Linksys E-series build BTGui-VPN plus Nocat
    n60g         Linksys E-series build BTGui-VPN plus TOR Project
    n60t         Linksys E-series build BT-VPN
    n60b         Linksys E-series build Big-VPN
    n60o         Linksys E-series build Mega-VPN
    n60z         Linksys E-series build AIO
    n60i         Linksys E-series build Mini for E2500
    n60j         Linksys E-series build MiniIPv6 for E2500
    n60v         Linksys E-series build IPv6-VPN for E2000
    n60m         Linksys E-series build Max for E2000
           Linksys E-Series with 64k Nvram/8MB Flash(E800/E900/E1200v2/E1500)
    n64e         Linksys E-series(64k Nvram) build VPN
    n64c         Linksys E-series(64k Nvram) build BTGui-VPN
    n64d         Linksys E-series(64k Nvram) build BTGui-VPN plus Nocat
    n64g         Linksys E-series(64k Nvram) build BTGui-VPN plus TOR Project
    n64u         Linksys E-series(64k Nvram) build BT
    n64t         Linksys E-series(64k Nvram) build BT-VPN
    n64b         Linksys E-series(64k Nvram) build Big-VPN
    n64o         Linksys E-series(64k Nvram) build Mega-VPN
    n64v         Linksys E-series(64k Nvram) build IPv6-VPN
    n64m         Linksys E-series(64k Nvram) build Max
           Routers with wl_high module
    rtn53        Asus RT-N53 with wl_high module (dualband support)
    e2500        Linksys E2500 with wl_high module (dualband support)
    e3200        Linksys E3200/E2500v3 with wl_high module (dualband support) / max 16MB
    n6           Tenda N6 with wl_high module (dualband support)
    n60          Tenda N60 with wl_high module (dualband support)
           Netgear WNR3500L v2 builds (128MB Flash)
    v2e          Netgear WNR3500Lv2 build VPN
    v2z          Netgear WNR3500Lv2 build AIO
    
    r64e         RT-N66u build VPN
    r64z         RT-N66u build AIO
    
    ..etc..      other build configs
    clean        -C router clean
    cleanimage   rm -rf image
    cleantools   clean btools, mksquashfs
    cleankernel  -C Linux distclean (but preserves .config)
    distclean    distclean of Linux & busybox (but preserve .configs)
    prepk        -C Linux oldconfig dep
    
    # m 对应的参数
    bin OPENVPN=y BBEXTRAS=y EBTABLES=y IPV6SUPP=y B=E BUILD_DESC="Max" USB="" NOCAT=y NFS=y SNMP=y DNSCRYPT=y PPTPD=y TOR=y IPSEC=y SAMBA3=y TR_EXTRAS=y
    
    # o 对应的参数
    bin OPENVPN=y NTFS=y BBEXTRAS=y USBEXTRAS=y EBTABLES=y MEDIASRV=y IPV6SUPP=y B=E BUILD_DESC="Mega-VPN" USB="USB" NOCAT=y BTCLIENT=y DNSCRYPT=y SNMP=y UPS=y PPTPD=y TR_EXTRAS=y TOR=y IPSEC=y RAID=y DNSSEC=y TINC=y NANO=y
    
    # lz的试验参数
    make distclean && time make bin V1=RT-N5x- V2=-131-netcore-q3 OPENVPN=y BBEXTRAS=y EBTABLES=y IPV6SUPP=y B=E BUILD_DESC="Max" USB="" NOCAT=y NFS=y SNMP=y DNSCRYPT=y PPTPD=y TOR=y IPSEC=y TR_EXTRAS=y NTFS=y USBEXTRAS=y MEDIASRV=y IPV6SUPP=y USB="USB" MIPS32=r2 | tee ~/outputfile_final.txt
    
    # 测试看有没有
    sudo ./extract-firmware.sh /home/oglop/tomato/tomato_clean/release/src-rt/image/tomato-K26USB-1.28.RT-N5x-MIPSR2-131-netcore-q3-Max.trx  /home/oglop/tomato/tomato_clean/release/src-rt/image/extract
    Firmware Mod Kit (extract) 0.99, (c)2011-2013 Craig Heffner, Jeremy Collake
    
    Preparing tools ...
    Scanning firmware...
    
    Scan Time:     2015-09-15 19:53:17
    Signatures:    193
    Target File:   /home/oglop/tomato/tomato_clean/release/src-rt/image/tomato-K26USB-1.28.RT-N5x-MIPSR2-131-netcore-q3-Max.trx
    MD5 Checksum:  f54375f6c3b437d0ecf10341f0dc582e
    
    DECIMAL         HEX             DESCRIPTION
    -------------------------------------------------------------------------------------------------------
    0               0x0             TRX firmware header, little endian, header size: 28 bytes,  image size: 9396224 bytes, CRC32: 0xD8D68CCB flags/version: 0x10000
    28              0x1C            gzip compressed data, from Unix, NULL date: Thu Jan  1 08:00:00 1970, max compression
    969728          0xECC00         Squashfs filesystem, little endian, version 3.0, size: 8422141 bytes,  1347 inodes, blocksize: 65536 bytes, created: Tue Sep 15 19:41:28 2015 
    
    Extracting 969728 bytes of trx header image at offset 0
    Extracting squashfs file system at offset 969728
    Extracting squashfs files...
    Firmware extraction successful!
    Firmware parts can be found in '/home/oglop/tomato/tomato_clean/release/src-rt/image/extract/*'
    [oglop@localhost fmk]$ readelf -s /home/oglop/tomato/tomato_clean/release/src-rt/image/extract/rootfs/lib/libc.so.0 | grep fchdir
       149: 00008150    84 FUNC    GLOBAL DEFAULT    6 fchdir
    

    有了!但不幸的是trx文件有9.4mb,必须得去掉几个功能,不然放不进8mb的q3,但是究竟是哪个参数让他有的呢?无脑乱猜一个一个试么?当然作为强迫症人士,这样乱猜是不好的,我们应该用“科学“的方法达到目的,在log中我们可以看到

    libc.so.0: Attempted to remove 685/1242 symbols. 433.67K - 255.27K = 178.41K
    

    而在release/src-rt/router/Makefile里,我们相应的会看到

    install $(LIBDIR)/libc.so.0 $(TARGETDIR)/lib/
    ...
    ifneq ($(TCONFIG_OPTIMIZE_SHARED_LIBS),y)
    	install $(LIBDIR)/libresolv.so.0 $(TARGETDIR)/lib/
    	$(STRIP) $(TARGETDIR)/lib/*.so.0
    endif
    

    所以make的时候只是把libc.so从工具链目录下拷过去,然后strip了,如过你去router目录下,make menuconfig然后把optimize shared libs关了大概可以,不过那样我jffs空间必然会少很多,所以这里乱搞下,在strip的时候保留我要的symbol

  4. 手动试验

    # 我把makefile的操作手动来一遍试试,先把一些so文件拷过去
    STRIP="/opt/brcm/hndtools-mipsel-linux/bin/mipsel-uclibc-strip"
    LIBDIR=/home/oglop/tomato/tomato_clean/tools/brcm/K26/hndtools-mipsel-uclibc-4.2.4/lib
    TARGETDIR=/home/oglop/tomato/tomato_clean/release/src-rt/router/mipsel-uclibc/target
    
    sudo cp $LIBDIR/ld-uClibc.so.0 $TARGETDIR/lib/
    sudo cp $LIBDIR/libcrypt.so.0 $TARGETDIR/lib/
    sudo cp $LIBDIR/libpthread.so.0 $TARGETDIR/lib/
    sudo cp $LIBDIR/libgcc_s.so.1 $TARGETDIR/lib/
    sudo $STRIP $TARGETDIR/lib/libgcc_s.so.1
    sudo cp $LIBDIR/libc.so.0 $TARGETDIR/lib/
    sudo cp $LIBDIR/libdl.so.0 $TARGETDIR/lib/
    sudo cp $LIBDIR/libm.so.0 $TARGETDIR/lib/
    sudo cp $LIBDIR/libnsl.so.0 $TARGETDIR/lib/
    
    # strip所有的,但是不要strip libc.so
    # strip 发生在 release/src/btools/libfoo.pl 这个脚本里
    # 下面我们来试一下
    export TARGETDIR=/home/oglop/tomato/tomato_clean/release/src-rt/router/mipsel-uclibc/target
    export SRCBASE=/home/oglop/tomato/tomato_clean/release/src
    export TOOLCHAIN=/home/oglop/tomato/tomato/tools/brcm
    
    cd /home/oglop/tomato/tomato_clean/release/src/btools/
    ./libfoo.pl
    
    

    # 果然是他干的
    所以lz在下面无脑的把fchdir加回去

    
    	# keep this symbol for libc
    	my @keep_symbols=("fchdir");
    	my $tmp;
    	if ($name eq "libc.so.0"){
    		foreach $tmp (@keep_symbols) {
    			@unused = grep !/$tmp/, @unused;
    			push @used, $tmp;
    		}
    	}
    

    lz和上面的的strip加引号一起搞了个patch,放这里了

    diff -aur --exclude=".git" ~/tomato/tomato_intact/release/src ~/tomato/tomato_latest/release/src > ~/tomato/libc_strip.patc
    # 应用patch的时候 
    cd ~/tomato/tomato_q3
    patch -p5 < ~/tomato/libc_strip.patch
    
    
    # 再来一遍
    cd release/src-rt
    rm ~/outputfile.txt
    make distclean
    time make V1=RT-N5x- V2=-131-netcore-q3 r2m | tee ~/outputfile.txt
    
    

    webui 里upgrade之后,世界终于和谐了 … 如下图所示:
    mine tomato

  5. update 2015-11-02:
    shibby升级到v132,我也来跟着升级一下:(上面的几处修改以避免错误的步骤似乎都不用做了,lz在一台新装的机器上试的,有错再说),当然保留fchdir的那一步还是做了的

    git clone -b tomato-shibby-RT-AC https://github.com/tomatofirmware/tomato.git
    
    cd tomato/release/src-rt
    rm ~/outputfile.txt
    make distclean
    time make V1=RT-N5x- V2=-132-netcore-q3 r2m | tee ~/outputfile.txt
    
    

    当然131升132以前,得把jffs里的东西拷出来(安全第一,万一没了呢),关jffs,升级,开jffs,再拷回去

    mkdir q3_jffs && cd q3_jffs
    #拷出来
    scp -rp root@192.168.2.22:/jffs/* .
    #拷回去 似乎在rt-n66u上升级了以后里面东西还在
    scp -rp * root@192.168.2.22:/jffs/
    

    待续 …

文件下载链接:
tomato-K26-1.28.RT-N5x-MIPSR2-131-netcore-q3-Max.trx
tomato-K26-1.28.RT-N5x-MIPSR2-132-netcore-q3-Max.trx

builds
参考:

How to build, and rebuild Tomato, FOR TOTAL NOOBS
Help: Shibby or Koitsu Firmware Build Question
tomato主Makefile流程简略分析(原创)
Shibby – How to find correct firmware, souce code and compile?
How do I save terminal output to a file?
磊科Q3刷机及SS翻墙总结
Git: How to find out on which branch tag is?
更新Q3 WEB刷机包 Q3 NI360 WEB互刷NR235W NR236W固件集合 W3000R 海蜘蛛 TT WF2409
生活就是无尽折腾,Q3刷机
NI360 路由器大变身
磊科 Netcore Q3 原版 cfe
10个磊科 Q3/Ni360 可刷固件[新增OpenWrt]
磊科q3开箱文及使用感受,拆机,简单一步改236W~
紫光m300 路由器与磊科ni360 q360 nr235 ddwrt tomato等互刷折腾备忘 – cfe
磊科Q3也能TTL/JTAG,顺便求JTAG救砖
[黑科技]shadowsocks服务器端配置
[LINKSYS(soho级,非Cisco)] 磊科 Netcore Q3 原版 cfe

Advertisements

2 responses to “编译带fchdir的<8mb的tomato-K26-1.28.RT-N5x-MIPSR2-131-Max

  1. svi 一月 18, 2016 @ 3:08 下午

    赞一个。Q3刷了下可用。就是系统型号识别的zte的N218N。可以按照http://tt.onv.cc/?lang=zh的做法,改为Q3的么?

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: