brcm47xx: rework vendor fw handling to don't duplicate upgrade calls
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / base-files / lib / upgrade / platform.sh
index 9b21e319bb6e50de6fe44cfc7890e4eb8715ade0..0fc0388f6d67d381c2d2d6615fc50043b33dd990 100644 (file)
@@ -98,7 +98,7 @@ platform_check_image() {
                                error=1
                        }
 
-                       if ! otrx -c "$1" -o "$header_len"; then
+                       if ! otrx check "$1" -o "$header_len"; then
                                echo "No valid TRX firmware in the CHK image"
                                error=1
                        fi
@@ -113,13 +113,13 @@ platform_check_image() {
                                error=1
                        }
 
-                       if ! otrx -c "$1" -o 32; then
+                       if ! otrx check "$1" -o 32; then
                                echo "No valid TRX firmware in the CyberTAN image"
                                error=1
                        fi
                ;;
                "trx")
-                       if ! otrx -c "$1"; then
+                       if ! otrx check "$1"; then
                                echo "Invalid (corrupted?) TRX firmware"
                                error=1
                        fi
@@ -133,29 +133,25 @@ platform_check_image() {
        return $error
 }
 
-platform_do_upgrade_chk() {
+platform_extract_trx_from_chk() {
        local header_len=$((0x$(get_magic_long_at "$1" 4)))
-       local trx="/tmp/$1.trx"
 
-       dd if="$1" of="$trx" bs=$header_len skip=1
-       shift
-       default_do_upgrade "$trx" "$@"
+       dd if="$1" of="$2" bs=$header_len skip=1
 }
 
-platform_do_upgrade_cybertan() {
-       local trx="/tmp/$1.trx"
-
-       dd if="$1" of="$trx" bs=32 skip=1
-       shift
-       default_do_upgrade "$trx" "$@"
+platform_extract_trx_from_cybertan() {
+       dd if="$1" of="$2" bs=32 skip=1
 }
 
 platform_do_upgrade() {
        local file_type=$(brcm47xx_identify "$1")
+       local trx="$1"
 
        case "$file_type" in
-               "chk")          platform_do_upgrade_chk "$ARGV";;
-               "cybertan")     platform_do_upgrade_cybertan "$ARGV";;
-               *)              default_do_upgrade "$ARGV";;
+               "chk")          trx="/tmp/$1.trx"; platform_extract_trx_from_chk "$1" "$trx";;
+               "cybertan")     trx="/tmp/$1.trx"; platform_extract_trx_from_cybertan "$1" "$trx";;
        esac
+
+       shift
+       default_do_upgrade "$trx" "$@"
 }