Feat: support P4 Rev 3.2 & H4 (stub), update stub JSONs - #376
Conversation
📝 WalkthroughWalkthroughThis PR adds ESP32-P4 revision 302 and ESP32H4 efuse-based power-on/revision handling in esp_loader.ts, refactors flashBegin/runStub/readFlash protocol logic, updates stub selection in index.ts to support new chip/revision mappings, regenerates embedded firmware stub JS modules with new hashed filenames, and updates stub JSON payloads including new ESP32S3 plugin data. ChangesESP32-P4/H4 stub and loader update
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/stubs/esp32s3.json`:
- Around line 8-28: The stub loader currently ignores the new NAND plugin
metadata, so the NAND blob never gets uploaded or dispatched. Update the stub
model in src/stubs/index.ts to include plugin_first_opcode, plugin_table_offset,
plugin_table_entries, and plugins.nand, then extend the upload logic in
src/esp_loader.ts to send the plugin section alongside text/data and preserve
the plugin dispatch table for the stub entry path. Use the existing stub shape
and esp_loader upload flow to locate the changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8085b657-5225-44c1-9eac-5b70e04d11b1
📒 Files selected for processing (46)
js/modules/esp32-BRKoi17y.jsjs/modules/esp32-DW9TTzBw.jsjs/modules/esp32c2-B2rZuByC.jsjs/modules/esp32c2-Btgr_lwh.jsjs/modules/esp32c3-CHKfoI8W.jsjs/modules/esp32c3-DvICuzl3.jsjs/modules/esp32c5-BDW4KtLo.jsjs/modules/esp32c5-Dz0QiUXa.jsjs/modules/esp32c6-Bl9Nuzrv.jsjs/modules/esp32c6-il8tTxAG.jsjs/modules/esp32c61-DFH7YXsW.jsjs/modules/esp32c61-thKzxBGf.jsjs/modules/esp32h2-BK2Oz0x8.jsjs/modules/esp32h2-CxoUHv_P.jsjs/modules/esp32h4-BOgv2e75.jsjs/modules/esp32p4-CmXpP18K.jsjs/modules/esp32p4-D3jLP-jY.jsjs/modules/esp32p4-rev1-JwKc7e7M.jsjs/modules/esp32p4r3-CqI71ojR.jsjs/modules/esp32s2-9bABqiJs.jsjs/modules/esp32s2-iX3WoDbg.jsjs/modules/esp32s3-C9Iakqrc.jsjs/modules/esp32s3-DGwDVIgz.jsjs/modules/esp32s31-Cu0bI6XV.jsjs/modules/esp32s31-cyImlcoa.jsjs/modules/esp8266-CUwxJpGa.jsjs/modules/esp8266-DI9O9acR.jsjs/modules/esptool.jssrc/const.tssrc/esp_loader.tssrc/stubs/esp32.jsonsrc/stubs/esp32c2.jsonsrc/stubs/esp32c3.jsonsrc/stubs/esp32c5.jsonsrc/stubs/esp32c6.jsonsrc/stubs/esp32c61.jsonsrc/stubs/esp32h2.jsonsrc/stubs/esp32h4.jsonsrc/stubs/esp32p4-rev1.jsonsrc/stubs/esp32p4.jsonsrc/stubs/esp32p4r3.jsonsrc/stubs/esp32s2.jsonsrc/stubs/esp32s3.jsonsrc/stubs/esp32s31.jsonsrc/stubs/esp8266.jsonsrc/stubs/index.ts
💤 Files with no reviewable changes (14)
- js/modules/esp32c3-CHKfoI8W.js
- src/stubs/esp32p4r3.json
- js/modules/esp32p4-D3jLP-jY.js
- js/modules/esp32s3-DGwDVIgz.js
- js/modules/esp32c5-BDW4KtLo.js
- js/modules/esp32p4r3-CqI71ojR.js
- js/modules/esp8266-CUwxJpGa.js
- js/modules/esp32c61-thKzxBGf.js
- js/modules/esp32c6-il8tTxAG.js
- js/modules/esp32c2-Btgr_lwh.js
- js/modules/esp32s31-cyImlcoa.js
- js/modules/esp32-BRKoi17y.js
- js/modules/esp32h2-CxoUHv_P.js
- js/modules/esp32s2-iX3WoDbg.js
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates stub handling and loader behavior to add ESP32-H4 stub support, improve ESP32-P4 revision-specific flash power handling, and align flash read/erase protocols with expected ROM/stub semantics.
Changes:
- Add ESP32-H4 and ESP32-P4 Rev1 stub JSONs; update stub selection logic (including JSON default-export normalization).
- Extend
ESPLoaderwith ESP32-H4 revision detection and broaden ESP32-P4 flash power-on handling to Rev 3.1/3.2. - Adjust stub startup robustness and refine erase/read-flash protocol behavior (timeouts, parameter semantics, ACK strategy).
Reviewed changes
Copilot reviewed 31 out of 46 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/stubs/index.ts | Adds JSON default normalization and updates chip-family stub mapping (ESP32-H4, ESP32-P4 rev split). |
| src/stubs/esp32p4r3.json | Removes the legacy ESP32-P4 Rev3 stub JSON. |
| src/stubs/esp32p4-rev1.json | Adds a dedicated ESP32-P4 Rev1 stub JSON. |
| src/stubs/esp32h4.json | Adds ESP32-H4 stub JSON. |
| src/stubs/esp32c2.json | Updates embedded stub payload values. |
| src/stubs/esp32.json | Updates embedded stub payload values. |
| src/esp_loader.ts | Adds H4 revision decoding, expands P4 flash power-on logic, and updates erase/read-flash/stub-start flows. |
| src/const.ts | Adds ESP32-P4 efuse constants used for Rev 3.2 handling. |
| js/modules/esp8266-CUwxJpGa.js | Removes a bundled stub module artifact. |
| js/modules/esp32s31-cyImlcoa.js | Removes a bundled stub module artifact. |
| js/modules/esp32s3-DGwDVIgz.js | Removes a bundled stub module artifact. |
| js/modules/esp32s2-iX3WoDbg.js | Removes a bundled stub module artifact. |
| js/modules/esp32p4r3-CqI71ojR.js | Removes a bundled stub module artifact. |
| js/modules/esp32p4-D3jLP-jY.js | Removes a bundled stub module artifact. |
| js/modules/esp32h2-CxoUHv_P.js | Removes a bundled stub module artifact. |
| js/modules/esp32c61-thKzxBGf.js | Removes a bundled stub module artifact. |
| js/modules/esp32c6-il8tTxAG.js | Removes a bundled stub module artifact. |
| js/modules/esp32c5-BDW4KtLo.js | Removes a bundled stub module artifact. |
| js/modules/esp32c3-CHKfoI8W.js | Removes a bundled stub module artifact. |
| js/modules/esp32c2-Btgr_lwh.js | Removes a bundled stub module artifact. |
| js/modules/esp32-BRKoi17y.js | Removes a bundled stub module artifact. |
Files not reviewed (14)
- js/modules/esp32-DW9TTzBw.js: Generated file
- js/modules/esp32c2-B2rZuByC.js: Generated file
- js/modules/esp32c3-DvICuzl3.js: Generated file
- js/modules/esp32c5-Dz0QiUXa.js: Generated file
- js/modules/esp32c6-Bl9Nuzrv.js: Generated file
- js/modules/esp32c61-DFH7YXsW.js: Generated file
- js/modules/esp32h2-BK2Oz0x8.js: Generated file
- js/modules/esp32h4-BOgv2e75.js: Generated file
- js/modules/esp32p4-CmXpP18K.js: Generated file
- js/modules/esp32p4-rev1-JwKc7e7M.js: Generated file
- js/modules/esp32s2-9bABqiJs.js: Generated file
- js/modules/esp32s3-C9Iakqrc.js: Generated file
- js/modules/esp32s31-Cu0bI6XV.js: Generated file
- js/modules/esp8266-DI9O9acR.js: Generated file
Comments suppressed due to low confidence (1)
src/stubs/index.ts:1
- Adding
default?: LoadedStubto the stub payload type conflates the JSON data shape with the dynamic-import module wrapper shape. This makes the type recursive and also makes it easy to accidentally carry adefaultproperty through the returned stub object. Prefer modeling imports as a union (e.g.,LoadedStub | { default: LoadedStub }) or a separateLoadedStubModuletype, and keepLoadedStubdescribing only the JSON payload fields.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thx! |
This PR adds support for ESP32-P4 Rev 3.2 and ESP32-H4 (stub), upgrades all chip stubs to esp-flasher-stub v1.0.0, and fixes several issues related to flash operations and stub loading.
Changes
Stub Upgrade to esp-flasher-stub v1.0.0
All chip stub binaries have been updated from the legacy flasher stub to esp-flasher-stub v1.0.0.
Due to behavioral differences between the new stub and the legacy stub,
readFlashparameters have been fine-tuned accordingly:FLASH_SECTOR_SIZE(4096) +maxInFlightPackets = 64, matching esptool's defaultREAD_FLASHprotocolblockSize→packetSize,maxInFlight→maxInFlightPackets)ESP32-P4 Rev 3.2 (302) Support
powerOnFlash()to handle both Rev 3.1 (301) and Rev 3.2 (302):ESP32-H4 Stub Support
esp32h4.jsonstub fileBug Fixes / Improvements
IS_STUB ? DEFAULT_TIMEOUT : timeoutPerMb(...)totimeoutPerMb(...)flash_beginencrypted flag: Replaced theIS_STUBshortcut with an explicit chip allowlist, aligning more precisely with esptool's behaviormemFinishin atry-catchto tolerate native USB chips that do not send a ROM MEM_END response after the stub takes overreadPackettimeout from 500 ms to 2500 ms_commandLockafter stub is loaded to prevent potential command queue deadlocksstubs/index.ts: Addedstubcode?.default ?? stubcodeto correctly handle ES module default exports from JSON importsTesting
Validated on the following hardware:
Summary by CodeRabbit
New Features
Bug Fixes