-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Standardise usage of rom_get_sys_info function #3094
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
Open
lurch
wants to merge
1
commit into
develop
Choose a base branch
from
bootrom_sysinfo_tweaks
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25
−14
Open
Changes from all commits
Commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,12 @@ | |||||
| #include "pico/bootrom.h" | ||||||
| #include "pico/unique_id.h" | ||||||
|
|
||||||
| static_assert(PICO_UNIQUE_BOARD_ID_SIZE_BYTES <= FLASH_UNIQUE_ID_SIZE_BYTES, "Board ID size must at least be the size of flash ID"); | ||||||
| #if PICO_RP2040 | ||||||
| static_assert(PICO_UNIQUE_BOARD_ID_SIZE_BYTES <= FLASH_UNIQUE_ID_SIZE_BYTES, "Board ID size cannot be greater than the size of flash ID"); | ||||||
| #else | ||||||
| #define SYS_INFO_DEVICE_ID_SIZE_BYTES 8 | ||||||
| static_assert(PICO_UNIQUE_BOARD_ID_SIZE_BYTES <= SYS_INFO_DEVICE_ID_SIZE_BYTES, "Board ID size cannot be greater than the size of device ID"); | ||||||
| #endif | ||||||
|
|
||||||
| static pico_unique_board_id_t retrieved_id; | ||||||
|
|
||||||
|
|
@@ -38,16 +43,22 @@ static void __attribute__((PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES)) _retrieve_uniq | |||||
| #error unique board ID size is greater than flash unique ID size | ||||||
| #endif | ||||||
| #else | ||||||
| rom_get_sys_info_fn func = (rom_get_sys_info_fn) rom_func_lookup(ROM_FUNC_GET_SYS_INFO); | ||||||
| union { | ||||||
| uint32_t words[9]; | ||||||
| uint8_t bytes[9 * 4]; | ||||||
| } out; | ||||||
| __unused int rc = func(out.words, 9, SYS_INFO_CHIP_INFO); | ||||||
| assert(rc == 4); | ||||||
| for (int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; i++) { | ||||||
| retrieved_id.id[i] = out.bytes[PICO_UNIQUE_BOARD_ID_SIZE_BYTES - 1 + 2 * 4 - i]; | ||||||
| } | ||||||
| #if PICO_UNIQUE_BOARD_ID_SIZE_BYTES <= SYS_INFO_DEVICE_ID_SIZE_BYTES | ||||||
| union { | ||||||
| uint32_t words[4]; | ||||||
| uint8_t bytes[4 * 4]; | ||||||
| } out; | ||||||
| int words_returned = rom_get_sys_info(out.words, 4, SYS_INFO_CHIP_INFO); | ||||||
|
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. Ditto on
Suggested change
|
||||||
| assert(words_returned == 4); | ||||||
| if (words_returned == count_of(out.words) && out.words[0] == SYS_INFO_CHIP_INFO) { | ||||||
| for (int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; i++) { | ||||||
| // The device ID is in words 3 and 4, so skip the first two words (i.e. the first 8 bytes) | ||||||
| retrieved_id.id[i] = out.bytes[PICO_UNIQUE_BOARD_ID_SIZE_BYTES - 1 + 2 * 4 - i]; | ||||||
| } | ||||||
| } | ||||||
| #else | ||||||
| #error unique board ID size is greater than device unique ID size | ||||||
| #endif | ||||||
| #endif | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
Oops, something went wrong.
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.
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.
I think using
count_ofmight be clearer - and then the uses inbootrom.hcould be updated tocount_oftooThere 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.
Okay, I can change all of these. Is it still appropriate for
count_ofto continue being used in thewords_returned == count_of(result)check on the next line too? This would mean that the number5only appears in theuint32_t result[5]line. (Which would be fine with me, I'm always happy to see the elimination of duplicated magic-numbers; I'm just double-checking that this is what's desired.)And in that case I guess it might make sense to fold #3089 into this PR too.
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.
I think it's still appropriate - I also agree it's nice to remove the magic numbers.
Re folding the PRs, I don't mind - you could make the changes to use
count_ofin the existingbootrom.hfunctions in that PR, or fold it into this one and do it hereThere 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.
Taking that idea of removing magic-numbers even further, perhaps it would also make sense to add e.g.
to
bootrom_constants.h, and then we could do?
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.
Yeah, that sounds good too - for all the
SYS_INFO_XXXdefines having a correspondingSYS_INFO_XXX_WORDS_RETURNEDrather than just having it in the comment above.