bcm53xx: support Netgear R8500 in sysupgrade
[openwrt.git] / target / linux / bcm53xx / base-files / lib / upgrade / platform.sh
index 131f6dd..20d9e29 100644 (file)
@@ -24,9 +24,12 @@ platform_expected_image() {
        local machine=$(platform_machine)
 
        case "$machine" in
+               "dlink,dir-885l")       echo "seama wrgac42_dlink.2015_dir885l"; return;;
                "netgear,r6250v1")      echo "chk U12H245T00_NETGEAR"; return;;
                "netgear,r6300v2")      echo "chk U12H240T00_NETGEAR"; return;;
+               "netgear,r7000")        echo "chk U12H270T00_NETGEAR"; return;;
                "netgear,r8000")        echo "chk U12H315T00_NETGEAR"; return;;
+               "netgear,r8500")        echo "chk U12H334T00_NETGEAR"; return;;
        esac
 }
 
@@ -43,6 +46,10 @@ platform_identify() {
                        echo "chk"
                        return
                        ;;
+               "5ea3a417")
+                       echo "seama"
+                       return
+                       ;;
        esac
 
        magic=$(get_magic_long_at "$1" 14)
@@ -94,6 +101,21 @@ platform_check_image() {
                                error=1
                        fi
                ;;
+               "seama")
+                       local img_signature=$(oseama info "$1" | grep "Meta entry:.*signature=" | sed "s/.*=//")
+                       local dev_signature=$(platform_expected_image)
+                       echo "Found Seama image with device signature: $img_signature"
+
+                       [ -n "$dev_signature" -a "seama $img_signature" != "$dev_signature" ] && {
+                               echo "Firmware signature doesn't match device signature ($dev_signature)"
+                               error=1
+                       }
+
+                       $(oseama info "$1" -e 0 | grep -q "Meta entry:.*type=firmware") || {
+                               echo "Seama container doesn't have firmware entity"
+                               error=1
+                       }
+               ;;
                "trx")
                        if ! otrx check "$1"; then
                                echo "Invalid (corrupted?) TRX firmware"
@@ -110,6 +132,8 @@ platform_check_image() {
 }
 
 platform_pre_upgrade() {
+       export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /usr/bin/oseama /bin/sed"
+
        local file_type=$(platform_identify "$1")
        local dir="/tmp/sysupgrade-bcm53xx"
        local trx="$1"
@@ -121,6 +145,7 @@ platform_pre_upgrade() {
        case "$file_type" in
                "chk")          offset=$((0x$(get_magic_long_at "$1" 4)));;
                "cybertan")     offset=32;;
+               "seama")        return;;
        esac
 
        # Extract partitions from trx
@@ -191,6 +216,22 @@ platform_trx_from_cybertan_cmd() {
        echo -n dd bs=32 skip=1
 }
 
+platform_img_from_seama() {
+       local dir="/tmp/sysupgrade-bcm53xx"
+       local offset=$(oseama info "$1" -e 0 | grep "Entity offset:" | sed "s/.*:\s*//")
+       local size=$(oseama info "$1" -e 0 | grep "Entity size:" | sed "s/.*:\s*//")
+
+       # Busybox doesn't support required iflag-s
+       # echo -n dd iflag=skip_bytes,count_bytes skip=$offset count=$size
+
+       rm -fR $dir
+       mkdir -p $dir
+       dd if="$1" of=$dir/image-noheader.bin bs=$offset skip=1
+       dd if=$dir/image-noheader.bin of=$dir/image-entity.bin bs=$size count=1
+
+       echo -n $dir/image-entity.bin
+}
+
 platform_do_upgrade() {
        local file_type=$(platform_identify "$1")
        local trx="$1"
@@ -203,6 +244,7 @@ platform_do_upgrade() {
        case "$file_type" in
                "chk")          cmd=$(platform_trx_from_chk_cmd "$trx");;
                "cybertan")     cmd=$(platform_trx_from_cybertan_cmd "$trx");;
+               "seama")        trx=$(platform_img_from_seama "$trx");;
        esac
 
        default_do_upgrade "$trx" "$cmd"