2 # Copyright (C) 2011 OpenWrt.org
5 .
/lib
/functions
/system.sh
9 RAMFS_COPY_DATA
='/lib/ar71xx.sh /etc/fw_env.config /var/lock/fw_printenv.lock'
10 RAMFS_COPY_BIN
='nandwrite fw_printenv fw_setenv'
15 PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD
=0
17 platform_find_partitions
() {
18 local first dev size erasesize name
19 while read dev size erasesize name
; do
20 name
=${name#'"'}; name
=${name%'"'}
22 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin|rootfs|filesystem
)
23 if [ -z "$first" ]; then
26 echo "$erasesize:$first:$name"
34 platform_find_kernelpart
() {
36 for part
in "${1%:*}" "${1#*:}"; do
38 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin
)
46 platform_find_rootfspart
() {
48 for part
in "${1%:*}" "${1#*:}"; do
49 [ "$part" != "$2" ] && echo "$part" && break
53 platform_do_upgrade_combined
() {
54 local partitions
=$
(platform_find_partitions
)
55 local kernelpart
=$
(platform_find_kernelpart
"${partitions#*:}")
56 local erase_size
=$
((0x
${partitions%%:*})); partitions
="${partitions#*:}"
57 local kern_length
=0x$
(dd if="$1" bs
=2 skip
=1 count
=4 2>/dev
/null
)
58 local kern_blocks
=$
(($kern_length / $CI_BLKSZ))
59 local root_blocks
=$
((0x$
(dd if="$1" bs
=2 skip
=5 count
=4 2>/dev
/null
) / $CI_BLKSZ))
61 if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \
62 [ ${kern_blocks:-0} -gt 0 ] && \
63 [ ${root_blocks:-0} -gt 0 ] && \
64 [ ${erase_size:-0} -gt 0 ];
66 local rootfspart
=$
(platform_find_rootfspart
"$partitions" "$kernelpart")
68 [ -f "$UPGRADE_BACKUP" ] && append
="-j $UPGRADE_BACKUP"
70 if [ "$PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD" -ne 1 ]; then
71 ( dd if="$1" bs
=$CI_BLKSZ skip
=1 count
=$kern_blocks 2>/dev
/null
; \
72 dd if="$1" bs
=$CI_BLKSZ skip
=$
((1+$kern_blocks)) count
=$root_blocks 2>/dev
/null
) | \
73 mtd
-r $append -F$kernelpart:$kern_length:$CI_LDADR,rootfs
write - $partitions
74 elif [ -n "$rootfspart" ]; then
75 dd if="$1" bs
=$CI_BLKSZ skip
=1 count
=$kern_blocks 2>/dev
/null | \
76 mtd
write - $kernelpart
77 dd if="$1" bs
=$CI_BLKSZ skip
=$
((1+$kern_blocks)) count
=$root_blocks 2>/dev
/null | \
78 mtd
-r $append write - $rootfspart
81 PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD
=0
84 tplink_get_image_hwid
() {
85 get_image
"$@" |
dd bs
=4 count
=1 skip
=16 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
88 tplink_get_image_mid
() {
89 get_image
"$@" |
dd bs
=4 count
=1 skip
=17 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
92 tplink_get_image_boot_size
() {
93 get_image
"$@" |
dd bs
=4 count
=1 skip
=37 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
96 tplink_pharos_check_support_list
() {
102 # Here $image is given to dd directly instead of using get_image;
103 # otherwise the skip will take almost a second (as dd can't seek)
104 dd if="$image" bs
=1 skip
=$offset count
=1024 2>/dev
/null |
tr -d "$trargs" |
(
105 while IFS
= read -r line
; do
106 [ "$line" = "$model" ] && exit 0
113 tplink_pharos_check_image
() {
114 local image_magic
="$(get_magic_long "$1")"
115 local board_magic
="$2"
116 [ "$image_magic" != "$board_magic" ] && {
117 echo "Invalid image magic '$image_magic'. Expected '$board_magic'."
121 local model_string
="$3"
124 # New images have the support list at 7802888, old ones at 1511432
125 tplink_pharos_check_support_list
"$1" 7802888 "$model_string" "$trargs" || \
126 tplink_pharos_check_support_list
"$1" 1511432 "$model_string" "$trargs" ||
{
127 echo "Unsupported image (model not in support-list)"
134 seama_get_type_magic
() {
135 get_image
"$@" |
dd bs
=1 count
=4 skip
=53 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
138 wrgg_get_image_magic
() {
139 get_image
"$@" |
dd bs
=4 count
=1 skip
=8 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
142 cybertan_get_image_magic
() {
143 get_image
"$@" |
dd bs
=8 count
=1 skip
=0 2>/dev
/null |
hexdump -v -n 8 -e '1/1 "%02x"'
146 cybertan_check_image
() {
147 local magic
="$(cybertan_get_image_magic "$1")"
148 local fw_magic
="$(cybertan_get_hw_magic)"
150 [ "$fw_magic" != "$magic" ] && {
151 echo "Invalid image, ID mismatch, got:$magic, but need:$fw_magic"
158 platform_do_upgrade_compex
() {
160 local fw_part
=$PART_NAME
161 local fw_mtd
=$
(find_mtd_part
$fw_part)
162 local fw_length
=0x$
(dd if="$fw_file" bs
=2 skip
=1 count
=4 2>/dev
/null
)
163 local fw_blocks
=$
(($fw_length / 65536))
165 if [ -n "$fw_mtd" ] && [ ${fw_blocks:-0} -gt 0 ]; then
167 [ -f "$UPGRADE_BACKUP" ] && append
="-j $UPGRADE_BACKUP"
170 dd if="$fw_file" bs
=64k skip
=1 count
=$fw_blocks 2>/dev
/null | \
171 mtd
$append write - "$fw_part"
176 local magic_long
="$(get_magic_long "$1")"
177 local fw_part_size
=$
(mtd_get_part_size firmware
)
179 case "$magic_long" in
181 [ "$fw_part_size" != "16318464" ] && {
182 echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes"
187 [ "$fw_part_size" != "7929856" ] && {
188 echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes"
197 platform_check_image
() {
198 local board
=$
(board_name
)
199 local magic
="$(get_magic_word "$1")"
200 local magic_long
="$(get_magic_long "$1")"
202 [ "$#" -gt 1 ] && return 1
331 [ "$magic" != "2705" ] && {
332 echo "Invalid image type."
362 [ "$magic_long" != "68737173" -a "$magic_long" != "19852003" ] && {
363 echo "Invalid image type."
375 platform_check_image_allnet
"$1" && return 0
391 [ "$magic" != "4349" ] && {
392 echo "Invalid image. Use *-sysupgrade.bin files on this board"
396 local md5_img
=$
(dd if="$1" bs
=2 skip
=9 count
=16 2>/dev
/null
)
397 local md5_chk
=$
(fwtool
-q -t -i /dev
/null
"$1"; dd if="$1" bs
=$CI_BLKSZ skip
=1 2>/dev
/null |
md5sum -); md5_chk
="${md5_chk%% *}"
399 if [ -n "$md5_img" -a -n "$md5_chk" ] && [ "$md5_img" = "$md5_chk" ]; then
402 echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
432 tellstick-znet-lite|\
499 local magic_ver
="0100"
502 tl-wdr3320-v2|tl-wdr6500-v2
)
507 [ "$magic" != "$magic_ver" ] && {
508 echo "Invalid image type."
517 hwid
=$
(tplink_get_hwid
)
518 mid
=$
(tplink_get_mid
)
519 imagehwid
=$
(tplink_get_image_hwid
"$1")
520 imagemid
=$
(tplink_get_image_mid
"$1")
522 [ "$hwid" != "$imagehwid" -o "$mid" != "$imagemid" ] && {
523 echo "Invalid image, hardware ID mismatch, hw:$hwid $mid image:$imagehwid $imagemid."
529 boot_size
=$
(tplink_get_image_boot_size
"$1")
530 [ "$boot_size" != "00000000" ] && {
531 echo "Invalid image, it contains a bootloader."
540 dir825b_check_image
"$1" && return 0
571 rb-2011uias-2hnd-r2|\
574 nand_do_platform_check routerboard
$1
585 nand_do_platform_check
$board $1
593 tplink_pharos_check_image
"$1" "7f454c46" "$(tplink_pharos_get_model_string)" '' && return 0
598 tplink_pharos_check_image
"$1" "01000000" "$(tplink_pharos_v2_get_model_string)" '\0\xff\r' && return 0
602 tplink_pharos_check_image
"$1" "7f454c46" "$(tplink_pharos_v2_get_model_string)" '\0\xff\r' && return 0
625 platform_check_image_openmesh
"$magic_long" "$1" && return 0
630 merakinand_do_platform_check
$board $1
637 [ "$magic_long" != "5ea3a417" ] && {
638 echo "Invalid image, bad magic: $magic_long"
642 local typemagic
=$
(seama_get_type_magic
"$1")
643 [ "$typemagic" != "6669726d" ] && {
644 echo "Invalid image, bad type: $typemagic"
653 cybertan_check_image
"$1" && return 0
659 [ "$magic_long" != "19852003" ] && {
660 echo "Invalid image type."
667 alfa_check_image
"$1" && return 0
677 hw_magic
="$(ar71xx_get_mtd_part_magic firmware)"
678 [ "$magic_long" != "$hw_magic" ] && {
679 echo "Invalid image, hardware ID mismatch, hw:$hw_magic image:$magic_long."
686 [ "$magic_long" != "32303034" ] && {
687 echo "Invalid image type."
694 [ "$magic_long" != "32323030" ] && {
695 echo "Invalid image type."
702 local magic
=$
(wrgg_get_image_magic
"$1")
703 [ "$magic" != "21030820" ] && {
704 echo "Invalid image, bad type: $magic"
710 # these boards use metadata images
724 rb-962uigs-5hact2hnt|\
736 echo "Sysupgrade is not yet supported on $board."
740 platform_pre_upgrade
() {
741 local board
=$
(board_name
)
753 rb-962uigs-5hact2hnt|\
761 # erase firmware if booted from initramfs
762 [ -z "$(rootfs_type)" ] && mtd erase firmware
767 platform_nand_pre_upgrade
() {
768 local board
=$
(board_name
)
773 local fw_mtd
=$
(find_mtd_part kernel
)
774 fw_mtd
="${fw_mtd/block/}"
775 [ -n "$fw_mtd" ] ||
return
777 local board_dir
=$
(tar tf
"$1" |
grep -m 1 '^sysupgrade-.*/$')
778 board_dir
=${board_dir%/}
779 [ -n "$board_dir" ] ||
return
782 tar xf
"$1" ${board_dir}/kernel
-O | nandwrite
-o "$fw_mtd" -
785 case "$(fw_printenv -n dualPartition)" in
787 fw_setenv dualPartition imgB
788 fw_setenv ActImg NokiaImageB
791 fw_setenv dualPartition imgA
792 fw_setenv ActImg NokiaImageA
795 ubiblock
-r /dev
/ubiblock0_0
2>/dev
/null
>/dev
/null
796 rm -f /dev
/ubiblock0_0
797 ubidetach
-d 0 2>/dev
/null
>/dev
/null
799 CI_KERNPART
=kernel_alt
804 platform_do_upgrade
() {
805 local board
=$
(board_name
)
809 platform_do_upgrade_allnet
"0x9f050000" "$1"
821 platform_do_upgrade_combined
"$1"
824 platform_do_upgrade_allnet
"0x9f080000" "$1"
829 platform_do_upgrade_allnet
"0xbf0a0000" "$1"
833 platform_do_upgrade_dir825b
"$1"
855 platform_do_upgrade_openmesh
"$1"
891 rb-2011uias-2hnd-r2|\
901 merakinand_do_upgrade
"$1"
905 MTD_CONFIG_ARGS
="-s 0x180000"
906 default_do_upgrade
"$1"
910 platform_do_upgrade_compex
"$1"
913 default_do_upgrade
"$1"