Skip to content

[sw-sysemu] erbium boot protocol support - #119

Open
AFOliveira wants to merge 6 commits into
aifoundry-org:masterfrom
AFOliveira:fix/erbium-sysreg-reset-values
Open

[sw-sysemu] erbium boot protocol support #119
AFOliveira wants to merge 6 commits into
aifoundry-org:masterfrom
AFOliveira:fix/erbium-sysreg-reset-values

Conversation

@AFOliveira

Copy link
Copy Markdown
Member

This allows users to rely on the erbium boot protocol without needing the actual bootrom code. For app developers using a simulator without timing modelling, the only real implication is how PC and SP get set at the beginning, either automatically from the ELF entry point or explicitly via --payload_pc/--payload_sp.

Creating a new method and three flags was the cleanest approach to this I could find.

From now on, the first 128 bytes of the MRAM are reserved to boot protocol.

@AFOliveira
AFOliveira requested review from glguida and vidas March 31, 2026 14:10
@AFOliveira
AFOliveira force-pushed the fix/erbium-sysreg-reset-values branch from c2690dd to afeba21 Compare March 31, 2026 14:16

@glguida glguida left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Possibly a better way to implement this would be to add:

--payload_pc/sp or --boot_pc/sp (payload is a bootrom term afterall) to manually set them
or
--payload_elf (or boot_elf) to indicate that an elf is special.

And I would -- in the examples -- define the system area (once we settle on a size) on a different area altogether (MSYS), rather than defining MRAM and them manually decreasing the size and increasing the start.

Comment thread sw-sysemu/examples/common/erbium.ld
Comment thread sw-sysemu/sys_emu/sys_emu.cpp Outdated
@AFOliveira
AFOliveira force-pushed the fix/erbium-sysreg-reset-values branch from cf78857 to 39f9e88 Compare March 31, 2026 20:42
@AFOliveira

Copy link
Copy Markdown
Member Author

@glguida I think I addressed all the comments, if I got them right.

@glguida

glguida commented Apr 1, 2026

Copy link
Copy Markdown
Member

Almost. :-)

The major prolbem I have with this is that this also changes the option for ETSOC-1 sysemu. That's not good and need to be changed.

Then I would go to either using boot or payload, not a mix of both.

Comment thread sw-sysemu/tests/erbium/src/pma_mram_rw.c Outdated
@AFOliveira
AFOliveira force-pushed the fix/erbium-sysreg-reset-values branch 2 times, most recently from d40d352 to c091932 Compare April 2, 2026 12:03
@AFOliveira

Copy link
Copy Markdown
Member Author

@glguida The new boot_elf is now safeguarded with #if ERBIUM_EMU, I think that's the straightforward solution to this problem.

I also thought about putting a EMU_HAS_BOOTROM flag, but it would be confusing as ET-SoC1 also has a ROM, the design in the simulator is just different. Let me know if this is it.

@glguida

glguida commented Apr 2, 2026

Copy link
Copy Markdown
Member

Okay thats' better now. Please let's maintain some commit hygiene, do not add fixes on top of a PR, just fix the original comments.

One thing that would be really useful would be a checker that we're not writing the system area. would be nice if that was an option.

@AFOliveira

Copy link
Copy Markdown
Member Author

One thing that would be really useful would be a checker that we're not writing the system area

Is "system area" the first 0x100 of the MRAM? We are checking that PMA and on boot_load.

@AFOliveira
AFOliveira force-pushed the fix/erbium-sysreg-reset-values branch from c091932 to d7a2ed1 Compare April 2, 2026 12:43
@glguida

glguida commented Apr 2, 2026

Copy link
Copy Markdown
Member

One thing that would be really useful would be a checker that we're not writing the system area

Is "system area" the first 0x100 of the MRAM? We are checking that PMA and on boot_load.

Sorry I completely missed that part. But this is not how hardware behaves, right?

Warn when software stores to the first 256 bytes of MRAM (0x40000000-
0x400000FF), which is reserved for boot protocol vectors. The store is
allowed through (no fault) since the hardware does not enforce write
protection here — the bootrom sets up MPROT for that.

Uses WARN_HART(memory, ...) so -Werror=memory promotes it to an error.
Cache operations are exempt since they don't modify data.
Start MRAM at MRAM_BASE + 256 in linker scripts so code and data are
placed after the boot protocol reserved region. Update tests that used
hardcoded addresses within the reserved range.
Change return type from void to uint64_t so callers can capture the
entry address from the ELF header. No existing callers are modified.
Platform-dispatched method that reads payload PC and SP from MRAM boot
vectors and sets enabled harts accordingly. CLI overrides (payload_pc,
payload_sp) are written to MRAM before reading, so the MRAM always
reflects the actual boot configuration.

Erbium implementation reads from MRAM offsets 0x28 (PC) and 0x20 (SP).
Declaration and implementation are guarded with EMU_ERBIUM.

Follows the same dispatcher pattern as pma.cpp (boot-protocol.cpp
includes boot-protocol_er.cpp based on platform).
@AFOliveira
AFOliveira force-pushed the fix/erbium-sysreg-reset-values branch from d7a2ed1 to cf03713 Compare April 2, 2026 15:42
@AFOliveira

Copy link
Copy Markdown
Member Author

Sorry I completely missed that part. But this is not how hardware behaves, right?

As agreed privately, I added a way of addressing this error that is not emulating HW, as that region can indeed be written in HW, but shouldn't.

I chose just a WARN_HART instead of a full checker class given the relatively small scope of this problem and to avoid boilerplate code that would come with a full checker for something that we can do inline. Please, let me know if you agree.

I also have a question - should we only use this when we are using the flags for emulating bootROM in the simulator?
I.e. this flag can be noisy if we want to write to that region, like if we are running a boot ROM so should I hide behind the flags that emulate that BootROM was already ran?

… protocol

Add boot_elf, payload_pc and payload_sp CLI flags for Erbium boot
protocol control. --boot_elf loads an ELF and uses its entry point as
the payload PC. --payload_pc/--payload_sp override explicitly.

After warm reset, call apply_boot_protocol() which writes any CLI
overrides to MRAM, reads the final boot vectors, and sets all enabled
harts' PC and SP accordingly. Only runs when at least one boot protocol
flag is specified.

All flags and logic are guarded with EMU_ERBIUM. Help text included.
Add tests for the Erbium boot protocol:
- boot_protocol_pc: verify --boot_elf sets PC from ELF entry point
- boot_protocol_sp: verify --payload_sp sets initial stack pointer
- pma_mram_boot_region: verify stores to boot protocol region succeed
  (with warning, no fault)

Add run-boot-protocol Makefile target that re-runs all tests with
--boot_elf to verify they work under the boot protocol flow.
@AFOliveira
AFOliveira force-pushed the fix/erbium-sysreg-reset-values branch from cf03713 to c61500f Compare April 3, 2026 07:25
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.

3 participants