1 linksys_get_target_firmware
() {
2 cur_boot_part
=$
(/usr
/sbin
/fw_printenv
-n boot_part
)
4 if [ "$cur_boot_part" = "1" ]; then
5 # current primary boot - update alt boot
6 target_firmware
="alt_kernel"
8 # In the Linksys EA6350v3, it is enough to set the boot_part as the boot command line is
9 # bootcmd=if test $boot_part = 1; then run bootpart1; else run bootpart2; fi
10 # - You probably want to use that if your device's uboot does not eval bootcmd
11 #fw_setenv bootcmd "run altnandboot"
12 elif [ "$cur_boot_part" = "2" ]; then
13 # current alt boot - update primary boot
14 target_firmware
="kernel"
16 #fw_setenv bootcmd "run nandboot"
19 # re-enable recovery so we get back if the new firmware is broken
20 fw_setenv auto_recovery
yes
21 # see /etc/init.d/zlinksys_recovery
23 echo "$target_firmware"
26 linksys_get_root_magic
() {
27 (get_image
"$@" |
dd skip
=786432 bs
=4 count
=1 |
hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev
/null
30 platform_do_upgrade_linksys
() {
31 local magic_long
="$(get_magic_long "$1")"
34 local part_label
="$(linksys_get_target_firmware)"
35 touch /var
/lock
/fw_printenv.lock
37 if [ ! -n "$part_label" ]; then
38 echo "cannot find target partition"
42 local target_mtd
=$
(find_mtd_part
$part_label)
44 [ "$magic_long" = "73797375" ] && {
45 CI_KERNPART
="$part_label"
46 if [ "$part_label" = "kernel" ]; then
49 CI_UBIPART
="alt_rootfs"
52 # remove "squashfs" vol (in case we are flashing over a stock image, which is also UBI)
54 local mtdnum
="$( find_mtd_index "$CI_UBIPART" )"
55 if [ ! "$mtdnum" ]; then
56 echo "cannot find ubi mtd partition $CI_UBIPART"
60 local ubidev
="$( nand_find_ubi "$CI_UBIPART" )"
61 if [ ! "$ubidev" ]; then
62 ubiattach
-m "$mtdnum"
64 ubidev
="$( nand_find_ubi "$CI_UBIPART" )"
67 if [ "$ubidev" ]; then
68 local squash_ubivol
="$( nand_find_volume $ubidev squashfs )"
70 [ "$squash_ubivol" ] && ubirmvol
/dev
/$ubidev -N squashfs || true
73 # complete std upgrade
76 [ "$magic_long" = "27051956" ] && {
77 # This magic is for a uImage (which is a sysupgrade image)
78 # check firmwares' rootfs types
79 local oldroot
="$(linksys_get_root_magic $target_mtd)"
80 local newroot
="$(linksys_get_root_magic "$1")"
82 if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ]; then
83 # we're upgrading from a firmware with UBI to one with UBI
84 # erase everything to be safe
85 # - Is that really needed? Won't remove (or comment) the if, because it may be needed in a future device.
86 #mtd erase $part_label
87 #get_image "$1" | mtd -n write - $part_label
88 echo "writing \"$1\" UBI image to \"$part_label\" (UBI)..."
89 get_image
"$1" | mtd
write - $part_label
91 echo "writing \"$1\" image to \"$part_label\""
92 get_image
"$1" | mtd
write - $part_label