-
-
Notifications
You must be signed in to change notification settings - Fork 773
simplify flash area api #6492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
simplify flash area api #6492
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,9 @@ | |
|
|
||
| #ifdef KERNEL_MODE | ||
|
|
||
| #define FLASH_QUADWORD_WORDS (4) | ||
| #define FLASH_QUADWORD_SIZE (FLASH_QUADWORD_WORDS * sizeof(uint32_t)) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed 5477623 |
||
| #ifdef STM32U585xx | ||
| #define FLASH_BANK_PAGES 128 | ||
| #define FLASH_SECTOR_COUNT (FLASH_BANK_PAGES * 2) | ||
|
|
@@ -168,8 +171,8 @@ secbool flash_sector_erase(uint16_t sector) { | |
| return sectrue; | ||
| } | ||
|
|
||
| secbool flash_write_quadword(uint16_t sector, uint32_t offset, | ||
| const uint32_t *data) { | ||
| static secbool flash_write_quadword(uint16_t sector, uint32_t offset, | ||
| const uint32_t *data) { | ||
| uint32_t address = | ||
| (uint32_t)flash_get_address(sector, offset, FLASH_QUADWORD_SIZE); | ||
| if (address == 0) { | ||
|
|
||
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
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
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
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
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 149
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 19458
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 268
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 892
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 920
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 26882
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 2061
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 1529
🏁 Script executed:
Repository: trezor/trezor-firmware
Length of output: 653
Confirm alignment expectations in secret_write and improve BHK array size maintainability.
At line 147,
secret_writepassesconst uint8_t *datadirectly toflash_area_write_data, which casts it toconst uint32_t *(line 162 in flash_area.c) and dereferences it. The flash_area.h header documents that data must be aligned to flash block size, butsecret_writedoes not enforce or document this contract to callers—add alignment documentation to its signature or ensure all callers provide properly aligned buffers.For lines 431–437, the BHK regeneration loop correctly uses
ARRAY_LENGTH(val)andsizeof(val), so that pattern is sound. However,val[8]is hardcoded while elsewhere the codebase usesSECRET_BHK_LEN / sizeof(uint32_t)(line 401). Consider defining the array size asuint32_t val[SECRET_BHK_LEN / sizeof(uint32_t)]for consistency and maintainability.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coderabbit is right, strictly speaking we break some rules here.
HAL function requires that data address is aligned to 32bits, which we incorrectly translate to requirement for block alignment.
The 32 bit requirement is presumably because of unaligned access to the data, but we have that enabled so it works anyway.
As this is also not handled elsewhere in codebase, i suggest we dont deal with tis in this PR, but potentially fix this as separate issue.
what do you think, @cepetr ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. Unaligned arrays are handled correctly on cortex-m.
However, I think we should reconsider this practice we agreed on previously, as it could cause significant issues in the future on platforms that do not support it.