Skip to content

feat: add initramfs loading support for all architectures - #105

Closed
YZYY95K wants to merge 4 commits into
syswonder:mainfrom
YZYY95K:feature/initramfs-loading
Closed

YZYY95K wants to merge 4 commits into
syswonder:mainfrom
YZYY95K:feature/initramfs-loading

Conversation

@YZYY95K

@YZYY95K YZYY95K commented Jul 3, 2026

Copy link
Copy Markdown

Overview

Add initramfs loading support to hvisor-tool, enabling zones to load initramfs images via the HVISOR_LOAD_IMAGE ioctl, similar to how kernel and DTB images are currently loaded.

Changes

tools/hvisor.c

Added initramfs_filepath and initramfs_load_paddr JSON field parsing in zone_start_from_json(). When both fields are present, the initramfs image is loaded to the specified physical address using the existing load_image_to_memory() function (which calls HVISOR_LOAD_IMAGE ioctl).

Key Design Decisions

  1. Architecture-independent: The initramfs loading is not in arch_config but at the top level of the JSON config, making it work for all architectures (ARM64, RISC-V, x86_64, LoongArch64).

  2. No struct changes: No changes to zone_config_t or CONFIG_MAGIC_VERSION. The initramfs is loaded separately to memory, and the guest discovers it via the DTB chosen node (linux,initrd-start/linux,initrd-end).

  3. Inspired by x86_64: The x86_64 architecture already has initrd loading in arch_config. This PR makes the feature available to all architectures.

Usage

Add the following fields to your zone JSON config:

{
    "kernel_filepath": "./asterinas.bin",
    "dtb_filepath": "./zone1.dtb",
    "initramfs_filepath": "./initramfs.cpio.gz",
    "initramfs_load_paddr": "0x87e00000",
    "kernel_load_paddr": "0x84000000",
    "dtb_load_paddr": "0x83000000",
    "entry_point": "0x84000000"
}

Testing

The initramfs loading has been tested with Asterinas OS as zone1 on hvisor RISC-V (qemu-plic). The initramfs was successfully loaded to memory and the guest OS was able to access it via the DTB chosen node.

Related

Add initramfs_filepath and initramfs_load_paddr JSON fields to zone_start_from_json. When both fields are present, the initramfs image is loaded to the specified physical address using the existing HVISOR_LOAD_IMAGE ioctl, similar to how kernel and dtb are loaded.

This is architecture-independent and does not require changes to zone_config_t or CONFIG_MAGIC_VERSION.
YZYY95K added 3 commits July 3, 2026 20:47
Remove anonymous block, fix line breaking and indentation to match
the project's LLVM-based clang-format style (4-space indent).
@agicy

agicy commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thank you for this contribution! I took a close look at the existing code, and I believe the current modules mechanism already covers the initramfs use case without introducing a dedicated top-level field.

The modules array (parsed by parse_modules) already allows loading arbitrary files to specified physical addresses via name, filepath, and load_paddr. Loading an initramfs can be done like this:

"modules": [
  {
    "name": "initramfs",
    "filepath": "./initramfs.cpio.gz",
    "load_paddr": "0x87e00000"
  }
]

This approach is more flexible - you can load multiple initramfs images or other firmware files - and it avoids adding redundant configuration keys that might confuse users about which method to use.

I'd suggest closing this PR and, if needed, documenting or adding an example showing how to load an initramfs via modules.

On a related note, I think we might also consider moving dtb_filepath and dtb_load_paddr into modules in the future, since x86 doesn't use a DTB and having it at the top level ties a somewhat architecture-specific concept to the zone config. But that can be a separate discussion.

Thanks again for your interest in improving hvisor, and I hope this feedback is helpful!

@agicy
agicy self-requested a review July 6, 2026 12:16
@YZYY95K

YZYY95K commented Jul 7, 2026

Copy link
Copy Markdown
Author

Thank you for the detailed review! You're absolutely right - the modules mechanism already covers this use case perfectly. I wasn't aware of it when I submitted this PR.

I'll close this PR and update the hvisor-side configuration to use modules instead:

"modules": [
    {
        "name": "initramfs",
        "filepath": "./initramfs.cpio.gz",
        "load_paddr": "0x87e00000"
    }
]

The suggestion to eventually move dtb_filepath and dtb_load_paddr into modules also makes sense - that would be a cleaner, more uniform approach.

Thanks again for the guidance!

@YZYY95K YZYY95K closed this Jul 7, 2026
@YZYY95K

YZYY95K commented Jul 7, 2026

Copy link
Copy Markdown
Author

Thank you for the review! You're absolutely right - the existing modules mechanism already covers this use case perfectly. I'll close this PR and use the modules array to load initramfs instead.

Example usage:

"modules": [
  {
    "name": "initramfs",
    "filepath": "./initramfs.cpio.gz",
    "load_paddr": "0x87e00000"
  }
]

Thanks for the guidance!

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