2 # Copyright (C) 2014-2015 OpenWrt.org
5 linksys_get_target_firmware
() {
6 cur_boot_part
=`/usr/sbin/fw_printenv -n boot_part`
8 if [ "$cur_boot_part" = "1" ]
10 # current primary boot - update alt boot
11 target_firmware
="kernel2"
13 #In EA8500 bootcmd is always "bootipq", so don't change
14 #fw_setenv bootcmd "run altnandboot"
15 elif [ "$cur_boot_part" = "2" ]
17 # current alt boot - update primary boot
18 target_firmware
="kernel1"
20 #In EA8500 bootcmd is always "bootipq", so don't change
21 #fw_setenv bootcmd "run nandboot"
24 # re-enable recovery so we get back if the new firmware is broken
25 fw_setenv auto_recovery
yes
27 echo "$target_firmware"
30 linksys_get_root_magic
() {
31 (get_image
"$@" |
dd skip
=786432 bs
=4 count
=1 |
hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev
/null
34 platform_do_upgrade_linksys
() {
35 local magic_long
="$(get_magic_long "$1")"
38 local part_label
="$(linksys_get_target_firmware)"
39 touch /var
/lock
/fw_printenv.lock
41 if [ ! -n "$part_label" ]
43 echo "cannot find target partition"
47 local target_mtd
=$
(find_mtd_part
$part_label)
49 [ "$magic_long" = "73797375" ] && {
50 CI_KERNPART
="$part_label"
51 if [ "$part_label" = "kernel1" ]
59 # remove "squashfs" vol (in case we are flashing over a stock image, which is also UBI)
61 local mtdnum
="$( find_mtd_index "$CI_UBIPART" )"
62 if [ ! "$mtdnum" ]; then
63 echo "cannot find ubi mtd partition $CI_UBIPART"
67 local ubidev
="$( nand_find_ubi "$CI_UBIPART" )"
68 if [ ! "$ubidev" ]; then
69 ubiattach
-m "$mtdnum"
71 ubidev
="$( nand_find_ubi "$CI_UBIPART" )"
74 if [ "$ubidev" ]; then
76 local squash_ubivol
="$( nand_find_volume $ubidev squashfs )"
79 [ "$squash_ubivol" ] && ubirmvol
/dev
/$ubidev -N squashfs || true
83 # complete std upgrade
86 [ "$magic_long" = "27051956" ] && {
87 # check firmwares' rootfs types
88 local oldroot
="$(linksys_get_root_magic $target_mtd)"
89 local newroot
="$(linksys_get_root_magic "$1")"
91 if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ]
92 # we're upgrading from a firmware with UBI to one with UBI
94 # erase everything to be safe
96 get_image
"$1" | mtd
-n write - $part_label
98 get_image
"$1" | mtd
write - $part_label
103 linksys_preupgrade
() {
104 export RAMFS_COPY_BIN
="${RAMFS_COPY_BIN} /usr/sbin/fw_printenv /usr/sbin/fw_setenv"
105 export RAMFS_COPY_BIN
="${RAMFS_COPY_BIN} /bin/mkdir /bin/touch"
106 export RAMFS_COPY_DATA
="${RAMFS_COPY_DATA} /etc/fw_env.config /var/lock/fw_printenv.lock"
110 append sysupgrade_pre_upgrade linksys_preupgrade