Skip to content

Add support for user "hooks"#709

Open
bigbrett wants to merge 2 commits intowolfSSL:masterfrom
bigbrett:hooks
Open

Add support for user "hooks"#709
bigbrett wants to merge 2 commits intowolfSSL:masterfrom
bigbrett:hooks

Conversation

@bigbrett
Copy link
Contributor

@bigbrett bigbrett commented Mar 3, 2026

Adds a generic hook framework allowing users to inject custom logic at defined points in the boot process (pre-init, post-init, boot, panic). Each hook is independently enabled via build macros and implemented in a user-supplied source file.

This is useful for the large number of customers that want to use the upstream HAL for their part without modifying it, but might need to do additional work to support board-specific hardware, safe state setting, etc.

Semi-related fix: Wraps wolfBoot_panic() definition in do {} while (0) for syntactic correctness when used in single-line if statements (currently was broken in hal/pic32c.c, and a few other locations)

Copilot AI review requested due to automatic review settings March 3, 2026 18:26
@bigbrett bigbrett self-assigned this Mar 3, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a configurable hooks framework to let downstream users inject custom logic at key boot/loader/panic points without patching wolfBoot, and updates panic handling to be syntactically safe in single-line if statements.

Changes:

  • Introduces include/hooks.h and integrates hook invocation points (pre-init, post-init, boot, panic) guarded by build macros.
  • Extends the build system (options.mk) to compile a user-supplied hooks source file and define per-hook feature macros.
  • Adds documentation and CI coverage for hooks behavior on the simulator; updates wolfBoot_panic() macro for statement-safety.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/update_ram.c Calls boot hook prior to do_boot() when enabled.
src/update_flash_hwswap.c Calls boot hook prior to do_boot() when enabled.
src/update_flash.c Calls boot hook prior to do_boot() when enabled.
src/update_disk.c Calls boot hook prior to do_boot() when enabled.
src/loader.c Adds preinit/postinit hook call sites in loader flow.
options.mk Adds hook build knobs and compiles user hook file into the build.
include/loader.h Integrates panic hook and wraps armored panic macro in do { } while (0).
include/hooks.h New public hook API header and per-hook prototypes.
include/hal.h Removes stray whitespace line.
docs/hooks.md New user documentation for hook API, timing, and build flags.
docs/README.md Links to hooks documentation.
.github/workflows/test-hooks-simulator.yml CI coverage to validate hook invocation counts per scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants