diff --git a/m5latest.sh b/m5latest.sh index 8424835..1c0db5f 100755 --- a/m5latest.sh +++ b/m5latest.sh @@ -1,5 +1,7 @@ #!/bin/bash +source ./lib.sh + if [ "$1" == "-h" ] || [ "$1" == "help" ] || [ "$1" == "h" ] ; then echo "Usage: m5latest.sh [y] [y/n]" echo " 第一引数の y : ビルド完了まで待ち、ダウンロード後に自動で書込みを行います。" @@ -90,37 +92,69 @@ curl -o latest.partitions.bin -s -X POST -d "uid=${MYUID}&login=${LOGIN}&type=partitions" ${URL} curl -o latest.bootloader.bin -s -X POST -d "uid=${MYUID}&login=${LOGIN}&type=bootloader" ${URL} # 書き込みを行う - serials=`arduino-cli board list | grep USB | awk '{print $1}'` - seriallist=($serials) if [ "$1" == "y" ]; then yn='y' else read -p "書き込みを行いますか?(y/n): " yn fi if [ $yn = "y" ]; then - if [ -z "${serials}" ]; then - echo "デバイスがみつかりませんでした。" - sleep 2 - echo "デバイスを接続しているのに認識しないときは、ドライバを入れてください。" - sleep 2 - echo "https://ftdichip.com/drivers/vcp-drivers/ → Click here to download の hereをおす。ZIP解凍して実行。" - exit + # 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 - for ser in ${seriallist[@]} ; do - echo ${ser} - arduino-cli upload --fqbn esp32:esp32:m5stack_stickc_${board} -p ${ser} --input-file latest.bin - done + + # 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 "latest.bootloader.bin" ]; then + echo "Bootloader file not found: latest.bootloader.bin" + exit 1 + fi + if [ ! -f "latest.partitions.bin" ]; then + echo "Partitions file not found: latest.partitions.bin" + exit 1 + fi + if [ ! -f "latest.bin" ]; then + echo "Firmware file not found: latest.bin" + exit 1 + fi + + echo "Flashing ESP32 firmware using esptool..." + echo "Bootloader: latest.bootloader.bin" + echo "Partitions: latest.partitions.bin" + echo "Main firmware: latest.bin" + + # Upload the firmware using esptool.py + $BUILD_TOOL --chip esp32 --port "$PORT" --baud 460800 write-flash -z \ + 0x1000 "latest.bootloader.bin" \ + 0x8000 "latest.partitions.bin" \ + 0x10000 "latest.bin" + + echo "Flashing completed." fi - # 接続デバイスが1つのみの場合、シリアルモニタを開くか確認 - if [[ "${#seriallist[@]}" -eq 1 ]]; then - if [ -z "$2" ]; then - read -p "シリアルモニタを開きますか?(y/n): " yn - else - yn=$2 - fi - if [ $yn = "y" ]; then - echo "終了するときはCtrl+Cを押してください。" - arduino-cli monitor -p ${seriallist[0]} --config 115200 - fi + # シリアルモニタを開くか確認 + if [ -z "$2" ]; then + read -p "シリアルモニタを開きますか?(y/n): " yn + else + yn=$2 + fi + if [ $yn = "y" ]; then + echo "終了するときはCtrl+Cを押してください。" + arduino-cli monitor -p "$PORT" --config 115200 fi fi diff --git a/upload_by_hash.sh b/upload_by_hash.sh index fdb38d9..5eb771f 100755 --- a/upload_by_hash.sh +++ b/upload_by_hash.sh @@ -1,5 +1,7 @@ #!/bin/bash +source ./lib.sh + if [ -z "$1" ]; then echo "Usage: $0 " @@ -34,30 +36,60 @@ fi # 書き込みを行う -serials=`arduino-cli board list | grep USB | awk '{print $1}'` -seriallist=($serials) - -if [ -z "${serials}" ]; then - echo "デバイスがみつかりませんでした。" - sleep 2 - echo "デバイスを接続しているのに認識しないときは、ドライバを入れてください。" - sleep 2 - echo "https://ftdichip.com/drivers/vcp-drivers/ → Click here to download - の hereをおす。ZIP解凍して実行。" - exit +# 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 -for ser in ${seriallist[@]} ; do - echo ${ser} - arduino-cli upload --fqbn esp32:esp32:m5stack_stickc_${board} -p ${ser} --input-file byhash.bin -done -# 接続デバイスが1つのみの場合、シリアルモニタを開くか確認 -if [[ "${#seriallist[@]}" -eq 1 ]]; then - read -p "シリアルモニタを開きますか?(y/n): " yn - if [ $yn = "y" ]; then - echo "終了するときはCtrl+Cを押してください。" - arduino-cli monitor -p ${seriallist[0]} --config 115200 - 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