openwrt tftp 升級軟件的方法

1.升級前需要知道的知識
硬件接上串口,啓動的時候不斷的按任意鍵進入uboot模式,用printenv命令查看環境
ath> printenv
bootargs=console=ttyS0,115200 root=31:02 rootfstype=jffs2 init=/sbin/init mtdparts=ath-nor0:256k(u-boot),64k(u-boot-env),14528k(rootfs),1408k(uImage),64k(mib0),64k(ART)
bootcmd=bootm 0x9fe80000
bootdelay=2
baudrate=115200
ethaddr=0x00:0xaa:0xbb:0xcc:0xdd:0xee
ipaddr=192.168.1.1
serverip=192.168.1.10
dir=
lu=tftp 0x80060000 ${dir}u-boot.bin&&erase 0x9f000000 +$filesize&&cp.b $fileaddr 0x9f000000 $filesize
lf=tftp 0x80060000 ${dir}ap151${bc}-jffs2&&erase 0x9f050000 +0xE30000&&cp.b $fileaddr 0x9f050000 $filesize
lk=tftp 0x80060000 ${dir}vmlinux${bc}.lzma.uImage&&erase 0x9fe80000 +$filesize&&cp.b $fileaddr 0x9fe80000 $filesize
stdin=serial
stdout=serial
stderr=serial
ethact=eth0

Environment size: 684/65532 bytes
ath>
上面中的環境變量與tftp升級相關的是下面三行內容:
lu=tftp 0x80060000 ${dir}u-boot.bin&&erase 0x9f000000 +$filesize&&cp.b $fileaddr 0x9f000000 $filesize
lf=tftp 0x80060000 ${dir}ap151${bc}-jffs2&&erase 0x9f050000 +0xE30000&&cp.b $fileaddr 0x9f050000 $filesize
lk=tftp 0x80060000 ${dir}vmlinux${bc}.lzma.uImage&&erase 0x9fe80000 +$filesize&&cp.b $fileaddr 0x9fe80000 $filesize

設置lu lf 和 lk 爲別名,代替後面的命令集
lu=tftp 0x80060000 ${dir}u-boot.bin&&erase 0x9f000000 +$filesize&&cp.b $fileaddr 0x9f000000 $filesize
    (1) 將u-boot.bin文件上傳到0x80060000地址;注意${dir}u-boot.bin&&erase代指相對應的需要升級的文件名  
    (2)然後從地址0x9f000000開始,擦除filesize大小;
    (3)從fileaddr地址中複製數據,大小爲filesize,到地址0x9f000000.也就是說設備的地址從0x9f000000開始,到 0x9f000000+filesize裏面存放的是u-boot。

lf=tftp 0x80060000 ${dir}ap151${bc}-jffs2&&erase 0x9f050000 +0xE30000&&cp.b $fileaddr 0x9f050000 $filesize
     (1)上傳${dir}ap151${bc}-jffs2到地址0x80060000;注意${dir}ap151${bc}-jffs2代指相對應的需要升級的文件名
     (2)然後從地址0x9f050000開始,擦除0xE30000大小;
     (3)從fileaddr地址中複製數據,大小爲filesize,到地址0x9f050000也就是說設備的地址從0x9f050000開始,到 0x9f050000+filesize裏面存放的是rootfs。
 

lk=tftp 0x80060000 ${dir}vmlinux${bc}.lzma.uImage&&erase 0x9fe80000 +$filesize&&cp.b $fileaddr 0x9fe80000 $filesize
     (1)上傳${dir}vmlinux${bc}.lzma.uImage 到地址0x80060000;注意${dir}vmlinux${bc}.lzma.uImage代指相對應的需要升級的文件名
     (2)然後從地址0x9fE80000開始,擦除filesize大小;
     (3)從fileaddr地址中複製數據,大小爲filesize,到地址0x9E80000
也就是說設備的地址從0x9fE80000開始,到 0x9fE80000+filesize裏面存放的是kernel。


2.開始升級
openwrt編譯後/bin/ar71xx/目錄下會生成對應的升級軟件

找到和自己手上對應的硬件對應的軟件,我編譯的是ap151-16M的flash的firmware,如上圖與我的硬件相關的文件有四個:
openwrt-ar71xx-ap151-16M-qca-legacy-uboot.bin
openwrt-ar71xx-generic-ap151-16M-kernel.bin
openwrt-ar71xx-generic-ap151-16M-rootfs-squashfs.bin
openwrt-ar71xx-generic-ap151-16M-squashfs-sysupgrade.bin
升級方式有兩種:
第一種升級方式(uboot.bin+kernel.bin+squashfs.bin):
升級uboot:
tftp 0x80060000 openwrt-ar71xx-ap151-16M-qca-legacy-uboot.bin
erase 0x9f000000 +0x28bec;cp.b 0x80060000 0x9f000000 0x28bec

0x28bec是uboot文件的大小,第一條命令下完之後可以看到文件的大小,如下所示
TFTP fromserver 192.168.1.10; our IP address is 192.168.1.1
Filename'openwrt-ar71xx-ap151-16M-qca-legacy-uboot.bin'.
Loadaddress: 0x80060000
Loading:#################################
done
Bytestransferred = 166892 (28bec hex)

(當然也可以不指定文件大小如升級uboot可以使用tftp 0x80060000 openwrt-ar71xx-ap151-16M-qca-legacy-uboot.bin;erase 0x9f000000 +0x40000;cp.b $fileaddr 0x9f000000 $filesize)
升級kernel:
tftp 0x80060000 openwrt-ar71xx-generic-ap151-16M-kernel.bin
erase 0x9f680000 +0x110000;cp.b 0x80060000 0x9f680000 0x110000


升級quashfs:
tftp 0x80060000openwrt-ar71xx-generic-ap151-16M-rootfs-squashfs.bin
erase 0x9f050000 +0x620000;cp.b 0x800600000x9f050000 0x620000


第二種升級方式(uboot.bin+sysupgrade.bin):

sysupgrade.bin將kernel和quashfs合成在一起了,所以只需要uboot.bin+sysupgrade.bin即可
升級uboot:
tftp 0x80060000 openwrt-ar71xx-ap151-16M-qca-legacy-uboot.bin
erase 0x9f000000 +0x28bec;cp.b 0x80060000 0x9f000000 0x28bec

升級sysupgrade.bin:
tftp 0x80060000 openwrt-ar71xx-generic-ap151-16M-squashfs-sysupgrade.bin
erase 0x9f050000 +0xf3c924; cp.b 0x80060000 0x9f050000 0xf3c924;reset


發現一個介紹uboot環境的很好的文章:

https://wiki.openwrt.org/doc/techref/bootloader/uboot.config



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章