Skip to content

Add WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK for platforms without alignment needs - #550

Open
kojiws wants to merge 1 commit into
wolfSSL:mainfrom
kojiws:disable_align8_check
Open

kojiws wants to merge 1 commit into
wolfSSL:mainfrom
kojiws:disable_align8_check

Conversation

@kojiws

@kojiws kojiws commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Some compilers, such as Renesas CC-RH, provide no way to specify the
alignment of a type or member. WH_ALIGN8 cannot be implemented for them.
whFlashUnit can then only have the ABI alignment of uint64_t, which can be
less than 8. The 8-byte alignment static_assert in wh_flash_unit.h can never
pass on these compilers, so wolfHSM cannot be built for them.

On many such platforms the flash driver accepts byte buffers with no
alignment requirement. There, the 8-byte alignment of whFlashUnit is not
needed, because NVM reads and writes whFlashUnit contents byte by byte
(nfLoad* / nfStore*). This change lets those platforms build by skipping
the alignment check.

Changes

  • Add an opt-in WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK. When it is defined,
    the whFlashUnit 8-byte alignment check (struct whFlashUnitAlignmentCheck
    and its static_assert) is skipped. The size check stays.
  • Document the option in wh_settings.h. The documentation states that flash
    callbacks must not assume 8-byte aligned buffers when the option is defined.

Testing

  • make and make run in test/ with FLASH_UNIT_SIZE=8 and
    FLASH_UNIT_SIZE=16: built with no warnings and all tests passed.
  • Simulated a compiler without an alignment attribute using clang, with an
    empty WH_ALIGN8 and #pragma pack(4) so that uint64_t is 4-byte
    aligned:
    • Without the option, the alignment static_assert fails as before.
    • With the option, the build succeeds for unit sizes 8 and 16.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 04:46
@kojiws kojiws self-assigned this Oct 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the opt-in flash-unit alignment-check option.

No open issues 🎉

What changed in this PR

Adds an opt-in configuration option to support compilers that cannot enforce 8-byte alignment for whFlashUnit, while preserving the size check and default alignment validation.

Changes:

  • Skip the alignment-check structure and assertion when WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK is defined.
  • Document the option and the requirement that flash callbacks accept buffers without guaranteed 8-byte alignment.
File Description
wolfhsm/​wh_settings.h Documents the option, its default, and callback alignment requirements.
wolfhsm/​wh_flash_unit.h Guards alignment validation with the new option while retaining size validation.

Review effort: Balanced

@kojiws kojiws changed the title Add WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK for unsupported compilers Add WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK for platforms without alignment needs Oct 28, 2026
@kojiws kojiws assigned wolfSSL-Bot and unassigned kojiws Oct 28, 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