Skip to content

refactor(aarch64,riscv64): unify kernel image detection#607

Open
Gelbpunkt wants to merge 1 commit into
hermit-os:mainfrom
Gelbpunkt:initrd-start-aarch64
Open

refactor(aarch64,riscv64): unify kernel image detection#607
Gelbpunkt wants to merge 1 commit into
hermit-os:mainfrom
Gelbpunkt:initrd-start-aarch64

Conversation

@Gelbpunkt
Copy link
Copy Markdown
Member

@Gelbpunkt Gelbpunkt commented May 15, 2026

This unifies the kernel image detection for both aarch64 and riscv64. riscv64 was incorrectly using the length of the module reg as the size of the kernel image, which was always 0, which is fixed by using the approach taken by the aarch64 code to parse the ELF header. On the other hand, aarch64 now falls back to linux,initrd-start and linux,initrd-end for detecting the kernel image thanks to these changes, which is necessary for cloud-hypervisor at the moment.

Copy link
Copy Markdown
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

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

We already have similar code for RISC-V: https://github.com/hermit-os/loader/blob/v0.5.6/src/arch/riscv64/mod.rs#L21-L51

It might make sense to unify them as methods on an trait FdtExt, but that might not be worth the effort. You can decide. :)

@Gelbpunkt
Copy link
Copy Markdown
Member Author

Ah, I didn't even bother checking the RISC-V code. That one is also slightly prettier than this approach. I'll try the FdtExt approach, that seems sensible.

@Gelbpunkt Gelbpunkt force-pushed the initrd-start-aarch64 branch from 80527af to baa7cc9 Compare May 21, 2026 21:20
@Gelbpunkt Gelbpunkt changed the title feat(aarch64): Fall back to detecting kernel at linux,initrd-start refactor(aarch64,riscv64): unify kernel image detection May 21, 2026
This unifies the kernel image detection for both aarch64 and riscv64.
riscv64 was incorrectly using the length of the module reg as the size
of the kernel image, which was always 0, which is fixed by using the
approach taken by the aarch64 code to parse the ELF header. On the other
hand, aarch64 now falls back to linux,initrd-start and linux,initrd-end
for detecting the kernel image thanks to these changes, which is
necessary for cloud-hypervisor at the moment.
@Gelbpunkt Gelbpunkt force-pushed the initrd-start-aarch64 branch from baa7cc9 to 3725077 Compare May 21, 2026 21:21
@Gelbpunkt Gelbpunkt requested a review from mkroening May 21, 2026 21:22
@Gelbpunkt
Copy link
Copy Markdown
Member Author

Gelbpunkt commented May 21, 2026

CI on aarch64 fails because the fdt is... invalid as far as I can tell. size-cells is set to 2 and address-cells set to 2, but the inserted module only has 32-bit components, i.e. is for size-cells 1 and address-cells 1. Not sure yet what's responsible for this, but it was already an issue before and the code just didn't properly parse/validate it

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