]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/kvm/efi.c: Add support for initial RAM disk file
authorSergiu Moga <sergiu.moga@protonmail.com>
Tue, 28 Mar 2023 14:20:01 +0000 (17:20 +0300)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 10:47:30 +0000 (10:47 +0000)
This enables the EFI stub to load an initial RAM disk file from the
same filesystem that the Unikraft image was loaded from (the EFI
System Partition) and register it as a `Memory Region Descriptor`.

The name of the `initrd` file is given through the
`CONFIG_UK_EFI_STUB_INITRD_FNAME` configuration entry and it tells
the loader the name of the file to load from the `\EFI\BOOT` directory
of the EFI System Partition.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #909

plat/kvm/Config.uk
plat/kvm/efi.c

index 2e8f7b278c9e0c61f67015d87af2c9a0ccec2e2c..9b2ef33c490da519e59db8c33d66e4688cf1b9a0 100644 (file)
@@ -49,6 +49,10 @@ config KVM_BOOT_EFI_STUB_CMDLINE_FNAME
        string "Name of the command line arguments file"
        default "$(UK_NAME).cmdl"
 
+config KVM_BOOT_EFI_STUB_INITRD_FNAME
+       string "Name of the initial RAM disk file"
+       default "$(UK_NAME).initrd"
+
 endif
 
 choice
index 648bca6b4ee4859813a263c337df07741626882a..60fedcd1b6bcaca7e171868c28e28658a621cf5c 100644 (file)
@@ -482,6 +482,33 @@ static void uk_efi_setup_bootinfo_cmdl(struct ukplat_bootinfo *bi)
        bi->cmdline_len = len;
 }
 
+static void uk_efi_setup_bootinfo_initrd(struct ukplat_bootinfo *bi)
+{
+       struct ukplat_memregion_desc mrd = {0};
+       struct uk_efi_ld_img_hndl *uk_img_hndl;
+       char *initrd;
+       __sz len;
+       int rc;
+
+       if (sizeof(CONFIG_KVM_BOOT_EFI_STUB_INITRD_FNAME) <= 1)
+               return;
+
+       uk_img_hndl = uk_efi_get_uk_img_hndl();
+
+       uk_efi_read_file(uk_img_hndl->device_handle,
+                        UK_EFI_ABS_FNAME(CONFIG_KVM_BOOT_EFI_STUB_INITRD_FNAME),
+                        (char **)&initrd, &len);
+
+       mrd.pbase = (__paddr_t)initrd;
+       mrd.vbase = (__vaddr_t)initrd;
+       mrd.len = PAGE_ALIGN_UP(len);
+       mrd.type = UKPLAT_MEMRT_INITRD;
+       mrd.flags = UKPLAT_MEMRF_READ | UKPLAT_MEMRF_MAP;
+       rc = ukplat_memregion_list_insert(&bi->mrds, &mrd);
+       if (unlikely(rc < 0))
+               uk_efi_crash("Failed to insert initrd mrd\n");
+}
+
 static void uk_efi_setup_bootinfo(void)
 {
        const char bl[] = "EFI_STUB";
@@ -495,6 +522,7 @@ static void uk_efi_setup_bootinfo(void)
        memcpy(bi->bootloader, bl, sizeof(bl));
        memcpy(bi->bootprotocol, bp, sizeof(bp));
        uk_efi_setup_bootinfo_cmdl(bi);
+       uk_efi_setup_bootinfo_initrd(bi);
        uk_efi_setup_bootinfo_mrds(bi);
 
        bi->efi_st = (__u64)uk_efi_st;