summaryrefslogtreecommitdiffstats
path: root/target/linux/ar71xx/base-files/lib/upgrade
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/ar71xx/base-files/lib/upgrade')
-rw-r--r--target/linux/ar71xx/base-files/lib/upgrade/dir825.sh177
-rw-r--r--target/linux/ar71xx/base-files/lib/upgrade/openmesh.sh (renamed from target/linux/ar71xx/base-files/lib/upgrade/om2p.sh)56
-rwxr-xr-xtarget/linux/ar71xx/base-files/lib/upgrade/platform.sh77
3 files changed, 283 insertions, 27 deletions
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/dir825.sh b/target/linux/ar71xx/base-files/lib/upgrade/dir825.sh
new file mode 100644
index 000000000..e16128a9c
--- /dev/null
+++ b/target/linux/ar71xx/base-files/lib/upgrade/dir825.sh
@@ -0,0 +1,177 @@
+#!/bin/sh
+#
+# Copyright (C) 2012 OpenWrt.org
+#
+
+. /lib/functions.sh
+. /lib/ar71xx.sh
+
+get_mtd_part_size() {
+ local part_name=$1
+ local first dev size erasesize name
+ while read dev size erasesize name; do
+ name=${name#'"'}; name=${name%'"'}
+ if [ "$name" = "$part_name" ]; then
+ echo $((0x$size))
+ break
+ fi
+ done < /proc/mtd
+}
+
+get_magic_at() {
+ local mtddev=$1
+ local pos=$2
+ dd bs=1 count=2 skip=$pos if=$mtddev 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
+}
+
+dir825b_is_caldata_valid() {
+ local mtddev=$1
+ local magic
+
+ magic=$(get_magic_at $mtddev 4096)
+ [ "$magic" != "a55a" ] && return 0
+
+ magic=$(get_magic_at $mtddev 20480)
+ [ "$magic" != "a55a" ] && return 0
+
+ return 1
+}
+
+dir825b_copy_caldata() {
+ local cal_src=$1
+ local cal_dst=$2
+ local mtd_src
+ local mtd_dst
+ local md5_src
+ local md5_dst
+
+ mtd_src=$(find_mtd_part $cal_src)
+ [ -z "$mtd_src" ] && {
+ echo "no $cal_src partition found"
+ return 1
+ }
+
+ mtd_dst=$(find_mtd_part $cal_dst)
+ [ -z "$mtd_dst" ] && {
+ echo "no $cal_dst partition found"
+ return 1
+ }
+
+ dir825b_is_caldata_valid "$mtd_src" && {
+ echo "no valid calibration data found in $cal_src"
+ return 1
+ }
+
+ dir825b_is_caldata_valid "$mtd_dst" && {
+ echo "Copying calibration data from $cal_src to $cal_dst..."
+ dd if="$mtd_src" 2>/dev/null | mtd -q -q write - "$cal_dst"
+ }
+
+ md5_src=$(md5sum "$mtd_src") && md5_src="${md5_src%% *}"
+ md5_dst=$(md5sum "$mtd_dst") && md5_dst="${md5_dst%% *}"
+
+ [ "$md5_src" != "$md5_dst" ] && {
+ echo "calibration data mismatch $cal_src:$md5_src $cal_dst:$md5_dst"
+ return 1
+ }
+
+ return 0
+}
+
+dir825b_do_upgrade_combined() {
+ local fw_part=$1
+ local fw_file=$2
+ local fw_mtd=$(find_mtd_part $fw_part)
+ local fw_length=0x$(dd if="$fw_file" bs=2 skip=1 count=4 2>/dev/null)
+ local fw_blocks=$(($fw_length / 65536))
+
+ if [ -n "$fw_mtd" ] && [ ${fw_blocks:-0} -gt 0 ]; then
+ local append=""
+ [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
+
+ sync
+ dd if="$fw_file" bs=64k skip=1 count=$fw_blocks 2>/dev/null | \
+ mtd $append write - "$fw_part"
+ fi
+}
+
+dir825b_check_image() {
+ local magic="$(get_magic_long "$1")"
+ local fw_mtd=$(find_mtd_part "firmware_orig")
+
+ case "$magic" in
+ "27051956")
+ ;;
+ "43493030")
+ local md5_img=$(dd if="$1" bs=2 skip=9 count=16 2>/dev/null)
+ local md5_chk=$(dd if="$1" bs=64k skip=1 2>/dev/null | md5sum -); md5_chk="${md5_chk%% *}"
+ local fw_len=$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null)
+ local fw_part_len=$(get_mtd_part_size "firmware")
+
+ if [ -z "$fw_mtd" ]; then
+ ask_bool 0 "Do you have a backup of the caldata partition?" || {
+ echo "Warning, please make sure that you have a backup of the caldata partition."
+ echo "Once you have that, use 'sysupgrade -i' for upgrading to the 'fat' firmware."
+ return 1
+ }
+ fi
+
+ if [ -z "$md5_img" -o -z "$md5_chk" ]; then
+ echo "Unable to get image checksums. Maybe you are using a streamed image?"
+ return 1
+ fi
+
+ if [ "$md5_img" != "$md5_chk" ]; then
+ echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
+ return 1
+ fi
+
+ fw_len=$((0x$fw_len))
+ fw_part_len=${fw_part_len:-0}
+
+ if [ $fw_part_len -lt $fw_len ]; then
+ echo "The upgrade image is too big (size:$fw_len available:$fw_part_len)"
+ return 1
+ fi
+ ;;
+ *)
+ echo "Unsupported image format."
+ return 1
+ ;;
+ esac
+
+ return 0
+}
+
+platform_do_upgrade_dir825b() {
+ local magic="$(get_magic_long "$1")"
+ local fw_mtd=$(find_mtd_part "firmware_orig")
+
+ case "$magic" in
+ "27051956")
+ if [ -n "$fw_mtd" ]; then
+ # restore calibration data before downgrading to
+ # the normal image
+ dir825b_copy_caldata "caldata" "caldata_orig" || {
+ echo "unable to restore calibration data"
+ exit 1
+ }
+ PART_NAME="firmware_orig"
+ else
+ PART_NAME="firmware"
+ fi
+ default_do_upgrade "$ARGV"
+ ;;
+ "43493030")
+ if [ -z "$fw_mtd" ]; then
+ # backup calibration data before upgrading to the
+ # fat image
+ dir825b_copy_caldata "caldata" "caldata_copy" || {
+ echo "unable to backup calibration data"
+ exit 1
+ }
+ fi
+ dir825b_do_upgrade_combined "firmware" "$ARGV"
+ ;;
+ esac
+}
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/om2p.sh b/target/linux/ar71xx/base-files/lib/upgrade/openmesh.sh
index d9a8bbb7f..5179875fe 100644
--- a/target/linux/ar71xx/base-files/lib/upgrade/om2p.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/openmesh.sh
@@ -1,9 +1,9 @@
-# The U-Boot loader of the OM2P requires image sizes and checksums to be
-# provided in the U-Boot environment.
-# The OM2P comes with 2 main partitions - while one is active sysupgrade
-# will flash the other. The boot order is changed to boot the newly
-# flashed partition. If the new partition can't be booted due to upgrade
-# failures the previously used partition is loaded.
+# The U-Boot loader of the OpenMesh devices requires image sizes and
+# checksums to be provided in the U-Boot environment.
+# The OpenMesh devices come with 2 main partitions - while one is active
+# sysupgrade will flash the other. The boot order is changed to boot the
+# newly flashed partition. If the new partition can't be booted due to
+# upgrade failures the previously used partition is loaded.
trim()
{
@@ -34,7 +34,7 @@ platform_add_ramfs_ubootenv()
}
append sysupgrade_pre_upgrade platform_add_ramfs_ubootenv
-platform_check_image_om2p()
+platform_check_image_openmesh()
{
local img_magic=$1
local img_path=$2
@@ -56,6 +56,17 @@ platform_check_image_om2p()
case "$img_board_target" in
OM2P)
+ [ "$board" = "om2p" ] && break
+ [ "$board" = "om2p-lc" ] && break
+ [ "$board" = "om2p-hs" ] && break
+ echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+ return 1
+ ;;
+ MR600)
+ [ "$board" = "mr600" ] && break
+ [ "$board" = "mr600v2" ] && break
+ echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+ return 1
;;
*)
echo "Invalid board target ($img_board_target). Use the correct image for this platform"
@@ -102,13 +113,14 @@ platform_check_image_om2p()
return 0
}
-platform_do_upgrade_om2p()
+platform_do_upgrade_openmesh()
{
- local img_path=$1
- local kernel_start_addr= kernel_size= kernel_md5=
+ local img_path=$1 img_board_target=
+ local kernel_start_addr= kernel_start_addr1= kernel_start_addr2=
+ local kernel_size= kernel_md5=
local rootfs_size= rootfs_checksize= rootfs_md5=
- local kernel_bsize= total_size=7340032
- local data_offset=$((64 * 1024)) block_size=$((256 * 1024)) offset=
+ local kernel_bsize= total_size=
+ local data_offset=$((64 * 1024)) block_size= offset=
local uboot_env_upgrade="/tmp/fw_env_upgrade"
local cfg_size= kernel_size= rootfs_size=
local append=""
@@ -119,8 +131,24 @@ platform_do_upgrade_om2p()
kernel_size=$(dd if="$img_path" bs=2 skip=71 count=4 2>/dev/null)
rootfs_size=$(dd if="$img_path" bs=2 skip=107 count=4 2>/dev/null)
+ img_board_target=$(trim $(dd if="$img_path" bs=4 skip=1 count=8 2>/dev/null))
cfg_content=$(dd if="$img_path" bs=1 skip=$data_offset count=$(echo $((0x$cfg_size))) 2>/dev/null)
+ case $img_board_target in
+ OM2P)
+ block_size=$((256 * 1024))
+ total_size=7340032
+ kernel_start_addr1=0x9f1c0000
+ kernel_start_addr2=0x9f8c0000
+ ;;
+ MR600)
+ block_size=$((64 * 1024))
+ total_size=7995392
+ kernel_start_addr1=0x9f0b0000
+ kernel_start_addr2=0x9f850000
+ ;;
+ esac
+
kernel_md5=$(cfg_value_get "$cfg_content" "vmlinux" "md5sum")
rootfs_md5=$(cfg_value_get "$cfg_content" "rootfs" "md5sum")
rootfs_checksize=$(cfg_value_get "$cfg_content" "rootfs" "checksize")
@@ -147,12 +175,12 @@ platform_do_upgrade_om2p()
printf "kernel_size_1 %u\n" $(($kernel_bsize / 1024)) >> $uboot_env_upgrade
printf "rootfs_size_1 %u\n" $((($total_size - $kernel_bsize) / 1024)) >> $uboot_env_upgrade
printf "bootseq 1,2\n" >> $uboot_env_upgrade
- kernel_start_addr=0x9f1c0000
+ kernel_start_addr=$kernel_start_addr1
else
printf "kernel_size_2 %u\n" $(($kernel_bsize / 1024)) >> $uboot_env_upgrade
printf "rootfs_size_2 %u\n" $((($total_size - $kernel_bsize) / 1024)) >> $uboot_env_upgrade
printf "bootseq 2,1\n" >> $uboot_env_upgrade
- kernel_start_addr=0x9f8c0000
+ kernel_start_addr=$kernel_start_addr2
fi
printf "vmlinux_start_addr %s\n" $kernel_start_addr >> $uboot_env_upgrade
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 2992aed32..817123b6d 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -15,7 +15,7 @@ platform_find_partitions() {
while read dev size erasesize name; do
name=${name#'"'}; name=${name%'"'}
case "$name" in
- vmlinux.bin.l7|vmlinux|kernel|linux|rootfs|filesystem)
+ vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin|rootfs|filesystem)
if [ -z "$first" ]; then
first="$name"
else
@@ -31,7 +31,7 @@ platform_find_kernelpart() {
local part
for part in "${1%:*}" "${1#*:}"; do
case "$part" in
- vmlinux.bin.l7|vmlinux|kernel|linux)
+ vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin)
echo "$part"
break
;;
@@ -65,6 +65,10 @@ tplink_get_image_hwid() {
get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
}
+tplink_get_image_boot_size() {
+ get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
+}
+
platform_check_image() {
local board=$(ar71xx_board_name)
local magic="$(get_magic_word "$1")"
@@ -74,7 +78,8 @@ platform_check_image() {
case "$board" in
all0315n | \
- all0258n )
+ all0258n | \
+ cap4200ag)
platform_check_image_allnet "$1" && return 0
return 1
;;
@@ -83,7 +88,9 @@ platform_check_image() {
ap113 | \
ap121 | \
ap121-mini | \
- ap136 | \
+ ap136-010 | \
+ ap136-020 | \
+ ap135-020 | \
ap96 | \
db120 | \
hornet-ub | \
@@ -97,18 +104,17 @@ platform_check_image() {
;;
ap81 | \
ap83 | \
+ ap132 | \
dir-600-a1 | \
dir-615-c1 | \
dir-615-e4 | \
- dir-825-b1 | \
- dir-825-b1-openwrt | \
- dir-825-b1-tostock | \
+ dir-825-c1 | \
+ dir-835-a1 | \
ew-dorin | \
ew-dorin-router | \
mzk-w04nu | \
mzk-w300nh | \
tew-632brp | \
- tew-673gru | \
tew-712br | \
wrt400n | \
airrouter | \
@@ -116,6 +122,7 @@ platform_check_image() {
nanostation-m | \
rocket-m | \
rw2458n | \
+ wndap360 | \
wzr-hp-g300nh2 | \
wzr-hp-g300nh | \
wzr-hp-g450h | \
@@ -125,30 +132,47 @@ platform_check_image() {
whr-hp-gn | \
wlae-ag300n | \
nbg460n_550n_550nh | \
- unifi )
+ unifi | \
+ unifi-outdoor )
[ "$magic" != "2705" ] && {
echo "Invalid image type."
return 1
}
return 0
;;
+
+ dir-825-b1 | \
+ tew-673gru)
+ dir825b_check_image "$1" && return 0
+ ;;
+
+ mr600 | \
+ mr600v2 | \
om2p | \
+ om2p-hs | \
om2p-lc)
- platform_check_image_om2p "$magic_long" "$1" && return 0
+ platform_check_image_openmesh "$magic_long" "$1" && return 0
return 1
;;
tl-mr11u | \
tl-mr3020 | \
+ tl-mr3040 | \
tl-mr3220 | \
+ tl-mr3220-v2 | \
tl-mr3420 | \
+ tl-mr3420-v2 | \
+ tl-wa7510n | \
tl-wa901nd | \
tl-wa901nd-v2 | \
+ tl-wdr3500 | \
tl-wdr4300 | \
tl-wr703n | \
+ tl-wr720n-v3 | \
tl-wr741nd | \
tl-wr741nd-v4 | \
tl-wr841n-v1 | \
tl-wr841n-v7 | \
+ tl-wr841n-v8 | \
tl-wr941nd | \
tl-wr1041n-v2 | \
tl-wr1043nd | \
@@ -169,6 +193,21 @@ platform_check_image() {
return 1
}
+ local boot_size
+
+ boot_size=$(tplink_get_image_boot_size "$1")
+ [ "$boot_size" != "00000000" ] && {
+ echo "Invalid image, it contains a bootloader."
+ return 1
+ }
+
+ return 0
+ ;;
+ uap-pro)
+ [ "$magic_long" != "19852003" ] && {
+ echo "Invalid image type."
+ return 1
+ }
return 0
;;
wndr3700)
@@ -196,7 +235,8 @@ platform_check_image() {
all0305 | \
eap7660d | \
ja76pf | \
- ja76pf2)
+ ja76pf2 | \
+ jwap003)
[ "$magic" != "4349" ] && {
echo "Invalid image. Use *-sysupgrade.bin files on this board"
return 1
@@ -231,7 +271,8 @@ platform_do_upgrade() {
pb42 | \
pb44 | \
ja76pf | \
- ja76pf2)
+ ja76pf2 | \
+ jwap003)
platform_do_upgrade_combined "$ARGV"
;;
all0258n )
@@ -240,9 +281,19 @@ platform_do_upgrade() {
all0315n )
platform_do_upgrade_allnet "0x9f080000" "$ARGV"
;;
+ cap4200ag)
+ platform_do_upgrade_allnet "0xbf0a0000" "$ARGV"
+ ;;
+ dir-825-b1 |\
+ tew-673gru)
+ platform_do_upgrade_dir825b "$ARGV"
+ ;;
+ mr600 | \
+ mr600v2 | \
om2p | \
+ om2p-hs | \
om2p-lc)
- platform_do_upgrade_om2p "$ARGV"
+ platform_do_upgrade_openmesh "$ARGV"
;;
*)
default_do_upgrade "$ARGV"