add sysupgrade support
[openwrt/openwrt.git] / target / linux / mvebu / base-files / lib / upgrade / linksys.sh
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 platform_do_upgrade_linksys() {
26 local magic_long="$(get_magic_long "$1")"
27
28 mkdir -p /var/lock
29 local part_label="$(linksys_get_target_firmware)"
30 touch /var/lock/fw_printenv.lock
31
32 if [ ! -n "$part_label" ]
33 then
34 echo "cannot find target partition"
35 exit 1
36 fi
37
38 # we don't know, what filesystem does the other partition use,
39 # nuke it tobe safe
40 mtd erase $part_label
41 get_image "$1" | mtd -n write - $part_label
42 }
43
44 linksys_preupgrade() {
45 export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /usr/sbin/fw_printenv /usr/sbin/fw_setenv"
46 export RAMFS_COPY_BIN="${RAMFS_COPY_BIN} /bin/mkdir /bin/touch"
47 export RAMFS_COPY_DATA="${RAMFS_COPY_DATA} /etc/fw_env.config /var/lock/fw_printenv.lock"
48
49 [ -f /tmp/sysupgrade.tgz ] && {
50 cp /tmp/sysupgrade.tgz /tmp/syscfg/sysupgrade.tgz
51 }
52 }
53
54 append sysupgrade_pre_upgrade linksys_preupgrade