#!/bin/bash
source ./lib.sh
# Get esptool command
BUILD_TOOL=$(lib_get_esptool_command)
# BUILD_TOOLの文字列の長さが20以上の場合は、終了する
if [ ${#BUILD_TOOL} -ge 20 ]; then
echo "==="
echo "Please execute the script again."
echo "==="
exit 1
fi
# Find port - Cross-platform detection
PORT=$(lib_detect_esptool_port)
# Check if PORT is set, otherwise prompt user
if [ -z "$PORT" ]; then
lib_no_esp_device_message_and_exit
fi
echo "Using port: $PORT"
# Define the paths to the firmware files
BUILD_PATH="FactoryTest/build/esp32.esp32.m5stack_stickc_plus2"
BOOTLOADER_PATH="$BUILD_PATH/FactoryTest.ino.bootloader.bin"
PARTITIONS_PATH="$BUILD_PATH/FactoryTest.ino.partitions.bin"
FIRMWARE_PATH="$BUILD_PATH/FactoryTest.ino.bin"
# Check if all required files exist
if [ ! -f "$BOOTLOADER_PATH" ]; then
echo "Bootloader file not found at $BOOTLOADER_PATH"
exit 1
fi
if [ ! -f "$PARTITIONS_PATH" ]; then
echo "Partitions file not found at $PARTITIONS_PATH"
exit 1
fi
if [ ! -f "$FIRMWARE_PATH" ]; then
echo "Firmware file not found at $FIRMWARE_PATH"
exit 1
fi
echo "Flashing complete ESP32 firmware..."
echo "Bootloader: $BOOTLOADER_PATH"
echo "Partitions: $PARTITIONS_PATH"
echo "Main firmware: $FIRMWARE_PATH"
# Upload the complete firmware using esptool.py
$BUILD_TOOL --chip esp32 --port "$PORT" --baud 460800 write_flash -z \
0x1000 "$BOOTLOADER_PATH" \
0x8000 "$PARTITIONS_PATH" \
0x10000 "$FIRMWARE_PATH"
echo "Flashing completed."