Skip to content

examples: zephyr_example: refactor (ESF-270) - #167

Closed
marekmatej wants to merge 2 commits into
espressif:masterfrom
marekmatej:feature/zephyr_port_sources
Closed

examples: zephyr_example: refactor (ESF-270)#167
marekmatej wants to merge 2 commits into
espressif:masterfrom
marekmatej:feature/zephyr_port_sources

Conversation

@marekmatej

Copy link
Copy Markdown
Contributor

Description

Improve the Zephyr integration as an 'External project module'. The Zephyr portion of the integration describes the module and the way to add it to a new project.

Use the Zephyr's iterable sections to store and use the binary firmware images.

Add a new example in the Zephyr integration folder, including an interactive shell.

Update the existing Zephyr example to reflect the improved module integration.

Motivation

This work improves the ESP Serial Flasher integration in Zephyr so it can be easily added to applications on various supported platforms and vendors.

Related

Testing

After you add the module as described in the Zephyr integration module and west update:

Build the original sample: west build -b esp32s3_devkitc//procpu ../esp-serial-flasher/examples/zephyr_example -p

Build new shell sample: west build -b esp32s3_devkitc//procpu ../esp-serial-flasher/zephyr/samples/shell -p

@github-actions

github-actions Bot commented Feb 5, 2026

Copy link
Copy Markdown
Messages
📖 This PR seems to be quite large (total lines of code: 1509), you might consider splitting it into smaller PRs

👋 Hello marekmatej, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 2b1e0e0

@github-actions github-actions Bot changed the title examples: zephyr_example: refactor examples: zephyr_example: refactor (ESF-270) Feb 5, 2026
@marekmatej
marekmatej force-pushed the feature/zephyr_port_sources branch 2 times, most recently from 950c559 to c7af97d Compare February 17, 2026 14:47
@Dzarda7
Dzarda7 requested a review from Copilot February 19, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Zephyr integration for the ESP Serial Flasher library as an 'External project module', improving its integration with Zephyr RTOS projects. The refactoring introduces a more modular structure using Zephyr's iterable sections for binary firmware management, adds a new interactive shell sample, and updates the existing example to use the improved integration.

Changes:

  • Restructured Zephyr module with new build system (subsys directory) and devicetree bindings
  • Implemented binary firmware storage using Zephyr's iterable sections pattern
  • Added new interactive shell sample with comprehensive ESP Serial Flasher commands
  • Updated existing Zephyr example to use simplified API and devicetree-based configuration

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 35 comments.

Show a summary per file
File Description
zephyr/module.yml Updated module name and structure to include DTS root, samples, and tests directories
zephyr/Kconfig Added new config options for shell and static resources support
zephyr/subsys/esp_loader/CMakeLists.txt New modular build system replacing old zephyr/CMakeLists.txt
zephyr/subsys/esp_loader/bin_images_sections.cmake CMake function to convert binary files to C arrays using iterable sections
zephyr/subsys/esp_loader/include/bin_image.h Header defining bin_image structure and DEFINE_IMAGE macro for iterable sections
zephyr/subsys/esp_loader/sections-rom.ld Linker script for iterable sections support
zephyr/dts/bindings/misc/esp-loader/espressif,esp-loader.yaml Devicetree binding for ESP loader node configuration
port/zephyr_port.h Simplified API removing loader_zephyr_config_t structure
port/zephyr_port.c Refactored to use devicetree directly and added SYS_INIT for automatic initialization
zephyr/samples/shell/ New interactive shell sample with comprehensive ESP Serial Flasher commands
examples/zephyr_example/ Updated to use new devicetree-based configuration and iterable sections
zephyr/CMakeLists.txt Deleted - functionality moved to subsys/esp_loader/CMakeLists.txt

Comment thread zephyr/Kconfig Outdated
Comment thread zephyr/samples/shell/src/shell.c Outdated
Comment thread port/zephyr_port.c Outdated
Comment thread zephyr/Kconfig Outdated
Comment on lines +40 to +42
# Compute MD5 hash of the file
execute_process(COMMAND md5sum ${bin} OUTPUT_VARIABLE md5_output)
string(REGEX REPLACE " .*" "" md5_hash ${md5_output})

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The md5sum command may not be portable across all platforms. On macOS, the command is md5 -q instead of md5sum, and on Windows, it may not be available at all. Consider using CMake's built-in file(MD5 ...) command instead for better cross-platform compatibility: file(MD5 ${bin} md5_hash).

Suggested change
# Compute MD5 hash of the file
execute_process(COMMAND md5sum ${bin} OUTPUT_VARIABLE md5_output)
string(REGEX REPLACE " .*" "" md5_hash ${md5_output})
# Compute MD5 hash of the file (use CMake's built-in MD5 for portability)
file(MD5 ${bin} md5_hash)

Copilot uses AI. Check for mistakes.
Comment thread zephyr/subsys/esp_loader/CMakeLists.txt Outdated
Comment thread zephyr/samples/shell/prj.conf Outdated
Comment thread zephyr/samples/shell/src/main.c Outdated
Comment thread zephyr/samples/shell/src/main.c Outdated
Comment thread examples/zephyr_example/src/shell.c
@Dzarda7

Dzarda7 commented Feb 19, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the improvements for zephyr port. Sorry it took me so long to add some comments to it. I am not that familiar with zephyr, so I was trying to study it a bit, also other responsibilities were there.

Regarding the implementation. I think that the shell is really cool, but should not be part of the library. It duplicates code from the examples_common and adds unnecessary maintenance burden and is out of scope of the library. That is the first thing.

Second, there are some breaking changes in the port, for example loader_port_zephyr_init changed signature. It is also called using SYS_INIT and is also part of the public api, which is confusing. But this is something I think of quite regularly in recent times if changes in port should be considered breaking change or if we should mention in the documentation, that it can change based on the new SDK versions. Will let you know, but in these cases seems quite redundant to do it.

There are also other small changes, but I will address them individually. Overall thanks for this, looks nice.

@Dzarda7 Dzarda7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole iterable_section is great addition and I would like to include binaries directly without converting it to array, but it should also be part of the example, not the library as we do not know what source user wants to use.

Comment thread port/zephyr_port.c
#include <esp_loader_io.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(esf, CONFIG_ESP_SERIAL_FLASHER_LOG_LEVEL);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_ESP_SERIAL_FLASHER_LOG_LEVEL is nice improvement, but inconsistent with other ports and documentation which uses SERIAL_FLASHER_DEBUG_TRACE

Comment on lines +5 to +7
- `bootloader_0x0.bin` - ESP32 bootloader binary flashed at offset 0x0
- `partition-table_0x8000.bin` - Partition table configuration at offset 0x8000
- `app_0x10000.bin` - Main application binary at offset 0x10000

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this change is unnecessary and also not true as bootloader will be flashed at address based on the target.

@marekmatej
marekmatej force-pushed the feature/zephyr_port_sources branch 4 times, most recently from a7b519b to 7f83e8f Compare February 24, 2026 12:34
@marekmatej
marekmatej force-pushed the feature/zephyr_port_sources branch 6 times, most recently from 4ee73e2 to 88f31ca Compare March 11, 2026 22:41
Update Zephyr port to better integrate with dts and use of off-tree subsystem.
Update example accordingly and add shell commands for manual target access.

Signed-off-by: Marek Matej <marek.matej@espressif.com>
Fix the board name to the supported name.
Use latter Zephyr version and actually supported boards.
Update packages for subsystems and hals.

Signed-off-by: Marek Matej <marek.matej@espressif.com>
@marekmatej
marekmatej force-pushed the feature/zephyr_port_sources branch from 88f31ca to 2b1e0e0 Compare April 3, 2026 00:43
@Dzarda7

Dzarda7 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

This was done elsewhere and already merged 174f3ea.

@Dzarda7 Dzarda7 closed this Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants