1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#!/bin/sh
# Copyright (C) 2006 Joey Hess <joeyh@debian.org>
# Copyright (C) 2006 Martin Michlmayr <tbm@cyrius.com>
# Copyright (C) 2007 Gordon Farquharson <gordonfarquharson@gmail.com>
# This code is covered by the GNU General Public License.
set -e
error() {
echo "$@" >&2
exit 1
}
check_mtd() {
if [ ! -e /proc/mtd ]; then
error "/proc/mtd doesn't exist"
fi
}
mtdblock() {
grep "$1" /proc/mtd | cut -d: -f 1 | sed 's/mtd/\/dev\/mtdblock/'
}
# See http://www.nslu2-linux.org/wiki/Info/BootFlash -- the NSLU2 uses a
# 16 byte MTD header, the first four bytes (big endian) give the length of
# the remainder of the image, and the remaining bytes are zero. Generate
# this header.
sercomm_header() {
perl -e 'print pack("N4", shift)' "$1"
}
nslu2_swap() {
if [ "$little_endian" ]; then
devio "<<"$1 "xp $,4"
else
cat $1
fi
}
apex_file=/boot/apex.flash
if [ ! -e $apex_file ]; then
error "Can't find $apex_file"
fi
machine=$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//')
case "$machine" in
"Linksys NSLU2")
check_mtd
case "$(dpkg --print-architecture)" in
arm|armel)
little_endian=1
;;
armeb)
little_endian=0
;;
esac
mtdloader=$(mtdblock Loader)
if [ -z "$mtdloader" ]; then
error "Cannot find mtd partition 'Loader'"
fi
lsize=$(wc -c $apex_file | awk '{print $1}')
mtdblocksize=131072
pad=$(expr $mtdblocksize - $lsize - 16)
# Store non-default APEX configuration
tmp=$(tempfile)
(apex-env printenv | egrep -v '\*=') > $tmp
printf "Flashing loader: " >&2
(
sercomm_header $(expr $lsize + 16)
nslu2_swap $apex_file
perl -e "print pack(\"C\", 0xff) x $pad"
) > "$mtdloader" || error "failed."
# Write the stored APEX configuration. For each line,
# remove whitespace from the start and the end of the
# line, and use all the characters, including
# whitespace, after '=' as the value.
while read line
do
key=$(echo $line | cut -d '=' -f1 | awk '{print $1}')
val=$(echo $line | awk '{$1=""; $2=""; print substr($0,3)}')
apex-env setenv "$key" "$val"
done < $tmp
rm $tmp
echo "done." >&2
;;
*)
error "Unsupported platform."
;;
esac
|