Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟢 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_CHECKis 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
WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK for unsupported compilersWOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK for platforms without alignment needs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some compilers, such as Renesas CC-RH, provide no way to specify the
alignment of a type or member.
WH_ALIGN8cannot be implemented for them.whFlashUnit can then only have the ABI alignment of
uint64_t, which can beless than 8. The 8-byte alignment static_assert in
wh_flash_unit.hcan neverpass 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 skippingthe alignment check.
Changes
WOLFHSM_CFG_FLASH_UNIT_NO_ALIGN8_CHECK. When it is defined,the whFlashUnit 8-byte alignment check (
struct whFlashUnitAlignmentCheckand its static_assert) is skipped. The size check stays.
wh_settings.h. The documentation states that flashcallbacks must not assume 8-byte aligned buffers when the option is defined.
Testing
makeandmake runintest/withFLASH_UNIT_SIZE=8andFLASH_UNIT_SIZE=16: built with no warnings and all tests passed.empty
WH_ALIGN8and#pragma pack(4)so thatuint64_tis 4-bytealigned: