tl-wr802n v1: 通过tuboot.bin进行固件更新 – 安装OpenWrt 15.05

我们已经可以从tplink官方提供的代码编译出了tl-wr802n v1可用的bootloader, 并且将tuboot.bin写入到flash也可以正常运行。之后,我们看一下如何进入uboot的交互模式,并通过编译出来的uboot程序进行固件升级,写入openwrt 15.05固件。

  • 准备工作

之前焊接的串口线只能用来输出log信息,但是不能用于字串输入,原因是电路板上的R23电阻没有焊接,使得Rx与CPU的连线是断开的,所以我们需要补焊这颗电阻,经实践,可以使用阻值为1k 0402的贴片电阻。

路由器的bootloader/fw可以支持4MB, 8M, 16M的SPI flash, 可以顺便将flash升级为16M( 如w25Q128), 当然你还需要一个SPI编程器,将tuboot.bin烧进去。

软件上,在编译bootloader的时候,在生成include/config.h配置文件的时候,要指定FLASH_SIZE=4 (4M); FLASH_SIZE=8 (8M); FLASH_SIZE=16 (16M);

  • 查看当前固件布局(tp-link官方固件)

从kernel log中可以看到:

[    0.000000] Linux version 2.6.31 (tplink@localhost.localdomain) (gcc version 4.3.3 (GCC) ) #1 Thu May 7 16:10:04 CST 2015
...
[    0.392000] 5 cmdlinepart partitions found on MTD device ath-nor0
[    0.400000] Creating 5 MTD partitions on "ath-nor0":
[    0.404000] 0x000000000000-0x000000020000 : "u-boot"
[    0.408000] 0x000000020000-0x000000120000 : "kernel"
[    0.416000] 0x000000120000-0x0000003e0000 : "rootfs"
[    0.424000] 0x0000003e0000-0x0000003f0000 : "config"
[    0.428000] 0x0000003f0000-0x000000400000 : "art"
[    0.436000] ->Oops: flash id 0xef4016 .
...

可以看到u-boot(bootloader)占用了开始的128kB, kernel占用了1MB, art占用了最后的64kB

  • 进入u-boot交互模式的方法

当log中出现”Autobooting in 1 seconds”的时候,快速输入tpl

之后可以进入交互模式,执行uboot built-in command:

ap143-2.0> help
?       - alias for 'help'
boot    - boot default, i.e., run 'bootcmd'
bootd   - boot default, i.e., run 'bootcmd'
bootm   - boot application image from memory
cp      - memory copy
erase   - erase FLASH memory
help    - print online help
mct   - simple RAM test
md      - memory display
mm      - memory modify (auto-incrementing)
mtest   - simple RAM test
mw      - memory write (fill)
nm      - memory modify (constant address)
ping	- send ICMP ECHO_REQUEST to network host
printenv- print environment variables
progmac - Set ethernet MAC addresses
progmac2 - Set ethernet MAC addresses
reset   - Perform RESET of the CPU
run     - run commands in an environment variable
setenv  - set environment variables
tftpboot- boot image via network using TFTP protocol
version - print monitor version

当然,包含最常用的几个命令:

  1. bootm
  2. ping
  3. printenv
  4. setenv
  5. tftpboot
  • 搭建tftp服务器

首先你需要在PC端搭建一个tftp服务器。我有RPi 2B, 并且安装了最新的Raspbian系统,可以这么做:

$ sudo apt-get install atftpd
$ mkdir -pv ~/srv
$ cd ~/srv && sudo atftpd -v --daemon `pwd`

tl-wr802n v1的CPU (QCA9533)与基本的硬件配置与tl-wr841n v9是一样的, 具体可以看:

https://wiki.openwrt.org/toh/tp-link/tl-wr841nd

如果你使用的是4M的flash, 你可以下载openwrt官方的固件:

https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/openwrt-15.05-ar71xx-generic-tl-wr841n-v9-squashfs-factory.bin

[2016-01-25 20:25:12]

只要flash大于4M即可安装(由于image使用了SquashFS + JFFS2 + OverlayFS)。

由于我已经将flash芯片更换为16M的w25q128, 并在本地编译了openwrt的代码:最终在bin/ar71xx中生成16M版本的固件:

openwrt-ar71xx-generic-tl-wr841n-v9-squashfs-factory.bin

将文件copy到~/srv中,同时修改ip地址为192.168.1.10:

$ cp openwrt-ar71xx-generic-tl-wr841n-v9-squashfs-factory.bin ~/srv
$ ifconfig eth0 192.168.1.10

NOTE:

文件名称太长可能会下载失败,如果下载失败,试试将文件名称改短。同时要注意文件权限(Linux)。

当然,你可以以更改路由器的ip地址和指定的server的ip地址:

ap143-2.0> setenv ipaddr 10.0.0.25
ap143-2.0> setenv serverip 10.0.0.13
  • 固件下载

用网线将tl-wr802n与RPi 2B相连,开始下载固件:

在串口终端中输入:

ap143-2.0> tftpboot 0x80100000 openwrt-ar71xx-generic-tl-wr841n-v9-squashfs-factory.bin
eth1 link down
enet0 port4 up
dup 1 speed 100
Using eth0 device
TFTP from server 192.168.1.10; our IP address is 192.168.1.1
Filename 'wr802n.bin'.
Load address: 0x80100000
Loading: *#################################################################
	 #######################################################
done
Bytes transferred = 16252928 (f80000 hex)

NOTE:  指定RAM地址的时候需要注意 0x80010000开始的一段地址是给uboot使用的,需要保留。

擦除flash中的相关block:

ap143-2.0> erase 0x9f020000 +0xf80000
Erasing flash... 
First 0x2 last 0xf9 sector size 0x10000
 ...
Erased 248 sectors

将固件写入flash中:

ap143-2.0> cp.b 0x80100000 0x9f020000 0xf80000
Copy to Flash... write addr: 9f020000
done

重启:

ap143-2.0> reset
  • 新固件布局(16MB)
[    0.690000] m25p80 spi0.0: found w25q128, expected m25p80
[    0.700000] m25p80 spi0.0: w25q128 (16384 Kbytes)
[    0.700000] 5 tp-link partitions found on MTD device spi0.0
[    0.710000] Creating 5 MTD partitions on "spi0.0":
[    0.710000] 0x000000000000-0x000000020000 : "u-boot"
[    0.720000] 0x000000020000-0x0000001356b0 : "kernel"
[    0.730000] 0x0000001356b0-0x000000ff0000 : "rootfs"
[    0.730000] mtd: device 2 (rootfs) set to be root filesystem
[    0.740000] 1 squashfs-split partitions found on MTD device rootfs
[    0.740000] 0x000000300000-0x000000ff0000 : "rootfs_data"
[    0.750000] 0x000000ff0000-0x000001000000 : "art"
[    0.760000] 0x000000020000-0x000000ff0000 : "firmware"
  • 写入art文件:

从源flash中提取完整的固件,art是文件最后的64KB:

$ dd if=tl-wr802n_fw.bin of=tl-wr802n_fw_art.bin bs=$((0x10000)) count=1 skip=$((0x3f))

得到了64KB的art后,之后的方法同之前的固件下载。

ap143-2.0> setenv ipaddr 10.0.0.25
ap143-2.0> setenv serverip 10.0.0.13
ap143-2.0> tftp 0x80100000 artHACKED.bin
eth1 link down
Using eth0 device
TFTP from server 10.0.0.13; our IP address is 10.0.0.25
Filename 'artHACKED.bin'.
Load address: 0x80100000
Loading: #############
done
Bytes transferred = 65536 (10000 hex)
ap143-2.0> erase 0x9fff0000 +0x10000
Erasing flash... 
First 0xff last 0xff sector size 0x10000
 255
Erased 1 sectors
ap143-2.0> cp.b 0x80100000 0x9fff0000 0x10000
Copy to Flash... write addr: 9fff0000
done

NOTE: 关于30 dBm tx power hack (v9)

请参考:https://wiki.openwrt.org/toh/tp-link/tl-wr841nd

Note: 30 dBm tx power can't be set if your wireless country is any that allow higher channel than channel 11 (i.e. Viet Nam). If you encounter this situation, I suggest you should change your country to 00 - World

1. First, install jow's reghack, follow those instructions (for ar71xx): http://luci.subsignal.org/~jow/reghack/README.txt
2. Flash this OpenWrt image with ART partition unlocked: https://goo.gl/InZONA
3. Download this hacked ART image: https://goo.gl/bz8oo1
4. Make a backup of your original ART:
dd if=/dev/mtd4 of=/tmp/orig_art.bin
5. Use SCP to transfer it to a safe place, then delete it from /tmp folder.
6. Transfer the hacked ART to the /tmp folder via SCP.
7. Run:
mtd -r write /tmp/artHACKED.bin art
8. Your router will reboot. After that, you will be able to set 30 dBm tx power.
  • 2016-01-26 20:23:36]第一次开机

由于tl-wr802n v1仅有的一个网口被识别成了WAN口,而OpenWrt系统默认情况下是不开WiFi的,并且WAN口防火墙的策略是reject所有的input, 所以即使路由器上已经开启了ssh server(dropbear), 你也是没办法登录的。

解决的办法是:

在串口终端中关闭防火墙,将路由器接入到另外一下路由器中,找到它的IP地址,在电脑上打开路由器的配置网页,到Network->Firewall->Zones->wan(wan, wan6)=>REJECT将input那一列由reject改成accept。

关闭防火墙:

# /etc/init.d/firewall stop

当然,也可以在串口终端中通过vi进行修改(将/etc/config/firewall文件中的config zone中的option input ‘REJECT’ 改成’ACCEPT’:

config zone
        option name 'wan'
        list network 'wan'
        list network 'wan6'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        option input 'ACCEPT'

 

评论

1 Comment on "tl-wr802n v1: 通过tuboot.bin进行固件更新 – 安装OpenWrt 15.05"

提醒我
avatar

hello
游客
hello
1 年 7 月 之前

请教一个问题:tl-wr841n-v9编译出16M的固件,需要修改哪些地方?我修改后编译出来的factory是16M,但是其中的rootfs和kernel还是4M时候的布局,麻烦指教一下,多谢

wpDiscuz