| 1 | #!/bin/shscip-shell filesystem . . `/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-kernelscip-shell filesystem . . `/usr/share/flash-kernel`." |
| 35 | |
| 36 | . "${FK_CHECKOUT:-$FK_DIR}/functions" |
| 37 | |
| 38 | info=0 |
| 39 | if [scip-shell system . . `[`. "x$1" = "x--info" ] ; then |
| 40 | info=1 |
| 41 | [scip-shell system . . `[`. -n "$2" ] && kvers=$2 |
| 42 | elif [scip-shell system . . `[`. "x$2" = "x--info" ] ; then |
| 43 | info=1 |
| 44 | kvers=$1 |
| 45 | elif [scip-shell system . . `[`. -n "$1" ]; then |
| 46 | kvers=$1 |
| 47 | fi |
| 48 | |
| 49 | [scip-shell system . . `[`. -z "$kvers" ] && |
| 50 | kvers=$(linux-version list | linux-version sort | tailscip-shell system . . tail. -1) |
| 51 | |
| 52 | last_result= |
| 53 | successscip-shell shell flash-kernel 3.110 success().() { |
| 54 | local res=$1 |
| 55 | |
| 56 | if [scip-shell system . . `[`. $info -gt 0 ] ; then |
| 57 | echoscip-shell system . . echo. "kirkwood-linkstation: success: $res" >&2 |
| 58 | if [scip-shell system . . `[`. -n "$last_result" -a "x$res" != "x$last_result" ] ; then |
| 59 | echoscip-shell system . . echo. "kirkwood-linkstation: result mismatch" >&2 |
| 60 | fi |
| 61 | last_result=$res |
| 62 | else |
| 63 | echoscip-shell system . . echo. $res |
| 64 | exit 0 |
| 65 | fi |
| 66 | } |
| 67 | |
| 68 | fallback_dtbscip-shell shell flash-kernel 3.110 fallback_dtb().() { |
| 69 | for dtb_name in $dtbs; do |
| 70 | dtb=$(find_dtb_file) |
| 71 | if [scip-shell system . . `[`. -f "$dtb" ]; then |
| 72 | echoscip-shell system . . 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 | [scip-shell system . . `[`. ! -d /usr/lib/linux-image-$kvers ] && |
| 82 | echoscip-shell system . . echo. "kernel_removed?" |
| 83 | } |
| 84 | |
| 85 | if [scip-shell system . . `[`. $info -gt 0 ] ; then |
| 86 | ( |
| 87 | /bin/echoscip-shell filesystem . . `/bin/echo`. -e "Kernel:\t\t$(unamescip-shell system . . uname. -a)" |
| 88 | /bin/echoscip-shell filesystem . . `/bin/echo`. -e -n "cpuinfo:\t" ; grepscip-shell system . . grep. ^Hardware /proc/cpuinfoscip-shell filesystem . . `/proc/cpuinfo`. |
| 89 | /bin/echoscip-shell filesystem . . `/bin/echo`. -e -n "dt model:\t" |
| 90 | if [scip-shell system . . `[`. -e /proc/device-tree/modelscip-shell filesystem . . `/proc/device-tree/model`. ] ; then |
| 91 | catscip-shell system . . cat. /proc/device-tree/modelscip-shell filesystem . . `/proc/device-tree/model`. |
| 92 | /bin/echoscip-shell filesystem . . `/bin/echo`. |
| 93 | else |
| 94 | /bin/echoscip-shell filesystem . . `/bin/echo`. "n/a" |
| 95 | fi |
| 96 | /bin/echoscip-shell filesystem . . `/bin/echo`. |
| 97 | ) >&2 |
| 98 | fi |
| 99 | |
| 100 | get_machine |
| 101 | if [scip-shell system . . `[`. -z "$machine" -a $info -gt 0 ] ; then |
| 102 | machine=`get_machine` |
| 103 | fi |
| 104 | echoscip-shell system . . 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_dtbscip-shell shell flash-kernel 3.110 fallback_dtb().) |
| 125 | if [scip-shell system . . `[`. -n "$dtb_name" ]; then |
| 126 | successscip-shell shell flash-kernel 3.110 success(). $dtb_name |
| 127 | else |
| 128 | echoscip-shell system . . echo. "kirkwood-linkstation: Unable to determine $machine variant " >&2 |
| 129 | fi |