Installing FreeBSD on TP-Link TL-WR1043ND
Posted: July 1st, 2013 | Author: hiren | Filed under: FreeBSD, wifi, wireless | Tags: wifi mips embedded | 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:
Got usb to ttl serial cable to connect to the tx, rx and gnd pins.
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
[email protected]:/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:
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:
gpio0: [GIANT-LOCKED]
gpio0: function_set: 0x2000
gpio0: function_clear: 0x0
gpio0: gpio pinmask=0x1c02ae
gpioc0:
gpiobus0:
gpioled1:
gpioled2:
gpioled3:
gpioiic0:
iicbb0:
iicbus0:
iic0:
rtl8366rb0:
rtl8366rb0: rev. 3
miibus0:
ukphy0:
ukphy0: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus1:
ukphy1:
ukphy1: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus2:
ukphy2:
ukphy2: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus3:
ukphy3:
ukphy3: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
miibus4:
ukphy4:
ukphy4: none, 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, 1000baseT-FDX-master, auto
etherswitch0:
ehci0:
usbus0: set host controller mode
usbus0: EHCI version 1.0
usbus0: set host controller mode
usbus0 on ehci0
arge0:
arge0: Overriding MAC from EEPROM
arge0: finishing attachment, phymask 0000, proxy null
arge0: Ethernet address: 64:70:02:cd:94:56
arge1:
arge1: finishing attachment, phymask 0000, proxy null
arge1: Ethernet address: 64:70:02:cd:94:57
ath0:
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:
spibus0:
mx25l0:
mx25l0: s25sl064a, sector 65536 bytes, 128 sectors
ar71xx_wdog0:
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:
uhub0:
map/rootfs.uzip: 1123 x 16384 blocks
hwpmc: SOFT/16/64/0x67
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.
I enjoyed reading about your FreeBSD experience and look forward to more updates! Your work reminds me of a project which I have to finish… which is modding a Seagate Dockstar as a home network firewall but this newer hardware looks pretty nice I must admit!
-Eddie
I am glad you find it enjoyable!
Segate Dockstar also looks pretty slick and promising. Specially 1.2GHz processor. Not enough ram though.
Hi, Thank you for your blog I have enjoyed reading about your experience. I have a question if you don’t mind. On my attempt to do a build using the scripts you mention I got an error message “kernel image is too big” at the very end. What did you have to do to reduce the kernel build size?
Thanks!
Yeah, kernel has grown just a bit too big in last few months. You can turn off things you do not want in the kernel config file ($src/sys/mips/conf/TP-WN1043ND). Or try building with a couple months old -current source tree. Hope this helps. Let me know if you need more info.
Hi, thank you for your reply. I’ve just returned from traveling abroad and will try out your suggestions.
Hi,
I have tried to add the line “options NO_GAMES= true # do not build games (games/ subdir)” to $src/sys/mips/conf/TP-WN1043ND but kernelbuild fails with message “unknown option “NO_GAMES””. Could you give me an example of an entry you made in TP-WN104ND that resulted in excluding something from the kernelbuild process. Thank you again.
Hi Cam.
I will hopefully have some more time at my hand to sit down and look at this. I am currently running about 4 months old kernel which fits just fine. As I said, kernel got a bit too big in last few months. If you want, you can checkout a bit older source tree and build the kernel out of that.
Also, games are not part of kernel so what you are doing is not going to help.
To determine how kernel is being build, you need to look at kernel config file for this router: http://svnweb.freebsd.org/base/head/sys/mips/conf/TP-WN1043ND?revision=239625&view=co And if you see on the top it is including AR91XX_BASE : http://svnweb.freebsd.org/base/head/sys/mips/conf/AR91XX_BASE?revision=253845&view=co
These files are already trimmed down to only needed things as it is. But to reduce more, you may want to disable debug options or something like that. As I said, I still haven’t gotten time to figure it out and test it.
Do not hesitate to ask questions if/when you get stuck.
Hi,
Thank for your assistance! So far I have gotten these results:
Building a kernel with all debugging references disabled in files: (AR91XX_BASE and TP-WN1043ND).
I first (as previously) used “svn checkout svn://svn.freebsd.org/base/head src” and resulted in this:
[email protected]:/tftpboot # ls -l
total 30048
-r-xr-xr-x 1 root wheel 5701481 Aug 15 14:31 kernel.TP-WN1043ND
-r-xr-xr-x 1 root wheel 18612343 Aug 15 14:31 kernel.TP-WN1043ND.symbols
-rwxr-xr-x 1 root wheel 6116352 Aug 15 14:32 mfsroot-tl-wr1043nd.img.uzip
[email protected]:/tftpboot #
Next I deleted everything in /src and used “svn checkout svn://svn.freebsd.org/base/stable/9/ src” and resutled in this message:
Populating `/root/work/freebsd/head/src/../mfsroot-tl-wr1043nd.img’
Image `/root/work/freebsd/head/src/../mfsroot-tl-wr1043nd.img’ complete
*** Running mkuzip to create a compressed filesystem ..
*** Target Done.
*** Target : tplink
4388+2 records in
4388+1 records out
2247039 bytes transferred in 2.756113 secs (815293 bytes/sec)
[mktplinkfw] *** error: kernel image is too big
[email protected]:/root/work/freebsd/head/src #
The build result was this:
[email protected]:/tftpboot # ls -l
total 17344
-r-xr-xr-x 1 root wheel 11953552 Aug 15 21:01 kernel.TP-WN1043ND
-rwxr-xr-x 1 root wheel 5713408 Aug 15 21:01 mfsroot-tl-wr1043nd.img.uzip
[email protected]:/tftpboot #
I am not sure why but the new build with the older code seems to be larger? Is there a step I have missed?
Best regards
Hi Cam,
Size depends on whats in the tree at that point in time.
For now, please use the image I’ve generated in may end:
http://www.strugglingcoder.info/pkgs/TP-WN1043ND.factory.bin
I am trying to look into how to shrink kernel and mfsroot.
Thank you! I will try it using your image. Hopefully later, I can work out how to make my own image by reducing the kernel size. Could you tell me what release you used to build your image? From what I have discovered it looks like the “/build/build/bin/build_freebsd” script is what needs to be edited. I have been trying various combinations but have not been able to get the image size below 11M. Here is what I have tried (so far):
…
# Create a make.conf
echo “#MALLOC_PRODUCTION=” > ${X_DESTDIR}/../make.conf.${BUILDNAME}
# Make a src.conf
echo ‘WITHOUT_KERBEROS=”YES”‘ > ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_KERBEROS_SUPPORT=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_NIS=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_NDIS=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_IPX=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_ATM=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_ICONV=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_CLANG_IS_CC=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_BLUETOOTH=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_EXAMPLES=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_MAN=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_RESCUE=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_SENDMAIL=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_ACPI=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_INET6=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_PAM=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_PF=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
echo ‘WITHOUT_IPFILTER=”YES”‘ >> ${X_DESTDIR}/../src.conf.${BUILDNAME}
Sorry for delayed response. We are still trying to finalize diffs for reducing the kernel and rootfs size but for now you can use http://www.strugglingcoder.info/patches/shrink_TP-WN1043ND_temp.txt – And that should generate smaller kernel.