#!/bin/bash
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
source ./lib.sh
# Get esptool command
BUILD_TOOL=$(lib_get_esptool_command)
# Find port - Cross-platform detection
PORT=$(lib_detect_esptool_port)
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="."
BOOTLOADER_PATH="$BUILD_PATH/byhash.bootloader.bin"
PARTITIONS_PATH="$BUILD_PATH/byhash.partitions.bin"
FIRMWARE_PATH="$BUILD_PATH/byhash.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."