4
0
raspi-alpine-builder/resources/scripts/ab_flash
2019-11-03 16:04:17 +01:00

41 lines
779 B
Plaintext
Executable File

#!/bin/bash
set -e
image_file=$1
if [ -z $image_file ]; then
echo "USAGE: $0 [IMAGE_PATH]"
return 1
fi
# change to directory containing update file
cd $(dirname $image_file)
# check integrity of image
sha256sum -c ${image_file}.sha256
# get current partition index
current_idx=$(rdev | sed 's#/dev/mmcblk0p\([^ ]*\).*#\1#')
if [ $current_idx -eq 2 ]; then
echo "Start update for partition B"
flash_idx=3
else
echo "Start update for partition A"
flash_idx=2
fi
flash_device="/dev/mmcblk0p${flash_idx}"
# flash device
gunzip -c ${image_file} | dd of=${flash_device} status=progress
# switch active partition
mount -o remount,rw /uboot
fw_setenv boot_partition ${flash_idx}
sync
mount -o remount,ro /uboot
echo "Update complete -> please reboot"