|
| 1 | +#!/bin/bash |
| 2 | +# MCUboot DFU update script. |
| 3 | +# |
| 4 | +# Performs a full update cycle: |
| 5 | +# 1. Print current image info |
| 6 | +# 2. Upload new image (marked for test swap) |
| 7 | +# 3. Reset device |
| 8 | +# 4. Confirm the running image |
| 9 | +# 5. Print image info again |
| 10 | +# |
| 11 | +# Usage: |
| 12 | +# ./dfu_update.sh --port /dev/ttyACM2 --image path/to/zephyr.signed.bin |
| 13 | +# ./dfu_update.sh --port /dev/ttyACM2 --image path/to/zephyr.signed.bin --wait 8 |
| 14 | + |
| 15 | +set -euo pipefail |
| 16 | + |
| 17 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 18 | +MCUBOOT_MGR="$SCRIPT_DIR/mcuboot_mgr.py" |
| 19 | + |
| 20 | +# Defaults |
| 21 | +PORT="" |
| 22 | +IMAGE="" |
| 23 | +WAIT=5 |
| 24 | + |
| 25 | +usage() { |
| 26 | + cat <<EOF |
| 27 | +Usage: $(basename "$0") [OPTIONS] |
| 28 | +
|
| 29 | +Options: |
| 30 | + --port PORT Serial port for SMP (required) |
| 31 | + --image PATH Path to signed firmware image (required) |
| 32 | + --wait SECONDS Seconds to wait after reset for device to boot (default: $WAIT) |
| 33 | + -h, --help Show this help |
| 34 | +EOF |
| 35 | + exit 1 |
| 36 | +} |
| 37 | + |
| 38 | +# Parse arguments |
| 39 | +while [[ $# -gt 0 ]]; do |
| 40 | + case "$1" in |
| 41 | + --port) PORT="$2"; shift 2 ;; |
| 42 | + --image) IMAGE="$2"; shift 2 ;; |
| 43 | + --wait) WAIT="$2"; shift 2 ;; |
| 44 | + -h|--help) usage ;; |
| 45 | + *) echo "ERROR: Unknown option: $1"; usage ;; |
| 46 | + esac |
| 47 | +done |
| 48 | + |
| 49 | +# Validate |
| 50 | +if [[ -z "$PORT" ]]; then |
| 51 | + echo "ERROR: --port is required" |
| 52 | + usage |
| 53 | +fi |
| 54 | +if [[ -z "$IMAGE" ]]; then |
| 55 | + echo "ERROR: --image is required" |
| 56 | + usage |
| 57 | +fi |
| 58 | +if [[ ! -f "$IMAGE" ]]; then |
| 59 | + echo "ERROR: Image file not found: $IMAGE" |
| 60 | + exit 1 |
| 61 | +fi |
| 62 | + |
| 63 | +echo "============================================================" |
| 64 | +echo " MCUboot DFU Update" |
| 65 | +echo "============================================================" |
| 66 | +echo " Port: $PORT" |
| 67 | +echo " Image: $IMAGE" |
| 68 | +echo " Wait: ${WAIT}s" |
| 69 | +echo "============================================================" |
| 70 | +echo |
| 71 | + |
| 72 | +# Step 1: Print current image info |
| 73 | +echo ">>> Step 1: Current image info" |
| 74 | +python3 "$MCUBOOT_MGR" -p "$PORT" info |
| 75 | +echo |
| 76 | + |
| 77 | +# Step 2: Upload image (mark for test swap) |
| 78 | +echo ">>> Step 2: Upload image" |
| 79 | +python3 "$MCUBOOT_MGR" -p "$PORT" upload "$IMAGE" --test |
| 80 | +echo |
| 81 | + |
| 82 | +# Step 3: Reset device |
| 83 | +echo ">>> Step 3: Reset device" |
| 84 | +python3 "$MCUBOOT_MGR" -p "$PORT" reset |
| 85 | +echo "Waiting ${WAIT}s for device to boot..." |
| 86 | +sleep "$WAIT" |
| 87 | +echo |
| 88 | + |
| 89 | +# Step 4: Confirm running image |
| 90 | +echo ">>> Step 4: Confirm running image" |
| 91 | +python3 "$MCUBOOT_MGR" -p "$PORT" confirm --slot 0 |
| 92 | +echo |
| 93 | + |
| 94 | +# Step 5: Print image info after update |
| 95 | +echo ">>> Step 5: Image info after update" |
| 96 | +python3 "$MCUBOOT_MGR" -p "$PORT" info |
| 97 | +echo |
| 98 | + |
| 99 | +echo "============================================================" |
| 100 | +echo " DFU update complete" |
| 101 | +echo "============================================================" |
0 commit comments