Skip to content

Commit 3731e11

Browse files
dobairolandradimkarnis
authored andcommitted
change: Add ability to switch between two sets of flasher stubs
1 parent 6e8632d commit 3731e11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+403
-33000
lines changed

.github/workflows/build_esptool.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
pip install --user -e .
5757
- name: Build with PyInstaller
5858
run: |
59-
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=ci/espressif.ico --add-data="${{ env.STUBS_DIR }}*.json${{ matrix.SEPARATOR }}${{ env.STUBS_DIR }}" esptool.py
59+
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=ci/espressif.ico --add-data="${{ env.STUBS_DIR }}1/*.json${{ matrix.SEPARATOR }}${{ env.STUBS_DIR }}1/" --add-data="${{ env.STUBS_DIR }}2/*.json${{ matrix.SEPARATOR }}${{ env.STUBS_DIR }}2/" esptool.py
6060
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=ci/espressif.ico --add-data="${{ env.EFUSE_DIR }}*.yaml${{ matrix.SEPARATOR }}${{ env.EFUSE_DIR }}" espefuse.py
6161
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=ci/espressif.ico espsecure.py
6262
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=ci/espressif.ico esp_rfc2217_server.py

.github/workflows/test_esptool.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,21 @@ jobs:
4646
pytest -m host_test
4747
pytest test/test_espsecure_hsm.py
4848
49-
- name: Build stub (Python 3.7 only)
50-
if: matrix.python-version == 3.7
51-
run: |
52-
export TOOLCHAIN_DIR=$HOME/toolchain
53-
54-
export ESP8266_BINDIR=$TOOLCHAIN_DIR/xtensa-lx106-elf/bin
55-
export ESP32_BINDIR=$TOOLCHAIN_DIR/xtensa-esp32-elf/bin
56-
export ESP32S2_BINDIR=$TOOLCHAIN_DIR/xtensa-esp32s2-elf/bin
57-
export ESP32S3_BINDIR=$TOOLCHAIN_DIR/xtensa-esp32s3-elf/bin
58-
export ESP32C3_BINDIR=$TOOLCHAIN_DIR/riscv32-esp-elf/bin
49+
check_stubs:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@master
5954

60-
export PATH=$PATH:$ESP8266_BINDIR:$ESP32_BINDIR:$ESP32S2_BINDIR:$ESP32S3_BINDIR:$ESP32C3_BINDIR
55+
- name: Set up Python 3.12
56+
uses: actions/setup-python@master
57+
with:
58+
python-version: 3.12
6159

62-
./ci/setup_ci_build_env.sh
63-
make -C flasher_stub V=1
64-
cd flasher_stub && python ./compare_stubs.py
60+
- name: Check if flasher stubs are up-to-date
61+
run: |
62+
./ci/download_flasher_stubs.py
63+
git diff --exit-code
6564
6665
lint_esptool:
6766
runs-on: ubuntu-latest

.gitlab-ci.yml

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ cache:
3434
paths:
3535
- "$CI_PROJECT_DIR/.cache/pip"
3636

37-
.use_esp_flasher_stub: &use_esp_flasher_stub |
38-
if [[ "$CI_USE_ESP_FLASHER_STUB" = "1" ]]
39-
then
40-
apt-get update && apt-get install -y jq
41-
wget https://api.github.com/repos/esp-rs/esp-flasher-stub/releases/latest -O /tmp/esp_flasher_stub.json
42-
echo "esp-flasher-stub version:"; cat /tmp/esp_flasher_stub.json | jq -r .tag_name
43-
mkdir /tmp/assets
44-
cat /tmp/esp_flasher_stub.json | jq -r .assets[].browser_download_url | while read -r url; do wget $url -P /tmp/assets; done
45-
for f in /tmp/assets/*.json; do fname=$(basename $f); cp $f esptool/targets/stub_flasher/stub_flasher_${fname#esp}; done
46-
echo "These are the changes in the repository:"
47-
git diff --stat
48-
fi
49-
5037
.test_template: &test_template
5138
stage: test
5239
image: python:3.7-bullseye
@@ -73,7 +60,7 @@ version_check:
7360
.host_tests_template: &host_tests_template
7461
<<: *test_template
7562
rules:
76-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
63+
- if: $CI_PIPELINE_SOURCE != "schedule"
7764
artifacts:
7865
when: always
7966
paths:
@@ -170,7 +157,7 @@ run_pre_commit_hooks:
170157
stage: test
171158
image: python:3.7-bullseye
172159
rules:
173-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
160+
- if: $CI_PIPELINE_SOURCE != "schedule"
174161
tags:
175162
- host_test
176163
script:
@@ -192,7 +179,7 @@ run_pre_commit_hooks:
192179
check_install_coverage:
193180
<<: *test_template
194181
rules:
195-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
182+
- if: $CI_PIPELINE_SOURCE != "schedule"
196183
artifacts:
197184
when: always
198185
paths:
@@ -210,7 +197,7 @@ check_install_coverage:
210197
check_install:
211198
<<: *test_template
212199
rules:
213-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
200+
- if: $CI_PIPELINE_SOURCE != "schedule"
214201
before_script:
215202
- pip install .
216203
script:
@@ -220,7 +207,7 @@ check_install:
220207
check_install_editable:
221208
<<: *test_template
222209
rules:
223-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
210+
- if: $CI_PIPELINE_SOURCE != "schedule"
224211
before_script:
225212
- pip install -e .
226213
script:
@@ -230,7 +217,7 @@ check_install_editable:
230217
check_install_system:
231218
<<: *test_template
232219
rules:
233-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
220+
- if: $CI_PIPELINE_SOURCE != "schedule"
234221
before_script:
235222
- pip install --user .
236223
script:
@@ -245,41 +232,19 @@ check_install_system:
245232
check_install_venv:
246233
<<: *test_template
247234
rules:
248-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
235+
- if: $CI_PIPELINE_SOURCE != "schedule"
249236
before_script:
250237
- python -m venv test_env
251238
- source test_env/bin/activate
252239
- python -m pip install .
253240
script:
254241
- *run_esptool
255242

256-
# Check the stub can build and that a stub built in CI has the same contents
257-
# as the one embedded in esptool
258243
check_stub_build:
259244
<<: *test_template
260-
rules:
261-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
262-
artifacts:
263-
when: always
264-
paths:
265-
- flasher_stub/build/
266-
- "**/.coverage*"
267-
- ".coverage*"
268-
expire_in: 1 week
269-
variables:
270-
TOOLCHAIN_DIR: "/root/.espressif/dist"
271-
272-
ESP8266_BINDIR: "${TOOLCHAIN_DIR}/xtensa-lx106-elf/bin"
273-
ESP32_BINDIR: "${TOOLCHAIN_DIR}/xtensa-esp32-elf/bin"
274-
ESP32S2_BINDIR: "${TOOLCHAIN_DIR}/xtensa-esp32s2-elf/bin"
275-
ESP32S3_BINDIR: "${TOOLCHAIN_DIR}/xtensa-esp32s3-elf/bin"
276-
ESP32C3_BINDIR: "${TOOLCHAIN_DIR}/riscv32-esp-elf/bin"
277-
278-
TOOLCHAIN_PATHS: "${ESP8266_BINDIR}:${ESP32_BINDIR}:${ESP32S2_BINDIR}:${ESP32S3_BINDIR}:${ESP32C3_BINDIR}"
279245
script:
280-
- ./ci/setup_ci_build_env.sh
281-
- make -C flasher_stub V=1 PATH="${TOOLCHAIN_PATHS}:${PATH}"
282-
- cd flasher_stub && coverage run --parallel-mode ./compare_stubs.py
246+
- ./ci/download_flasher_stubs.py
247+
- git diff --exit-code
283248

284249
.target_esptool_test:
285250
stage: test
@@ -292,7 +257,6 @@ check_stub_build:
292257
- pip install -e .[dev] --prefer-binary
293258
# libffi (needed for espsecure) version keeps changing in python docker images. Add a symlink to the installed version on Raspberry Pi
294259
- if [ $(uname -m) = "armv7l" ]; then ln -sfn /usr/lib/arm-linux-gnueabihf/libffi.so.7.1.0 /usr/lib/arm-linux-gnueabihf/libffi.so.6; fi
295-
- *use_esp_flasher_stub
296260
artifacts:
297261
reports:
298262
junit: test/report.xml
@@ -460,7 +424,7 @@ target_esp32p4:
460424
PYTHONPATH: "$PYTHONPATH:${CI_PROJECT_DIR}/test"
461425
COVERAGE_PROCESS_START: "${CI_PROJECT_DIR}/test/.covconf"
462426
rules:
463-
- if: $CI_USE_ESP_FLASHER_STUB != "1"
427+
- if: $CI_PIPELINE_SOURCE != "schedule"
464428
before_script:
465429
- pip install -e .[dev] --prefer-binary
466430
artifacts:
@@ -526,7 +490,7 @@ build_docs:
526490
tags:
527491
- build_docs
528492
rules:
529-
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_USE_ESP_FLASHER_STUB == "1"
493+
- if: $CI_PIPELINE_SOURCE == "schedule"
530494
when: never
531495
- changes:
532496
- "docs/**/*"
@@ -561,7 +525,7 @@ deploy_docs_preview:
561525
extends:
562526
- .deploy_docs_template
563527
rules:
564-
- if: $CI_COMMIT_REF_NAME == "master" || ($CI_PIPELINE_SOURCE == "schedule" && $CI_USE_ESP_FLASHER_STUB == "1")
528+
- if: $CI_COMMIT_REF_NAME == "master" || $CI_PIPELINE_SOURCE == "schedule"
565529
when: never
566530
- changes:
567531
- "docs/**/*"
@@ -579,7 +543,7 @@ deploy_docs_production:
579543
extends:
580544
- .deploy_docs_template
581545
rules:
582-
- if: $CI_COMMIT_REF_NAME == "master" && $CI_USE_ESP_FLASHER_STUB != "1"
546+
- if: $CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE != "schedule"
583547
changes:
584548
- "docs/**/*"
585549
- "CONTRIBUTING.rst"

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
include README.md
22
include LICENSE
3-
include esptool/targets/stub_flasher/*.json
3+
include esptool/targets/stub_flasher/1/*
4+
include esptool/targets/stub_flasher/2/*
45
include espefuse/efuse_defs/*.yaml
56
# sdist includes test/test*.py by default, but esptool.py tests
67
# are so far only intended to run from the git repo itself
78
prune test
8-
prune flasher_stub
99
prune .github
1010
prune docs
1111
exclude .git*

ci/download_flasher_stubs.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python
2+
#
3+
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
4+
# SPDX-License-Identifier: GPL-2.0-or-later
5+
6+
import glob
7+
import os
8+
import urllib.request
9+
10+
STUBS = (
11+
{
12+
"STUB_SET_VERSION": "1",
13+
"DOWNLOAD_URL": "https://github.com/espressif/esptool-legacy-flasher-stub/releases/download",
14+
"TAG_URL": "https://github.com/espressif/esptool-legacy-flasher-stub/releases/tag",
15+
"VERSION": "v1.2.0",
16+
"FILE_LIST": (
17+
"esp32",
18+
"esp32c2",
19+
"esp32c3",
20+
"esp32c5",
21+
"esp32c5beta3",
22+
"esp32c6",
23+
"esp32c6beta",
24+
"esp32h2",
25+
"esp32h2beta1",
26+
"esp32h2beta2",
27+
"esp32p4",
28+
"esp32s2",
29+
"esp32s3",
30+
"esp32s3beta2",
31+
"esp8266",
32+
),
33+
"LICENSE": "released as Free Software under GNU General Public License Version 2 or later",
34+
},
35+
{
36+
"STUB_SET_VERSION": "2",
37+
"DOWNLOAD_URL": "https://github.com/esp-rs/esp-flasher-stub/releases/download",
38+
"TAG_URL": "https://github.com/esp-rs/esp-flasher-stub/releases/tag",
39+
"VERSION": "v0.3.0",
40+
"FILE_LIST": (
41+
"esp32",
42+
"esp32c2",
43+
"esp32c3",
44+
"esp32c6",
45+
"esp32h2",
46+
"esp32s2",
47+
"esp32s3",
48+
),
49+
"LICENSE": "dual licensed under the Apache License Version 2.0 or the MIT license",
50+
},
51+
)
52+
53+
DESTINATION_DIR = "esptool/targets/stub_flasher"
54+
55+
README_TEMPLATE = """# Licensing
56+
57+
The binaries in JSON format distributed in this directory are {LICENSE}. They were released at {URL} from where the sources can be obtained.
58+
"""
59+
60+
61+
def main():
62+
for stub_set in STUBS:
63+
dest_sub_dir = os.path.join(DESTINATION_DIR, stub_set["STUB_SET_VERSION"])
64+
65+
""" The directory is cleaned up so we would detect if a stub was just committed into the repository but the
66+
name was not added into the FILE_LIST of STUBS. This would be an unwanted state because the checker would not
67+
detect any changes in that stub."""
68+
for old_file in glob.glob(os.path.join(dest_sub_dir, "*.json")):
69+
print(f"Removing old file {old_file}")
70+
os.remove(old_file)
71+
72+
for file_name in stub_set["FILE_LIST"]:
73+
file = ".".join((file_name, "json"))
74+
url = "/".join((stub_set["DOWNLOAD_URL"], stub_set["VERSION"], file))
75+
dest = os.path.join(dest_sub_dir, file)
76+
print(f"Downloading {url} to {dest}")
77+
urllib.request.urlretrieve(url, dest)
78+
79+
with open(os.path.join(dest_sub_dir, "README.md"), "w") as f:
80+
print(f"Writing README to {f.name}")
81+
f.write(
82+
README_TEMPLATE.format(
83+
LICENSE=stub_set["LICENSE"],
84+
URL="/".join((stub_set["TAG_URL"], stub_set["VERSION"])),
85+
)
86+
)
87+
88+
89+
if __name__ == "__main__":
90+
main()

ci/setup_ci_build_env.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

esptool/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
write_mem,
6767
)
6868
from esptool.config import load_config_file
69-
from esptool.loader import DEFAULT_CONNECT_ATTEMPTS, ESPLoader, list_ports
69+
from esptool.loader import DEFAULT_CONNECT_ATTEMPTS, StubFlasher, ESPLoader, list_ports
7070
from esptool.targets import CHIP_DEFS, CHIP_LIST, ESP32ROM
7171
from esptool.util import (
7272
FatalError,
@@ -145,6 +145,15 @@ def main(argv=None, esp=None):
145145
action="store_true",
146146
)
147147

148+
# --stub-version can be set with --no-stub so the tests wouldn't fail if this option is implied globally
149+
parser.add_argument(
150+
"--stub-version",
151+
default=os.environ.get("ESPTOOL_STUB_VERSION", StubFlasher.STUB_SUBDIRS[0]),
152+
choices=StubFlasher.STUB_SUBDIRS,
153+
# not a public option and is not subject to the semantic versioning policy
154+
help=argparse.SUPPRESS,
155+
)
156+
148157
parser.add_argument(
149158
"--trace",
150159
"-t",
@@ -679,6 +688,8 @@ def add_spi_flash_subparsers(
679688
print("esptool.py v%s" % __version__)
680689
load_config_file(verbose=True)
681690

691+
StubFlasher.set_preferred_stub_subdir(args.stub_version)
692+
682693
# operation function can take 1 arg (args), 2 args (esp, arg)
683694
# or be a member function of the ESPLoader class.
684695

0 commit comments

Comments
 (0)