2020-06-17 07:36:00 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
verbose=
|
|
|
|
board=
|
|
|
|
device=
|
|
|
|
dryrun=
|
|
|
|
imagedir=
|
2021-03-29 22:10:06 +00:00
|
|
|
default_freq=528
|
2021-03-29 22:01:38 +00:00
|
|
|
freq=
|
2021-05-13 14:23:52 +00:00
|
|
|
skip_delay=
|
2020-06-17 07:36:00 +00:00
|
|
|
|
|
|
|
get_boot_blockdev() {
|
|
|
|
# Find the blockdevice where /boot is mounted from
|
|
|
|
mount | sed -n -E 's:.*(/dev/mmcblk\d)p\d on /boot .*:\1:p'
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ;;
|
|
|
|
pine64,pinebook-pro*) board=pinebookpro ;;
|
|
|
|
pine64,rockpro64*) board=rockpro64 ;;
|
|
|
|
pine64,pinephone*) board=pinephone ;;
|
2021-05-24 22:46:07 +00:00
|
|
|
pine64,pinetab*) board=pinetab ;;
|
2020-06-17 07:36:00 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$device" ]; then
|
|
|
|
case "$board" in
|
|
|
|
wand|cubie|cubie2) device=/dev/mmcblk0p0 ;;
|
|
|
|
mx6cuboxi) device=/dev/mmcblk0 ;;
|
|
|
|
pinebookpro|rockpro64) device=/dev/mmcblk2 ;;
|
2021-05-24 22:46:07 +00:00
|
|
|
pinephone|pinetab) device=$(get_boot_blockdev) ;;
|
2020-06-17 07:36:00 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$imagedir" ]; then
|
|
|
|
imagedir="$(realpath $(dirname $0))"
|
|
|
|
[ -f "$imagedir/README.txt" ] || imagedir="/usr/share/u-boot"
|
|
|
|
fi
|
2021-03-29 22:01:38 +00:00
|
|
|
|
|
|
|
if [ -z "$freq" -a -e /proc/device-tree/memory/ram_freq ]; then
|
2021-05-10 20:51:07 +00:00
|
|
|
proc_freq=$(cat /proc/device-tree/memory/ram_freq 2>/dev/null)
|
|
|
|
if [ -n "$proc_freq" ]; then
|
|
|
|
echo "Detected clock: $proc_freq MHz"
|
|
|
|
default_freq="$proc_freq"
|
|
|
|
else
|
|
|
|
echo "WARNING: Failed to read clock from /proc/device-tree/memory/ram_freq"
|
|
|
|
echo "Using default clock: $default_freq MHz"
|
|
|
|
fi
|
2021-03-29 22:01:38 +00:00
|
|
|
elif [ -z "$freq" ]; then
|
|
|
|
echo Using default clock: $default_freq MHz
|
|
|
|
else
|
|
|
|
echo Changing clock: $freq MHz
|
|
|
|
fi
|
2020-06-17 07:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "ERROR: $@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
get_defaults
|
|
|
|
|
|
|
|
cat <<EOF
|
2021-05-13 14:23:52 +00:00
|
|
|
usage: $0 [-n,--dry-run] [-i,--imagedir <imagedir>] [-b|--board <board-type>] [-d|--device <device>] [-r|--ram-freq <freq>] [-s|--skip-delay]
|
2020-06-17 07:36:00 +00:00
|
|
|
|
|
|
|
options:
|
|
|
|
|
|
|
|
-b,--board <board> Specify the board type: wand, cubie, cubie2, cuboxi, pinebookpro, rockpro64
|
|
|
|
(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
|
|
|
|
|
2021-03-29 22:01:38 +00:00
|
|
|
-r,--ram-freq RAM clock speed, one of:
|
|
|
|
* 528 (default for new postmarketOS installations)
|
|
|
|
* 552 (default before v21.03 / edge 2021-04-05)
|
|
|
|
* 624
|
|
|
|
|
2021-05-13 14:23:52 +00:00
|
|
|
-s,--skip-delay Skip delay and flash the image immediately
|
|
|
|
|
2020-06-17 07:36:00 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2021-05-10 21:46:53 +00:00
|
|
|
validate_checksum() {
|
|
|
|
file="$1"
|
|
|
|
file_sha512="$file.sha512"
|
|
|
|
file_size=$(stat -c%s $file)
|
|
|
|
device="$2"
|
|
|
|
bs="$3"
|
|
|
|
seek="$4"
|
|
|
|
|
|
|
|
checksum0=$(cat $file_sha512 | awk {'print $1'})
|
|
|
|
checksum1=$(dd if=$device bs=1 skip=$(($seek * $bs)) count=$file_size status=none | sha512sum | awk {'print $1'})
|
|
|
|
if [ "$checksum0" != "$checksum1" ]; then
|
|
|
|
echo "File: $checksum0"
|
|
|
|
echo "Part: $checksum1"
|
|
|
|
die "Checksum failed"
|
|
|
|
fi
|
|
|
|
echo "Successful U-Boot image checksum verification on $device :"
|
|
|
|
echo -e "\t$checksum1"
|
|
|
|
}
|
|
|
|
|
2020-06-17 07:36:00 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
opt="$1"
|
|
|
|
shift
|
|
|
|
case "$opt" in
|
|
|
|
-b|--board)
|
|
|
|
case "$1" in
|
|
|
|
wand|wandboard) board="wand" ;;
|
|
|
|
cubie|cubieboard) board="cubie" ;;
|
|
|
|
cuboxi|mx6cuboxi) board="mx6cuboxi" ;;
|
|
|
|
pinebookpro) board="pinebookpro" ;;
|
|
|
|
rockpro64) board="rockpro64" ;;
|
|
|
|
pinephone) board="pinephone" ;;
|
2021-05-24 22:46:07 +00:00
|
|
|
pinetab) board="pinetab" ;;
|
2020-06-17 07:36:00 +00:00
|
|
|
*) usage; exit 1;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-d|--device)
|
|
|
|
device="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-i|--imagedir)
|
|
|
|
imagedir="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-n|--dry-run)
|
|
|
|
dryrun="echo"
|
|
|
|
;;
|
2021-03-29 22:01:38 +00:00
|
|
|
-r|--ram-freq)
|
|
|
|
case "$1" in
|
|
|
|
528) freq="528" ;;
|
|
|
|
552) freq="552" ;;
|
|
|
|
624) freq="624" ;;
|
|
|
|
*) usage; exit 1;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
;;
|
2021-05-13 14:23:52 +00:00
|
|
|
-s|--skip-delay)
|
|
|
|
skip_delay="yes"
|
|
|
|
;;
|
2020-06-17 07:36:00 +00:00
|
|
|
--)
|
|
|
|
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
|
2021-03-29 22:01:38 +00:00
|
|
|
if [ ! -z "$freq" ]; then
|
|
|
|
echo "/!\ Disclaimer warning:"
|
|
|
|
echo "Overclocking your device may render it unstable or prevent it to boot"
|
|
|
|
echo "If you're unable to boot your device you'll have to flash an image to a mSD card"
|
|
|
|
echo "then boot on it and update u-boot running this command:"
|
|
|
|
echo "update-u-boot -d /dev/mmcblk2"
|
|
|
|
echo
|
|
|
|
read -p "Continue? [y/Y] " -n 1 -r
|
|
|
|
echo
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
2021-05-13 14:23:52 +00:00
|
|
|
if [ -z "$skip_delay" ]; then
|
|
|
|
echo "Updating $board u-boot in $device in 3 seconds..."
|
|
|
|
sleep 3
|
|
|
|
else
|
|
|
|
echo "Updating $board u-boot in $device"
|
|
|
|
fi
|
2020-06-17 07:36:00 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-10 20:51:07 +00:00
|
|
|
if [ -z "$freq" ]; then
|
|
|
|
freq=$default_freq
|
|
|
|
fi
|
|
|
|
|
2020-06-17 07:36:00 +00:00
|
|
|
(
|
|
|
|
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=$device bs=1024 seek=8 status=none
|
|
|
|
;;
|
|
|
|
mx6cuboxi)
|
|
|
|
[ -e "$imagedir/mx6cuboxi" ] || die "iMX6 Cubox-i images not installed, apk add u-boot-cuboxi"
|
|
|
|
$dryrun dd if=$imagedir/mx6cuboxi/SPL of=$device bs=1k seek=1 status=none
|
|
|
|
$dryrun dd if=$imagedir/mx6cuboxi/u-boot.img of=$device bs=1k seek=69 status=none
|
|
|
|
;;
|
|
|
|
pinebookpro|rockpro64)
|
|
|
|
[ -e "$imagedir/pine64-rockpro64/" ] || die "rockpro64 images not installed, apk add u-boot-rockpro64"
|
|
|
|
$dryrun dd if=$imagedir/pine64-rockpro64/u-boot-rockchip.bin of=$device bs=1024 seek=32 status=none
|
|
|
|
;;
|
2021-05-24 22:46:07 +00:00
|
|
|
pinephone|pinetab)
|
2020-06-17 07:36:00 +00:00
|
|
|
[ -e "$imagedir/pine64-pinephone/" ] || die "pinephone images not installed, apk add u-boot-pinephone"
|
2021-05-12 14:56:16 +00:00
|
|
|
$dryrun dd if=$imagedir/pine64-pinephone/u-boot-sunxi-with-spl-$freq.bin of=$device bs=1024 seek=8 oflag=direct status=none
|
2021-05-10 21:46:53 +00:00
|
|
|
[ -z "$dryrun" ] && validate_checksum $imagedir/pine64-pinephone/u-boot-sunxi-with-spl-$freq.bin $device 1024 8
|
2020-06-17 07:36:00 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
$dryrun sync
|
|
|
|
) || die "U-Boot installation in $device failed"
|
|
|
|
|
|
|
|
[ -z "$dryrun" ] && echo "Completed successfully."
|