#!/bin/bash
source ./lib.sh
if [ -z "$1" ]; then
echo "Usage: $0 <hash>"
read -p "Enter the hash: " hash
if [ -z "$hash" ]; then
echo "No hash entered."
exit 1
fi
else
hash=$1
fi
# ダウンロードURL
URL="https://lattr.istlab.info/inobin/dl/${hash}"
RESPONCE_CODE=$(curl -s -o byhash.bin -w "%{http_code}" $URL)
if [ $RESPONCE_CODE -ne 200 ]; then
echo "Error: $RESPONCE_CODE"
exit 1
fi
curl -o byhash.partitions.bin -s ${URL}/partitions
curl -o byhash.bootloader.bin -s ${URL}/bootloader
echo "Downloaded ${hash} as [byhash.bin], [byhash.partitions.bin], [byhash.bootloader.bin]"
# もし、hashがp1ではじまっていたら、注意喚起する
if [[ $hash =~ ^p1 ]]; then
echo "注:Plus2(黄色)ではなく、Plus(オレンジ色)用のプログラムです。"
board="plus"
else
board="plus2"
fi
# 書き込みを行う
# Get esptool command
BUILD_TOOL=$(lib_get_esptool_command)
# BUILD_TOOLの文字列の長さが20以上の場合は、終了する
if [ ${#BUILD_TOOL} -ge 20 ]; then
echo $BUILD_TOOL
echo "==="
echo "Please execute the script again."
echo "(上記のメッセージを確認したあと) もう一度実行してください。"
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"
# Check if all required files exist
if [ ! -f "byhash.bootloader.bin" ]; then
echo "Bootloader file not found: byhash.bootloader.bin"
exit 1
fi
if [ ! -f "byhash.partitions.bin" ]; then
echo "Partitions file not found: byhash.partitions.bin"
exit 1
fi
if [ ! -f "byhash.bin" ]; then
echo "Firmware file not found: byhash.bin"
exit 1
fi
echo "Flashing ESP32 firmware using esptool..."
echo "Bootloader: byhash.bootloader.bin"
echo "Partitions: byhash.partitions.bin"
echo "Main firmware: byhash.bin"
# Upload the firmware using esptool.py
$BUILD_TOOL --chip esp32 --port "$PORT" --baud 460800 write-flash -z \
0x1000 "byhash.bootloader.bin" \
0x8000 "byhash.partitions.bin" \
0x10000 "byhash.bin"
echo "Flashing completed."
# シリアルモニタを開くか確認
read -p "シリアルモニタを開きますか?(y/n): " yn
if [ $yn = "y" ]; then
echo "終了するときはCtrl+Cを押してください。"
arduino-cli monitor -p "$PORT" --config 115200
fi