Skip to content

feat(esptool): Upgrade to esptool v5 #11487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions .github/scripts/package_esptool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash

set -euo pipefail

# Check version argument
if [[ $# -ne 3 ]]; then
echo "Usage: $0 <version> <base_folder> <json_path>"
echo "Example: $0 5.0.dev1 /tmp/esptool /tmp/esptool-5.0.dev1.json"
exit 1
fi

VERSION=$1
BASE_FOLDER=$2
JSON_PATH=$3

export COPYFILE_DISABLE=1

shopt -s nullglob # So for loop doesn't run if no matches

# Function to update JSON for a given host
function update_json_for_host {
local host=$1
local archive=$2

# Extract the old url from the JSON for this host, then replace only the filename
old_url=$(jq -r --arg host "$host" '
.packages[].tools[] | select(.name == "esptool_py") | .systems[] | select(.host == $host) | .url // empty
' "$tmp_json")
if [[ -n "$old_url" ]]; then
base_url="${old_url%/*}"
url="$base_url/$archive"
else
echo "No old url found for $host"
exit 1
fi

archiveFileName="$archive"
checksum="SHA-256:$(shasum -a 256 "$archive" | awk '{print $1}')"
size=$(stat -f%z "$archive")

# Use jq to update the JSON
jq --arg host "$host" \
--arg url "$url" \
--arg archiveFileName "$archiveFileName" \
--arg checksum "$checksum" \
--arg size "$size" \
'
.packages[].tools[]
|= if .name == "esptool_py" then
.systems = (
((.systems // []) | map(select(.host != $host))) + [{
host: $host,
url: $url,
archiveFileName: $archiveFileName,
checksum: $checksum,
size: $size
}]
)
else
.
end
' "$tmp_json" > "$tmp_json.new" && mv "$tmp_json.new" "$tmp_json"
}

cd "$BASE_FOLDER"

# Delete all archives before starting
rm -f esptool-*.tar.gz esptool-*.zip

for dir in esptool-*; do
# Check if directory exists and is a directory
if [[ ! -d "$dir" ]]; then
continue
fi

base="${dir#esptool-}"

# Add 'linux-' prefix if base doesn't contain linux/macos/win64
if [[ "$base" != *linux* && "$base" != *macos* && "$base" != *win64* ]]; then
base="linux-${base}"
fi

if [[ "$dir" == esptool-win* ]]; then
# Windows zip archive
zipfile="esptool-v${VERSION}-${base}.zip"
echo "Creating $zipfile from $dir ..."
zip -r "$zipfile" "$dir"
else
# Non-Windows: set permissions and tar.gz archive
tarfile="esptool-v${VERSION}-${base}.tar.gz"
echo "Setting permissions and creating $tarfile from $dir ..."
chmod -R u=rwx,g=rx,o=rx "$dir"
tar -cvzf "$tarfile" "$dir"
fi
done

# After the for loop, update the JSON for each archive
# Create a temporary JSON file to accumulate changes
tmp_json="${JSON_PATH}.tmp"
cp "$JSON_PATH" "$tmp_json"

for archive in esptool-v"${VERSION}"-*.tar.gz esptool-v"${VERSION}"-*.zip; do
[ -f "$archive" ] || continue

echo "Updating JSON for $archive"

# Determine host from archive name
case "$archive" in
*linux-amd64*) host="x86_64-pc-linux-gnu" ;;
*linux-armv7*) host="arm-linux-gnueabihf" ;;
*linux-aarch64*) host="aarch64-linux-gnu" ;;
*macos-amd64*) host="x86_64-apple-darwin" ;;
*macos-arm64*) host="arm64-apple-darwin" ;;
*win64*) hosts=("x86_64-mingw32" "i686-mingw32") ;;
*) echo "Unknown host for $archive"; continue ;;
esac

# For win64, loop over both hosts; otherwise, use a single host
if [[ "$archive" == *win64* ]]; then
for host in "${hosts[@]}"; do
update_json_for_host "$host" "$archive"
done
else
update_json_for_host "$host" "$archive"
fi
done

# After all archives are processed, move the temporary JSON to the final file
mv "$tmp_json" "$JSON_PATH"
70 changes: 35 additions & 35 deletions package/package_esp32_index.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
{
"packager": "esp32",
"name": "esptool_py",
"version": "4.9.dev3"
"version": "5.0.dev1"
},
{
"packager": "esp32",
Expand Down Expand Up @@ -469,56 +469,56 @@
},
{
"name": "esptool_py",
"version": "4.9.dev3",
"version": "5.0.dev1",
"systems": [
{
"host": "x86_64-pc-linux-gnu",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-linux-amd64.tar.gz",
"archiveFileName": "esptool-v4.9.dev3-linux-amd64.tar.gz",
"checksum": "SHA-256:4ecaf51836cbf4ea3c19840018bfef3b0b8cd8fc3c95f6e1e043ca5bbeab9bf0",
"size": "64958202"
"host": "aarch64-linux-gnu",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-linux-aarch64.tar.gz",
"archiveFileName": "esptool-v5.0.dev1-linux-aarch64.tar.gz",
"checksum": "SHA-256:bfafa7a7723ebbabfd8b6e3ca5ae00bfead0331de923754aeddb43b2c116a078",
"size": "58241736"
},
{
"host": "arm-linux-gnueabihf",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-linux-armv7.tar.gz",
"archiveFileName": "esptool-v4.9.dev3-linux-armv7.tar.gz",
"checksum": "SHA-256:fff818573bce483ee793ac83c8211f6abf764aa3350f198228859f696a0a0b36",
"size": "31530030"
"host": "x86_64-pc-linux-gnu",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-linux-amd64.tar.gz",
"archiveFileName": "esptool-v5.0.dev1-linux-amd64.tar.gz",
"checksum": "SHA-256:acd0486e96586b99d053a1479acbbbfcae8667227c831cdc53a171f9ccfa27ee",
"size": "100740042"
},
{
"host": "aarch64-linux-gnu",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-linux-aarch64.tar.gz",
"archiveFileName": "esptool-v4.9.dev3-linux-aarch64.tar.gz",
"checksum": "SHA-256:5b274bdff2f62e6a07c3c1dfa51b1128924621f661747eca3dbe0f77972f2f06",
"size": "33663882"
"host": "arm-linux-gnueabihf",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-linux-armv7.tar.gz",
"archiveFileName": "esptool-v5.0.dev1-linux-armv7.tar.gz",
"checksum": "SHA-256:ea77a38681506761bbb7b0b39c130811ed565667b67ebbdb4d6dcc6cb6e07368",
"size": "53451939"
},
{
"host": "x86_64-apple-darwin",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-macos-amd64.tar.gz",
"archiveFileName": "esptool-v4.9.dev3-macos-amd64.tar.gz",
"checksum": "SHA-256:c733c83b58fcf5f642fbb2fddb8ff24640c2c785126cba0821fb70c4a5ceea7a",
"size": "32767836"
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-macos-amd64.tar.gz",
"archiveFileName": "esptool-v5.0.dev1-macos-amd64.tar.gz",
"checksum": "SHA-256:900a8e90731208bee96647e0e207a43612b9452c2120c4fdc0ff4c6be226257b",
"size": "59631998"
},
{
"host": "arm64-apple-darwin",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-macos-arm64.tar.gz",
"archiveFileName": "esptool-v4.9.dev3-macos-arm64.tar.gz",
"checksum": "SHA-256:83c195a15981e6a5e7a130db2ccfb21e2d8093912e5b003681f9a5abadd71af7",
"size": "30121441"
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-macos-arm64.tar.gz",
"archiveFileName": "esptool-v5.0.dev1-macos-arm64.tar.gz",
"checksum": "SHA-256:3653f4de73cb4fc6a25351eaf663708e91c65ae3265d75bd54ca4315a4350bb4",
"size": "56349992"
},
{
"host": "i686-mingw32",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-win64.zip",
"archiveFileName": "esptool-v4.9.dev3-win64.zip",
"checksum": "SHA-256:890051a4fdc684ff6f4af18d0bb27d274ca940ee0eef716a9455f8c64b25b215",
"size": "36072564"
"host": "x86_64-mingw32",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-win64.zip",
"archiveFileName": "esptool-v5.0.dev1-win64.zip",
"checksum": "SHA-256:1e8fd89645daf94f2d4406ec73c9004e617ea921079515f9fd749205eece4d6d",
"size": "59102658"
},
{
"host": "x86_64-mingw32",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-win64.zip",
"archiveFileName": "esptool-v4.9.dev3-win64.zip",
"checksum": "SHA-256:890051a4fdc684ff6f4af18d0bb27d274ca940ee0eef716a9455f8c64b25b215",
"size": "36072564"
"host": "i686-mingw32",
"url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-win64.zip",
"archiveFileName": "esptool-v5.0.dev1-win64.zip",
"checksum": "SHA-256:1e8fd89645daf94f2d4406ec73c9004e617ea921079515f9fd749205eece4d6d",
"size": "59102658"
}
]
},
Expand Down
12 changes: 6 additions & 6 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ recipe.hooks.prebuild.2.pattern.windows=cmd /c if not exist "{build.path}\partit
recipe.hooks.prebuild.3.pattern.windows=cmd /c if not exist "{build.path}\partitions.csv" COPY "{runtime.platform.path}\tools\partitions\{build.partitions}.csv" "{build.path}\partitions.csv"

# Check if custom bootloader exist: source > variant > build.boot
recipe.hooks.prebuild.4.pattern_args=--chip {build.mcu} elf2image --flash_mode {build.flash_mode} --flash_freq {build.img_freq} --flash_size {build.flash_size} -o
recipe.hooks.prebuild.4.pattern_args=--chip {build.mcu} elf2image --flash-mode {build.flash_mode} --flash-freq {build.img_freq} --flash-size {build.flash_size} -o
recipe.hooks.prebuild.4.pattern=/usr/bin/env bash -c "[ -f "{build.source.path}"/bootloader.bin ] && cp -f "{build.source.path}"/bootloader.bin "{build.path}"/{build.project_name}.bootloader.bin || ( [ -f "{build.variant.path}"/{build.custom_bootloader}.bin ] && cp "{build.variant.path}"/{build.custom_bootloader}.bin "{build.path}"/{build.project_name}.bootloader.bin || "{tools.esptool_py.path}"/{tools.esptool_py.cmd} {recipe.hooks.prebuild.4.pattern_args} "{build.path}"/{build.project_name}.bootloader.bin "{compiler.sdk.path}"/bin/bootloader_{build.boot}_{build.boot_freq}.elf )"
recipe.hooks.prebuild.4.pattern.windows=cmd /c IF EXIST "{build.source.path}\bootloader.bin" ( COPY /y "{build.source.path}\bootloader.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( IF EXIST "{build.variant.path}\{build.custom_bootloader}.bin" ( COPY "{build.variant.path}\{build.custom_bootloader}.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( "{tools.esptool_py.path}\{tools.esptool_py.cmd}" {recipe.hooks.prebuild.4.pattern_args} "{build.path}\{build.project_name}.bootloader.bin" "{compiler.sdk.path}\bin\bootloader_{build.boot}_{build.boot_freq}.elf" ) )

Expand Down Expand Up @@ -163,7 +163,7 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.f
recipe.objcopy.partitions.bin.pattern={tools.gen_esp32part.cmd} -q "{build.path}/partitions.csv" "{build.path}/{build.project_name}.partitions.bin"

## Create bin
recipe.objcopy.bin.pattern_args=--chip {build.mcu} elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.img_freq}" --flash_size "{build.flash_size}" --elf-sha256-offset 0xb0 -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"
recipe.objcopy.bin.pattern_args=--chip {build.mcu} elf2image --flash-mode "{build.flash_mode}" --flash-freq "{build.img_freq}" --flash-size "{build.flash_size}" --elf-sha256-offset 0xb0 -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"
recipe.objcopy.bin.pattern="{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.objcopy.bin.pattern_args}

## Create Insights Firmware Package
Expand All @@ -176,7 +176,7 @@ recipe.hooks.objcopy.postobjcopy.2.pattern=/usr/bin/env bash -c "[ ! -d "{build.
recipe.hooks.objcopy.postobjcopy.2.pattern.windows=cmd /c if exist "{build.path}\libraries\ESP_SR" if exist "{compiler.sdk.path}\esp_sr\srmodels.bin" COPY /y "{compiler.sdk.path}\esp_sr\srmodels.bin" "{build.path}\srmodels.bin"

# Create merged binary
recipe.hooks.objcopy.postobjcopy.3.pattern_args=--chip {build.mcu} merge_bin -o "{build.path}/{build.project_name}.merged.bin" --fill-flash-size {build.flash_size} --flash_mode keep --flash_freq keep --flash_size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin"
recipe.hooks.objcopy.postobjcopy.3.pattern_args=--chip {build.mcu} merge-bin -o "{build.path}/{build.project_name}.merged.bin" --pad-to-size {build.flash_size} --flash-mode keep --flash-freq keep --flash-size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin"
recipe.hooks.objcopy.postobjcopy.3.pattern="{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.hooks.objcopy.postobjcopy.3.pattern_args}

## Save bin
Expand Down Expand Up @@ -285,22 +285,22 @@ debug.additional_config=debug_config.{build.mcu}
tools.esptool_py.upload.protocol=serial
tools.esptool_py.upload.params.verbose=
tools.esptool_py.upload.params.quiet=
tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash {upload.erase_cmd} -z --flash_mode keep --flash_freq keep --flash_size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" {upload.extra_flags}
tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default-reset --after hard-reset write-flash {upload.erase_cmd} -z --flash-mode keep --flash-freq keep --flash-size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" {upload.extra_flags}
tools.esptool_py.upload.pattern="{path}/{cmd}" {upload.pattern_args}

## Program Application
## -------------------
tools.esptool_py.program.params.verbose=
tools.esptool_py.program.params.quiet=
tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash -z --flash_mode keep --flash_freq keep --flash_size keep 0x10000 "{build.path}/{build.project_name}.bin"
tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default-reset --after hard-reset write-flash -z --flash-mode keep --flash-freq keep --flash-size keep 0x10000 "{build.path}/{build.project_name}.bin"
tools.esptool_py.program.pattern="{path}/{cmd}" {program.pattern_args}

## Erase Chip (before burning the bootloader)
## ------------------------------------------
tools.esptool_py.erase.protocol=serial
tools.esptool_py.erase.params.verbose=
tools.esptool_py.erase.params.quiet=
tools.esptool_py.erase.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset erase_flash
tools.esptool_py.erase.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default-reset --after hard-reset erase-flash
tools.esptool_py.erase.pattern="{path}/{cmd}" {erase.pattern_args}

## Burn Bootloader
Expand Down
Loading