16ab341fb5bcae3c1a68057fa9022de690e9b3c1
[openwrt/openwrt.git] / target / linux / pistachio / base-files / lib / upgrade / platform.sh
1 #
2 # Copyright (C) 2017 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 RAMFS_COPY_BIN='fw_printenv fw_setenv dmesg'
9 RAMFS_COPY_DATA="/etc/fw_env.config"
10 REQUIRE_IMAGE_METADATA=0
11
12 platform_check_image()
13 {
14 local board=$(board_name)
15
16 nand_do_platform_check $board $1
17 return $?
18 }
19
20 platform_do_upgrade() {
21 # TODO no need to switch to ramfs with dual partitions in
22 # fact we don't even want to reboot as part of seamless
23 # upgrades. Instead just upgrade opposite partition and mark
24 # the next reboot to boot from that partition. Could just call
25 # stage2 directly but need to refactor nand_upgrade_success
26 # for this to work.
27 # Also the nand functions don't allow url to be used
28
29 local board=$(board_name)
30
31 case "$board" in
32 img,pistachio-marduk)
33 local boot_partition=$(dmesg | grep "ubi0: attached.*" | sed "s/^.*\(firmware[0-1]\).*/\1/g")
34
35 echo "Current boot partiton $boot_partition (/dev/mtd$(find_mtd_index $boot_partition))"
36 mkdir -p /var/lock
37 if [ "$boot_partition" == "firmware0" ]; then
38 CI_UBIPART="firmware1"
39 fw_setenv boot_partition 1 || exit 1
40 else
41 CI_UBIPART="firmware0"
42 fw_setenv boot_partition 0 || exit 1
43 fi
44 echo "Upgrading partition $CI_UBIPART (/dev/mtd$(find_mtd_index $CI_UBIPART))"
45 ;;
46 esac
47
48 nand_do_upgrade $1
49 }