#!/bin/sh # License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. # # Flash a boot image to a phone in fastboot. The test slot (TEST_SLOT, a) is # the default; the fallback slot holds the known-good image and is written # only with FORCE_FALLBACK=1, and writing it does not make it active. The # device must report FASTBOOT_PRODUCT. # # Usage: flash.sh DEVICEDIR IMAGE [SLOT] set -eu . "$(dirname "$0")/lib.sh" [ $# -ge 2 ] || { echo "usage: $0 DEVICEDIR IMAGE [SLOT]" >&2; exit 2; } load_device "$1" img=$2 slot=${3:-$TEST_SLOT} [ "$FLASH_METHOD" = fastboot ] || die "flash method $FLASH_METHOD not implemented" [ "$slot" != "$FALLBACK_SLOT" ] || [ "${FORCE_FALLBACK:-0}" = 1 ] || die "slot $slot is the fallback; set FORCE_FALLBACK=1 to overwrite it" fastboot_ready prod=$(timeout 10 fastboot getvar product 2>&1 | sed -n 's/^product: *//p') [ "$prod" = "$FASTBOOT_PRODUCT" ] || die "product is '$prod', expected '$FASTBOOT_PRODUCT'" fastboot flash "$BOOT_PARTITION_PREFIX$slot" "$img" # the fallback is a reserve: writing it leaves the active slot as it is (the # test slot keeps booting, its successful flag and retry count untouched); # the test slot is made active, which resets its retry count (docs/BOOT.md) [ "$slot" = "$FALLBACK_SLOT" ] || fastboot set_active "$slot" fastboot reboot