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