Skip to content

Conversation

pamaury
Copy link
Contributor

@pamaury pamaury commented Oct 3, 2025

While looking at the chip info, I realized that there were several problems. Originally, the issue comes from the fact that we have a single cc_library that contains both the chip_info.h header and the chip_info.c data. This means that any binary using this dependency ends up including the kChipInfo data even if they didn't intend to. Coupled with the fact that several pieces of code directly refer to kChipInfo instead of the linker symbol _chip_info_start means that for example part of the ROM_EXT doesn't actually read from the ROM's chip_info but from a ROM_EXT-embedded chip info!

I decided to fix that by splitting the library into the header (which is what everyone but the ROM should use) and the data. I also eliminated the kChipInfo symbol from the header entirely and replaced all users with _chip_info_start. While doing so, I stumbled on a subtle linker problem which is that since kChipInfo becomes unused, it won't participate in linking (even if the section is marked as NODISARD) unless --whole-archive is used which fortunaltely bazel has a setting for (alwayslink=True).

I also decided to create a new ROM end-to-end test for the chip info to make sure that the data is present there. Maybe it might be worth also create a ROM_EXT end-to-end test to make sure that it uses the ROM chip info and not some other chip info but I leave that to a future PR.

Having all in one is problematic because it can cause
a non-ROM binary to include the chip info symbol which
will then be placed somewhere else and override the
actual ROM chip info. The ROM should be the only one
including the chip info data whereas all other binaries
only need the header.

Signed-off-by: Amaury Pouly <[email protected]>
Without this option, the chip_info symbol might get discarded if
it is not used directly.

Signed-off-by: Amaury Pouly <[email protected]>
@pamaury pamaury force-pushed the fix_chip_info branch 2 times, most recently from 4d77037 to cb4e92a Compare October 3, 2025 14:39
Some places were using a symbol provided by chip_info.h but
this symbol might not be present in the binary. Instead, the
expected way to access the symbol is to use the linker provided
one which uses a fixed address.

Signed-off-by: Amaury Pouly <[email protected]>
The chip_info became broken without anyone realizing because it
was untested. This test ensures that at least the chip info is
filled and has the expected version.

Signed-off-by: Amaury Pouly <[email protected]>
],
)

opentitan_test(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add an entry to the tesplan?

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