diff options
Diffstat (limited to 'target/linux/pistachio/base-files/lib')
3 files changed, 115 insertions, 0 deletions
diff --git a/target/linux/pistachio/base-files/lib/pistachio.sh b/target/linux/pistachio/base-files/lib/pistachio.sh new file mode 100755 index 0000000000..f9a16db3ed --- /dev/null +++ b/target/linux/pistachio/base-files/lib/pistachio.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +PISTACHIO_BOARD_NAME= +PISTACHIO_MODEL= + +pistachio_board_detect() { + local machine + local name + + machine=$(cat /proc/device-tree/model) + + case "$machine" in + "IMG Marduk (Creator Ci40)") + name="marduk" + ;; + *) + name="generic" + ;; + esac + + [ -z "$PISTACHIO_BOARD_NAME" ] && PISTACHIO_BOARD_NAME="$name" + [ -z "$PISTACHIO_MODEL" ] && PISTACHIO_MODEL="$machine" + + [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/" + + echo "$PISTACHIO_BOARD_NAME" > /tmp/sysinfo/board_name + echo "$PISTACHIO_MODEL" > /tmp/sysinfo/model +} + +pistachio_board_name() { + local name + [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name) + [ -z "$name" ] && name="unknown" + + echo "$name" +} diff --git a/target/linux/pistachio/base-files/lib/preinit/03_preinit_pistachio.sh b/target/linux/pistachio/base-files/lib/preinit/03_preinit_pistachio.sh new file mode 100755 index 0000000000..fda420e7d7 --- /dev/null +++ b/target/linux/pistachio/base-files/lib/preinit/03_preinit_pistachio.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +do_pistachio() { + . /lib/pistachio.sh + + pistachio_board_detect +} + +boot_hook_add preinit_main do_pistachio diff --git a/target/linux/pistachio/base-files/lib/upgrade/platform.sh b/target/linux/pistachio/base-files/lib/upgrade/platform.sh new file mode 100755 index 0000000000..5a886fbee6 --- /dev/null +++ b/target/linux/pistachio/base-files/lib/upgrade/platform.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# +# Copyright (C) 2017 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +. /lib/pistachio.sh + +RAMFS_COPY_BIN="/usr/sbin/fw_printenv /usr/sbin/fw_setenv /bin/mkdir /bin/dmesg /bin/sed /bin/grep" +RAMFS_COPY_DATA="/etc/fw_env.config" +REQUIRE_IMAGE_METADATA=0 + +platform_check_image() +{ + local board=$(pistachio_board_name) + + nand_do_platform_check $board $1 + return $? +} + +platform_pre_upgrade() { + # TODO no need to switch to ramfs with dual partitions in + # fact we don't even want to reboot as part of seamless + # upgrades. Instead just upgrade opposite partition and mark + # the next reboot to boot from that partition. Could just call + # stage2 directly but need to refactor nand_upgrade_success + # for this to work. + # Also the nand functions don't allow url to be used + nand_do_upgrade $1 +} + +platform_nand_pre_upgrade() { + local board=$(pistachio_board_name) + + case "$board" in + marduk) + local boot_partition=$(dmesg | grep "ubi0: attached.*" | sed "s/^.*\(firmware[0-1]\).*/\1/g") + + echo "Current boot partiton $boot_partition (/dev/mtd$(find_mtd_index $boot_partition))" + mkdir -p /var/lock + if [ "$boot_partition" == "firmware0" ]; then + CI_UBIPART="firmware1" + fw_setenv boot_partition 1 || exit 1 + else + CI_UBIPART="firmware0" + fw_setenv boot_partition 0 || exit 1 + fi + echo "Upgrading partition $CI_UBIPART (/dev/mtd$(find_mtd_index $CI_UBIPART))" + ;; + esac +} + +blink_led() { + . /etc/diag.sh; set_state upgrade +} +append sysupgrade_pre_upgrade blink_led |