summaryrefslogtreecommitdiff
path: root/target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh
diff options
context:
space:
mode:
authorJohn Crispin <john@openwrt.org>2015-12-12 06:42:29 +0000
committerJohn Crispin <john@openwrt.org>2015-12-12 06:42:29 +0000
commitabc84551c04783c2d59fdd4aa474d5a82ed30cf5 (patch)
tree3f79f01f69dc4a697f7e24095e789b12fc587dca /target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh
parent9e5044926b3344344c8390db03be22836277f967 (diff)
downloadmtk-20170518-abc84551c04783c2d59fdd4aa474d5a82ed30cf5.zip
mtk-20170518-abc84551c04783c2d59fdd4aa474d5a82ed30cf5.tar.gz
mtk-20170518-abc84551c04783c2d59fdd4aa474d5a82ed30cf5.tar.bz2
ar71xx: add support for Cisco's MR18
This patch adds support for Cisco's MR18. Detailed instructions for the flashing the device can be found in the OpenWrt forum thread: <https://forum.openwrt.org/viewtopic.php?id=59248> Signed-off-by: Chris R Blake <chrisrblake93@gmail.com> SVN-Revision: 47878
Diffstat (limited to 'target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh')
-rw-r--r--target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh137
1 files changed, 137 insertions, 0 deletions
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh b/target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh
new file mode 100644
index 0000000..fe78e9f
--- /dev/null
+++ b/target/linux/ar71xx/base-files/lib/upgrade/merakinand.sh
@@ -0,0 +1,137 @@
+#!/bin/sh
+#
+# Copyright (C) 2015 Chris Blake <chrisrblake93@gmail.com>
+#
+# Custom upgrade script for Meraki NAND devices (ex. MR18)
+# Based on dir825.sh and stock nand functions
+#
+. /lib/ar71xx.sh
+. /lib/functions.sh
+. /lib/upgrade/nand.sh
+
+get_magic_at() {
+ local mtddev=$1
+ local pos=$2
+ dd bs=1 count=2 skip=$pos if=$mtddev 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
+}
+
+mr18_is_caldata_valid() {
+ local mtddev=$1
+ local magic
+
+ magic=$(get_magic_at $mtddev 4096)
+ [ "$magic" != "0202" ] && return 0
+
+ magic=$(get_magic_at $mtddev 20480)
+ [ "$magic" != "0202" ] && return 0
+
+ magic=$(get_magic_at $mtddev 36864)
+ [ "$magic" != "0202" ] && return 0
+
+ return 1
+}
+
+merakinand_copy_caldata() {
+ local cal_src=$1
+ local cal_dst=$2
+ local ubidev=$( nand_find_ubi $CI_UBIPART )
+ local board_name="$(cat /tmp/sysinfo/board_name)"
+ local rootfs_size="$(ubinfo /dev/ubi0 -N rootfs_data | grep "Size" | awk '{ print $6 }')"
+
+ # Setup partitions using board name, in case of future platforms
+ case "$board_name" in
+ "mr18")
+ # Src is MTD
+ mtd_src=$(find_mtd_chardev $cal_src)
+ [ -n "$mtd_src" ] || {
+ echo "no mtd device found for partition $cal_src"
+ exit 1
+ }
+
+ # Dest is UBI
+ # TODO: possibly add create (hard to do when rootfs_data is expanded & mounted)
+ # Would need to be done from ramdisk
+ mtd_dst="$(nand_find_volume $ubidev $cal_dst)"
+ [ -n "$mtd_dst" ] || {
+ echo "no ubi device found for partition $cal_dst"
+ exit 1
+ }
+
+ mr18_is_caldata_valid "$mtd_src" && {
+ echo "no valid calibration data found in $cal_src"
+ exit 1
+ }
+
+ mr18_is_caldata_valid "/dev/$mtd_dst" && {
+ echo "Copying calibration data from $cal_src to $cal_dst..."
+ dd if="$mtd_src" of=/tmp/caldata.tmp 2>/dev/null
+ ubiupdatevol "/dev/$mtd_dst" /tmp/caldata.tmp
+ rm /tmp/caldata.tmp
+ sync
+ }
+ return 0
+ ;;
+ *)
+ echo "Unsupported device $board_name";
+ return 1
+ ;;
+ esac
+}
+
+merakinand_do_kernel_check() {
+ local board_name="$1"
+ local tar_file="$2"
+ local image_magic_word=`(tar xf $tar_file sysupgrade-$board_name/kernel -O 2>/dev/null | dd bs=1 count=4 skip=0 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"')`
+
+ # What is our kernel magic string?
+ case "$board_name" in
+ "mr18")
+ [ "$image_magic_word" == "8e73ed8a" ] && {
+ echo "pass" && return 0
+ }
+ ;;
+ esac
+
+ exit 1
+}
+
+merakinand_do_platform_check() {
+ local board_name="$1"
+ local tar_file="$2"
+ local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL -O | wc -c) 2> /dev/null`
+ local file_type="$(identify_tar $2 sysupgrade-$board_name/root)"
+ local kernel_magic="$(merakinand_do_kernel_check $1 $2)"
+
+ case "$board_name" in
+ "mr18")
+ [ "$control_length" = 0 -o "$file_type" != "squashfs" -o "$kernel_magic" != "pass" ] && {
+ echo "Invalid sysupgrade file for $board_name"
+ return 1
+ }
+ ;;
+ *)
+ echo "Unsupported device $board_name";
+ return 1
+ ;;
+ esac
+
+ return 0
+}
+
+merakinand_do_upgrade() {
+ local tar_file="$1"
+ local board_name="$(cat /tmp/sysinfo/board_name)"
+
+ # Do we need to do any platform tweaks?
+ case "$board_name" in
+ "mr18")
+ # Check and create UBI caldata if it's invalid
+ merakinand_copy_caldata "odm-caldata" "caldata"
+ nand_do_upgrade $1
+ ;;
+ *)
+ echo "Unsupported device $board_name";
+ exit 1
+ ;;
+ esac
+}