Files
2026-03-17 08:22:00 +01:00

139 lines
3.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Build script for ESP32 Android Auto Navigation Head Unit
# Uses Podman container with ESP-IDF Rust toolchain
set -e # Exit on error
BINARY_NAME="esp32-android-auto-nav"
# Parse arguments
BUILD_ONLY=false
NAV_ONLY=false
CROP_VIDEO=false
CARGO_FEATURES=""
for arg in "$@"; do
case $arg in
-b|--build-only|--no-flash)
BUILD_ONLY=true
shift
;;
-n|--nav-only)
NAV_ONLY=true
shift
;;
-c|--crop)
CROP_VIDEO=true
shift
;;
-h|--help)
echo "Usage: ./build.sh [OPTIONS]"
echo "Options:"
echo " -b, --build-only, --no-flash Build only, skip flashing prompt"
echo " -n, --nav-only Nav-only mode: text turn-by-turn, no video"
echo " -c, --crop Crop mode: center-crop 480×320 from 800×480 (faster)"
echo " -h, --help Show this help message"
exit 0
;;
esac
done
# Build feature list
FEATURE_LIST=""
if [ "$NAV_ONLY" = true ]; then
FEATURE_LIST="nav-only"
echo "📍 Mode: NAV-ONLY (turn-by-turn text, no H.264 video)"
elif [ "$CROP_VIDEO" = true ]; then
FEATURE_LIST="crop-video"
echo "🎬 Mode: CROP VIDEO (center 480×320 from 800×480, no scaling)"
else
echo "🎬 Mode: FULL VIDEO (H.264 decode + downscale + display)"
fi
if [ -n "$FEATURE_LIST" ]; then
CARGO_FEATURES="--features $FEATURE_LIST"
fi
echo "🔨 Building $BINARY_NAME (release)..."
echo ""
sudo podman run --rm \
--security-opt seccomp=unconfined \
--net=host \
--security-opt label=disable \
--user root \
-v $(pwd):/project \
-w /project \
docker.io/espressif/idf-rust:all_latest \
bash -c "export RUSTUP_HOME=/home/esp/.rustup && export CARGO_HOME=/home/esp/.cargo && source /home/esp/export-esp.sh && cargo build --release $CARGO_FEATURES"
echo ""
echo "✅ Build complete!"
echo "📦 Binary: target/xtensa-esp32s3-espidf/release/$BINARY_NAME"
echo ""
if [ "$BUILD_ONLY" = true ]; then
echo "✅ Build complete (skipping flash prompt)."
echo ""
echo "To flash later:"
echo " cargo espflash flash target/xtensa-esp32s3-espidf/release/$BINARY_NAME --monitor"
exit 0
fi
# Ask if user wants to flash
read -p "⚡ Flash to device now? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Detect USB serial device
USB_DEVICE=""
if [ -e /dev/ttyUSB0 ]; then
USB_DEVICE="/dev/ttyUSB0"
elif [ -e /dev/ttyACM0 ]; then
USB_DEVICE="/dev/ttyACM0"
else
echo "🔍 No USB device auto-detected."
read -p "Enter device path (e.g., /dev/ttyUSB0): " USB_DEVICE
fi
if [ -z "$USB_DEVICE" ] || [ ! -e "$USB_DEVICE" ]; then
echo "❌ Device $USB_DEVICE not found. Skipping flash."
exit 1
fi
# Fix USB device permissions
echo "🔧 Setting device permissions..."
sudo chmod 666 "$USB_DEVICE"
echo "📡 Flashing to $USB_DEVICE..."
echo ""
sudo podman run --rm \
--security-opt seccomp=unconfined \
--security-opt label=disable \
--user root \
--privileged \
--device="$USB_DEVICE:$USB_DEVICE" \
-v $(pwd):/project \
-w /project \
docker.io/espressif/idf-rust:all_latest \
bash -c "export RUSTUP_HOME=/home/esp/.rustup && export CARGO_HOME=/home/esp/.cargo && source /home/esp/export-esp.sh && espflash flash --port $USB_DEVICE target/xtensa-esp32s3-espidf/release/$BINARY_NAME"
echo ""
echo "✅ Flash complete!"
echo ""
echo "📺 To view serial output:"
echo " screen $USB_DEVICE 115200"
echo " (Press Ctrl+A then K to exit)"
echo ""
echo "Or install espflash on host:"
echo " cargo install espflash"
echo " espflash monitor --port $USB_DEVICE"
echo ""
echo "✅ Flash complete!"
else
echo ""
echo "To flash later:"
echo " cargo espflash flash target/xtensa-esp32s3-espidf/release/$BINARY_NAME --monitor"
fi