1. 程式人生 > >openwrt下web方式升級韌體提示檔案格式錯誤

openwrt下web方式升級韌體提示檔案格式錯誤

最近公司產品使用openwrt,其中在使用openwrt的web方式升級核心和檔案系統時(即sysupgrade韌體)時,發現校驗檔案時提示The uploaded image file does not contain a supported format. Make sure that you choose the generic image format for your platform.於是在網上找了些資料,總結如下:

網上提供的解決方法:

1.在openwrt-ar71xx-generic-db120-squashfs-sysupgrade.bin的起始位置增加32位元組,但是嘗試後無果。參考

OpenWrt image conversion
2.跟蹤呼叫過程,分析原因,寫的不是很清楚,不過給我提供了思路。參考openwrt Web刷寫新的韌體提示檔案格式問題

自己的解決思路:

1.使用wscp軟體將openwrt-ar71xx-generic-db120-squashfs-sysupgrade.bin檔案上傳至路由器檔案系統中。
2.使用sysupgrade命令升級openwrt-ar71xx-generic-db120-squashfs-sysupgrade.bin,命令如下:

openwrt-ar71xx-generic-db120-squashfs-sysupgrade
.bin

3.根據步驟2中提示的錯誤資訊,定位具體shell指令碼,我的板子提示如下資訊:

Invalid image type.
    Image check 'platform_check_image' failed.

4.根據提示錯誤資訊在板子上定位具體檔案,find / -type f|xargs grep “platform_check_image”,我最終定位在/lib/upgrade/platform.sh指令碼中。
5.在/lib/upgrade/platform.sh的platform_check_image函式中增加列印資訊:echo $magic_long,其中magic_long為openwrt-ar71xx-generic-db120-squashfs-sysupgrade.bin的頭4位元組,我的對不上,於是在openwrt根目錄下修改 vim ./linux/ar71xx/base-files/lib/upgrade/platform.sh中將magic_long修改成自己的升級韌體的頭四位元組(注意:十六進位制的),重新編譯核心,校驗通過。