| 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright (C) 2016 |
| 4 | # Roger Shimizu <[email protected]> |
| 5 | # |
| 6 | # Based on script kirkwood-qnap |
| 7 | # Copyright (C) 2014 Ian Campbell <[email protected]> |
| 8 | |
| 9 | # This program is free software; you can redistribute it and/or |
| 10 | # modify it under the terms of the GNU General Public License |
| 11 | # as published by the Free Software Foundation; either version 2 |
| 12 | # of the License, or (at your option) any later version. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this program; if not, write to the Free Software |
| 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, |
| 22 | # USA. |
| 23 | |
| 24 | # This script attempts to determine the correct device tree blob to |
| 25 | # use on kirkwood based Buffalo Linkstation devices, which varies according |
| 26 | # to DTB file ships with the kernel installed. |
| 27 | # |
| 28 | # This is required because there's a split/rename for device tree file of |
| 29 | # a few Buffalo Linkstation devices. With help of this script, kernel |
| 30 | # upgrade/downgrade would be smooth as usual. |
| 31 | |
| 32 | set -e |
| 33 | |
| 34 | FK_DIR="/usr/share/flash-kernel" |
| 35 | |
| 36 | . "${FK_CHECKOUT:-$FK_DIR}/functions" |
| 37 | |
| 38 | info=0 |
| 39 | if [ "x$1" = "x--info" ] ; then |
| 40 | info=1 |
| 41 | [ -n "$2" ] && kvers=$2 |
| 42 | elif [ "x$2" = "x--info" ] ; then |
| 43 | info=1 |
| 44 | kvers=$1 |
| 45 | elif [ -n "$1" ]; then |
| 46 | kvers=$1 |
| 47 | fi |
| 48 | |
| 49 | [ -z "$kvers" ] && |
| 50 | kvers=$(linux-version list | linux-version sort | tail -1) |
| 51 | |
| 52 | last_result= |
| 53 | success() { |
| 54 | local res=$1 |
| 55 | |
| 56 | if [ $info -gt 0 ] ; then |
| 57 | echo "kirkwood-linkstation: success: $res" >&2 |
| 58 | if [ -n "$last_result" -a "x$res" != "x$last_result" ] ; then |
| 59 | echo "kirkwood-linkstation: result mismatch" >&2 |
| 60 | fi |
| 61 | last_result=$res |
| 62 | else |
| 63 | echo $res |
| 64 | exit 0 |
| 65 | fi |
| 66 | } |
| 67 | |
| 68 | fallback_dtb() { |
| 69 | for dtb_name in $dtbs; do |
| 70 | dtb=$(find_dtb_file) |
| 71 | if [ -f "$dtb" ]; then |
| 72 | echo "$dtb_name" |
| 73 | return |
| 74 | fi |
| 75 | done |
| 76 | |
| 77 | # Workaround: DTB file will be removed before this script is invoked, |
| 78 | # when upgrading or removing kernel package. |
| 79 | # So here just provide a fake DTB as warning message, instead of error, |
| 80 | # which will block upgrading or removing of kernel package. |
| 81 | [ ! -d /usr/lib/linux-image-$kvers ] && |
| 82 | echo "kernel_removed?" |
| 83 | } |
| 84 | |
| 85 | if [ $info -gt 0 ] ; then |
| 86 | ( |
| 87 | /bin/echo -e "Kernel:\t\t$(uname -a)" |
| 88 | /bin/echo -e -n "cpuinfo:\t" ; grep ^Hardware /proc/cpuinfo |
| 89 | /bin/echo -e -n "dt model:\t" |
| 90 | if [ -e /proc/device-tree/model ] ; then |
| 91 | cat /proc/device-tree/model |
| 92 | /bin/echo |
| 93 | else |
| 94 | /bin/echo "n/a" |
| 95 | fi |
| 96 | /bin/echo |
| 97 | ) >&2 |
| 98 | fi |
| 99 | |
| 100 | get_machine |
| 101 | if [ -z "$machine" -a $info -gt 0 ] ; then |
| 102 | machine=`get_machine` |
| 103 | fi |
| 104 | echo "kirkwood-linkstation: machine: $machine" >&2 |
| 105 | |
| 106 | case $machine in |
| 107 | "Buffalo Linkstation LS-VL") |
| 108 | dtbs="kirkwood-linkstation-lsvl.dtb kirkwood-lswvl.dtb" |
| 109 | ;; |
| 110 | "Buffalo Linkstation LS-WSXL") |
| 111 | dtbs="kirkwood-linkstation-lswsxl.dtb kirkwood-lswxl.dtb" |
| 112 | ;; |
| 113 | "Buffalo Linkstation LS-WVL"|"Buffalo Linkstation LS-WVL/VL") |
| 114 | dtbs="kirkwood-linkstation-lswvl.dtb kirkwood-lswvl.dtb" |
| 115 | ;; |
| 116 | "Buffalo Linkstation LS-WXL"|"Buffalo Linkstation LS-WXL/WSXL") |
| 117 | dtbs="kirkwood-linkstation-lswxl.dtb kirkwood-lswxl.dtb" |
| 118 | ;; |
| 119 | *) |
| 120 | error "Unknown machine $machine" |
| 121 | ;; |
| 122 | esac |
| 123 | |
| 124 | dtb_name=$(fallback_dtb) |
| 125 | if [ -n "$dtb_name" ]; then |
| 126 | success $dtb_name |
| 127 | else |
| 128 | echo "kirkwood-linkstation: Unable to determine $machine variant " >&2 |
| 129 | fi |