3 # $(1): file to read magic from
4 # $(2): offset in bytes
6 dd if="$1" skip
=$2 bs
=1 count
=4 2>/dev
/null |
hexdump -v -e '1/1 "%02x"'
9 platform_flash_type
() {
10 # On NAND devices "rootfs" is UBI volume, so won't be find in /proc/mtd
11 grep -q "\"rootfs\"" /proc
/mtd
&& {
22 magic
=$
(get_magic_long
"$1")
34 magic
=$
(get_magic_long_at
"$1" 14)
35 [ "$magic" = "55324e44" ] && {
43 platform_check_image
() {
44 [ "$#" -gt 1 ] && return 1
46 [ "$(platform_flash_type)" = "nand" ] && {
47 echo "Firmware upgrade on NAND devices is not implemented."
51 local file_type
=$
(platform_identify
"$1")
55 local header_len
=$
((0x$
(get_magic_long_at
"$1" 4)))
56 local board_id_len
=$
(($header_len - 40))
57 local board_id
=$
(dd if="$1" skip
=40 bs
=1 count
=$board_id_len 2>/dev
/null |
hexdump -v -e '1/1 "%c"')
58 echo "Found CHK image with device board_id $board_id"
60 magic
=$
(get_magic_long_at
"$1" "$header_len")
61 [ "$magic" != "48445230" ] && {
62 echo "No valid TRX firmware in the CHK image"
69 local magic
=$
(dd if="$1" bs
=1 count
=4 2>/dev
/null |
hexdump -v -e '1/1 "%c"')
70 echo "Found CyberTAN image with device magic: $magic"
72 magic
=$
(get_magic_long_at
"$1" 32)
73 [ "$magic" != "48445230" ] && {
74 echo "No valid TRX firmware in the CyberTAN image"
84 echo "Invalid image type. Please use only .trx files"
90 # Extract TRX and use stadard upgrade method
91 platform_do_upgrade_chk
() {
92 local header_len
=$
((0x$
(get_magic_long_at
"$1" 4)))
93 local trx
="/tmp/$1.trx"
95 dd if="$1" of
="$trx" bs
=$header_len skip
=1
97 platform_do_upgrade_trx
"$trx" "$@"
100 # Extract TRX and use stadard upgrade method
101 platform_do_upgrade_cybertan
() {
102 local trx
="/tmp/$1.trx"
104 dd if="$1" of
="$trx" bs
=32 skip
=1
106 platform_do_upgrade_trx
"$trx" "$@"
109 platform_do_upgrade_trx
() {
110 local flash_type
=$
(platform_flash_type
)
112 case "$flash_type" in
114 default_do_upgrade
"$@"
117 echo "Firmware upgrade on NAND devices is REALLY unsupported."
122 platform_do_upgrade
() {
123 local file_type
=$
(platform_identify
"$1")
126 "chk") platform_do_upgrade_chk
"$ARGV";;
127 "cybertan") platform_do_upgrade_cybertan
"$ARGV";;
128 *) platform_do_upgrade_trx
"$ARGV";;