SyntaxHighlighter

2013年9月12日星期四

OpenWRT on WR703N with shadowsocks

TP-Link WR703N only have 4M flash, so we have to remove all unnecessary package and rebuild OpenWRT.

Note 1: If you do not need wifi, remove all package in kernel/wireless drivers. and wifi related tools.
Note 2: WR703N usb only support USB2.0, without hub, you only need core+usb2, ohci and uhci is not needed.

list of my ROM:
root@OpenWrt:~# opkg list-installed
base-files - 146-r37950
busybox - 1.19.4-7
chat - 2.4.5-10
comgt - 0.32-21
dnsmasq - 2.66-3
dropbear - 2012.55-2
firewall - 2013-08-14
ip6tables - 1.4.20-1
iptables - 1.4.20-1
jshn - 2013-08-01-04f194aa8a04926fe7f2e42bbf9ba6c62d49339e
kernel - 3.10.10-1-aafff7801ab1c4fd09e3d3383fb77582
kmod-crypto-aes - 3.10.10-1
kmod-crypto-arc4 - 3.10.10-1
kmod-crypto-core - 3.10.10-1
kmod-crypto-hash - 3.10.10-1
kmod-crypto-manager - 3.10.10-1
kmod-crypto-pcompress - 3.10.10-1
kmod-gpio-button-hotplug - 3.10.10-1
kmod-ip6tables - 3.10.10-1
kmod-ipt-conntrack - 3.10.10-1
kmod-ipt-core - 3.10.10-1
kmod-ipt-nat - 3.10.10-1
kmod-ipt-nathelper - 3.10.10-1
kmod-ipv6 - 3.10.10-1
kmod-leds-gpio - 3.10.10-1
kmod-ledtrig-default-on - 3.10.10-1
kmod-ledtrig-netdev - 3.10.10-1
kmod-ledtrig-timer - 3.10.10-1
kmod-lib-crc-ccitt - 3.10.10-1
kmod-nls-base - 3.10.10-1
kmod-ppp - 3.10.10-1
kmod-pppoe - 3.10.10-1
kmod-pppox - 3.10.10-1
kmod-scsi-core - 3.10.10-1
kmod-scsi-generic - 3.10.10-1
kmod-slhc - 3.10.10-1
kmod-usb-core - 3.10.10-1
kmod-usb-serial - 3.10.10-1
kmod-usb-serial-option - 3.10.10-1
kmod-usb-serial-wwan - 3.10.10-1
kmod-usb2 - 3.10.10-1
libblobmsg-json - 2013-08-01-04f194aa8a04926fe7f2e42bbf9ba6c62d49339e
libc - 0.9.33.2-1
libgcc - 4.6-linaro-1
libip4tc - 1.4.20-1
libip6tc - 1.4.20-1
libiwinfo - 46
libiwinfo-lua - 46
libjson-c - 0.11-2
libjson-script - 2013-08-01-04f194aa8a04926fe7f2e42bbf9ba6c62d49339e
liblua - 5.1.5-1
libnl-tiny - 0.1-3
libopenssl - 1.0.1e-2
libpthread - 0.9.33.2-1
librt - 0.9.33.2-1
libubox - 2013-08-01-04f194aa8a04926fe7f2e42bbf9ba6c62d49339e
libubus - 2013-08-08-b20a8a01c7faea5bcc9d34d10dcf7736589021b8
libubus-lua - 2013-08-08-b20a8a01c7faea5bcc9d34d10dcf7736589021b8
libuci - 2013-06-11.1-1
libuci-lua - 2013-06-11.1-1
libusb-1.0 - 1.0.9-1
libxtables - 1.4.20-1
lua - 5.1.5-1
luci - svn-r9902-1
luci-app-firewall - svn-r9902-1
luci-i18n-english - svn-r9902-1
luci-lib-core - svn-r9902-1
luci-lib-ipkg - svn-r9902-1
luci-lib-nixio - svn-r9902-1
luci-lib-sys - svn-r9902-1
luci-lib-web - svn-r9902-1
luci-mod-admin-core - svn-r9902-1
luci-mod-admin-full - svn-r9902-1
luci-proto-3g - svn-r9902-1
luci-proto-core - svn-r9902-1
luci-proto-ppp - svn-r9902-1
luci-sgi-cgi - svn-r9902-1
luci-theme-base - svn-r9902-1
luci-theme-bootstrap - svn-r9902-1
mtd - 20
netifd - 2013-08-29-814e09499e12edaea658f9f5594fe9917c0ecde4
opkg - 618-3
ppp - 2.4.5-10
procd - 2013-09-10-824a4b3da2c0be19ccf54a48dcd4c10677b82c1a-1
shadowsocks-libev - 1.3.3-9933435506b1c96e8bfe7a0fc5f305398fd0f62e
swconfig - 10
ubox - 2013-08-16.1-5290ec879aa4d9f4192df00aad4434b0f0afa872
ubus - 2013-08-08-b20a8a01c7faea5bcc9d34d10dcf7736589021b8
ubusd - 2013-08-08-b20a8a01c7faea5bcc9d34d10dcf7736589021b8
uci - 2013-06-11.1-1
uhttpd - 2013-07-31-fae8886f8aa5d996c8de607abea8b677216549b5
uhttpd-mod-ubus - 2013-07-31-fae8886f8aa5d996c8de607abea8b677216549b5
usb-modeswitch - 2013-08-20-575c8e8dec6d1f544debe867ebc0bde051209c17
zlib - 1.2.8-1

For shadowsocks, include libopenssl.

TD-SCDMA 3g.chat:
root@OpenWrt:~# cat /etc/chatscripts/3g.chat
ABORT   BUSY
ABORT   'NO CARRIER'
ABORT   ERROR
REPORT  CONNECT
TIMEOUT 10
""      "ATZ"
OK      "ATE0V1"
OK      "ATS0=0"
OK      'AT+CGDCONT=1,"IP","cmwap"'
OK      "AT+CFUN=1"
SAY     "Calling TD-SCDMA"
TIMEOUT 30
OK      "ATD*98*1#"
CONNECT ' '


Refs:
https://github.com/haohaolee/shadowsocks-openwrt

2013年7月30日星期二

Port uCOS to SMT32F103C8

Port µC/OS-II V2.90 to SMT32F103C8

1. Download files

    Download official µC/OS-II V2.86 port for STM32F103RB from Micrium website.
    Download official µC/OS-II V2.90 source code from Micrium website.
    Download official SMT32F103C8 standard peripherals firmware library V3.50 from ST website.

2. Prepare folder and files.

  2.1 Create project_root folder as $ROOT.
  2.2 Create $ROOT\APP $ROOT\BSP $ROOT\CMSIS $ROOT\FWlib $ROOT\Project $ROOT\uCOS-II $ROOT\Output
  2.3 Copy $STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\STM32F10x_StdPeriph_Driver\inc,src $ROOT\FWlib
        Copy  $STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport\* $ROOT\CMSIS
        Copy $STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\*.h/c $ROOT\CMSIS
        Copy $STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup $ROOT\CMSIS\startup
  2.4 Copy $Micrium\Software\uCOS-II\Source to $ROOT/uCOS-II(V2.90)\Source\*.*(except ucos_ii.c) $ROOT\uCOS-II\Source
        Copy $Micrium\Software\uCOS-II\Source to $ROOT/uCOS-II(V2.86)\Ports\*.*(except os_dbg.c) $ROOT\uCOS-II\Ports
  2.5 Copy $STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\*.h/c $ROOT\APP
  2.6 Copy $Micrium\Software\uCOS-II\Source to $ROOT/uCOS-II(V2.90)\Source\os_cfg.h $ROOT\APP
        Copy Copy $Micrium\Software\uCOS-II\Source to $ROOT/uCOS-II(V2.90)\Source\os_dbg.c $ROOT\uCOS-II\Ports
  2.7 Create your BSP files in $ROOT\BSP
  2.8 Create app_cfg.h in $ROOT\APP

3. Create uVision project file in $ROOT\Project

  Add groups and add files
  Define: STM32F10X_MD, USE_STDPERIPH_DRIVER
  Include: ..\CMSIS;..\FWlib\inc;..\uCOS-II\Ports;..\uCOS-II\Source;..\BSP;..\APP

4. Modify files

os_cpu.h

#if OS_CRITICAL_METHOD == 3
OS_CPU_SR  OS_CPU_SR_Save(void);
void       OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);
#endif

void       OSCtxSw(void);
void       OSIntCtxSw(void);
void       OSStartHighRdy(void);

// Interrupt handler
void       PendSV_Handler(void);
void       SysTick_Handler(void);

// system tick initializer
void       OS_CPU_SysTickInit(void);
#endif

os_cpu_a.asm

1. replace all GLOBAL to EXPORT
2. rename OS_CPU_PendSVHandler to PendSV_Handler
;********************************************************************************************************
;                                      CODE GENERATION DIRECTIVES
;********************************************************************************************************

;        RSEG CODE:CODE:NOROOT(2)
    AREA |.text|, CODE, READONLY, ALIGN=2
    THUMB
    REQUIRE8
    PRESERVE8

os_cpu_c.c

1. rename OS_CPU_SysTickHandler to SysTick_Handler
void  OS_CPU_SysTickInit (void)
{
    SysTick_Config(SystemCoreClock/OS_TICKS_PER_SEC);
}

stm32f10x_it.h/c

delete PendSV_Handler and SysTick_Handler

Write app_cfg.h os_cfg.h main.c stm32f10x_conf.h as your need.

---------------------------------END----------------------------

2013年1月13日星期日

OpenVPN on OpenWRT

需要注意的是在使用trunk 自己编译OpenWRT时,必须自己编译kmod-tun,不能使用repo的二进制文件 可能需要自己编译OpenVPN.

GoAgent on OpenWRT 解决崩溃问题

Follow官方WiKi进行安装

后发现打开ssl网站经常导致goagent崩溃,参考官方Issue
里面也提到了原因是libopenssl线程安全问题

参照
制作一个patch并重新编译替换libopenssl

[jejer@arch openwrt]$ cat  openssl.patch       
--- package/libs/openssl/Makefile       2013-01-13 08:31:13.693007113 +0800
+++ package/libs/openssl/Makefile.720n  2013-01-12 22:29:33.576217602 +0800
@@ -46,7 +46,7 @@
   SECTION:=libs
   SUBMENU:=SSL
   CATEGORY:=Libraries
-  DEPENDS:=+zlib
+  DEPENDS:=+zlib libpthread
   TITLE+= (libraries)
   MENU:=1
 endef
@@ -107,12 +107,13 @@
                        $(TARGET_CPPFLAGS) \
                        $(TARGET_LDFLAGS) -ldl \
                        -DOPENSSL_SMALL_FOOTPRINT \
+                       -DOPENSSL_THREADS -pthread -D_REENTRANT -D_THREAD_SAFE -D_THREADSAFE \
                        $(OPENSSL_NO_CIPHERS) \
                        $(OPENSSL_OPTIONS) \
        )
 endef
-TARGET_CFLAGS += $(FPIC)
+TARGET_CFLAGS += $(FPIC) -DOPENSSL_THREADS -pthread -D_REENTRANT -D_THREAD_SAFE -D_THREADSAFE
 define Build/Compile
        # XXX: OpenSSL "make depend" will look for installed headers before its own,
[jejer@arch openwrt]$ patch -p0 < openssl.patch 

make编译之后直接安装新的bin/ar71xx/packages/libopenssl_1.0.1c-1_ar71xx.ipk即可

2013年1月11日星期五

OpenWRT for WR720N

OpenWRT already officially support WR720N!
Ref:
http://wiki.openwrt.org/toh/tp-link/tl-wr720n

准备工作


Linux磁盘空间大概要准备10G.

先从svn checkout出OpenWRT
svn checkout svn://svn.openwrt.org/openwrt/trunk openwrt

进去看一下

[jejer@arch ~]$ cd openwrt/
[jejer@arch openwrt]$ ls
BSDmakefile LICENSE README feeds.conf.default package scripts toolchain
Config.in Makefile docs include rules.mk target tools

好了.

修改源文件


1. 720比703多一个网口,修改target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr703n.c

[jejer@arch openwrt]$ cat mach-tl-wr703n.c.patch
--- target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr703n.c  2013-01-11 09:38:21.023697097 +0800
+++ target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr703n.c.720n     2013-01-11 09:41:35.537043980 +0800
@@ -77,10 +77,12 @@
                         "USB power");
        ath79_register_usb();
-       ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
+       ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
+       ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
        ath79_register_mdio(0, 0x0);
        ath79_register_eth(0);
+       ath79_register_eth(1);
        ath79_register_wmac(ee, mac);
 }
[jejer@arch openwrt]$ patch -p0 < mach-tl-wr703n.c.patch
然后手动附加上一个/etc/config/network配置文件
[jejer@arch openwrt]$ mkdir -p files/etc/config/
[jejer@arch openwrt]$ vim files/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 'wan'
        option ifname 'eth0'
        option proto 'dhcp'
config interface 'lan'
        option ifname 'eth1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
2. 让OpenWRT的WEB界面通刷所有703N 720N固件
    703n的固件标识是:07030101,720n的是:07200103
    target/linux/ar71xx/base-files/lib/upgrade/platform.sh
[jejer@arch openwrt]$ cat platform.sh.patch
--- target/linux/ar71xx/base-files/lib/upgrade/platform.sh      2013-01-11 09:16:58.527929980 +0800
+++ target/linux/ar71xx/base-files/lib/upgrade/platform.sh.720n 2013-01-11 10:14:35.546380864 +0800
@@ -178,7 +178,13 @@
                local imageid
                hwid=$(tplink_get_hwid)
+               [ "$hwid" = "07200103" ] && {
+                       hwid="07030101"
+               }
                imageid=$(tplink_get_image_hwid "$1")
+               [ "$imageid" = "07200103" ] && {
+                       imageid="07030101"
+               }
                [ "$hwid" != "$imageid" ] && {
                        echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
[jejer@arch openwrt]$ patch -p0 < platform.sh.patch

3. 使路由的Router Model显示为    TP-LINK TL-WR720N V3
    target/linux/ar71xx/base-files/lib/ar71xx.sh
[jejer@arch openwrt]$ cat ar71xx.sh.patch
--- target/linux/ar71xx/base-files/lib/ar71xx.sh        2013-01-11 09:16:58.527929980 +0800
+++ target/linux/ar71xx/base-files/lib/ar71xx.sh.720n   2013-01-11 10:19:06.548365673 +0800
@@ -475,7 +475,7 @@
        [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
        echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
-       echo "$AR71XX_MODEL" > /tmp/sysinfo/model
+       echo "TP-LINK TL-WR720N V3" > /tmp/sysinfo/model
 }
 ar71xx_board_name() {
[jejer@arch openwrt]$ patch -p0 < ar71xx.sh.patch

4. 无线开启
    package/mac80211/files/lib/wifi/mac80211.sh
    package/madwifi/files/lib/wifi/madwifi.sh?
[jejer@arch openwrt]$ cat mac80211.sh.patch
--- package/mac80211/files/lib/wifi/mac80211.sh 2013-01-11 09:17:02.621297461 +0800
+++ package/mac80211/files/lib/wifi/mac80211.sh.720n    2013-01-11 10:37:01.223478065 +0800
@@ -591,7 +591,6 @@
 $dev_id
 $ht_capab
        # REMOVE THIS LINE TO ENABLE WIFI:
-       option disabled 1

 config wifi-iface
        option device   radio$devidx
[jejer@arch openwrt]$ patch -p0 < mac80211.sh.patch

5. 长按RESET恢复出厂设置
6. 模式切换开关

OpenWRT配置与编译

make clean
svn up
./scripts/feeds update -a
./scripts/feeds install -a
make defconfig
make menuconfig
Target System (Atheros AR7xxx/AR9xxx)
Target Profile (TP-LINK TL-WR703N)
LuCI--Collections--<*> luci
USB Storage http://wiki.openwrt.org/doc/howto/usb.storage
extroot http://wiki.openwrt.org/doc/howto/extroot
3G http://wiki.openwrt.org/doc/recipes/3gdongle
make V=99

参考链接

diff -Naur 旧的目录 新的目录 > patch文件
或者
diff -Naur 旧的文件 新的文件 > patch文件