esp32-mock-bootloader 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .venv/
7
+ venv/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ *.log
12
+ reports/.coverage*
13
+ htmlcov/
14
+ reports/htmlcov/
15
+ reports/coverage.xml
16
+ reports/coverage-summary.json
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,437 @@
1
+ Metadata-Version: 2.4
2
+ Name: esp32-mock-bootloader
3
+ Version: 0.1.0
4
+ Summary: Mock ESP32 ROM bootloader (SLIP) for CI and local upload testing without hardware
5
+ Project-URL: Homepage, https://github.com/lucasssvaz/esp32-mock-bootloader
6
+ Project-URL: Documentation, https://github.com/lucasssvaz/esp32-mock-bootloader#readme
7
+ Project-URL: Repository, https://github.com/lucasssvaz/esp32-mock-bootloader
8
+ Project-URL: Issues, https://github.com/lucasssvaz/esp32-mock-bootloader/issues
9
+ Author: Lucas Saavedra Vaz
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: bootloader,ci,embedded,esp32,esptool,slip
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Software Development :: Embedded Systems
18
+ Classifier: Topic :: System :: Emulators
19
+ Requires-Python: >=3.9
20
+ Requires-Dist: esptool
21
+ Provides-Extra: dev
22
+ Requires-Dist: hatch; extra == 'dev'
23
+ Requires-Dist: hatch-vcs; extra == 'dev'
24
+ Requires-Dist: pytest-cov>=7; extra == 'dev'
25
+ Requires-Dist: pytest-xdist>=3; extra == 'dev'
26
+ Requires-Dist: pytest>=8; extra == 'dev'
27
+ Provides-Extra: test
28
+ Requires-Dist: pytest-cov>=7; extra == 'test'
29
+ Requires-Dist: pytest-xdist>=3; extra == 'test'
30
+ Requires-Dist: pytest>=8; extra == 'test'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # esp32-mock-bootloader
34
+
35
+ A mock Espressif ROM bootloader for testing firmware uploads **without a board**.
36
+
37
+ Run it on your machine or in CI. Point **esptool**, **arduino-cli**, or any ROM-compatible flasher at a TCP port or serial path, and flash as if a chip were connected.
38
+
39
+ [![CI](https://github.com/lucasssvaz/esp32-mock-bootloader/actions/workflows/ci.yml/badge.svg)](https://github.com/lucasssvaz/esp32-mock-bootloader/actions/workflows/ci.yml)
40
+ [![PyPI](https://img.shields.io/pypi/v/esp32-mock-bootloader)](https://pypi.org/project/esp32-mock-bootloader/)
41
+ [![Python](https://img.shields.io/pypi/pyversions/esp32-mock-bootloader)](https://pypi.org/project/esp32-mock-bootloader/)
42
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
43
+
44
+ > **Stability:** version `0.x` is alpha. CLI flags and protocol details may change before `1.0.0`.
45
+
46
+ ## Table of contents
47
+
48
+ - [Overview](#overview)
49
+ - [Features](#features)
50
+ - [Requirements](#requirements)
51
+ - [Installation](#installation)
52
+ - [Quick start](#quick-start)
53
+ - [Usage](#usage)
54
+ - [CLI commands](#cli-commands)
55
+ - [Daemon lifecycle](#daemon-lifecycle)
56
+ - [Chip selection](#chip-selection)
57
+ - [Supported chips](#supported-chips)
58
+ - [Transports](#transports)
59
+ - [TCP (default)](#tcp-default)
60
+ - [PTY / serial path](#pty--serial-path)
61
+ - [Windows with com0com](#windows-with-com0com)
62
+ - [GitHub Actions](#github-actions)
63
+ - [Client examples](#client-examples)
64
+ - [How it works](#how-it-works)
65
+ - [Protocol references](#protocol-references)
66
+ - [Limitations](#limitations)
67
+ - [Development](#development)
68
+ - [Project layout](#project-layout)
69
+ - [AI disclosure](#ai-disclosure)
70
+ - [License](#license)
71
+
72
+ ## Overview
73
+
74
+ Real Espressif chips expose a **ROM bootloader** over serial. Upload tools speak a SLIP-framed binary protocol: sync, detect the SoC, write flash blocks, verify MD5, and so on.
75
+
76
+ **esp32-mock-bootloader** implements enough of that protocol for upload clients to complete a full flash cycle. It does **not** run your firmware or emulate peripherals — it only answers the bootloader conversation.
77
+
78
+ ```
79
+ esptool / arduino-cli / …
80
+
81
+
82
+ socket://127.0.0.1:PORT or /dev/tty* / COM*
83
+
84
+
85
+ esp32-mock-bootloader (SLIP server)
86
+
87
+
88
+ ACK + chip metadata + in-memory flash image
89
+ ```
90
+
91
+ Chip metadata comes from the installed **[esptool](https://github.com/espressif/esptool)** package. When Espressif adds a new SoC to esptool, this mock can support it without a code change here.
92
+
93
+ For protocol details and authoritative behavior, see [Protocol references](#protocol-references).
94
+
95
+ ## Features
96
+
97
+ - **No hardware** — run upload tests locally and in CI.
98
+ - **All esptool SoCs** — profiles are built from `esptool.targets.CHIP_DEFS`.
99
+ - **Auto chip detection** — `--chip auto` learns the SoC from client traffic.
100
+ - **TCP daemon** — background `start` / `stop` with stable `socket://` URLs.
101
+ - **PTY and COM paths** — Unix PTY, Windows com0com pairs, or socket fallback.
102
+ - **GitHub Action** — one step to start the mock; teardown runs automatically.
103
+ - **CI-ready** — tested on Ubuntu, Windows, and macOS with esptool integration tests.
104
+
105
+ ## Requirements
106
+
107
+ | Component | Version |
108
+ |-----------|---------|
109
+ | Python | 3.9 or newer |
110
+ | esptool | Installed automatically with this package (runtime dependency) |
111
+ | Upload client | e.g. pip `esptool`, or arduino-cli with a client that supports your transport |
112
+
113
+ Optional:
114
+
115
+ - **com0com** on Windows — for real `COMx` ports in local testing ([setup guide](#windows-with-com0com)).
116
+
117
+ ## Installation
118
+
119
+ From PyPI:
120
+
121
+ ```bash
122
+ pip install esp32-mock-bootloader
123
+ ```
124
+
125
+ Pin a release:
126
+
127
+ ```bash
128
+ pip install esp32-mock-bootloader==0.1.0
129
+ ```
130
+
131
+ From source (development):
132
+
133
+ ```bash
134
+ git clone https://github.com/lucasssvaz/esp32-mock-bootloader.git
135
+ cd esp32-mock-bootloader
136
+ pip install -e ".[dev]"
137
+ ```
138
+
139
+ ## Quick start
140
+
141
+ ```bash
142
+ # 1. Start the mock (background daemon on port 9876)
143
+ esp32-mock-bootloader start
144
+
145
+ # 2. Flash through it
146
+ esptool --chip esp32 \
147
+ --port "$(esp32-mock-bootloader url)" \
148
+ write-flash 0x10000 firmware.bin
149
+
150
+ # 3. Stop when done
151
+ esp32-mock-bootloader stop
152
+ ```
153
+
154
+ The daemon keeps running between steps 1 and 3. Use `status` to inspect it, or `url` to print the `socket://` address again.
155
+
156
+ ## Usage
157
+
158
+ ### CLI commands
159
+
160
+ | Command | Description |
161
+ |---------|-------------|
162
+ | `start` | Start the background daemon and exit once the port is ready |
163
+ | `stop` | Stop the daemon (safe to run if already stopped) |
164
+ | `status` | Show pid, chip mode, detected SoC, and URL (exit 1 if stopped) |
165
+ | `url` | Print `socket://127.0.0.1:PORT` |
166
+ | `chips` | List SoCs supported by the installed esptool |
167
+ | `run` | Run the server in the foreground (used internally; prefer `start`) |
168
+
169
+ Common flags for `start` and `run`:
170
+
171
+ | Flag | Default | Description |
172
+ |------|---------|-------------|
173
+ | `--chip` | `auto` | Chip profile, or `auto` to detect from client traffic |
174
+ | `--port` | `9876` | TCP port |
175
+ | `--bind` | `127.0.0.1` | Bind address |
176
+ | `--state-dir` | `~/.cache/esp32-mock-bootloader` | Daemon state and logs |
177
+ | `--startup-timeout` | `30` | Seconds `start` waits for the port (`start` only) |
178
+ | `--force` | off | Stop an existing daemon on the same port first (`start` only) |
179
+
180
+ `status --json` adds machine-readable output. Set `ESP32_MOCK_BOOTLOADER_STATE_DIR` to override the default state directory.
181
+
182
+ ### Daemon lifecycle
183
+
184
+ `start` writes state to `{state-dir}/port-{port}.json` and logs to `port-{port}.log`:
185
+
186
+ ```json
187
+ {
188
+ "pid": 12345,
189
+ "port": 9876,
190
+ "chip": "auto",
191
+ "url": "socket://127.0.0.1:9876",
192
+ "detected_chip": "esp32"
193
+ }
194
+ ```
195
+
196
+ `detected_chip` is filled after a client identifies the SoC (in `auto` mode).
197
+
198
+ ### Chip selection
199
+
200
+ | Mode | When to use |
201
+ |------|-------------|
202
+ | `--chip auto` | Client passes its own `--chip`; mock learns from registers (recommended for CI matrices) |
203
+ | `--chip esp32`, `esp32c6`, … | Fixed profile for every session |
204
+
205
+ In `auto` mode the mock:
206
+
207
+ 1. Returns a ROM-style error on the first `GET_SECURITY_INFO` so clients do not lock onto ESP32 via `chip_id` 0.
208
+ 2. Returns `0` for the legacy probe at `0x40001000` until chip-specific registers identify the SoC.
209
+ 3. Sets `detected_chip` from unique detect registers or efuse windows (addresses from esptool ROM classes).
210
+
211
+ ### Supported chips
212
+
213
+ Every target in the installed esptool `CHIP_DEFS` is available:
214
+
215
+ ```bash
216
+ esp32-mock-bootloader chips
217
+ esp32-mock-bootloader chips --json # detect registers and chip_id metadata
218
+ ```
219
+
220
+ New esptool releases can add SoCs without updating this package.
221
+
222
+ ## Transports
223
+
224
+ ### TCP (default)
225
+
226
+ The daemon listens on `127.0.0.1:PORT`. Pip-installed esptool accepts `socket://` URLs via pyserial.
227
+
228
+ ```bash
229
+ esp32-mock-bootloader start --port 9876
230
+ esptool --chip esp32c6 --port socket://127.0.0.1:9876 write-flash 0x10000 app.bin
231
+ ```
232
+
233
+ ### PTY / serial path
234
+
235
+ Use `--pty` with `run` when a tool expects a **device path** instead of a URL (common with arduino-cli):
236
+
237
+ ```bash
238
+ esp32-mock-bootloader run --pty --pty-path-file /tmp/mock-pty --chip esp32
239
+ esptool --chip esp32 --port "$(cat /tmp/mock-pty)" write-flash 0x10000 firmware.bin
240
+ ```
241
+
242
+ | Platform | `--pty` provides |
243
+ |----------|------------------|
244
+ | Linux / macOS | Real PTY device (e.g. `/dev/ttys003`) |
245
+ | Windows (local) | com0com virtual COM pair |
246
+ | Windows (CI) | `socket://127.0.0.1:PORT` fallback when no COM pair is configured |
247
+
248
+ ### Windows with com0com
249
+
250
+ Install [com0com](https://sourceforge.net/projects/com0com/). Run the mock on the **server** port; the path file receives the **client** port:
251
+
252
+ ```bat
253
+ esp32-mock-bootloader run --pty --pty-path-file mock.port ^
254
+ --com-port COM18 --com-peer COM19 --chip auto
255
+ esptool --chip esp32 --port COM19 write-flash 0x10000 firmware.bin
256
+ ```
257
+
258
+ Environment variables `ESP32_MOCK_COM_PORT` and `ESP32_MOCK_COM_PEER` work the same as `--com-port` / `--com-peer`.
259
+
260
+ **Helper script** (elevated prompt; creates a pair, runs esptool, removes the pair):
261
+
262
+ ```bat
263
+ python scripts\test_windows_com.py
264
+ ```
265
+
266
+ Set `ESP32_MOCK_KEEP_COM_PAIR=1` to leave the pair installed after the script exits.
267
+
268
+
269
+ ## GitHub Actions
270
+
271
+ The action starts the daemon in the main step and **stops it in a post step** when the job ends — including on failure. No manual `stop` required.
272
+
273
+ ```yaml
274
+ jobs:
275
+ upload-test:
276
+ runs-on: ubuntu-latest
277
+ steps:
278
+ - uses: actions/checkout@v4
279
+
280
+ - name: Mock bootloader
281
+ uses: lucasssvaz/esp32-mock-bootloader@v0.1.0
282
+ id: mock
283
+
284
+ - name: Flash test firmware
285
+ run: |
286
+ pip install esptool
287
+ esptool --chip esp32 \
288
+ --port "${{ steps.mock.outputs.url }}" \
289
+ --no-stub --before no-reset --after no-reset \
290
+ write-flash 0x10000 firmware.bin
291
+ ```
292
+
293
+ **Outputs:** `url` (`socket://…`), `port`.
294
+
295
+ **Inputs** (all optional):
296
+
297
+ | Input | Default | Description |
298
+ |-------|---------|-------------|
299
+ | `chip` | `auto` | Chip profile |
300
+ | `port` | `9876` | TCP port |
301
+ | `startup-timeout` | `30` | Startup wait in seconds |
302
+ | `python-version` | `3.x` | Python for `setup-python` |
303
+ | `version` | *(empty)* | PyPI pin (e.g. `0.1.0`); omit to install from the action checkout |
304
+
305
+ **Manual CLI in a workflow** (without the action):
306
+
307
+ ```yaml
308
+ - run: pip install esp32-mock-bootloader esptool
309
+ - run: esp32-mock-bootloader start
310
+ - run: |
311
+ esptool --chip esp32 --port "$(esp32-mock-bootloader url)" \
312
+ write-flash 0x10000 firmware.bin
313
+ - run: esp32-mock-bootloader stop
314
+ if: always()
315
+ ```
316
+
317
+ ## Client examples
318
+
319
+ **esptool** (TCP, no stub — typical for CI):
320
+
321
+ ```bash
322
+ esptool --chip esp32c6 \
323
+ --port socket://127.0.0.1:9876 \
324
+ --no-stub --before no-reset --after no-reset \
325
+ write-flash 0x10000 app.bin
326
+ ```
327
+
328
+ **arduino-cli:**
329
+
330
+ ```bash
331
+ arduino-cli compile -b esp32:esp32:esp32 \
332
+ -p socket://127.0.0.1:9876 --upload sketch.ino
333
+ ```
334
+
335
+ **Shell CI script:**
336
+
337
+ ```bash
338
+ esp32-mock-bootloader start
339
+ PORT="$(esp32-mock-bootloader url)"
340
+ # run your upload tests against "$PORT"
341
+ esp32-mock-bootloader stop
342
+ ```
343
+
344
+ ## How it works
345
+
346
+ The mock speaks SLIP-framed ROM commands. Implemented handlers include:
347
+
348
+ `SYNC`, `FLASH_BEGIN` / `DATA` / `END`, `FLASH_DEFL_*`, `MEM_*` (+ OHAI after `MEM_END`), `READ_REG`, `GET_SECURITY_INFO`, `WRITE_REG`, `SPI_SET_PARAMS`, `SPI_ATTACH`, `CHANGE_BAUDRATE`, `SPI_FLASH_MD5`.
349
+
350
+ Flash data is stored in an in-memory image (erased bytes default to `0xFF`). After a stub upload (`MEM_END` with entrypoint + `OHAI`), `SPI_FLASH_MD5` returns a **16-byte binary** digest; in ROM mode it returns **32-byte lowercase hex ASCII** — matching esptool’s `flash_md5sum()` expectations. Unknown commands receive a generic ACK.
351
+
352
+ The mock validates **protocol behavior**, not silicon accuracy. It does not model Wi-Fi, sleep, brownout, or real flash timing.
353
+
354
+ ## Protocol references
355
+
356
+ Implementation follows Espressif’s published bootloader protocol and the **esptool** reference client. Primary sources:
357
+
358
+ | Topic | Reference |
359
+ |-------|-----------|
360
+ | Serial protocol overview | [esptool serial protocol (ESP32)](https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/serial-protocol.html) — same command set is documented per chip under `esptool/en/latest/<chip>/advanced-topics/serial-protocol.html` |
361
+ | Flash upload & MD5 verify | [Verifying uploaded data](https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/serial-protocol.html#verifying-uploaded-data) — ROM returns 32 hex ASCII bytes; stub returns 16 raw MD5 bytes before the 2 status bytes |
362
+ | `SPI_FLASH_MD5` (`0x13`) | [Commands table](https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/serial-protocol.html#supported-by-stub-loader-and-rom-loader) |
363
+ | Stub upload & `OHAI` | [Functional description — initialization](https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/serial-protocol.html#functional-description) — `MEM_END` entrypoint, unsolicited `OHAI` SLIP packet |
364
+ | Client MD5 handling | [esptool `loader.py` — `flash_md5sum`](https://github.com/espressif/esptool/blob/master/esptool/loader.py) — `RESP_DATA_LEN` 32 (ROM) vs `RESP_DATA_LEN_STUB` 16 (stub); status bytes follow the digest |
365
+ | Stub lifecycle | [esptool `loader.py` — `run_stub`](https://github.com/espressif/esptool/blob/master/esptool/loader.py) — RAM download via `MEM_*`, then `mem_finish(entry)` |
366
+ | Chip profiles & detection | [esptool `targets` / `CHIP_DEFS`](https://github.com/espressif/esptool/tree/master/esptool/targets) — register addresses, magic values, security info |
367
+
368
+ **Integration tests** in downstream projects (e.g. [arduino-esp32 upload tests](https://github.com/espressif/arduino-esp32/blob/master/.github/workflows/upload-tests.yml)) exercise the default **stub** path (`flasher.py` / esptool without `--no-stub`). CI examples in this repo that pass `--no-stub` target the ROM MD5 format explicitly.
369
+
370
+ ## Limitations
371
+
372
+ - **Protocol emulator only** — no application code runs on the mock.
373
+ - **Client packaging matters** — some bundled esptool builds lack `socket://`; use PTY/COM or pip esptool.
374
+ - **com0com is local** — GitHub-hosted Windows runners use the socket fallback automatically.
375
+ - **Alpha API** — expect changes before `1.0.0`.
376
+
377
+ ## Development
378
+
379
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for pull request guidelines and AI disclosure expectations.
380
+
381
+ ```bash
382
+ git clone https://github.com/lucasssvaz/esp32-mock-bootloader.git
383
+ cd esp32-mock-bootloader
384
+ pip install -e ".[dev]"
385
+ ```
386
+
387
+ **Run tests:**
388
+
389
+ ```bash
390
+ pytest # parallel by default (pytest-xdist)
391
+ pytest -n0 # single process (debugging)
392
+ pytest -m "not esptool" # protocol unit tests only
393
+ pytest -m "not transport" # skip TCP/PTY integration
394
+ pytest tests/test_transports.py # transport matrix only
395
+ ```
396
+
397
+ **Coverage** (see [`reports/README.md`](reports/README.md)):
398
+
399
+ ```bash
400
+ pytest --cov=esp32_mock_bootloader \
401
+ --cov-report=term-missing \
402
+ --cov-report=html:reports/htmlcov \
403
+ --cov-report=xml:reports/coverage.xml
404
+ python scripts/check_coverage.py
405
+ ```
406
+
407
+ CI runs the full suite on Ubuntu, Windows, and macOS, enforces coverage baselines on Ubuntu, and uploads an HTML report artifact. Windows com0com tests run locally via `scripts/test_windows_com.py`.
408
+
409
+ **Build a release wheel:**
410
+
411
+ ```bash
412
+ hatch build
413
+ ```
414
+
415
+ ## Project layout
416
+
417
+ ```
418
+ esp32-mock-bootloader/
419
+ ├── CONTRIBUTING.md # PR guidelines and AI policy
420
+ ├── src/esp32_mock_bootloader/ # Python package (CLI, daemon, SLIP server)
421
+ ├── action/ # Node.js steps for the GitHub Action
422
+ ├── action.yml # Composite action entry point
423
+ ├── tests/ # pytest suite (protocol, esptool, transports)
424
+ ├── scripts/ # Coverage checker, Windows COM helper
425
+ ├── reports/ # Coverage config and baselines
426
+ └── .github/workflows/ # CI and release pipelines
427
+ ```
428
+
429
+ ## AI disclosure
430
+
431
+ This repository was developed with help from AI coding assistants. Every change is reviewed and tested by a human maintainer before merge or release.
432
+
433
+ Contributor expectations (disclosure, review, commit trailers) are in [CONTRIBUTING.md](CONTRIBUTING.md#ai-assisted-contributions).
434
+
435
+ ## License
436
+
437
+ Copyright 2026 Lucas Saavedra Vaz. Released under the [Apache-2.0](LICENSE) license.