2 # Copyright (C) 2011 OpenWrt.org
5 .
/lib
/functions
/system.sh
9 RAMFS_COPY_DATA
=/lib
/ar71xx.sh
14 platform_find_partitions
() {
15 local first dev size erasesize name
16 while read dev size erasesize name
; do
17 name
=${name#'"'}; name
=${name%'"'}
19 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin|rootfs|filesystem
)
20 if [ -z "$first" ]; then
23 echo "$erasesize:$first:$name"
31 platform_find_kernelpart
() {
33 for part
in "${1%:*}" "${1#*:}"; do
35 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin
)
43 platform_do_upgrade_combined
() {
44 local partitions
=$
(platform_find_partitions
)
45 local kernelpart
=$
(platform_find_kernelpart
"${partitions#*:}")
46 local erase_size
=$
((0x
${partitions%%:*})); partitions
="${partitions#*:}"
47 local kern_length
=0x$
(dd if="$1" bs
=2 skip
=1 count
=4 2>/dev
/null
)
48 local kern_blocks
=$
(($kern_length / $CI_BLKSZ))
49 local root_blocks
=$
((0x$
(dd if="$1" bs
=2 skip
=5 count
=4 2>/dev
/null
) / $CI_BLKSZ))
51 if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \
52 [ ${kern_blocks:-0} -gt 0 ] && \
53 [ ${root_blocks:-0} -gt 0 ] && \
54 [ ${erase_size:-0} -gt 0 ];
57 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append
="-j $CONF_TAR"
59 ( dd if="$1" bs
=$CI_BLKSZ skip
=1 count
=$kern_blocks 2>/dev
/null
; \
60 dd if="$1" bs
=$CI_BLKSZ skip
=$
((1+$kern_blocks)) count
=$root_blocks 2>/dev
/null
) | \
61 mtd
-r $append -F$kernelpart:$kern_length:$CI_LDADR,rootfs
write - $partitions
65 tplink_get_image_hwid
() {
66 get_image
"$@" |
dd bs
=4 count
=1 skip
=16 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
69 tplink_get_image_boot_size
() {
70 get_image
"$@" |
dd bs
=4 count
=1 skip
=37 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
73 seama_get_type_magic
() {
74 get_image
"$@" |
dd bs
=1 count
=4 skip
=53 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
77 cybertan_get_image_magic
() {
78 get_image
"$@" |
dd bs
=8 count
=1 skip
=0 2>/dev
/null |
hexdump -v -n 8 -e '1/1 "%02x"'
81 cybertan_check_image
() {
82 local magic
="$(cybertan_get_image_magic "$1")"
83 local fw_magic
="$(cybertan_get_hw_magic)"
85 [ "$fw_magic" != "$magic" ] && {
86 echo "Invalid image, ID mismatch, got:$magic, but need:$fw_magic"
93 platform_do_upgrade_compex
() {
95 local fw_part
=$PART_NAME
96 local fw_mtd
=$
(find_mtd_part
$fw_part)
97 local fw_length
=0x$
(dd if="$fw_file" bs
=2 skip
=1 count
=4 2>/dev
/null
)
98 local fw_blocks
=$
(($fw_length / 65536))
100 if [ -n "$fw_mtd" ] && [ ${fw_blocks:-0} -gt 0 ]; then
102 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append
="-j $CONF_TAR"
105 dd if="$fw_file" bs
=64k skip
=1 count
=$fw_blocks 2>/dev
/null | \
106 mtd
$append write - "$fw_part"
111 local magic_long
="$(get_magic_long "$1")"
112 local fw_part_size
=$
(mtd_get_part_size firmware
)
114 case "$magic_long" in
116 [ "$fw_part_size" != "16318464" ] && {
117 echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes"
123 [ "$fw_part_size" != "7929856" ] && {
124 echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes"
133 platform_check_image
() {
134 local board
=$
(ar71xx_board_name
)
135 local magic
="$(get_magic_word "$1")"
136 local magic_long
="$(get_magic_long "$1")"
138 [ "$#" -gt 1 ] && return 1
144 platform_check_image_allnet
"$1" && return 0
161 [ "$magic_long" != "68737173" -a "$magic_long" != "19852003" ] && {
162 echo "Invalid image type."
205 nbg460n_550n_550nh | \
209 [ "$magic" != "2705" ] && {
210 echo "Invalid image type."
218 dir825b_check_image
"$1" && return 0
223 cybertan_check_image
"$1" && return 0
229 [ "$magic_long" != "5ea3a417" ] && {
230 echo "Invalid image, bad magic: $magic_long"
234 local typemagic
=$
(seama_get_type_magic
"$1")
235 [ "$typemagic" != "6669726d" ] && {
236 echo "Invalid image, bad type: $typemagic"
250 platform_check_image_openmesh
"$magic_long" "$1" && return 0
296 [ "$magic" != "0100" ] && {
297 echo "Invalid image type."
304 hwid
=$
(tplink_get_hwid
)
305 imageid
=$
(tplink_get_image_hwid
"$1")
307 [ "$hwid" != "$imageid" ] && {
308 echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
314 boot_size
=$
(tplink_get_image_boot_size
"$1")
315 [ "$boot_size" != "00000000" ] && {
316 echo "Invalid image, it contains a bootloader."
324 alfa_check_image
"$1" && return 0
329 [ "$magic_long" != "19852003" ] && {
330 echo "Invalid image type."
340 hw_magic
="$(ar71xx_get_mtd_part_magic firmware)"
341 [ "$magic_long" != "$hw_magic" ] && {
342 echo "Invalid image, hardware ID mismatch, hw:$hw_magic image:$magic_long."
349 nand_do_platform_check
$board $1
353 routerstation-pro | \
365 [ "$magic" != "4349" ] && {
366 echo "Invalid image. Use *-sysupgrade.bin files on this board"
370 local md5_img
=$
(dd if="$1" bs
=2 skip
=9 count
=16 2>/dev
/null
)
371 local md5_chk
=$
(dd if="$1" bs
=$CI_BLKSZ skip
=1 2>/dev
/null |
md5sum -); md5_chk
="${md5_chk%% *}"
373 if [ -n "$md5_img" -a -n "$md5_chk" ] && [ "$md5_img" = "$md5_chk" ]; then
376 echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
383 echo "Sysupgrade is not yet supported on $board."
387 platform_do_upgrade
() {
388 local board
=$
(ar71xx_board_name
)
392 routerstation-pro | \
401 platform_do_upgrade_combined
"$ARGV"
405 platform_do_upgrade_compex
"$ARGV"
408 platform_do_upgrade_allnet
"0x9f050000" "$ARGV"
411 platform_do_upgrade_allnet
"0x9f080000" "$ARGV"
415 platform_do_upgrade_allnet
"0xbf0a0000" "$ARGV"
419 platform_do_upgrade_dir825b
"$ARGV"
429 platform_do_upgrade_openmesh
"$ARGV"
432 MTD_CONFIG_ARGS
="-s 0x180000"
433 default_do_upgrade
"$ARGV"
436 default_do_upgrade
"$ARGV"
443 ( ps |
grep -v 'grep' |
grep '/dev/watchdog' ) && {
444 echo 'Could not disable watchdog'
449 append sysupgrade_pre_upgrade disable_watchdog