2 # Copyright (C) 2011 OpenWrt.org
5 . /lib/functions/system.sh
8 RAMFS_COPY_BIN='nandwrite'
13 PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD=0
15 platform_find_partitions() {
16 local first dev size erasesize name
17 while read dev size erasesize name; do
18 name=${name#'"'}; name=${name%'"'}
20 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin|rootfs|filesystem)
21 if [ -z "$first" ]; then
24 echo "$erasesize:$first:$name"
32 platform_find_kernelpart() {
34 for part in "${1%:*}" "${1#*:}"; do
36 vmlinux.bin.l7|vmlinux|kernel|linux|linux.bin)
44 platform_find_rootfspart() {
46 for part in "${1%:*}" "${1#*:}"; do
47 [ "$part" != "$2" ] && echo "$part" && break
51 platform_do_upgrade_combined() {
52 local partitions=$(platform_find_partitions)
53 local kernelpart=$(platform_find_kernelpart "${partitions#*:}")
54 local erase_size=$((0x${partitions%%:*})); partitions="${partitions#*:}"
55 local kern_length=0x$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null)
56 local kern_blocks=$(($kern_length / $CI_BLKSZ))
57 local root_blocks=$((0x$(dd if="$1" bs=2 skip=5 count=4 2>/dev/null) / $CI_BLKSZ))
59 if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \
60 [ ${kern_blocks:-0} -gt 0 ] && \
61 [ ${root_blocks:-0} -gt 0 ] && \
62 [ ${erase_size:-0} -gt 0 ];
64 local rootfspart=$(platform_find_rootfspart "$partitions" "$kernelpart")
66 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
68 if [ "$PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD" -ne 1 ]; then
69 ( dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null; \
70 dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null ) | \
71 mtd -r $append -F$kernelpart:$kern_length:$CI_LDADR,rootfs write - $partitions
72 elif [ -n "$rootfspart" ]; then
73 dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null | \
74 mtd write - $kernelpart
75 dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null | \
76 mtd -r $append write - $rootfspart
79 PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD=0
82 tplink_get_image_hwid() {
83 get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
86 tplink_get_image_mid() {
87 get_image "$@" | dd bs=4 count=1 skip=17 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
90 tplink_get_image_boot_size() {
91 get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
94 tplink_pharos_check_image() {
95 local magic_long="$(get_magic_long "$1")"
96 [ "$magic_long" != "7f454c46" ] && {
97 echo "Invalid image magic '$magic_long'"
101 local model_string="$(tplink_pharos_get_model_string)"
104 # Here $1 is given to dd directly instead of get_image as otherwise the skip
105 # will take almost a second (as dd can't seek then)
107 # This will fail if the image isn't local, but that's fine: as the
108 # read loop won't be executed at all, it will return true, so the image
109 # is accepted (loading the first 1.5M of a remote image for this check seems
111 dd if="$1" bs=1 skip=1511432 count=1024 2>/dev/null | while read line; do
112 [ "$line" = "$model_string" ] && break
114 echo "Unsupported image (model not in support-list)"
121 seama_get_type_magic() {
122 get_image "$@" | dd bs=1 count=4 skip=53 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
125 wrgg_get_image_magic() {
126 get_image "$@" | dd bs=4 count=1 skip=8 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
129 cybertan_get_image_magic() {
130 get_image "$@" | dd bs=8 count=1 skip=0 2>/dev/null | hexdump -v -n 8 -e '1/1 "%02x"'
133 cybertan_check_image() {
134 local magic="$(cybertan_get_image_magic "$1")"
135 local fw_magic="$(cybertan_get_hw_magic)"
137 [ "$fw_magic" != "$magic" ] && {
138 echo "Invalid image, ID mismatch, got:$magic, but need:$fw_magic"
145 platform_do_upgrade_compex() {
147 local fw_part=$PART_NAME
148 local fw_mtd=$(find_mtd_part $fw_part)
149 local fw_length=0x$(dd if="$fw_file" bs=2 skip=1 count=4 2>/dev/null)
150 local fw_blocks=$(($fw_length / 65536))
152 if [ -n "$fw_mtd" ] && [ ${fw_blocks:-0} -gt 0 ]; then
154 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
157 dd if="$fw_file" bs=64k skip=1 count=$fw_blocks 2>/dev/null | \
158 mtd $append write - "$fw_part"
163 local magic_long="$(get_magic_long "$1")"
164 local fw_part_size=$(mtd_get_part_size firmware)
166 case "$magic_long" in
168 [ "$fw_part_size" != "16318464" ] && {
169 echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes"
174 [ "$fw_part_size" != "7929856" ] && {
175 echo "Invalid image magic \"$magic_long\" for $fw_part_size bytes"
184 platform_check_image() {
185 local board=$(board_name)
186 local magic="$(get_magic_word "$1")"
187 local magic_long="$(get_magic_long "$1")"
189 [ "$#" -gt 1 ] && return 1
193 [ "$magic" != "2705" ] && {
194 echo "Invalid image type."
202 echo "Sysupgrade is not yet supported on $board."
206 platform_do_upgrade() {
207 local board=$(board_name)
211 default_do_upgrade "$ARGV"
218 ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
219 echo 'Could not disable watchdog'
224 append sysupgrade_pre_upgrade disable_watchdog