Installing FreeBSD on TP-Link TL-WR1043ND

Posted: July 1st, 2013 | Author: | Filed under: FreeBSD, wifi, wireless | Tags: | 11 Comments »

I decided to play with some wireless router and put FreeBSD on it. Adrian suggested TL-WR1043ND so I bought it.

I’ve used Adrian Chadd’s scripts do this. All the commands for flashing is also from him. A *huge* thanks to him.

I’ve also referenced OpenWRT page a lot.

Serial connection was the first thing I had to determine. Figured out serial pinouts from the OpenWRT page. Did my first soldering job:
image

Got usb to ttl serial cable to connect to the tx, rx and gnd pins.
image

After having serial connection setup, next thing was to load FreeBSD on it. (It comes with preloaded linux on it.) I grabbed image building tool from Adrian Chadd’s scripts and generated an image out of freebsd-head suitable for this board: TP-WN1043ND.factory.bin

Now, what you do is, plug usb end of the serial cable into laptop which FreeBSD presents as a cuaUN device. (Check your dmesg o/p to know value of “N”)
Connect to it via:

#cu -s 115200 -l /dev/cuaU0

Now power on the router and interrupt the boot process by typing “tpl” to drop into “uboot” prompt.
uboot looks like this:

ar7100> printenv
bootargs=console=ttyS0,115200 root=31:02 rootfstype=jffs2 init=/sbin/init mtdparts=ar9100-nor0:128k(u-boot),1024k(kernel),4096k(rootfs
),64k(art)
bootcmd=bootm 0xbf020000
bootdelay=1
baudrate=115200
ethaddr=00:1D:0F:11:22:33
ipaddr=192.168.0.2
serverip=192.168.0.5
stdin=serial
stdout=serial
stderr=serial
ethact=eth0

Environment size: 317/131068 bytes

Now starts the fleshing of firmware part. The first step below is *VERY* important…

# This erases the flash between uboot and the firmware configuration area. Whatever you do, don't mistype this!
erase 0xbf020000 +7c0000

Now, we should setup the tftp part so that we can get image we prepared from tftpserver (laptop) to tftpclient (router board). uboot is very specific about the IP addresses of both server and client. As per “printenv”, server IP *must* be 192.168.0.5 so assign that IP to the ethernet interface (via ifconfig alias). Run a network cable from laptop to one if the LAN ports of the router. (Original instructions suggest using the WAN port which did not work for me (because of which I wasted 2 frustrating weeks debugging)). Start tftpserver on laptop and copy prepared image in respective location (/tftpboot by default)

Let’s transfer/copy the image to router via tftp into RAM:

ar7100> tftpboot 0x81000000 TP-WN1043ND.factory.bin
dup 1 speed 1000
Using eth0 device
TFTP from server 192.168.0.5; our IP address is 192.168.0.2
Filename 'TP-WN1043ND.factory.bin'.
Load address: 0x81000000
Loading: T T T T T T T T #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
############################
done
Bytes transferred = 8126464 (7c0000 hex)

Next step is to copy firmware image from RAM to the flash.

cp.b 0x81000000 0xbf020000 0x7c0000

Let’s boot the damn thing :-)

bootm 0xbf020000
## Booting image at bf020000 ...
Uncompressing Kernel Image ... OK

Starting kernel ...

CPU platform: Atheros AR9132 rev 2
CPU Frequency=400 MHz
CPU DDR Frequency=400 MHz
CPU AHB Frequency=200 MHz
platform frequency: 400000000
arguments:
a0 = 00000007
a1 = a1f77fb0
a2 = a1f78440
a3 = 00000008
Cmd line:argv is invalid
Environment:
envp is invalid
Cache info:
picache_stride = 4096
picache_loopcount = 16
pdcache_stride = 4096
pdcache_loopcount = 8
cpu0: MIPS Technologies processor v116.147
MMU: Standard TLB, 16 entries
L1 i-cache: 4 ways of 512 sets, 32 bytes per line
L1 d-cache: 4 ways of 256 sets, 32 bytes per line
Config1=0x9ee3519e
Config3=0x20
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2013 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 10.0-CURRENT #0 r248805M: Wed Dec 31 16:00:00 PST 1969
hirenp@dummy:/home/hirenp/work/freebsd/head/obj/mipseb/mips.mips/usr/home/hirenp/work/freebsd/head/src/sys/TP-WN1043ND mips
gcc version 4.2.1 20070831 patched [FreeBSD]
WARNING: WITNESS option enabled, expect reduced performance.
real memory = 33554432 (32768K bytes)
avail memory = 24944640 (23MB)
random device not loaded; using insecure entropy
nexus0:
clock0: on nexus0
Timecounter "MIPS32" frequency 200000000 Hz quality 800
Event timer "MIPS32" frequency 200000000 Hz quality 800
apb0 at irq 4 on nexus0
uart0: <16550 or compatible> on apb0
uart0: console (115200,n,8,1)
gpio0: on apb0
gpio0: [GIANT-LOCKED]
gpio0: function_set: 0x2000
gpio0: function_clear: 0x0
gpio0: gpio pinmask=0x1c02ae
gpioc0: on gpio0
gpiobus0: on gpio0
gpioled1: at pin(s) 2 on gpiobus0
gpioled2: at pin(s) 5 on gpiobus0
gpioled3: at pin(s) 9 on gpiobus0
gpioiic0: at pin(s) 18-19 on gpiobus0
iicbb0: on gpioiic0
iicbus0: on iicbb0 master-only
iic0: on iicbus0
rtl8366rb0: at addr 0xa8 on iicbus0
rtl8366rb0: rev. 3
miibus0: on rtl8366rb0
ukphy0: PHY 0 on miibus0
ukphy0: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus1: on rtl8366rb0
ukphy1: PHY 1 on miibus1
ukphy1: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus2: on rtl8366rb0
ukphy2: PHY 2 on miibus2
ukphy2: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus3: on rtl8366rb0
ukphy3: PHY 3 on miibus3
ukphy3: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus4: on rtl8366rb0
ukphy4: PHY 4 on miibus4
ukphy4: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
etherswitch0: on rtl8366rb0
ehci0: at mem 0x1b000100-0x1bffffff irq 1 on nexus0
usbus0: set host controller mode
usbus0: EHCI version 1.0
usbus0: set host controller mode
usbus0 on ehci0
arge0: at mem 0x19000000-0x19000fff irq 2 on nexus0
arge0: Overriding MAC from EEPROM
arge0: finishing attachment, phymask 0000, proxy null
arge0: Ethernet address: 64:70:02:cd:94:56
arge1: at mem 0x1a000000-0x1a000fff irq 3 on nexus0
arge1: finishing attachment, phymask 0000, proxy null
arge1: Ethernet address: 64:70:02:cd:94:57
ath0: at mem 0x180c0000-0x180effff irq 0 on nexus0
ath0: eeprom @ 0x1fff1000
ath0: eeprom data @ 0xbfff1000
ath0: [HT] enabling HT modes
ath0: [HT] 2 RX streams; 2 TX streams
ath0: AR9130 mac 20.1 RF2133 phy 10.2
ath0: 2GHz radio: 0x0000; 5GHz radio: 0x00d0
spi0: at mem 0x1f000000-0x1f00000f on nexus0
spibus0: on spi0
mx25l0: at cs 0 on spibus0
mx25l0: s25sl064a, sector 65536 bytes, 128 sectors
ar71xx_wdog0: on nexus0
ar71xx_wdog0: Previous reset was due to watchdog timeout
Timecounters tick every 1.000 msec
rtl8366rb0port0: link state changed to DOWN
rtl8366rb0port1: link state changed to DOWN
rtl8366rb0port2: link state changed to DOWN
rtl8366rb0port3: link state changed to DOWN
rtl8366rb0port4: link state changed to DOWN
usbus0: 480Mbps High Speed USB v2.0
ugen0.1: at usbus0
uhub0: on usbus0
map/rootfs.uzip: 1123 x 16384 blocks
hwpmc: SOFT/16/64/0x67 MIPS24K/2/32/0x1ff
WARNING: WITNESS option enabled, expect reduced performance.
Root mount waiting for: usbus0
uhub0: 1 port with 1 removable, self powered
Trying to mount root from ufs:map/rootfs.uzip []...
warning: no time-of-day clock registered, system time will not be set accurately
May 24 18:55:57 init: login_getclass: unknown class 'daemon'
rtl8366rb0port1: link state changed to UP
*** Populating /var ..
*** Loading configuration files ..
*** Restoring from /dev/map/cfg ..
gunzip: unknown compression format
1+0 records in
1+0 records out
65536 bytes transferred in 0.088297 secs (742223 bytes/sec)
0 blocks
*** Completed.
*** setting up hostname
*** Load kernel modules
kldload: can't load bridgestp: File exists
kldload: can't load if_bridge: No such file or directory
kldload: can't load random: File exists
*** bringing up loopback ..
*** Starting networking via /etc/rc.d/base/net
dev.ath.0.txq_mcastq_maxdepth: 512 -> 32
sysctl: unknown oid 'dev.ath.1.txq_mcastq_maxdepth': No such file or directory
*** Interface: arge0: start
*** Interface: arge0: done
*** Interface: bridge0: start
bridge0: Ethernet address: 9e:de:f8:cb:67:4f
arge0: promiscuous mode enabled
bridge0: link state changed to UP
*** Interface: bridge0: done
*** Default password/login databases ..
*** inetd
*** Done!

FreeBSD/mips (freebsd-wifi-build) (ttyu0)

# df -k
Filesystem 1024-blocks Used Avail Capacity Mounted on
map/rootfs.uzip 17695 16769 -489 103% /
devfs 1 1 0 100% /dev
/dev/md0 828 8 756 1% /tmp
/dev/md1 828 56 708 7% /var
/dev/md2 828 436 328 57% /etc
#

Next up is _actually_ using this thing: creating wireless network and other fun stuff.