]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[lkrn] Allow a single initrd to be passed to the booted kernel
authorMichael Brown <mcb30@ipxe.org>
Wed, 21 May 2025 13:28:29 +0000 (14:28 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 21 May 2025 13:56:10 +0000 (14:56 +0100)
Allow a single initrd image to be passed verbatim to the booted RISC-V
kernel, as a proof of concept.

We do not yet support reshuffling to make optimal use of available
memory, or dynamic construction of CPIO headers, but this is
sufficient to allow iPXE to start up the Fedora 42 kernel with its
matching initrd image.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/image/lkrn.c
src/include/ipxe/lkrn.h

index 4f04c3ff6784a0e96edd3bca2d480a452a0887f5..15e9c0d7bc7cdb01a36697fda5f4f8e7e8e65d10 100644 (file)
@@ -153,8 +153,10 @@ static int lkrn_fdt ( struct image *image, struct lkrn_context *ctx ) {
        int rc;
 
        /* Build device tree (which may change system memory map) */
-       if ( ( rc = fdt_create ( &fdt, image->cmdline, 0, 0 ) ) != 0 )
+       if ( ( rc = fdt_create ( &fdt, image->cmdline, ctx->initrd,
+                                ctx->initrd_len ) ) != 0 ) {
                goto err_create;
+       }
        len = be32_to_cpu ( fdt->totalsize );
 
        /* Place device tree after kernel, rounded up to a page boundary */
@@ -197,6 +199,7 @@ static int lkrn_fdt ( struct image *image, struct lkrn_context *ctx ) {
  */
 static int lkrn_exec ( struct image *image ) {
        struct lkrn_context ctx;
+       struct image *initrd;
        int rc;
 
        /* Parse header */
@@ -207,6 +210,15 @@ static int lkrn_exec ( struct image *image ) {
        if ( ( rc = lkrn_ram ( image, &ctx ) ) != 0 )
                return rc;
 
+       /* Locate initrd image, if any */
+       if ( ( initrd = first_image() ) != NULL ) {
+               ctx.initrd = virt_to_phys ( initrd->data );
+               ctx.initrd_len = initrd->len;
+               DBGC ( image, "LKRN %s initrd %s at [%#08lx,%#08lx)\n",
+                      image->name, initrd->name, ctx.initrd,
+                      ( ctx.initrd + ctx.initrd_len ) );
+       }
+
        /* Create device tree (which may change system memory map) */
        if ( ( rc = lkrn_fdt ( image, &ctx ) ) != 0 )
                return rc;
index 59aabdd4ba7f314ddc2bf32863b7005f4abb611a..43daa8006836d39676887ea7f218e6ccf5965fc7 100644 (file)
@@ -54,6 +54,10 @@ struct lkrn_context {
        physaddr_t entry;
        /** Device tree */
        physaddr_t fdt;
+       /** Initial ramdisk (if any) */
+       physaddr_t initrd;
+       /** Length of initial ramdisk (if any) */
+       size_t initrd_len;
 };
 
 /** Compressed kernel image header */