Skip to content

Commit 3af0b44

Browse files
authored
Update PlatformIO build script (#7579)
This PR brings updates according to the latest changes in the Arduino core: - Bootloader binaries are now generated from elf files - Updated CI scripts - Updated esptoolpy to v4.2.1 - Minor clean-up by removing obsolete code Resolves #7572
1 parent 7c09346 commit 3af0b44

File tree

3 files changed

+37
-84
lines changed

3 files changed

+37
-84
lines changed

Diff for: .github/scripts/install-platformio-esp32.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespres
44
PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git"
55

66
TOOLCHAIN_VERSION="8.4.0+2021r2-patch3"
7-
ESPTOOLPY_VERSION="~1.30100.0"
7+
ESPTOOLPY_VERSION="~1.40201.0"
88
ESPRESSIF_ORGANIZATION_NAME="espressif"
99

1010
echo "Installing Python Wheel ..."

Diff for: .github/scripts/on-push.sh

+5-20
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,11 @@ else
9393
build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
9494
build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"
9595

96-
# PlatformIO ESP32 Test
97-
# OPTIONS="board_build.mcu = esp32s2"
98-
# build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
99-
# build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino"
100-
101-
python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32s2" --project-option="board_build.partitions = huge_app.csv"
102-
python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32c3" --project-option="board_build.partitions = huge_app.csv"
103-
104-
echo "Hacking in S3 support ..."
105-
replace_script="import json; import os;"
106-
replace_script+="fp=open(os.path.expanduser('~/.platformio/platforms/espressif32/platform.json'), 'r+');"
107-
replace_script+="data=json.load(fp);"
108-
replace_script+="data['packages']['toolchain-xtensa-esp32']['optional']=True;"
109-
replace_script+="data['packages']['toolchain-xtensa-esp32s3']['optional']=False;"
110-
replace_script+="data['packages']['tool-esptoolpy']['owner']='tasmota';"
111-
replace_script+="data['packages']['tool-esptoolpy']['version']='https://github.com/tasmota/esptool/releases/download/v4.2.1/esptool-4.2.1.zip';"
112-
replace_script+="fp.seek(0);fp.truncate();json.dump(data, fp, indent=2);fp.close()"
113-
python -c "$replace_script"
114-
115-
python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32s3" --project-option="board_build.partitions = huge_app.csv"
96+
# Basic sanity testing for other series
97+
for board in "esp32-c3-devkitm-1" "esp32-s2-saola-1" "esp32-s3-devkitc-1"
98+
do
99+
python -m platformio ci --board "$board" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.partitions = huge_app.csv"
100+
done
116101

117102
#build_pio_sketches "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries"
118103
fi

Diff for: tools/platformio-build.py

+31-63
Original file line numberDiff line numberDiff line change
@@ -82,52 +82,41 @@ def get_bootloader_image(variants_dir):
8282
return (
8383
variant_bootloader
8484
if isfile(variant_bootloader)
85-
else join(
86-
FRAMEWORK_DIR,
87-
"tools",
88-
"sdk",
89-
build_mcu,
90-
"bin",
91-
"bootloader_${__get_board_boot_mode(__env__)}_${__get_board_f_flash(__env__)}.bin",
85+
else generate_bootloader_image(
86+
join(
87+
FRAMEWORK_DIR,
88+
"tools",
89+
"sdk",
90+
build_mcu,
91+
"bin",
92+
"bootloader_${__get_board_boot_mode(__env__)}_${__get_board_f_flash(__env__)}.elf",
93+
)
9294
)
9395
)
9496

9597

96-
def get_patched_bootloader_image(original_bootloader_image, bootloader_offset):
97-
patched_bootloader_image = join(env.subst("$BUILD_DIR"), "patched_bootloader.bin")
98+
def generate_bootloader_image(bootloader_elf):
9899
bootloader_cmd = env.Command(
99-
patched_bootloader_image,
100-
original_bootloader_image,
101-
env.VerboseAction(
102-
" ".join(
103-
[
104-
'"$PYTHONEXE"',
105-
join(
106-
platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"
107-
),
108-
"--chip",
109-
build_mcu,
110-
"merge_bin",
111-
"-o",
112-
"$TARGET",
113-
"--flash_mode",
114-
"${__get_board_flash_mode(__env__)}",
115-
"--flash_freq",
116-
"${__get_board_f_flash(__env__)}",
117-
"--flash_size",
118-
board_config.get("upload.flash_size", "4MB"),
119-
"--target-offset",
120-
bootloader_offset,
121-
bootloader_offset,
122-
"$SOURCE",
123-
]
124-
),
125-
"Updating bootloader headers",
126-
),
100+
join("$BUILD_DIR", "bootloader.bin"),
101+
bootloader_elf,
102+
env.VerboseAction(" ".join([
103+
'"$PYTHONEXE" "$OBJCOPY"',
104+
"--chip", build_mcu, "elf2image",
105+
"--flash_mode", "${__get_board_flash_mode(__env__)}",
106+
"--flash_freq", "${__get_board_f_flash(__env__)}",
107+
"--flash_size", board_config.get("upload.flash_size", "4MB"),
108+
"-o", "$TARGET", "$SOURCES"
109+
]), "Building $TARGET"),
127110
)
111+
128112
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", bootloader_cmd)
129113

130-
return patched_bootloader_image
114+
# Because the Command always returns a NodeList, we have to
115+
# access the first element in the list to get the Node object
116+
# that actually represents the bootloader image.
117+
# Also, this file is later used in generic Python code, so the
118+
# Node object in converted to a generic string
119+
return str(bootloader_cmd[0])
131120

132121

133122
def add_tinyuf2_extra_image():
@@ -210,34 +199,13 @@ def add_tinyuf2_extra_image():
210199
# Process framework extra images
211200
#
212201

213-
# Starting with v2.0.4 the Arduino core contains updated bootloader images that have
214-
# innacurate default headers. This results in bootloops if firmware is flashed via
215-
# OpenOCD (e.g. debugging or uploading via debug tools). For this reason, before
216-
# uploading or debugging we need to adjust the bootloader binary according to
217-
# the values of the --flash-size and --flash-mode arguments.
218-
# Note: This behavior doesn't occur if uploading is done via esptoolpy, as esptoolpy
219-
# overrides the binary image headers before flashing.
220-
221-
bootloader_patch_required = bool(
222-
env.get("PIOFRAMEWORK", []) == ["arduino"]
223-
and (
224-
"debug" in env.GetBuildType()
225-
or env.subst("$UPLOAD_PROTOCOL") in board_config.get("debug.tools", {})
226-
or env.IsIntegrationDump()
227-
)
228-
)
229-
230-
bootloader_image_path = get_bootloader_image(variants_dir)
231-
bootloader_offset = "0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000"
232-
if bootloader_patch_required:
233-
bootloader_image_path = get_patched_bootloader_image(
234-
bootloader_image_path, bootloader_offset
235-
)
236-
237202
env.Append(
238203
LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")],
239204
FLASH_EXTRA_IMAGES=[
240-
(bootloader_offset, bootloader_image_path),
205+
(
206+
"0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000",
207+
get_bootloader_image(variants_dir),
208+
),
241209
("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")),
242210
("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")),
243211
]

0 commit comments

Comments
 (0)