Skip to content

Commit 684b796

Browse files
committed
change: Stub support overhaul
This overhauls the stub support added by @higaski, and covers: 1. Switching to the esp-flasher-stub project for stub sources, while adding the ability to override the source and version of the stubs. This ensures licensing compatibility with esp-serial-flasher and any project that depends on it, as esptool stubs were licensed under GPL. It also ensures easier future support for new features. 2. Adding an example and documentation 3. Overhauling the stub source file generation process, which is now done at the CMake configure stage instead of being a separate build target, and uses .template files instead of in-source strings. 4. Adding support for the Zephyr port use 5. Edge-case, code smell and timing fixes
1 parent ec1fc06 commit 684b796

26 files changed

+648
-295
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Stub sources correctness checks
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
pre_commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Configure the stub example with the stub version argument
19+
run: idf.py reconfigure -DSERIAL_FLASHER_STUB_PULL_VERSION='0.3.0'
20+
working-directory: ${{github.workspace}}/examples/esp32_stub_example
21+
22+
- name: Run git diff to check if the sources in the repo match the generated ones
23+
run: git diff --exit-code

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.vscode
21
build
32
sdkconfig
43
sdkconfig.old

.gitlab-ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ variables:
3636
- cd $CI_PROJECT_DIR/examples/esp32_example
3737
- idf.py build -DMD5_ENABLED=1
3838
- idf.py build -DMD5_ENABLED=0
39+
- cd $CI_PROJECT_DIR/examples/esp32_stub_example
40+
- idf.py build
3941
- cd $CI_PROJECT_DIR/examples/esp32_load_ram_example
4042
- idf.py build
4143
- cd $CI_PROJECT_DIR/examples/esp32_spi_load_ram_example
@@ -55,6 +57,16 @@ run_pre_commit:
5557
- pip install pre-commit
5658
- pre-commit run --show-diff-on-failure --from-ref origin/master --to-ref HEAD
5759

60+
check_stub_source_correctness:
61+
stage: pre_check
62+
image: espressif/idf:latest
63+
tags:
64+
- internet
65+
script:
66+
- cd $CI_PROJECT_DIR/examples/esp32_stub_example
67+
- idf.py reconfigure -DSERIAL_FLASHER_STUB_PULL_VERSION='0.3.0'
68+
- git diff --exit-code
69+
5870
# Special case as ESP-IDF v4.3 is not supported by the usb_host_cdc_acm component
5971
# required by the USB CDC ACM interface port and its example
6072
build_idf_v4.3:
@@ -71,6 +83,8 @@ build_idf_v4.3:
7183
- cd $CI_PROJECT_DIR/examples/esp32_example
7284
- idf.py build -DMD5_ENABLED=1
7385
- idf.py build -DMD5_ENABLED=0
86+
- cd $CI_PROJECT_DIR/examples/esp32_stub_example
87+
- idf.py build
7488
- cd $CI_PROJECT_DIR/examples/esp32_load_ram_example
7589
- idf.py build
7690
- cd $CI_PROJECT_DIR/examples/esp32_spi_load_ram_example

CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ endif()
144144

145145
target_compile_definitions(${target} PUBLIC ${defs})
146146

147-
# esp_stubs.[ch] codegen
148-
include(cmake/add_gen_esp_stubs_target.cmake)
149-
add_gen_esp_stubs_target(VERSION 4.7.0)
147+
# This segment pulls the flasher stubs at a specified version at wish, and generates the
148+
# esp_stubs.c/h files, overwriting the library provided ones.
149+
# It is also possible to override stub generation to use a custom url or a local folder.
150+
# Please check if the license under which the custom stub sources are released fits your usecase.
151+
if (DEFINED SERIAL_FLASHER_STUB_PULL_VERSION OR DEFINED SERIAL_FLASHER_STUB_PULL_OVERRIDE_PATH)
152+
include(cmake/serial_flasher_pull_stubs.cmake)
153+
serial_flasher_pull_stubs(
154+
VERSION ${SERIAL_FLASHER_STUB_PULL_VERSION}
155+
SOURCE ${SERIAL_FLASHER_STUB_PULL_SOURCE}
156+
PATH_OVERRIDE ${SERIAL_FLASHER_STUB_PULL_OVERRIDE_PATH}
157+
)
158+
endif()

cmake/add_gen_esp_stubs_target.cmake

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

cmake/esp_stubs.c.template

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Copyright 2020-{current_year} Espressif Systems (Shanghai) CO LTD
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// auto-generated stubs from esp-flasher-stub v{stub_version}
17+
18+
#include "esp_stubs.h"
19+
20+
static bool stub_running = false;
21+
22+
bool esp_stub_get_running(void)
23+
{{
24+
return stub_running;
25+
}}
26+
27+
void esp_stub_set_running(bool stub_status)
28+
{{
29+
stub_running = stub_status;
30+
}}
31+
32+
#if (defined SERIAL_FLASHER_INTERFACE_UART) || (defined SERIAL_FLASHER_INTERFACE_USB)
33+
34+
#if __STDC_VERSION__ >= 201112L
35+
_Static_assert(ESP8266_CHIP == 0, "Stub order matches target_chip_t enumeration");
36+
_Static_assert(ESP32_CHIP == 1, "Stub order matches target_chip_t enumeration");
37+
_Static_assert(ESP32S2_CHIP == 2, "Stub order matches target_chip_t enumeration");
38+
_Static_assert(ESP32C3_CHIP == 3, "Stub order matches target_chip_t enumeration");
39+
_Static_assert(ESP32S3_CHIP == 4, "Stub order matches target_chip_t enumeration");
40+
_Static_assert(ESP32C2_CHIP == 5, "Stub order matches target_chip_t enumeration");
41+
_Static_assert(ESP32_RESERVED0_CHIP == 6, "Stub order matches target_chip_t enumeration");
42+
_Static_assert(ESP32H2_CHIP == 7, "Stub order matches target_chip_t enumeration");
43+
_Static_assert(ESP32C6_CHIP == 8, "Stub order matches target_chip_t enumeration");
44+
_Static_assert(ESP_MAX_CHIP == {max_chip_number}, "Stub order matches target_chip_t enumeration");
45+
#endif
46+
47+
const esp_stub_t esp_stub[ESP_MAX_CHIP] = {{

cmake/esp_stubs.h.template

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright 2020-{current_year} Espressif Systems (Shanghai) CO LTD
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// auto-generated stubs from esp-flasher-stub v{stub_version}
17+
18+
#pragma once
19+
20+
#include <stdint.h>
21+
#include <stdbool.h>
22+
#include "esp_loader.h"
23+
24+
#ifdef __cplusplus
25+
extern "C" {{
26+
#endif
27+
28+
bool esp_stub_get_running(void);
29+
void esp_stub_set_running(bool stub_status);
30+
31+
#if (defined SERIAL_FLASHER_INTERFACE_UART) || (defined SERIAL_FLASHER_INTERFACE_USB)
32+
33+
typedef struct {{
34+
esp_loader_bin_header_t header;
35+
esp_loader_bin_segment_t segments[2];
36+
}} esp_stub_t;
37+
38+
extern const esp_stub_t esp_stub[ESP_MAX_CHIP];
39+
40+
#endif
41+
42+
#ifdef __cplusplus
43+
}}
44+
#endif

cmake/gen_esp_stubs.py

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

0 commit comments

Comments
 (0)