brcm47xx: detect (and still reject for now) CyberTAN fw format
[openwrt.git] / target / linux / brcm47xx / base-files / lib / upgrade / platform.sh
1 PART_NAME=firmware
2
3 # $(1): file to read magic from
4 # $(2): offset in bytes
5 get_magic_long_at() {
6         dd if="$1" skip=$2 bs=1 count=4 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
7 }
8
9 brcm47xx_identify() {
10         local magic
11
12         magic=$(get_magic_long "$1")
13         case "$magic" in
14                 "48445230")
15                         echo "trx"
16                         return
17                         ;;
18                 "2a23245e")
19                         echo "chk"
20                         return
21                         ;;
22         esac
23
24         magic=$(get_magic_long_at "$1" 14)
25         [ "$magic" = "55324e44" ] && {
26                 echo "cybertan"
27                 return
28         }
29
30         echo "unknown"
31 }
32
33 platform_check_image() {
34         [ "$#" -gt 1 ] && return 1
35
36         local file_type=$(brcm47xx_identify "$1")
37
38         case "$file_type" in
39                 "trx") return 0;;
40                 *)
41                         echo "Invalid image type. Please use only .trx files"
42                         return 1
43                 ;;
44         esac
45 }
46
47 # use default for platform_do_upgrade()