Files
makronix/mobile/tools/flash.sh
T
lotherkandClaude Sonnet 5.5 73c9de51a6 licence: the CNCL line in every file Makronix wrote (tools, docs, www, mobile, top level)
consmirror.c: the BSD notice is replaced (Makronix's own file).  Files with
changes of other sessions pending are left for their commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:50:26 +00:00

32 lines
1.3 KiB
Bash

#!/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