Skip to content

Standardise usage of rom_get_sys_info function#3094

Open
lurch wants to merge 1 commit into
developfrom
bootrom_sysinfo_tweaks
Open

Standardise usage of rom_get_sys_info function#3094
lurch wants to merge 1 commit into
developfrom
bootrom_sysinfo_tweaks

Conversation

@lurch

@lurch lurch commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

I copied the rom_get_sys_info usage-pattern from bootrom.h.
RP2350 Datasheet says "You should always check (the first word in the returned buffer) before interpreting the buffer.", so do that too.
Also some small unique_id tidy-ups.

RP2350 Datasheet says "You should always check (the first word in the returned buffer) before interpreting the buffer.", so do that.
Also some small unique_id tidy-ups.
@lurch lurch added this to the 2.4.0 milestone Jul 22, 2026
@lurch
lurch requested review from peterharperuk and will-v-pi July 22, 2026 15:28
uint32_t result[5];
rom_get_sys_info_fn func = (rom_get_sys_info_fn) rom_func_lookup_inline(ROM_FUNC_GET_SYS_INFO);
if (5 == func(result, count_of(result), SYS_INFO_BOOT_RANDOM)) {
int words_returned = rom_get_sys_info(result, 5, SYS_INFO_BOOT_RANDOM);

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.

I think using count_of might be clearer - and then the uses in bootrom.h could be updated to count_of too

Suggested change
int words_returned = rom_get_sys_info(result, 5, SYS_INFO_BOOT_RANDOM);
int words_returned = rom_get_sys_info(result, count_of(result), SYS_INFO_BOOT_RANDOM);

Copy link
Copy Markdown
Contributor Author

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_of to continue being used in the words_returned == count_of(result) check on the next line too? This would mean that the number 5 only appears in the uint32_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.

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.

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_of in the existing bootrom.h functions in that PR, or fold it into this one and do it here

Copy link
Copy Markdown
Contributor Author

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.

#define SYS_INFO_BOOT_RANDOM_WORDS_RETURNED     _u(4)

to bootrom_constants.h, and then we could do

uint32_t result[SYS_INFO_BOOT_RANDOM_WORDS_RETURNED + 1];

?

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.

Yeah, that sounds good too - for all the SYS_INFO_XXX defines having a corresponding SYS_INFO_XXX_WORDS_RETURNED rather than just having it in the comment above.

uint32_t words[4];
uint8_t bytes[4 * 4];
} out;
int words_returned = rom_get_sys_info(out.words, 4, SYS_INFO_CHIP_INFO);

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.

Ditto on count_of

Suggested change
int words_returned = rom_get_sys_info(out.words, 4, SYS_INFO_CHIP_INFO);
int words_returned = rom_get_sys_info(out.words, count_of(out.words), SYS_INFO_CHIP_INFO);

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