aboutsummaryrefslogtreecommitdiffstats
path: root/main/u-boot/update-u-boot
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2016-07-29 14:47:56 +0300
committerTimo Teräs <timo.teras@iki.fi>2016-07-29 12:04:17 +0000
commit29342e7fec72ee44bc0f12c0fad15f2daf3e91fb (patch)
treef5c1aac27621fc0a06ea822ff86ea74f2bf97109 /main/u-boot/update-u-boot
parenta600a036424adc98d633178efe8289adb411df24 (diff)
downloadaports-29342e7fec72ee44bc0f12c0fad15f2daf3e91fb.tar.bz2
aports-29342e7fec72ee44bc0f12c0fad15f2daf3e91fb.tar.xz
main/u-boot: add update-u-boot script for upgrading bootloader
Diffstat (limited to 'main/u-boot/update-u-boot')
-rwxr-xr-xmain/u-boot/update-u-boot115
1 files changed, 115 insertions, 0 deletions
diff --git a/main/u-boot/update-u-boot b/main/u-boot/update-u-boot
new file mode 100755
index 0000000000..069d654755
--- /dev/null
+++ b/main/u-boot/update-u-boot
@@ -0,0 +1,115 @@
+#!/bin/sh
+
+verbose=
+board=
+device=
+dryrun=
+imagedir=
+
+get_defaults() {
+ if [ -z "$board" -a -e /sys/firmware/devicetree/base/compatible ]; then
+ case "$(cat /sys/firmware/devicetree/base/compatible 2>/dev/null)" in
+ wand,*) board=wand ;;
+ esac
+ fi
+
+ if [ -z "$device" ]; then
+ case "$board" in
+ wand|cubie|cubie2) device=/dev/mmcblk0p0 ;;
+ esac
+ fi
+
+ if [ -z "$imagedir" ]; then
+ imagedir="$(realpath $(dirname $0))"
+ [ -f "$imagedir/README.txt" ] || imagedir="/usr/share/u-boot"
+ fi
+}
+
+die() {
+ echo "ERROR: $@"
+ exit 1
+}
+
+usage() {
+ get_defaults
+
+ cat <<EOF
+usage: $0 [-b|--board <board-type>] [-d|--device <device>]
+
+options:
+
+ -b,--board <board> Specify the board type: wand, cubie, cubie2
+ (current default: ${board:-none})
+
+ -d,--device <device> Specify the device where to install u-boot
+ (current default: ${device:-none})
+
+ -i,--imagedir <imagedir> Specify u-boot image directory
+ (current default: ${imagedir:-none})
+
+ -n,--dry-run Print commands but don't execute them
+
+EOF
+}
+
+while [ $# -gt 0 ]; do
+ opt="$1"
+ shift
+ case "$opt" in
+ -b|--board)
+ case "$1" in
+ wand|wandboard) board="wand" ;;
+ cubie|cubieboard) board="cubie" ;;
+ *) usage; exit 1;;
+ esac
+ shift
+ ;;
+ -d|--device)
+ device="$1"
+ shift
+ ;;
+ -i|--imagedir)
+ imagedir="$1"
+ shift
+ ;;
+ -n|--dry-run)
+ dryrun="echo"
+ ;;
+ --)
+ break
+ ;;
+ -*)
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+get_defaults
+if [ -z "$board" -o -z "$device" -o -z "$imagedir" -o ! -e "$imagedir" ]; then
+ usage
+ exit 1
+fi
+
+if [ -z "$dryrun" ]; then
+ echo "Updating $board u-boot in $device in 3 seconds..."
+ sleep 3
+fi
+
+(
+set -e
+case "$board" in
+wand)
+ [ -e "$imagedir/wandboard" ] || die "wandboard images not installed, apk add u-boot-wandboard"
+ $dryrun dd if=$imagedir/wandboard/SPL of=$device bs=1k seek=1 status=none
+ $dryrun dd if=$imagedir/wandboard/u-boot.img of=$device bs=1k seek=69 status=none
+ ;;
+cubie|cubie2)
+ [ -e "$imagedir/Cubieboard${board#cubie}" ] || die "Cubieboard images not installed, apk add u-boot-cubieboard"
+ $dryrun dd if=$imagedir/Cubieboard${board#cubie}/u-boot-sunxi-with-spl.bin of=/dev/sda bs=1024 seek=8 status=none
+ ;;
+esac
+$dryrun sync
+) || die "U-Boot installation in $device failed"
+
+[ -z "$dryrun" ] && echo "Completed successfully."