#!/usr/bin/env sh # Argument parsing instead of positional arguments while true; do case "$1" in '-b'|'--binary') binary=$2 shift 2 continue ;; '-s'|'--serial') serial=$2 shift 2 continue ;; '-f'|'--flasher-target') flasher_target=$2 shift 2 continue ;; '-t'|'--target') bin_target=$2 shift 2 continue ;; '-i'|'--flash-image') flash_image="--flash" shift 1 continue ;; '--') shift break ;; *) break ;; esac done if [[ -z $binary ]]; then binary=nop fi echo "Flashing '${binary}' example" if [[ -z $serial ]]; then serial=/dev/ttyUSB0 fi echo "Flashing using TTY device: '${serial}'" if [[ -z $flasher_target ]]; then flasher_target=$(rustc -vV | sed -n 's|host: ||p') fi echo "Using target-triple for 'flasher' tool: ${flasher_target}" if [[ -z $bin_target ]]; then bin_target=$(cat .cargo/config.toml | sed -n 's|target="\(.*\)"|\1|p') fi echo "Using target-triple for '${binary}' binary: ${bin_target}" if [[ -d ../build ]]; then rm -rf ../build fi pushd ../flasher cargo clean && cargo build --release --target ${flasher_target} mkdir -p ../build mv ../target/${flasher_target}/release/flasher ../build/bin-flasher popd cargo clean ../build/bin-flasher --serial ${serial} --target ${bin_target} ${flash_image}