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
/class
/ubi
/ubi
0/mtd_num
)
12 case $
(grep -E ^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
47 platform_do_upgrade_linksys
() {
48 local magic_long
="$(get_magic_long "$1")"
51 local part_label
="$(linksys_get_target_firmware)"
52 touch /var
/lock
/fw_printenv.lock
54 if [ ! -n "$part_label" ]
56 echo "cannot find target partition"
60 local target_mtd
=$
(find_mtd_part
$part_label)
62 [ "$magic_long" = "73797375" ] && {
63 CI_KERNPART
="$part_label"
64 if [ "$part_label" = "kernel1" ]
72 # remove "squashfs" vol (in case we are flashing over a stock image, which is also UBI)
74 local mtdnum
="$( find_mtd_index "$CI_UBIPART" )"
75 if [ ! "$mtdnum" ]; then
76 echo "cannot find ubi mtd partition $CI_UBIPART"
80 local ubidev
="$( nand_find_ubi "$CI_UBIPART" )"
81 if [ ! "$ubidev" ]; then
82 ubiattach
-m "$mtdnum"
84 ubidev
="$( nand_find_ubi "$CI_UBIPART" )"
87 if [ "$ubidev" ]; then
89 local squash_ubivol
="$( nand_find_volume $ubidev squashfs )"
92 [ "$squash_ubivol" ] && ubirmvol
/dev
/$ubidev -N squashfs || true
96 # complete std upgrade
97 if nand_upgrade_tar
"$1" ; then
98 nand_do_upgrade_success
100 nand_do_upgrade_failure
104 [ "$magic_long" = "27051956" ] && {
105 get_image
"$1" | mtd
write - $part_label