2 # Copyright (C) 2014-2015 OpenWrt.org
5 linksys_get_target_firmware() {
7 local cur_boot_part mtd_ubi0
9 cur_boot_part=`/usr/sbin/fw_printenv -n boot_part`
10 if [ -z "${cur_boot_part}" ] ; then
11 mtd_ubi0=$(cat /sys/devices/virtual/ubi/ubi0/mtd_num)
12 case $(egrep ^mtd${mtd_ubi0}: /proc/mtd | cut -d '"' -f 2) in
20 >&2 printf "Current boot_part='%s' selected from ubi0/mtd_num='%s'" \
21 "${cur_boot_part}" "${mtd_ubi0}"
24 case $cur_boot_part in
28 bootcmd "run altnandboot"
36 bootcmd "run nandboot"
47 linksys_get_root_magic() {
48 (get_image "$@" | dd skip=786432 bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
51 platform_do_upgrade_linksys() {
52 local magic_long="$(get_magic_long "$1")"
55 local part_label="$(linksys_get_target_firmware)"
56 touch /var/lock/fw_printenv.lock
58 if [ ! -n "$part_label" ]
60 echo "cannot find target partition"
64 local target_mtd=$(find_mtd_part $part_label)
66 [ "$magic_long" = "73797375" ] && {
67 CI_KERNPART="$part_label"
68 if [ "$part_label" = "kernel1" ]
77 [ "$magic_long" = "27051956" -o "$magic_long" = "0000a0e1" ] && {
78 # check firmwares' rootfs types
79 local target_mtd=$(find_mtd_part $part_label)
80 local oldroot="$(linksys_get_root_magic $target_mtd)"
81 local newroot="$(linksys_get_root_magic "$1")"
83 if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ]
84 # we're upgrading from a firmware with UBI to one with UBI
86 # erase everything to be safe
88 get_image "$1" | mtd -n write - $part_label
90 get_image "$1" | mtd write - $part_label
95 platform_copy_config_linksys() {
96 cp -f "$UPGRADE_BACKUP" "/tmp/syscfg/$BACKUP_FILE"