OpenWrt – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
4 | office | 1 | # |
2 | # Copyright (C) 2014 OpenWrt.org |
||
3 | # |
||
4 | |||
5 | linksys_get_target_firmware() { |
||
6 | cur_boot_part=`/usr/sbin/fw_printenv -n boot_part` |
||
7 | target_firmware="" |
||
8 | if [ "$cur_boot_part" = "1" ] |
||
9 | then |
||
10 | # current primary boot - update alt boot |
||
11 | target_firmware="kernel2" |
||
12 | fw_setenv boot_part 2 |
||
13 | fw_setenv bootcmd "run altnandboot" |
||
14 | elif [ "$cur_boot_part" = "2" ] |
||
15 | then |
||
16 | # current alt boot - update primary boot |
||
17 | target_firmware="kernel1" |
||
18 | fw_setenv boot_part 1 |
||
19 | fw_setenv bootcmd "run nandboot" |
||
20 | fi |
||
21 | |||
22 | echo "$target_firmware" |
||
23 | } |
||
24 | |||
25 | linksys_get_root_magic() { |
||
26 | (get_image "$@" | dd skip=786432 bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null |
||
27 | } |
||
28 | |||
29 | platform_do_upgrade_linksys() { |
||
30 | local magic_long="$(get_magic_long "$1")" |
||
31 | |||
32 | mkdir -p /var/lock |
||
33 | local part_label="$(linksys_get_target_firmware)" |
||
34 | touch /var/lock/fw_printenv.lock |
||
35 | |||
36 | if [ ! -n "$part_label" ] |
||
37 | then |
||
38 | echo "cannot find target partition" |
||
39 | exit 1 |
||
40 | fi |
||
41 | |||
42 | local target_mtd=$(find_mtd_part $part_label) |
||
43 | |||
44 | [ "$magic_long" = "73797375" ] && { |
||
45 | CI_KERNPART="$part_label" |
||
46 | if [ "$part_label" = "kernel1" ] |
||
47 | then |
||
48 | CI_UBIPART="rootfs1" |
||
49 | else |
||
50 | CI_UBIPART="rootfs2" |
||
51 | fi |
||
52 | |||
53 | nand_upgrade_tar "$1" |
||
54 | } |
||
55 | [ "$magic_long" = "27051956" ] && { |
||
56 | # check firmwares' rootfs types |
||
57 | local target_mtd=$(find_mtd_part $part_label) |
||
58 | local oldroot="$(linksys_get_root_magic $target_mtd)" |
||
59 | local newroot="$(linksys_get_root_magic "$1")" |
||
60 | |||
61 | if [ "$newroot" = "55424923" -a "$oldroot" = "55424923" ] |
||
62 | # we're upgrading from a firmware with UBI to one with UBI |
||
63 | then |
||
64 | # erase everything to be safe |
||
65 | mtd erase $part_label |
||
66 | get_image "$1" | mtd -n write - $part_label |
||
67 | else |
||
68 | get_image "$1" | mtd write - $part_label |
||
69 | fi |
||
70 | } |
||
71 | } |