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"
59 echo "Flashing CHK images in unsupported. Please use only .trx files."
63 local magic
=$
(dd if="$1" bs
=1 count
=4 2>/dev
/null |
hexdump -v -e '1/1 "%c"')
64 echo "Found CyberTAN image with device magic: $magic"
65 echo "Flashing CyberTAN images in unsupported. Please use only .trx files."
72 echo "Invalid image type. Please use only .trx files"
78 # Extract TRX and use stadard upgrade method
79 platform_do_upgrade_chk
() {
80 local header_len
=$
((0x$
(get_magic_long_at
"$1" 4)))
81 local trx
="/tmp/$1.trx"
83 dd if="$1" of
="$trx" bs
=$header_len skip
=1
85 platform_do_upgrade_trx
"$trx" "$@"
88 # Extract TRX and use stadard upgrade method
89 platform_do_upgrade_cybertan
() {
90 local trx
="/tmp/$1.trx"
92 dd if="$1" of
="$trx" bs
=32 skip
=1
94 platform_do_upgrade_trx
"$trx" "$@"
97 platform_do_upgrade_trx
() {
98 local flash_type
=$
(platform_flash_type
)
100 case "$flash_type" in
102 default_do_upgrade
"$@"
105 echo "Firmware upgrade on NAND devices is REALLY unsupported."
110 platform_do_upgrade
() {
111 local file_type
=$
(platform_identify
"$1")
114 "chk") platform_do_upgrade_chk
"$ARGV";;
115 "cybertan") platform_do_upgrade_cybertan
"$ARGV";;
116 *) platform_do_upgrade_trx
"$ARGV";;